[clang] [clang] Remove an incorrect assertion in ConstantFoldAttrs (PR #105789)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 22 23:59:41 PDT 2024


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/105789

Evaluating the attribute expression can be successful without resulting in a value. Namely, when the expression is of type void.



>From 920eb8d753070b72b8ba0b2766333d7db9bed0a9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 23 Aug 2024 08:54:12 +0200
Subject: [PATCH] [clang] Remove an incorrect assertion in ConstantFoldAttrs

Evaluating the attribute expression can be successful without resulting
in a value. Namely, when the expression is of type void.
---
 clang/lib/Sema/SemaAttr.cpp          | 4 ++--
 clang/test/SemaCXX/attr-annotate.cpp | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index a1724820472b59..51354963c0831e 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -439,8 +439,8 @@ bool Sema::ConstantFoldAttrArgs(const AttributeCommonInfo &CI,
         Diag(Note.first, Note.second);
       return false;
     }
-    assert(Eval.Val.hasValue());
-    E = ConstantExpr::Create(Context, E, Eval.Val);
+    if (Eval.Val.hasValue())
+      E = ConstantExpr::Create(Context, E, Eval.Val);
   }
 
   return true;
diff --git a/clang/test/SemaCXX/attr-annotate.cpp b/clang/test/SemaCXX/attr-annotate.cpp
index 846ef4119f1d7c..ff538fee9cb3c7 100644
--- a/clang/test/SemaCXX/attr-annotate.cpp
+++ b/clang/test/SemaCXX/attr-annotate.cpp
@@ -134,3 +134,7 @@ constexpr int foldable_but_invalid() {
 template <typename T> [[clang::annotate()]] void f2() {}
 // expected-error at -1 {{'annotate' attribute takes at least 1 argument}}
 }
+
+namespace test5 {
+  void bir [[clang::annotate("B", (void)1)]] ();
+}



More information about the cfe-commits mailing list