Skip to content

Commit 0f4dc42

Browse files
authored
[clang][bytecode] Initialize elements in __builtin_elementwise_popcount (#118457)
1 parent 4849d59 commit 0f4dc42

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,7 @@ static bool interp__builtin_elementwise_popcount(InterpState &S, CodePtr OpPC,
17911791
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
17921792
Dst.atIndex(I).deref<T>() =
17931793
T::from(Arg.atIndex(I).deref<T>().toAPSInt().popcount());
1794+
Dst.atIndex(I).initialize();
17941795
});
17951796
}
17961797

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
// RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify=expected,both
88
// RUN: %clang_cc1 -triple avr -std=c++20 -Wno-string-plus-int -verify=ref,both %s -Wno-constant-evaluated
99

10+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
11+
#define LITTLE_END 1
12+
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
13+
#define LITTLE_END 0
14+
#else
15+
#error "huh?"
16+
#endif
17+
1018
extern "C" {
1119
typedef decltype(sizeof(int)) size_t;
1220
extern size_t wcslen(const wchar_t *p);
@@ -1140,6 +1148,10 @@ namespace ElementwisePopcount {
11401148
static_assert(__builtin_elementwise_popcount(0L) == 0);
11411149
static_assert(__builtin_elementwise_popcount(0xF0F0L) == 8);
11421150
static_assert(__builtin_elementwise_popcount(~0LL) == 8 * sizeof(long long));
1151+
1152+
#if __INT_WIDTH__ == 32
1153+
static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_popcount((vector4char){1, 2, 3, 4})) == (LITTLE_END ? 0x01020101 : 0x01010201));
1154+
#endif
11431155
}
11441156

11451157
namespace BuiltinMemcpy {

0 commit comments

Comments
 (0)