https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/106714
>From f78ac3974423d2cd01bc73ed0de854ce4d6f50cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Fri, 30 Aug 2024 13:45:37 +0200 Subject: [PATCH] [clang][bytecode] Implement __noop This does nothing and returns 0. --- clang/lib/AST/ByteCode/Function.cpp | 3 ++- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 4 ++++ clang/test/AST/ByteCode/ms.cpp | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) 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); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits