aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2023-11-16 07:30:54 +0100
committerGitHub <noreply@github.com>2023-11-16 07:30:54 +0100
commitbffa8e1d1aeebdcfca935f7b998e8e100bca08a4 (patch)
tree953d9d19d3fef3f28d793a201436902dbc0b8fa5 /clang
parentc3b9c36f3ab4d9021951a00c9a6798e3fe0a48a5 (diff)
downloadllvm-bffa8e1d1aeebdcfca935f7b998e8e100bca08a4.zip
llvm-bffa8e1d1aeebdcfca935f7b998e8e100bca08a4.tar.gz
llvm-bffa8e1d1aeebdcfca935f7b998e8e100bca08a4.tar.bz2
[clang][Interp] Implement __builtin_clrsb (#72243)
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/Interp/InterpBuiltin.cpp16
-rw-r--r--clang/test/AST/Interp/builtin-functions.cpp14
2 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 0536fe4..8c5efe2 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -448,6 +448,15 @@ static bool interp__builtin_parity(InterpState &S, CodePtr OpPC,
return true;
}
+static bool interp__builtin_clrsb(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *Func, const CallExpr *Call) {
+ PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+ APSInt Val = peekToAPSInt(S.Stk, ArgT);
+ pushInt(S, Val.getBitWidth() - Val.getSignificantBits());
+ return true;
+}
+
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
const CallExpr *Call) {
InterpFrame *Frame = S.Current;
@@ -592,6 +601,13 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
return retInt(S, OpPC, Dummy);
break;
+ case Builtin::BI__builtin_clrsb:
+ case Builtin::BI__builtin_clrsbl:
+ case Builtin::BI__builtin_clrsbll:
+ if (interp__builtin_clrsb(S, OpPC, Frame, F, Call))
+ return retInt(S, OpPC, Dummy);
+ break;
+
default:
return false;
}
diff --git a/clang/test/AST/Interp/builtin-functions.cpp b/clang/test/AST/Interp/builtin-functions.cpp
index 14604a2b..acc2dc3 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -310,3 +310,17 @@ namespace parity {
char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : -1];
}
+namespace clrsb {
+ char clrsb1[__builtin_clrsb(0) == BITSIZE(int) - 1 ? 1 : -1];
+ char clrsb2[__builtin_clrsbl(0L) == BITSIZE(long) - 1 ? 1 : -1];
+ char clrsb3[__builtin_clrsbll(0LL) == BITSIZE(long long) - 1 ? 1 : -1];
+ char clrsb4[__builtin_clrsb(~0) == BITSIZE(int) - 1 ? 1 : -1];
+ char clrsb5[__builtin_clrsbl(~0L) == BITSIZE(long) - 1 ? 1 : -1];
+ char clrsb6[__builtin_clrsbll(~0LL) == BITSIZE(long long) - 1 ? 1 : -1];
+ char clrsb7[__builtin_clrsb(1) == BITSIZE(int) - 2 ? 1 : -1];
+ char clrsb8[__builtin_clrsb(~1) == BITSIZE(int) - 2 ? 1 : -1];
+ char clrsb9[__builtin_clrsb(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1];
+ char clrsb10[__builtin_clrsb(~(1 << (BITSIZE(int) - 1))) == 0 ? 1 : -1];
+ char clrsb11[__builtin_clrsb(0xf) == BITSIZE(int) - 5 ? 1 : -1];
+ char clrsb12[__builtin_clrsb(~0x1f) == BITSIZE(int) - 6 ? 1 : -1];
+}