[all-commits] [llvm/llvm-project] 524c64: [clang][DebugInfo] Emit DISubprogram for extern fu...

eddyz87 via All-commits all-commits at lists.llvm.org
Fri Oct 28 08:08:16 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 524c640090a8463305acbafd7606f1db3c1256e2
      https://github.com/llvm/llvm-project/commit/524c640090a8463305acbafd7606f1db3c1256e2
  Author: Eduard Zingerman <eddyz87 at gmail.com>
  Date:   2022-10-28 (Fri, 28 Oct 2022)

  Changed paths:
    M clang/lib/CodeGen/CGDebugInfo.cpp
    M clang/test/CodeGen/debug-info-extern-call.c
    M llvm/lib/IR/Verifier.cpp
    M llvm/test/Verifier/callsite-dbgloc.ll

  Log Message:
  -----------
  [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




More information about the All-commits mailing list