Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] Guard against null in template instantiation process #97913

Closed
wants to merge 1 commit into from

Conversation

smanna12
Copy link
Contributor

@smanna12 smanna12 commented Jul 6, 2024

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.

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.
@smanna12 smanna12 requested a review from tahonermann July 6, 2024 21:51
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 6, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 6, 2024

@llvm/pr-subscribers-clang

Author: None (smanna12)

Changes

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 --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,

@smanna12 smanna12 closed this Jul 15, 2024
@smanna12 smanna12 deleted the TempNullBug branch July 15, 2024 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants