[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:58:38 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 f12bfc7bea827fd3962b0dee20601fa216639ceb 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 | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 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..1497ac85306fd
--- /dev/null
+++ b/clang/test/SemaCXX/pr98102.cpp
@@ -0,0 +1,33 @@
+// 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 _Tp, typename _Args>
+struct Constructible : BC<__is_constructible(_Tp, _Args)> {};
+
+template <typename T>
+using Requires = T::value;
+
+template <typename T>
+struct optional {
+ template <typename U, Requires<Constructible<T, U>> = true>
+ optional(U) {}
+};
+
+struct MO {};
+struct S : MO {};
+struct TB {
+ TB(optional<S>) {}
+};
+
+class TD : public TB, MO {
+ using TB::TB;
+};
+
+void foo() {
+ static_assert(Constructible<TD, TD>::value);
+}
More information about the cfe-commits
mailing list