Skip to content

Commit

Permalink
[clang][bytecode] Implement __builtin_arithmetic_fence (llvm#113937)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr authored Oct 28, 2024
1 parent 7c55426 commit b46a048
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,15 @@ static bool interp__builtin_operator_delete(InterpState &S, CodePtr OpPC,
S, OpPC, *AllocForm, DynamicAllocator::Form::Operator, BlockDesc, Source);
}

static bool interp__builtin_arithmetic_fence(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func,
const CallExpr *Call) {
const Floating &Arg0 = S.Stk.peek<Floating>();
S.Stk.push<Floating>(Arg0);
return true;
}

bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
const CallExpr *Call, uint32_t BuiltinID) {
const InterpFrame *Frame = S.Current;
Expand Down Expand Up @@ -2111,6 +2120,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
return false;
break;

case Builtin::BI__arithmetic_fence:
if (!interp__builtin_arithmetic_fence(S, OpPC, Frame, F, Call))
return false;
break;

default:
S.FFDiag(S.Current->getLocation(OpPC),
diag::note_invalid_subexpr_in_const_expr)
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Sema/arithmetic-fence-builtin.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - -verify -x c++ %s
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - -verify -x c++ %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -verify -x c++ %s
// RUN: %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -verify -x c++ %s -fexperimental-new-constant-interpreter
// RUN: not %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -x c++ %s \
// RUN: -fprotect-parens 2>&1 | FileCheck -check-prefix=PPC %s
// RUN: not %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -x c++ %s -fexperimental-new-constant-interpreter \
// RUN: -fprotect-parens 2>&1 | FileCheck -check-prefix=PPC %s
// RUN: %clang_cc1 -triple spir64 -emit-llvm -o - -verify -x c++ %s
// RUN: %clang_cc1 -triple spir64 -emit-llvm -o - -verify -x c++ %s -fexperimental-new-constant-interpreter
#ifndef PPC
int v;
template <typename T> T addT(T a, T b) {
Expand Down

0 comments on commit b46a048

Please sign in to comment.