This is an archive of the discontinued LLVM Phabricator instance.

[clang][Diagnostics] Provide a source range for 'use of undeclared identifier' diagnostics
AbandonedPublic

Authored by tbaeder on May 9 2023, 4:12 AM.

Details

Summary

Just a small improvement.

Before:

array.cpp:1279:9: error: use of undeclared identifier 'foo'
 1279 | int a = foo();
      |         ^
array.cpp:1280:9: error: use of undeclared identifier 'foo'
 1280 | int b = foo;
      |         ^
2 errors generated.

After:

array.cpp:1279:9: error: use of undeclared identifier 'foo'
 1279 | int a = foo();
      |         ^~~
array.cpp:1280:9: error: use of undeclared identifier 'foo'
 1280 | int b = foo;
      |         ^~~
2 errors generated.

Diff Detail

Event Timeline

tbaeder created this revision.May 9 2023, 4:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 4:12 AM
tbaeder requested review of this revision.May 9 2023, 4:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 4:12 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

The changes are reasonable but should have test coverage. We test source ranges with -fdiagnostics-print-source-range-info as in https://github.com/llvm/llvm-project/blob/929a8c9f72dc405779a8aaf82304efdb7f1ab5e4/clang/test/Misc/diag-greatergreater.cpp#L4

Right, I expect (hope?) precommit CI to fail, but I'm stuck at an airport right now so I'll leave tests for when I'm back home.

tbaeder updated this revision to Diff 521215.May 10 2023, 11:40 PM
tbaeder added inline comments.May 10 2023, 11:43 PM
clang/lib/Sema/SemaExpr.cpp
2187

I'm not passing the TypoRange here now, which regresses the test case I posted. Apparently the handling of -fmacro-backtrace-limit depends on the range passed here? That seems weird.

tbaeder updated this revision to Diff 521236.May 11 2023, 2:39 AM
aaron.ballman added inline comments.May 11 2023, 11:12 AM
clang/lib/Sema/SemaExpr.cpp
2187

Is it failing within checkRangesForMacroArgExpansion() in DiagnosticRenderer.cpp? It looks like this change effectively undoes the work from ecd36ee80b7a6ac73c84da19f8a75c4c025a7625

clang/test/Misc/reduced-diags-macros-backtrace.cpp
30–38

These notes make it harder to read the diagnostic instead of easier, I think they should remain suppressed.

42–56

Same here.

tbaeder added inline comments.May 12 2023, 2:27 AM
clang/lib/Sema/SemaExpr.cpp
2187

Well yes, the test case below simply didn't have any source ranges before (Ranges was empty), but now it does. The code behaves as expected I assume, just that... it doesn't do what I'd expect it to do. And it doesn't do what the test case below expects either.

I agree that the output before this patch is better (for the below test case), but the output shouldn't be affected by the source range we pass :/

aaron.ballman added inline comments.May 12 2023, 7:20 AM
clang/lib/Sema/SemaExpr.cpp
2187

Yeah, but I think you'll have to solve this issue before we can land these changes.

tbaeder abandoned this revision.May 15 2023, 1:15 AM

Abandoning this. The code in question was dead before as far as I can tell, since the Ranges list was always empty. I can't add this without regressing any of the existing tests.