[clang] Fix bug (PR #104811)

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


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

>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 1/2] 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;

>From 437793d9f1cb091d8a9adc364eb3f986e844fefe Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Mon, 19 Aug 2024 09:18:52 -0700
Subject: [PATCH 2/2] Fix patch

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

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 823292fe0197d3..a3cc211a67c726 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13520,7 +13520,8 @@ 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");
+    assert((!Result.isInvalid() && Init) &&
+           "Should have a valid initializer at this point");
 
     IsParenListInit = !InitSeq.steps().empty() &&
                       InitSeq.step_begin()->Kind ==



More information about the cfe-commits mailing list