Skip to content

Commit

Permalink
[NFC][Clang] Fix static code analyzer concern about null value derefe…
Browse files Browse the repository at this point in the history
…rence

CurLexer is dereferenced and should not be null in clang::Preprocessor::SkipExcludedConditionalBlock(clang::SourceLocation, clang::SourceLocation, bool, bool, clang::SourceLocation)

This patch adds an assert for NULL value check of pointer CurLexer and splits up all predicates so that, when/if a failure occurs, we'll be able to tell which predicate failed.

Reviewed By: tahonermann

Differential Revision: https://reviews.llvm.org/D158293
  • Loading branch information
smanna12 committed Sep 5, 2023
1 parent c4a769b commit 33b02d7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/Lex/PPDirectives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation HashTokenLoc,
llvm::SaveAndRestore SARSkipping(SkippingExcludedConditionalBlock, true);

++NumSkipped;
assert(!CurTokenLexer && CurPPLexer && "Lexing a macro, not a file?");
assert(!CurTokenLexer && "Conditional PP block cannot appear in a macro!");
assert(CurPPLexer && "Conditional PP block must be in a file!");
assert(CurLexer && "Conditional PP block but no current lexer set!");

if (PreambleConditionalStack.reachedEOFWhileSkipping())
PreambleConditionalStack.clearSkipInfo();
Expand Down

0 comments on commit 33b02d7

Please sign in to comment.