diff options
author | Eduard Zingerman <eddyz87@gmail.com> | 2022-10-28 07:59:08 -0700 |
---|---|---|
committer | Yonghong Song <yhs@fb.com> | 2022-10-28 08:07:54 -0700 |
commit | 524c640090a8463305acbafd7606f1db3c1256e2 (patch) | |
tree | ca8aee33c71fe50c4cb0ee3cd20f8f2ce2a74552 /clang/lib/CodeGen/CGDebugInfo.cpp | |
parent | ee9bbfa5e6acaea6d2a116bc29b7086441f86b6a (diff) | |
download | llvm-524c640090a8463305acbafd7606f1db3c1256e2.zip llvm-524c640090a8463305acbafd7606f1db3c1256e2.tar.gz llvm-524c640090a8463305acbafd7606f1db3c1256e2.tar.bz2 |
[clang][DebugInfo] Emit DISubprogram for extern functions with reserved names
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
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index aa02821..4b56e15 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -4228,17 +4228,11 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke, if (Func->getSubprogram()) return; - // Do not emit a declaration subprogram for a builtin, a function with nodebug - // attribute, or if call site info isn't required. Also, elide declarations - // for functions with reserved names, as call site-related features aren't - // interesting in this case (& also, the compiler may emit calls to these - // functions without debug locations, which makes the verifier complain). - if (CalleeDecl->getBuiltinID() != 0 || CalleeDecl->hasAttr<NoDebugAttr>() || + // Do not emit a declaration subprogram for a function with nodebug + // attribute, or if call site info isn't required. + if (CalleeDecl->hasAttr<NoDebugAttr>() || getCallSiteRelatedAttrs() == llvm::DINode::FlagZero) return; - if (CalleeDecl->isReserved(CGM.getLangOpts()) != - ReservedIdentifierStatus::NotReserved) - return; // If there is no DISubprogram attached to the function being called, // create the one describing the function in order to have complete |