[clang] Fix bug (PR #104811)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 19 09:12:34 PDT 2024


https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/104811

None

>From fc81a200eac8e9e2da34e60d3de1c6bd61fc1c99 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Mon, 19 Aug 2024 09:11:42 -0700
Subject: [PATCH] Fix bug

---
 clang/lib/Sema/SemaDecl.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 503e93f9257137..823292fe0197d3 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13518,6 +13518,10 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
     }
 
     Init = Result.getAs<Expr>();
+
+    // Assert that Init is non-null only if no errors have occurred.
+    assert((!Result.isInvalid() && Init) && "Should have a valid initializer at this point");
+
     IsParenListInit = !InitSeq.steps().empty() &&
                       InitSeq.step_begin()->Kind ==
                           InitializationSequence::SK_ParenthesizedListInit;



More information about the cfe-commits mailing list