[clang] [llvm] [clang] report inlining decisions with -Wattribute-{warning|error} (PR #73552)
Nick Desaulniers via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 27 11:34:03 PST 2023
================
@@ -794,6 +795,13 @@ void BackendConsumer::DontCallDiagHandler(const DiagnosticInfoDontCall &D) {
? diag::err_fe_backend_error_attr
: diag::warn_fe_backend_warning_attr)
<< llvm::demangle(D.getFunctionName()) << D.getNote();
+
+ SmallVector<StringRef> InliningDecisions = D.getInliningDecisions();
+ InliningDecisions.push_back(D.getCaller());
+ for (const auto &[index, value] : llvm::enumerate(InliningDecisions))
+ Diags.Report(LocCookie, index ? diag::note_fe_backend_inlined
----------------
nickdesaulniers wrote:
Ah right, the use of `LocCookie` is problematic here.
Take this example ([from the RFC](https://discourse.llvm.org/t/rfc-improving-clangs-middle-and-back-end-diagnostics/69261)):
```c
#include <string.h>
__attribute__((error("bad memcpy"))) void bad(void);
static void *my_memcpy(void *restrict dest, size_t dest_size,
const void *restrict src, size_t src_size,
size_t n) {
if (n > dest_size || n > src_size)
bad();
return memcpy(dest, src, n);
}
void my_driver (void) {
unsigned char src [42], dst [42];
my_memcpy(dst, 42, src, 42, 0);
my_memcpy(dst, 42, src, 42, 42);
my_memcpy(dst, 42, src, 42, 4096);
my_memcpy(dst, 42, src, 42, 1);
}
```
No LocCookie:
```sh
$ clang /tmp/x.c -O2
/tmp/x.c:8:9: error: call to 'bad' declared with 'error' attribute: bad memcpy
8 | bad();
| ^
note: called by function 'my_memcpy'
note: inlined by function 'my_driver'
1 error generated.
```
w/ LocCookie:
```sh
$ clang /tmp/x.c -O2
/tmp/x.c:8:9: error: call to 'bad' declared with 'error' attribute: bad memcpy
8 | bad();
| ^
/tmp/x.c:8:9: note: called by function 'my_memcpy'
/tmp/x.c:8:9: note: inlined by function 'my_driver'
1 error generated.
```
The `LocCookie` is pointing to the function call to `bad();`, not the call to `my_memcpy` because that information was not retained. (We don't retain such debug info unless debug info (or optimization remarks) were requested; I discuss this in the RFC. I think it's preferable to have no line+col info on the note rather than wrong line+col info).
https://github.com/llvm/llvm-project/pull/73552
More information about the cfe-commits
mailing list