[clang] [clang] Add source range to 'use of undeclared identifier' diagnostics (PR #117671)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 3 10:38:17 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>
================
@@ -454,62 +454,43 @@ void DiagnosticRenderer::emitSingleMacroExpansion(
SpellingRanges, {});
}
-/// Check that the macro argument location of Loc starts with ArgumentLoc.
-/// The starting location of the macro expansions is used to differeniate
-/// different macro expansions.
-static bool checkLocForMacroArgExpansion(SourceLocation Loc,
- const SourceManager &SM,
- SourceLocation ArgumentLoc) {
- SourceLocation MacroLoc;
- if (SM.isMacroArgExpansion(Loc, &MacroLoc)) {
- if (ArgumentLoc == MacroLoc) return true;
- }
-
- return false;
-}
-
-/// Check if all the locations in the range have the same macro argument
-/// expansion, and that the expansion starts with ArgumentLoc.
-static bool checkRangeForMacroArgExpansion(CharSourceRange Range,
- const SourceManager &SM,
- SourceLocation ArgumentLoc) {
- SourceLocation BegLoc = Range.getBegin(), EndLoc = Range.getEnd();
- while (BegLoc != EndLoc) {
- if (!checkLocForMacroArgExpansion(BegLoc, SM, ArgumentLoc))
- return false;
- BegLoc.getLocWithOffset(1);
- }
-
- return checkLocForMacroArgExpansion(BegLoc, SM, ArgumentLoc);
-}
-
/// A helper function to check if the current ranges are all inside the same
/// macro argument expansion as Loc.
-static bool checkRangesForMacroArgExpansion(FullSourceLoc Loc,
- ArrayRef<CharSourceRange> Ranges) {
+static bool
+rangesInsideSameMacroArgExpansion(FullSourceLoc Loc,
+ ArrayRef<CharSourceRange> Ranges) {
assert(Loc.isMacroID() && "Must be a macro expansion!");
- SmallVector<CharSourceRange, 4> SpellingRanges;
- mapDiagnosticRanges(Loc, Ranges, SpellingRanges);
-
- // Count all valid ranges.
- unsigned ValidCount =
- llvm::count_if(Ranges, [](const auto &R) { return R.isValid(); });
+ {
----------------
AaronBallman wrote:
Is the extra compound statement helpful?
https://github.com/llvm/llvm-project/pull/117671
More information about the cfe-commits
mailing list