[clang] [Clang] Correct the DeclRefExpr's Type after the initializer gets instantiated (PR #133212)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 27 02:11:31 PDT 2025


================
@@ -19849,11 +19849,14 @@ static void DoMarkVarDeclReferenced(
           SemaRef.InstantiateVariableDefinition(PointOfInstantiation, Var);
         });
 
-        // Re-set the member to trigger a recomputation of the dependence bits
-        // for the expression.
-        if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E))
+        if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) {
+          // Re-set the member to trigger a recomputation of the dependence bits
+          // for the expression.
           DRE->setDecl(DRE->getDecl());
-        else if (auto *ME = dyn_cast_or_null<MemberExpr>(E))
+          if (SemaRef.Context.getAsIncompleteArrayType(DRE->getType()) &&
+              !SemaRef.Context.getAsIncompleteArrayType(Var->getType()))
+            DRE->setType(Var->getType());
+        } else if (auto *ME = dyn_cast_or_null<MemberExpr>(E))
----------------
zyn0217 wrote:

> And I found out we have a completeExprArrayBound function - I suspect we might want to use that. Can you look into it?

I'm surprised we have such a function, thanks! I made it call `getCompletedType()` which seems to target to the IncompleteArrayTypes and calls `completeExprArrayBound()` if possible

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


More information about the cfe-commits mailing list