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

via cfe-commits cfe-commits at lists.llvm.org
Thu May 15 13:53:02 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/140137.diff


1 Files Affected:

- (modified) clang/lib/Lex/Preprocessor.cpp (+2) 


``````````diff
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);
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/140137


More information about the cfe-commits mailing list