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

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 8 18:22:16 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Yuxuan Chen (yuxuanchen1997)

<details>
<summary>Changes</summary>

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. 

---
Full diff: https://github.com/llvm/llvm-project/pull/98102.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaInit.cpp (+4) 


``````````diff
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

``````````

</details>


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


More information about the cfe-commits mailing list