[clang] [Clang] Guard against null in template instantiation process (PR #97913)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 6 14:51:49 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (smanna12)

<details>
<summary>Changes</summary>

This patch adds a null check for InstantiatedFrom to prevent dereferencing a null pointer during the template instantiation process in clang::Sema::SetupConstraintScope().

The fix ensures that the function exits early with an appropriate error if the InstantiatedFrom pointer is not valid.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaConcept.cpp (+3) 


``````````diff
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 202dd86c67f62..353276e9b2802 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -636,6 +636,9 @@ bool Sema::SetupConstraintScope(
             ? FD->getInstantiatedFromMemberFunction()
             : FD->getInstantiatedFromDecl();
 
+    if (!InstantiatedFrom)
+      return true;
+
     InstantiatingTemplate Inst(
         *this, FD->getPointOfInstantiation(),
         Sema::InstantiatingTemplate::ConstraintsCheck{}, InstantiatedFrom,

``````````

</details>


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


More information about the cfe-commits mailing list