https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/69912
>From 40a32854cab91eb98aeb4788cabd4aa14d305d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Mon, 23 Oct 2023 12:23:45 +0200 Subject: [PATCH] [clang][Interp] Implement IntegralAP::truncate() --- clang/lib/AST/Interp/IntegralAP.h | 5 ++--- clang/test/AST/Interp/intap.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/Interp/IntegralAP.h b/clang/lib/AST/Interp/IntegralAP.h index 45e5b49546270aa..f8d47ca183f3a67 100644 --- a/clang/lib/AST/Interp/IntegralAP.h +++ b/clang/lib/AST/Interp/IntegralAP.h @@ -137,9 +137,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 27fae1b904351ce..c19e8c1367e9f4f 100644 --- a/clang/test/AST/Interp/intap.cpp +++ b/clang/test/AST/Interp/intap.cpp @@ -118,4 +118,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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits