[clang] [clang] fix sema init crash for not checking a ExprResult (PR #98102)

Yuxuan Chen via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 8 18:21:45 PDT 2024


https://github.com/yuxuanchen1997 created https://github.com/llvm/llvm-project/pull/98102

We ran into a FE crash and root caused to `ER.get()` on line 5584 here being nullptr. I think this is a result of not checking if ER here is invalid. 

We have been using automated reduction tools (like CReduce) for a while and it is not performing well and would like to ask upstream opinions on whether this condition here is handled correctly. Preferably with help to write a small, well contained crash-on-valid test case. 

I do have a crash-on-invalid test [here](https://gist.github.com/yuxuanchen1997/2bbfc1b9d78fe43ed8784a5db11eac98), would really appreciate any pointers. 

>From 82e3cb025e8eafdae5f7ee42fc9d1dddd4235d5b Mon Sep 17 00:00:00 2001
From: Yuxuan Chen <yuxuanchen1997 at outlook.com>
Date: Mon, 8 Jul 2024 18:16:17 -0700
Subject: [PATCH] [clang] fix sema init crash for not checking a ExprResult

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

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 41753a1661ace..80286302e9b9d 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5576,6 +5576,10 @@ static void TryOrBuildParenListInitialization(
       ExprResult ER;
       ER = IS.Perform(S, SubEntity, SubKind,
                       Arg ? MultiExprArg(Arg) : std::nullopt);
+
+      if (ER.IsInvalid())
+        return false;
+
       if (InitExpr)
         *InitExpr = ER.get();
       else



More information about the cfe-commits mailing list