[clang] 57c5718 - [clang][bytecode] `extOrTrunc()` when pushing builtin results (#204516)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 18 00:46:55 PDT 2026
Author: Timm Baeder
Date: 2026-06-18T09:46:51+02:00
New Revision: 57c571877d732dd032f9216fe6b478efff2919bb
URL: https://github.com/llvm/llvm-project/commit/57c571877d732dd032f9216fe6b478efff2919bb
DIFF: https://github.com/llvm/llvm-project/commit/57c571877d732dd032f9216fe6b478efff2919bb.diff
LOG: [clang][bytecode] `extOrTrunc()` when pushing builtin results (#204516)
We're not necessarily using an APSInt of the appropriate size from the
start, so get it to the right bitwidth here.
Added:
Modified:
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/AST/ByteCode/builtin-functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 55907bf11506b..b16a34543757b 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -100,7 +100,7 @@ static void pushInteger(InterpState &S, const APSInt &Val, QualType QT) {
if (T == PT_IntAPS) {
unsigned BitWidth = S.getASTContext().getIntWidth(QT);
auto Result = S.allocAP<IntegralAP<true>>(BitWidth);
- Result.copy(Val);
+ Result.copy(Val.extOrTrunc(BitWidth));
S.Stk.push<IntegralAP<true>>(Result);
return;
}
@@ -108,7 +108,7 @@ static void pushInteger(InterpState &S, const APSInt &Val, QualType QT) {
if (T == PT_IntAP) {
unsigned BitWidth = S.getASTContext().getIntWidth(QT);
auto Result = S.allocAP<IntegralAP<false>>(BitWidth);
- Result.copy(Val);
+ Result.copy(Val.extOrTrunc(BitWidth));
S.Stk.push<IntegralAP<false>>(Result);
return;
}
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 57157392f6a6e..3074a84986520 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -856,6 +856,8 @@ namespace ctz {
char ctz53[__builtin_ctzg((unsigned __int128)0x10, 42) == 4 ? 1 : -1];
char ctz54[__builtin_ctzg((unsigned __int128)1 << (BITSIZE(__int128) - 1)) == BITSIZE(__int128) - 1 ? 1 : -1];
char ctz55[__builtin_ctzg((unsigned __int128)1 << (BITSIZE(__int128) - 1), 42) == BITSIZE(__int128) - 1 ? 1 : -1];
+
+ static_assert(__builtin_elementwise_ctzg((__int128)42) == 1, "");
#endif
#ifndef __AVR__
int ctz56 = __builtin_ctzg((unsigned _BitInt(128))0);
More information about the cfe-commits
mailing list