Skip to content

Commit b46a048

Browse files
authored
[clang][bytecode] Implement __builtin_arithmetic_fence (#113937)
1 parent 7c55426 commit b46a048

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,15 @@ static bool interp__builtin_operator_delete(InterpState &S, CodePtr OpPC,
16701670
S, OpPC, *AllocForm, DynamicAllocator::Form::Operator, BlockDesc, Source);
16711671
}
16721672

1673+
static bool interp__builtin_arithmetic_fence(InterpState &S, CodePtr OpPC,
1674+
const InterpFrame *Frame,
1675+
const Function *Func,
1676+
const CallExpr *Call) {
1677+
const Floating &Arg0 = S.Stk.peek<Floating>();
1678+
S.Stk.push<Floating>(Arg0);
1679+
return true;
1680+
}
1681+
16731682
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
16741683
const CallExpr *Call, uint32_t BuiltinID) {
16751684
const InterpFrame *Frame = S.Current;
@@ -2111,6 +2120,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
21112120
return false;
21122121
break;
21132122

2123+
case Builtin::BI__arithmetic_fence:
2124+
if (!interp__builtin_arithmetic_fence(S, OpPC, Frame, F, Call))
2125+
return false;
2126+
break;
2127+
21142128
default:
21152129
S.FFDiag(S.Current->getLocation(OpPC),
21162130
diag::note_invalid_subexpr_in_const_expr)

clang/test/Sema/arithmetic-fence-builtin.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - -verify -x c++ %s
2+
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - -verify -x c++ %s -fexperimental-new-constant-interpreter
23
// RUN: %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -verify -x c++ %s
4+
// RUN: %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -verify -x c++ %s -fexperimental-new-constant-interpreter
35
// RUN: not %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -x c++ %s \
46
// RUN: -fprotect-parens 2>&1 | FileCheck -check-prefix=PPC %s
7+
// RUN: not %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -x c++ %s -fexperimental-new-constant-interpreter \
8+
// RUN: -fprotect-parens 2>&1 | FileCheck -check-prefix=PPC %s
59
// RUN: %clang_cc1 -triple spir64 -emit-llvm -o - -verify -x c++ %s
10+
// RUN: %clang_cc1 -triple spir64 -emit-llvm -o - -verify -x c++ %s -fexperimental-new-constant-interpreter
611
#ifndef PPC
712
int v;
813
template <typename T> T addT(T a, T b) {

0 commit comments

Comments
 (0)