Skip to content

Commit f838d6b

Browse files
authored
[clang][bytecode] Implement __noop (llvm#106714)
This does nothing and returns 0.
1 parent 4ed9092 commit f838d6b

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

clang/lib/AST/ByteCode/Function.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ bool Function::isVirtual() const {
6161
static bool isUnevaluatedBuiltin(unsigned BuiltinID) {
6262
return BuiltinID == Builtin::BI__builtin_classify_type ||
6363
BuiltinID == Builtin::BI__builtin_os_log_format_buffer_size ||
64-
BuiltinID == Builtin::BI__builtin_constant_p;
64+
BuiltinID == Builtin::BI__builtin_constant_p ||
65+
BuiltinID == Builtin::BI__noop;
6566
}
6667

6768
bool Function::isUnevaluatedBuiltin() const {

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
15931593
return false;
15941594
break;
15951595

1596+
case Builtin::BI__noop:
1597+
pushInteger(S, 0, Call->getType());
1598+
break;
1599+
15961600
default:
15971601
S.FFDiag(S.Current->getLocation(OpPC),
15981602
diag::note_invalid_subexpr_in_const_expr)

clang/test/AST/ByteCode/ms.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -verify=ref,both %s -fms-extensions
2-
// RUN: %clang_cc1 -verify=expected,both %s -fexperimental-new-constant-interpreter -fms-extensions
1+
// RUN: %clang_cc1 -verify=ref,both %s -fms-extensions -fcxx-exceptions
2+
// RUN: %clang_cc1 -verify=expected,both %s -fexperimental-new-constant-interpreter -fms-extensions -fcxx-exceptions
33

44
// ref-no-diagnostics
55
// expected-no-diagnostics
@@ -8,3 +8,14 @@
88
static_assert(_rotl(0x01, 5) == 32);
99

1010
static_assert(alignof(__unaligned int) == 1, "");
11+
12+
static_assert(__noop() == 0, "");
13+
14+
constexpr int noopIsActuallyNoop() {
15+
int a = 0;
16+
__noop(throw);
17+
__noop(++a);
18+
__noop(a = 100);
19+
return a;
20+
}
21+
static_assert(noopIsActuallyNoop() == 0);

0 commit comments

Comments
 (0)