Skip to content

[Clang][Sema] Fix crash when rebuilding MemberExprs with invalid object expressions #97455

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

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

sdkrystian
Copy link
Member

Fixes #95778

@sdkrystian sdkrystian requested a review from AaronBallman July 2, 2024 18:05
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 2, 2024

@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)

Changes

Fixes #95778


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

2 Files Affected:

  • (modified) clang/lib/Sema/TreeTransform.h (+3)
  • (modified) clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp (+31)
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 51ba22f99e3a3..5a4144b48822a 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -2896,6 +2896,9 @@ class TreeTransform {
     SS.Adopt(QualifierLoc);
 
     Base = BaseResult.get();
+    if (Base->containsErrors())
+      return ExprError();
+
     QualType BaseType = Base->getType();
 
     if (isArrow && !BaseType->isPointerType())
diff --git a/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp b/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
index 982e5372f5b0c..f32f49ef4539a 100644
--- a/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
@@ -574,3 +574,34 @@ namespace N4 {
     }
   };
 } // namespace N4
+
+namespace N5 {
+  struct A {
+    int x;
+  };
+
+  template<typename T>
+  void f() {
+    A y = T::x; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
+    y.x;
+  }
+
+  template void f<int>(); // expected-note {{in instantiation of}}
+
+  struct B {
+    template<typename T>
+    B(T&&);
+
+    int x;
+  };
+
+  template<typename T>
+  void g(T y) {
+    B z([&]() { // expected-note {{while substituting into a lambda expression here}}
+      h(&y); // expected-error {{use of undeclared identifier 'h'}}
+    });
+    z.x;
+  }
+
+  template void g(int); // expected-note {{in instantiation of}}
+} // namespace N5

@sdkrystian sdkrystian merged commit dfc8004 into llvm:main Jul 9, 2024
10 checks passed
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
…ct expressions (llvm#97455)

This patch fixes an assertion failure which occurs when the object expression of a `MemberExpr` is transformed into an expression with a dependent type for which the `DeclContext` cannot be computed (e.g. a `RecoveryExpr`). Fixes llvm#95778.
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.

Clang assertion "dependent lookup context that isn't the current instantiation?"
3 participants