[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 27 17:34:16 PDT 2023


================
@@ -7095,6 +7157,22 @@ class APValueToBufferConverter {
     return true;
   }
 
+  bool visitVector(const APValue &Val, QualType Ty, CharUnits Offset) {
+    const VectorType *VTy = Ty->castAs<VectorType>();
+
+    APInt Bits;
+    if (!BitcastVectorToAPInt(Info, VTy, Val, Bits))
+      return false;
+
+    assert(Bits.getBitWidth() == Info.Ctx.getTypeSize(Ty));
+
+    unsigned Width = Bits.getBitWidth();
+    SmallVector<uint8_t, 8> Bytes(Width / 8);
+    llvm::StoreIntToMemory(Bits, &*Bytes.begin(), Width / 8);
+    Buffer.writeObject(Offset, Bytes);
----------------
zygoloid wrote:

Are the padding bits of an x86 fp80 vector defined? If not, we'll need to avoid marking them as initialized here...

https://github.com/llvm/llvm-project/pull/66894


More information about the cfe-commits mailing list