
Callsite `DISubprogram` entries are not generated for: - builtin functions; - external functions with reserved names (e.g. names starting from "__"). This limitation was added by the commit [1] as a workaround for the situation described in [2] that triggered the IR verifier error. The goal of the present commit is to lift this limitation by adjusting the IR verifier logic. The logic behind [1] is to avoid the following situation: - a `DISubprogram` is added for some builtin function; - there is some location where this builtin is also emitted by a transformation (w/o debug location); - the `Verifier::visitCallBase` sees a call to a function with `DISubprogram` but w/o debug location and emits an error. Here is an updated example of such situation taken from [2]: ``` extern "C" int memcmp(void *, void *, long); struct a { int b; int c; int d; }; struct e { int f[1000]; }; bool foo(e g, e &h) { // DISubprogram for memcmp is created here when [1] is commented out return memcmp(&g, &h, sizeof(e)); } bool bar(a &g, a &h) { // memcmp might be generated here by MergeICmps return g.b == h.b && g.c == h.c && g.d == h.d; } ``` This triggers the verifier error when: - compiled for AArch64: `clang++ -c -g -Oz -target aarch64-unknown-linux-android21 test.cpp`; - [1] check is commented out. Instead of forbidding generation of `DISubprogram` entries as in [1] one can instead adjust the verifier to additionally check if callee has a body. Functions w/o bodies cannot be inlined and thus verifier warning is not necessary. E.g. `llvm::InlineFunction` requires functions for which `GlobalValue::isDeclaration() == false`. [1] 568db780bb7267651a902da8e85bc59fc89aea70 [2] https://bugs.chromium.org/p/chromium/issues/detail?id=1022296 Differential Revision: https://reviews.llvm.org/D136041
52 lines
2.2 KiB
C
52 lines
2.2 KiB
C
// When entry values are emitted, expect a subprogram for extern decls so that
|
|
// the dwarf generator can describe call site parameters at extern call sites.
|
|
//
|
|
// Initial implementation relied on the 'retainedTypes:' from the corresponding
|
|
// DICompileUnit, so we also ensure that we do not store the extern declaration
|
|
// subprogram into the 'retainedTypes:'.
|
|
//
|
|
// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -S -emit-llvm %s -o - \
|
|
// RUN: | FileCheck %s -check-prefix=DECLS-FOR-EXTERN
|
|
|
|
// Similarly, when the debugger tuning is gdb, expect a subprogram for extern
|
|
// decls so that the dwarf generator can describe information needed for tail
|
|
// call frame reconstrution.
|
|
//
|
|
// RUN: %clang -gdwarf-4 -O2 -target x86_64-none-linux-gnu -ggdb -S -emit-llvm %s -o - \
|
|
// RUN: | FileCheck %s -check-prefix=DECLS-FOR-EXTERN
|
|
//
|
|
// Do not emit a subprogram for extern decls when entry values are disabled and
|
|
// the tuning is not set to gdb.
|
|
//
|
|
// RUN: %clang -gdwarf-4 -O2 -target x86_64-none-linux-gnu -gsce -S -emit-llvm %s -o - \
|
|
// RUN: | FileCheck %s -check-prefix=NO-DECLS-FOR-EXTERN
|
|
|
|
// DECLS-FOR-EXTERN-NOT: !DICompileUnit({{.*}}retainedTypes: !{{[0-9]+}}
|
|
// DECLS-FOR-EXTERN: [[INT_TYPE:![0-9]+]] = !DIBasicType(name: "int",
|
|
// DECLS-FOR-EXTERN: !DISubprogram(name: "fn1"
|
|
// DECLS-FOR-EXTERN-SAME: type: [[FN1_TYPE:![0-9]+]],
|
|
// DECLS-FOR-EXTERN: [[FN1_TYPE]] = !DISubroutineType(types: [[FN1_TYPES:![0-9]+]])
|
|
// DECLS-FOR-EXTERN: [[FN1_TYPES]] = !{[[X_TYPE:![0-9]+]],
|
|
// DECLS-FOR-EXTERN: [[X_TYPE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "x",
|
|
// DECLS-FOR-EXTERN-SAME: baseType: [[INT_TYPE]])
|
|
// DECLS-FOR-EXTERN: !DISubprogram(name: "memcmp"
|
|
// DECLS-FOR-EXTERN: !DISubprogram(name: "__some_reserved_name"
|
|
|
|
// NO-DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "fn1"
|
|
// NO-DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "memcmp"
|
|
// NO-DECLS-FOR-EXTERN-NOT: !DISubprogram(name: "__some_reserved_name"
|
|
|
|
typedef int x;
|
|
extern x fn1(int a, int b);
|
|
extern int memcmp(const void *s1, const void *s2, unsigned long n);
|
|
extern void __some_reserved_name(void);
|
|
|
|
int fn2 (int *src, int *dst) {
|
|
int x = 4, y = 5;
|
|
int res = fn1(x, y);
|
|
int res2 = memcmp(dst, src, res);
|
|
__some_reserved_name();
|
|
return res + res2;
|
|
}
|
|
|