[clang] [Clang][Sema] Fix crash when rebuilding MemberExprs with invalid object expressions (PR #97455)

Krystian Stasiowski via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 3 13:23:35 PDT 2024


================
@@ -2896,6 +2896,9 @@ class TreeTransform {
     SS.Adopt(QualifierLoc);
 
     Base = BaseResult.get();
+    if (Base->containsErrors())
+      return ExprError();
----------------
sdkrystian wrote:

@mizvekov The problems arise when we build a `MemberExpr` for a class member access expression with an object expression that isn't dependent (as far as clang is concerned), but is _indirectly_ dependent (i.e. may instantiate to an expression of a different type). If the object expression is transformed into a `RecoveryExpr`, we end up with a `MemberExpr` that has the type `ASTContext::DependentTy` -- which we _could_ recover from by rebuilding it as a `RecoveryExpr` (or `CXXDependentScopeMemberExpr`), but the simplest solution is to simply bail as we do in practically every other case when part of the class member access expression instantiates to something invalid.

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


More information about the cfe-commits mailing list