[clang] a9af8f8 - [clang][Interp] Implement IntegralAP::truncate() (#69912)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 5 00:26:33 PDT 2023
Author: Timm Baeder
Date: 2023-11-05T08:26:29+01:00
New Revision: a9af8f8882f9d64870d3b60adfbe07e59c63c523
URL: https://github.com/llvm/llvm-project/commit/a9af8f8882f9d64870d3b60adfbe07e59c63c523
DIFF: https://github.com/llvm/llvm-project/commit/a9af8f8882f9d64870d3b60adfbe07e59c63c523.diff
LOG: [clang][Interp] Implement IntegralAP::truncate() (#69912)
Added:
Modified:
clang/lib/AST/Interp/IntegralAP.h
clang/test/AST/Interp/intap.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/IntegralAP.h b/clang/lib/AST/Interp/IntegralAP.h
index 9aefea6d0c47ed9..1f535d420bcd54b 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -140,9 +140,8 @@ template <bool Signed> class IntegralAP final {
return NameStr;
}
- IntegralAP truncate(unsigned bitWidth) const {
- assert(false);
- return V;
+ IntegralAP truncate(unsigned BitWidth) const {
+ return IntegralAP(V.trunc(BitWidth));
}
IntegralAP<false> toUnsigned() const {
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 02a860eb0986c15..db9f516131af474 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -121,4 +121,20 @@ namespace AddSubOffset {
static_assert(*P2 == 1,"");
}
+namespace Bitfields {
+ struct S1 {
+ unsigned _BitInt(128) a : 2;
+ };
+ constexpr S1 s1{100}; // ref-warning {{changes value from 100 to 0}} \
+ // expected-warning {{changes value from 100 to 0}}
+ constexpr S1 s12{3};
+ static_assert(s12.a == 3, "");
+
+ struct S2 {
+ unsigned __int128 a : 2;
+ };
+ constexpr S2 s2{100}; // ref-warning {{changes value from 100 to 0}} \
+ // expected-warning {{changes value from 100 to 0}}
+}
+
#endif
More information about the cfe-commits
mailing list