[clang] [Clang] Added check for unexpanded pack in attribute [[assume]] (PR #91893)
Azmat Yusuf via cfe-commits
cfe-commits at lists.llvm.org
Sun May 12 11:10:31 PDT 2024
https://github.com/azmat-y created https://github.com/llvm/llvm-project/pull/91893
Added a check for unexpanded parameter pack in attribute [[assume]]. Tested it with expected-error statements from clang fronted. This fixes #91232. @Sirraide
>From cbb35bd010f2d46ae70367549a2838841a55aeb7 Mon Sep 17 00:00:00 2001
From: Azmat Yusuf <azmatyusuf2022 at gmail.com>
Date: Sun, 12 May 2024 20:49:14 +0530
Subject: [PATCH] [Clang] Added check for unexpanded pack in attribute
[[assume]]
---
clang/lib/Sema/SemaStmtAttr.cpp | 5 +++++
clang/test/SemaCXX/cxx23-assume.cpp | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 1c84830b6ddd2..36f8ecadcfab7 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -670,6 +670,11 @@ ExprResult Sema::ActOnCXXAssumeAttr(Stmt *St, const ParsedAttr &A,
}
auto *Assumption = A.getArgAsExpr(0);
+
+ if (DiagnoseUnexpandedParameterPack(Assumption)) {
+ return ExprError();
+ }
+
if (Assumption->getDependence() == ExprDependence::None) {
ExprResult Res = BuildCXXAssumeExpr(Assumption, A.getAttrName(), Range);
if (Res.isInvalid())
diff --git a/clang/test/SemaCXX/cxx23-assume.cpp b/clang/test/SemaCXX/cxx23-assume.cpp
index 8676970de14f6..e67d72ae0a995 100644
--- a/clang/test/SemaCXX/cxx23-assume.cpp
+++ b/clang/test/SemaCXX/cxx23-assume.cpp
@@ -138,3 +138,8 @@ constexpr int foo() {
}
static_assert(foo() == 0);
+
+template <bool ...val>
+void f() {
+ [[assume(val)]]; // expected-error {{expression contains unexpanded parameter pack}}
+}
More information about the cfe-commits
mailing list