[clang] dd32ad1 - [Clang][Lex][NFC] Assert getExternalSource() in updateOutOfDateIdentifier (#140137)

via cfe-commits cfe-commits at lists.llvm.org
Fri May 16 06:27:01 PDT 2025


Author: Shafik Yaghmour
Date: 2025-05-16T06:26:56-07:00
New Revision: dd32ad1c3787c51e72d496c03ab7948c98f93e06

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

LOG: [Clang][Lex][NFC] Assert getExternalSource() in updateOutOfDateIdentifier (#140137)

Static analysis flagged the unconditional access of getExternalSource().
We don't initialize ExternalSource during construction but via
setExternalSource(). If this is not set it will violate the invariant
covered by the assert.

Added: 
    

Modified: 
    clang/lib/Lex/Preprocessor.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 9ea7b95622c76..4c2dbbe881b48 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -759,6 +759,8 @@ void Preprocessor::HandlePoisonedIdentifier(Token & Identifier) {
 
 void Preprocessor::updateOutOfDateIdentifier(const IdentifierInfo &II) const {
   assert(II.isOutOfDate() && "not out of date");
+  assert(getExternalSource() &&
+         "getExternalSource() should not return nullptr");
   getExternalSource()->updateOutOfDateIdentifier(II);
 }
 


        


More information about the cfe-commits mailing list