[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 21 23:49:27 PDT 2024


================
@@ -13456,6 +13458,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
     return;
   }
 
+  if (VDecl->isInvalidDecl()) {
+    CorrectDelayedTyposInExpr(Init, VDecl);
+    ExprResult Recovery =
+        CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), {Init});
+    if (Expr *E = Recovery.get())
----------------
mizvekov wrote:

Oops. I think this is still UB, please double check:
```suggestion
    if (ExprResult Recovery =
         CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), {Init}))
         VDecl->setInit(Recovery.get());
```

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


More information about the cfe-commits mailing list