[clang] [clang] Add source range to 'use of undeclared identifier' diagnostics (PR #117671)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 26 01:47:55 PST 2024
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/117671 at github.com>
tbaederr wrote:
It's the same problem again.
For this code:
```c++
#define F(x) x + 1
#define G(x) F(x) + 2
#define ADD(x,y) G(x) + y
#define LEVEL4(x) ADD(p,x)
#define LEVEL3(x) LEVEL4(x)
#define LEVEL2(x) LEVEL3(x)
#define LEVEL1(x) LEVEL2(x)
int a = LEVEL1(b);
```
The previous output was:
```
./array.cpp:34:9: error: use of undeclared identifier 'p'
34 | int a = LEVEL1(b);
| ^
./array.cpp:32:19: note: expanded from macro 'LEVEL1'
32 | #define LEVEL1(x) LEVEL2(x)
| ^
./array.cpp:31:19: note: expanded from macro 'LEVEL2'
31 | #define LEVEL2(x) LEVEL3(x)
| ^
./array.cpp:30:19: note: expanded from macro 'LEVEL3'
30 | #define LEVEL3(x) LEVEL4(x)
| ^
./array.cpp:29:23: note: expanded from macro 'LEVEL4'
29 | #define LEVEL4(x) ADD(p,x)
| ^
./array.cpp:34:16: error: use of undeclared identifier 'b'
34 | int a = LEVEL1(b);
| ^
2 errors generated.
```
and we now print:
```
./array.cpp:34:9: error: use of undeclared identifier 'p'
34 | int a = LEVEL1(b);
| ^~~~~~~~~
./array.cpp:32:19: note: expanded from macro 'LEVEL1'
32 | #define LEVEL1(x) LEVEL2(x)
| ^~~~~~~~~
./array.cpp:31:19: note: expanded from macro 'LEVEL2'
31 | #define LEVEL2(x) LEVEL3(x)
| ^~~~~~~~~
./array.cpp:30:19: note: expanded from macro 'LEVEL3'
30 | #define LEVEL3(x) LEVEL4(x)
| ^~~~~~~~~
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
./array.cpp:28:20: note: expanded from macro 'ADD'
28 | #define ADD(x,y) G(x) + y
| ^
./array.cpp:27:16: note: expanded from macro 'G'
27 | #define G(x) F(x) + 2
| ^
./array.cpp:26:14: note: expanded from macro 'F'
26 | #define F(x) x + 1
| ^
./array.cpp:34:16: error: use of undeclared identifier 'b'
34 | int a = LEVEL1(b);
| ^
./array.cpp:32:26: note: expanded from macro 'LEVEL1'
32 | #define LEVEL1(x) LEVEL2(x)
| ^
./array.cpp:31:26: note: expanded from macro 'LEVEL2'
31 | #define LEVEL2(x) LEVEL3(x)
| ^
./array.cpp:30:26: note: expanded from macro 'LEVEL3'
30 | #define LEVEL3(x) LEVEL4(x)
| ^
./array.cpp:29:25: note: expanded from macro 'LEVEL4'
29 | #define LEVEL4(x) ADD(p,x)
| ^
./array.cpp:28:25: note: expanded from macro 'ADD'
28 | #define ADD(x,y) G(x) + y
| ^
2 errors generated.
```
but this is not a bug introduced by the changes, rather, the newly supplied (valid!) source ranges now get taken into account in `checkRangesForMacroArgExpansion()` in `Frontend/DiagnosticRenderer.cpp`.
https://github.com/llvm/llvm-project/pull/117671
More information about the cfe-commits
mailing list