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

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 5 04:36:10 PDT 2023


================
@@ -7441,6 +7500,28 @@ static bool handleLValueToRValueBitCast(EvalInfo &Info, APValue &DestValue,
   return true;
 }
 
+static bool handleLValueToRValueBitCast(EvalInfo &Info, APValue &DestValue,
+                                        APValue &SourceValue,
+                                        const CastExpr *BCE) {
+  assert(CHAR_BIT == 8 && Info.Ctx.getTargetInfo().getCharWidth() == 8 &&
+         "no host or target supports non 8-bit chars");
+  assert(SourceValue.isLValue() &&
+         "LValueToRValueBitcast requires an lvalue operand!");
+
+  if (!checkBitCastConstexprEligibility(&Info, Info.Ctx, BCE))
+    return false;
----------------
DaMatrix wrote:

I did it this way so that `handleLValueToRValueBitCast` would be able to break out early to avoid copying the source LValue into an RValue if the expression wasn't eligible, but now that you mention it it doesn't make much sense to do an expensive check twice in order to optimize the exceptional path. Will remove this from `handleLValueToRValueBitCast`.

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


More information about the cfe-commits mailing list