[clang] f838d6b - [clang][bytecode] Implement __noop (#106714)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 2 04:50:24 PDT 2024
Author: Timm Baeder
Date: 2024-09-02T13:50:22+02:00
New Revision: f838d6b1b2d84d3149685c3a3896dc82889563f7
URL: https://github.com/llvm/llvm-project/commit/f838d6b1b2d84d3149685c3a3896dc82889563f7
DIFF: https://github.com/llvm/llvm-project/commit/f838d6b1b2d84d3149685c3a3896dc82889563f7.diff
LOG: [clang][bytecode] Implement __noop (#106714)
This does nothing and returns 0.
Added:
Modified:
clang/lib/AST/ByteCode/Function.cpp
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/AST/ByteCode/ms.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Function.cpp b/clang/lib/AST/ByteCode/Function.cpp
index 25da6ae1bc7b61..52d6d05211f642 100644
--- a/clang/lib/AST/ByteCode/Function.cpp
+++ b/clang/lib/AST/ByteCode/Function.cpp
@@ -61,7 +61,8 @@ bool Function::isVirtual() const {
static bool isUnevaluatedBuiltin(unsigned BuiltinID) {
return BuiltinID == Builtin::BI__builtin_classify_type ||
BuiltinID == Builtin::BI__builtin_os_log_format_buffer_size ||
- BuiltinID == Builtin::BI__builtin_constant_p;
+ BuiltinID == Builtin::BI__builtin_constant_p ||
+ BuiltinID == Builtin::BI__noop;
}
bool Function::isUnevaluatedBuiltin() const {
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 1a71bff25d2540..81e49f203524b7 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1593,6 +1593,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
return false;
break;
+ case Builtin::BI__noop:
+ pushInteger(S, 0, Call->getType());
+ break;
+
default:
S.FFDiag(S.Current->getLocation(OpPC),
diag::note_invalid_subexpr_in_const_expr)
diff --git a/clang/test/AST/ByteCode/ms.cpp b/clang/test/AST/ByteCode/ms.cpp
index fe5ed219946e76..35ffcbccae3b3a 100644
--- a/clang/test/AST/ByteCode/ms.cpp
+++ b/clang/test/AST/ByteCode/ms.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -verify=ref,both %s -fms-extensions
-// RUN: %clang_cc1 -verify=expected,both %s -fexperimental-new-constant-interpreter -fms-extensions
+// RUN: %clang_cc1 -verify=ref,both %s -fms-extensions -fcxx-exceptions
+// RUN: %clang_cc1 -verify=expected,both %s -fexperimental-new-constant-interpreter -fms-extensions -fcxx-exceptions
// ref-no-diagnostics
// expected-no-diagnostics
@@ -8,3 +8,14 @@
static_assert(_rotl(0x01, 5) == 32);
static_assert(alignof(__unaligned int) == 1, "");
+
+static_assert(__noop() == 0, "");
+
+constexpr int noopIsActuallyNoop() {
+ int a = 0;
+ __noop(throw);
+ __noop(++a);
+ __noop(a = 100);
+ return a;
+}
+static_assert(noopIsActuallyNoop() == 0);
More information about the cfe-commits
mailing list