[clang] f05e818 - [clang][Interp] Fix BooleanToSignedIntegral casts for IntAP(S) (#102302)

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 7 04:52:04 PDT 2024


Author: Timm Baeder
Date: 2024-08-07T13:52:00+02:00
New Revision: f05e8186a439cf538f383dfbde68eca364a5acec

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

LOG: [clang][Interp] Fix BooleanToSignedIntegral casts for IntAP(S) (#102302)

We were not doing the final Neg here.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Compiler.cpp
    clang/test/AST/Interp/vectors.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp
index 95f4fe9bd0becf..11fe2acf2d7b95 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -480,19 +480,25 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
       }
     }
 
+    auto maybeNegate = [&]() -> bool {
+      if (CE->getCastKind() == CK_BooleanToSignedIntegral)
+        return this->emitNeg(*ToT, CE);
+      return true;
+    };
+
     if (ToT == PT_IntAP)
-      return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE);
+      return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE) &&
+             maybeNegate();
     if (ToT == PT_IntAPS)
-      return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE);
+      return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE) &&
+             maybeNegate();
 
     if (FromT == ToT)
       return true;
     if (!this->emitCast(*FromT, *ToT, CE))
       return false;
 
-    if (CE->getCastKind() == CK_BooleanToSignedIntegral)
-      return this->emitNeg(*ToT, CE);
-    return true;
+    return maybeNegate();
   }
 
   case CK_PointerToBoolean:

diff  --git a/clang/test/AST/Interp/vectors.cpp b/clang/test/AST/Interp/vectors.cpp
index b25d4d8a2df9aa..cf10d9416e9567 100644
--- a/clang/test/AST/Interp/vectors.cpp
+++ b/clang/test/AST/Interp/vectors.cpp
@@ -90,3 +90,14 @@ namespace Temporaries {
   };
   int &&s = S().w[1];
 }
+
+#ifdef __SIZEOF_INT128__
+namespace bigint {
+  typedef __attribute__((__ext_vector_type__(4))) __int128 bigint4;
+  constexpr bigint4 A = (bigint4)true;
+  static_assert(A[0] == -1, "");
+  static_assert(A[1] == -1, "");
+  static_assert(A[2] == -1, "");
+  static_assert(A[3] == -1, "");
+}
+#endif


        


More information about the cfe-commits mailing list