aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/contrib/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp b/contrib/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp
index 22b957988f46..18c8be7a7293 100644
--- a/contrib/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp
+++ b/contrib/llvm-project/clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -18,7 +18,6 @@
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/None.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
@@ -148,7 +147,7 @@ void DiagnosticRenderer::emitStoredDiagnostic(StoredDiagnostic &Diag) {
void DiagnosticRenderer::emitBasicNote(StringRef Message) {
emitDiagnosticMessage(FullSourceLoc(), PresumedLoc(), DiagnosticsEngine::Note,
- Message, None, DiagOrStoredDiag());
+ Message, std::nullopt, DiagOrStoredDiag());
}
/// Prints an include stack when appropriate for a particular
@@ -394,6 +393,13 @@ mapDiagnosticRanges(FullSourceLoc CaretLoc, ArrayRef<CharSourceRange> Ranges,
}
}
+ // There is a chance that begin or end is invalid here, for example if
+ // specific compile error is reported.
+ // It is possible that the FileID's do not match, if one comes from an
+ // included file. In this case we can not produce a meaningful source range.
+ if (Begin.isInvalid() || End.isInvalid() || BeginFileID != EndFileID)
+ continue;
+
// Do the backtracking.
SmallVector<FileID, 4> CommonArgExpansions;
computeCommonMacroArgExpansionFileIDs(Begin, End, SM, CommonArgExpansions);
@@ -446,7 +452,7 @@ void DiagnosticRenderer::emitSingleMacroExpansion(
Message << "expanded from macro '" << MacroName << "'";
emitDiagnostic(SpellingLoc, DiagnosticsEngine::Note, Message.str(),
- SpellingRanges, None);
+ SpellingRanges, std::nullopt);
}
/// Check that the macro argument location of Loc starts with ArgumentLoc.
@@ -487,20 +493,18 @@ static bool checkRangesForMacroArgExpansion(FullSourceLoc Loc,
SmallVector<CharSourceRange, 4> SpellingRanges;
mapDiagnosticRanges(Loc, Ranges, SpellingRanges);
- /// Count all valid ranges.
- unsigned ValidCount = 0;
- for (const auto &Range : Ranges)
- if (Range.isValid())
- ValidCount++;
+ // Count all valid ranges.
+ unsigned ValidCount =
+ llvm::count_if(Ranges, [](const auto &R) { return R.isValid(); });
if (ValidCount > SpellingRanges.size())
return false;
- /// To store the source location of the argument location.
+ // To store the source location of the argument location.
FullSourceLoc ArgumentLoc;
- /// Set the ArgumentLoc to the beginning location of the expansion of Loc
- /// so to check if the ranges expands to the same beginning location.
+ // Set the ArgumentLoc to the beginning location of the expansion of Loc
+ // so to check if the ranges expands to the same beginning location.
if (!Loc.isMacroArgExpansion(&ArgumentLoc))
return false;