diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-12-23 23:19:54 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-12-27 16:00:53 +0100 |
| commit | 84a00109ff526e1663c2d8aa260c6065b8f142f0 (patch) | |
| tree | 53413359f65a5f0f14bd4142d9c8b873f054cbdc /validation/backend | |
| parent | 69a789a78d4e64052628307f25310e195a50f5ee (diff) | |
| download | sparse-dev-84a00109ff526e1663c2d8aa260c6065b8f142f0.tar.gz | |
llvm: fix: previous function ref MUST be reused
In sparse-llvm, when a reference to a function is made via
get_sym_value(), for example for a call, the reference is
created with LLVMAddFunction() and if needed later, the existing
reference is returned via LLVMGetNamedFunction().
This is the correct way to do it.
However, when emitting the code for a function definition, a fresh
reference is always made. If a previous reference to this function
already existed, the second one will have a slightly different name:
the given name suffixed by ".<somenumber>". LLVM does this for every
created references, to disambiguate them. As consequence, the
compiled function will not be name "<functionname>", as expected,
but "<functionname>.<somenumber>".
Fix this by always using get_sym_value() when emitting the code
for the function definition as this will return the reference
for the given function name if it already exist.
This has the added bonus to remove some code duplication.
CC: Dibyendu Majumdar <mobile@majumdar.org.uk>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/backend')
| -rw-r--r-- | validation/backend/fn-ref.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/validation/backend/fn-ref.c b/validation/backend/fn-ref.c new file mode 100644 index 00000000..d987a28b --- /dev/null +++ b/validation/backend/fn-ref.c @@ -0,0 +1,32 @@ +extern int fun0(int a); +extern int fun1(int a); + +int foo(int a); +int foo(int a) +{ + int v = fun0(a); + return v; +} + +void *bar(int a) +{ + return fun1; +} + +int fun0(int a) +{ + return a + 0; +} + +int fun1(int a) +{ + return a + 1; +} + +/* + * check-name: llvm function reference + * check-command: sparse-llvm-dis -Wno-decl $file + * + * check-output-ignore + * check-output-excludes: fun[0-9]\.[1-9] + */ |
