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

Yuxuan Chen via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 9 20:20:39 PDT 2024


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

>From 588762c4c3a1e01f4cf2bd418a8545b79a6b5371 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 1/2] [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..a27ed02fc73b8 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

>From 1f9905b3d593e18caab81920f86a3588f1a97644 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen <ych at meta.com>
Date: Tue, 9 Jul 2024 19:52:34 -0700
Subject: [PATCH 2/2] Add a crash-on-valid unit test

---
 clang/test/SemaCXX/pr98102.cpp | 38 ++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 clang/test/SemaCXX/pr98102.cpp

diff --git a/clang/test/SemaCXX/pr98102.cpp b/clang/test/SemaCXX/pr98102.cpp
new file mode 100644
index 0000000000000..504bfc802d4cf
--- /dev/null
+++ b/clang/test/SemaCXX/pr98102.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+template <bool v>
+struct BC {
+  static constexpr bool value = v;
+};
+
+template <typename B>
+struct A : B {
+  static constexpr bool value = B::value;
+};
+
+template <typename T>
+using _Requires = A<T>::value;
+
+template <typename _Tp, typename _Args>
+struct __is_constructible_impl : BC<__is_constructible(_Tp, _Args)> {};
+
+template <typename _Tp>
+struct optional {
+  template <typename _Up, _Requires<__is_constructible_impl<_Tp, _Up>> = true>
+  optional(_Up) {}
+};
+
+struct MO {};
+struct S : MO {};
+struct TB {
+  TB(optional<S>) {}
+};
+
+class TD : public TB, MO {
+  using TB::TB;
+};
+
+void foo() {
+  static_assert(__is_constructible_impl<TD, TD>::value);
+}



More information about the cfe-commits mailing list