[clang] eaea4d1 - [clang] The ms-extension __noop should return zero in a constexpr context. (#106849)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 2 02:15:47 PDT 2024
Author: c8ef
Date: 2024-09-02T11:15:44+02:00
New Revision: eaea4d15acd4cab92e6287d692d2652066c3368a
URL: https://github.com/llvm/llvm-project/commit/eaea4d15acd4cab92e6287d692d2652066c3368a
DIFF: https://github.com/llvm/llvm-project/commit/eaea4d15acd4cab92e6287d692d2652066c3368a.diff
LOG: [clang] The ms-extension __noop should return zero in a constexpr context. (#106849)
Fixes #106713.
Added:
Modified:
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/builtins.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index b5dfd4dd32b63c..3dc13c14c00343 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12720,8 +12720,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
}
case Builtin::BI__noop:
- // __noop always evaluates successfully
- return true;
+ // __noop always evaluates successfully and returns 0.
+ return Success(0, E);
case Builtin::BI__builtin_is_constant_evaluated: {
const auto *Callee = Info.CurrentCall->getCallee();
diff --git a/clang/test/SemaCXX/builtins.cpp b/clang/test/SemaCXX/builtins.cpp
index c6fbb8b514d671..f47ed3a1f7ebfc 100644
--- a/clang/test/SemaCXX/builtins.cpp
+++ b/clang/test/SemaCXX/builtins.cpp
@@ -177,5 +177,21 @@ static void __builtin_cpu_init(); // expected-error {{static declaration of '__b
#endif
#ifdef _MSC_VER
-constexpr int x = []{ __noop; return 0; }(); // expected-no-diagnostics
+constexpr int x = [] {
+ __noop;
+ return 0;
+}(); // expected-no-diagnostics
+static_assert([] { return __noop; }() == 0);
+static_assert([] { return __noop(4); }() == 0);
+extern int not_accessed;
+void not_called();
+static_assert([] { return __noop(not_accessed *= 6); }() == 0);
+static_assert([] { return __noop(not_called()); }() == 0);
+static_assert([] { return __noop(throw ""); }() == 0);
+static_assert([] { return __noop(throw "", throw ""); }() == 0);
+static_assert([] {
+ int a = 5;
+ __noop(++a);
+ return a;
+}() == 5);
#endif
More information about the cfe-commits
mailing list