Skip to content

Commit a9af8f8

Browse files
authored
[clang][Interp] Implement IntegralAP::truncate() (#69912)
1 parent 39edac2 commit a9af8f8

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

clang/lib/AST/Interp/IntegralAP.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ template <bool Signed> class IntegralAP final {
140140
return NameStr;
141141
}
142142

143-
IntegralAP truncate(unsigned bitWidth) const {
144-
assert(false);
145-
return V;
143+
IntegralAP truncate(unsigned BitWidth) const {
144+
return IntegralAP(V.trunc(BitWidth));
146145
}
147146

148147
IntegralAP<false> toUnsigned() const {

clang/test/AST/Interp/intap.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,20 @@ namespace AddSubOffset {
121121
static_assert(*P2 == 1,"");
122122
}
123123

124+
namespace Bitfields {
125+
struct S1 {
126+
unsigned _BitInt(128) a : 2;
127+
};
128+
constexpr S1 s1{100}; // ref-warning {{changes value from 100 to 0}} \
129+
// expected-warning {{changes value from 100 to 0}}
130+
constexpr S1 s12{3};
131+
static_assert(s12.a == 3, "");
132+
133+
struct S2 {
134+
unsigned __int128 a : 2;
135+
};
136+
constexpr S2 s2{100}; // ref-warning {{changes value from 100 to 0}} \
137+
// expected-warning {{changes value from 100 to 0}}
138+
}
139+
124140
#endif

0 commit comments

Comments
 (0)