[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:36:30 PST 2023
================
@@ -455,18 +455,11 @@ void DiagnosticInfoDontCall::print(DiagnosticPrinter &DP) const {
SmallVector<std::string> DiagnosticInfoDontCall::getInliningDecisions() const {
SmallVector<std::string> InliningDecisions;
- if (MDN) {
- const MDOperand &MO = MDN->getOperand(0);
- if (auto *MDT = dyn_cast<MDTuple>(MO)) {
- for (const MDOperand &MO : MDT->operands()) {
- if (auto *S = dyn_cast<MDString>(MO)) {
+ if (MDN)
+ if (auto *MDT = dyn_cast<MDTuple>(MDN->getOperand(0)))
+ for (const MDOperand &MO : MDT->operands())
+ if (auto *S = dyn_cast<MDString>(MO))
InliningDecisions.push_back(S->getString().str());
- }
- }
- } else if (auto *S = dyn_cast<MDString>(MO)) {
- InliningDecisions.push_back(S->getString().str());
- }
- }
----------------
nickdesaulniers wrote:
This change is wrong; it seems I don't have this captured in the existing tests, but doing a local integration test:
```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);
}
```
Before this change:
```sh
/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'
```
After this change:
```sh
$ /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'
1 error generated.
```
https://github.com/llvm/llvm-project/pull/73552
More information about the cfe-commits
mailing list