[clang] `__noop` not marked as constexpr #102064 (PR #105983)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 25 05:31:10 PDT 2024
https://github.com/ofAlpaca created https://github.com/llvm/llvm-project/pull/105983
Resolves #102064
I think the problem is that the function `bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinOp)` return default `false` directly when visiting expression of `__noop`.
Thus, `__noop` cannot be evaluated as constant initializer in here.
https://github.com/llvm/llvm-project/blob/b6603e1bf11dee4761e49af6581c8b8f074b705d/clang/lib/Sema/SemaDecl.cpp#L14402
By adding a `BI__noop` case in `bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, unsigned BuiltinOp)` should fix the problem.
Correct me if there is anything I misunderstood.
>From 7f13ff52821a6c2ba58236fe363fb9a3a378c33b Mon Sep 17 00:00:00 2001
From: ofAlpaca <frank70199 at gmail.com>
Date: Sun, 25 Aug 2024 17:02:11 +0800
Subject: [PATCH 1/3] Fix for GH102064
---
clang/include/clang/Basic/Builtins.td | 2 +-
clang/lib/AST/ExprConstant.cpp | 4 ++++
clang/test/SemaCXX/GH102064.cpp | 3 +++
3 files changed, 8 insertions(+), 1 deletion(-)
create mode 100644 clang/test/SemaCXX/GH102064.cpp
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index f5b15cf90d1f83..b42f7ea1d9de68 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -2516,7 +2516,7 @@ def IsoVolatileStore : MSLangBuiltin, Int8_16_32_64Template {
def Noop : MSLangBuiltin {
let Spellings = ["__noop"];
- let Attributes = [NoThrow];
+ let Attributes = [NoThrow, Constexpr];
let Prototype = "int(...)";
}
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5af712dd7257b1..d505346bccd9b3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12586,6 +12586,10 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
return false;
}
+ case Builtin::BI__noop:
+ // __noop always evaluates successfully
+ return true;
+
case Builtin::BI__builtin_is_constant_evaluated: {
const auto *Callee = Info.CurrentCall->getCallee();
if (Info.InConstantContext && !Info.CheckingPotentialConstantExpression &&
diff --git a/clang/test/SemaCXX/GH102064.cpp b/clang/test/SemaCXX/GH102064.cpp
new file mode 100644
index 00000000000000..52213b66e9eccc
--- /dev/null
+++ b/clang/test/SemaCXX/GH102064.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -std=c++20 -fms-extensions %s
+// expected-no-diagnostics
+constexpr int x = []{ __noop; return 0; }();
\ No newline at end of file
>From 676b1b352d7e3279c6e3681466605e88b81dfdde Mon Sep 17 00:00:00 2001
From: ofAlpaca <frank70199 at gmail.com>
Date: Sun, 25 Aug 2024 20:03:19 +0800
Subject: [PATCH 2/3] Add release note
---
clang/docs/ReleaseNotes.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 971df672b6ca1e..e60407061ccd3b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -861,6 +861,8 @@ Bug Fixes to Compiler Builtins
- Clang now allows pointee types of atomic builtin arguments to be complete template types
that was not instantiated elsewhere.
+- Fix ``__noop`` not marked as constexpr. (#GH102064)
+
Bug Fixes to Attribute Support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>From 9730d9c50033c44766b370ccc92de6575c1eca29 Mon Sep 17 00:00:00 2001
From: ofAlpaca <frank70199 at gmail.com>
Date: Sun, 25 Aug 2024 20:13:48 +0800
Subject: [PATCH 3/3] Update testcase for end of file newline
---
clang/test/SemaCXX/GH102064.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/SemaCXX/GH102064.cpp b/clang/test/SemaCXX/GH102064.cpp
index 52213b66e9eccc..0ed930439e3d75 100644
--- a/clang/test/SemaCXX/GH102064.cpp
+++ b/clang/test/SemaCXX/GH102064.cpp
@@ -1,3 +1,3 @@
// RUN: %clang_cc1 -std=c++20 -fms-extensions %s
// expected-no-diagnostics
-constexpr int x = []{ __noop; return 0; }();
\ No newline at end of file
+constexpr int x = []{ __noop; return 0; }();
More information about the cfe-commits
mailing list