[clang] feedb7c - [clang][Interp] Fix IntAP(s) to IntAP(s) casts (#69915)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 6 06:13:48 PST 2023


Author: Timm Baeder
Date: 2023-11-06T15:13:43+01:00
New Revision: feedb7c0db1e06b9082f9c015362cdbf334696ff

URL: https://github.com/llvm/llvm-project/commit/feedb7c0db1e06b9082f9c015362cdbf334696ff
DIFF: https://github.com/llvm/llvm-project/commit/feedb7c0db1e06b9082f9c015362cdbf334696ff.diff

LOG: [clang][Interp] Fix IntAP(s) to IntAP(s) casts (#69915)

This was still assert(false)'ed out, it's for casts between two IntAP/IntAPS expressions.
We can't just short-circuit for FromT == ToT because we need to consider the bitwidth when doing the cast.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/AST/Interp/intap.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 485893d58f487ae..a2cf682b2532bde 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -200,16 +200,13 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
     if (!this->visit(SubExpr))
       return false;
 
-    if (FromT == ToT) {
-      assert(ToT != PT_IntAP && ToT != PT_IntAPS);
-      return true;
-    }
-
     if (ToT == PT_IntAP)
       return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE);
     if (ToT == PT_IntAPS)
       return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE);
 
+    if (FromT == ToT)
+      return true;
     return this->emitCast(*FromT, *ToT, CE);
   }
 

diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index db9f516131af474..45961e6fc74b7a7 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -30,6 +30,17 @@ static_assert(UBitIntZero1 == 0, "");
 constexpr unsigned _BitInt(2) BI1 = 3u;
 static_assert(BI1 == 3, "");
 
+namespace APCast {
+  constexpr _BitInt(10) A = 1;
+  constexpr _BitInt(11) B = A;
+  static_assert(B == 1, "");
+  constexpr _BitInt(16) B2 = A;
+  static_assert(B2 == 1, "");
+  constexpr _BitInt(32) B3 = A;
+  static_assert(B3 == 1, "");
+  constexpr unsigned _BitInt(32) B4 = A;
+  static_assert(B4 == 1, "");
+}
 
 #ifdef __SIZEOF_INT128__
 namespace i128 {


        


More information about the cfe-commits mailing list