[clang] [Clang] Initialize AtLeastAsSpecialized to prevent undefined behavior… (PR #95195)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 11 21:42:53 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (smanna12)

<details>
<summary>Changes</summary>

… in Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs()

This patch fixes a static analyzer bug where the boolean variable `AtLeastAsSpecialized` was used uninitialized. The variable is now explicitly initialized to false before its potential modification within a lambda function to ensure that it always holds a valid value when returned, preventing undefined behavior due to uninitialized variable usage in `Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs()`.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+1-1) 


``````````diff
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index befeb38e1fe5b..df0d6908d0a78 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -6447,7 +6447,7 @@ bool Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(
   if (Inst.isInvalid())
     return false;
 
-  bool AtLeastAsSpecialized;
+  bool AtLeastAsSpecialized = false;
   runWithSufficientStackSpace(Info.getLocation(), [&] {
     AtLeastAsSpecialized =
         ::FinishTemplateArgumentDeduction(

``````````

</details>


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


More information about the cfe-commits mailing list