[clang] 33b02d7 - [NFC][Clang] Fix static code analyzer concern about null value dereference

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 5 12:49:10 PDT 2023


Author: Manna, Soumi
Date: 2023-09-05T12:48:43-07:00
New Revision: 33b02d766eb83656c2bb214ac3512311e99874a2

URL: https://github.com/llvm/llvm-project/commit/33b02d766eb83656c2bb214ac3512311e99874a2
DIFF: https://github.com/llvm/llvm-project/commit/33b02d766eb83656c2bb214ac3512311e99874a2.diff

LOG: [NFC][Clang] Fix static code analyzer concern about null value dereference

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

Added: 
    

Modified: 
    clang/lib/Lex/PPDirectives.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index eb660b9d6e75151..a4db8e7a84c07d5 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -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();


        


More information about the cfe-commits mailing list