[clang] [Clang][Sema] Fix crash when rebuilding MemberExprs with invalid object expressions (PR #97455)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 2 11:05:39 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Krystian Stasiowski (sdkrystian)
<details>
<summary>Changes</summary>
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/97455
More information about the cfe-commits
mailing list