[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 19:52:45 PDT 2024
https://github.com/yuxuanchen1997 updated https://github.com/llvm/llvm-project/pull/98102
>From 01a5dd6e5bfc612678818035b88f85fda5c039d1 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 619d5e7bfba3378420e95c3d9bfd6cc253cdc810 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 | 45 ++++++++++++++++++++++++++++++++++
1 file changed, 45 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..175a5ba80934f
--- /dev/null
+++ b/clang/test/SemaCXX/pr98102.cpp
@@ -0,0 +1,45 @@
+// 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 __and_ : B {
+ static constexpr bool value = true;
+};
+
+template <typename A>
+using _Requires = __and_<A>::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 Try : public TB, MO {
+ using TB::TB;
+};
+
+template <typename T>
+struct MQB;
+
+template <>
+struct MQB<Try> {
+ static_assert(__is_constructible_impl<Try, Try>::value);
+};
+
+void foo() {
+ MQB<Try> m;
+}
More information about the cfe-commits
mailing list