[clang] [clang][Interp] Support arbitrary precision constants (PR #79747)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 30 08:56:09 PST 2024


================
@@ -228,6 +229,42 @@ void emit(Program &P, std::vector<std::byte> &Code, const Floating &Val,
   Val.serialize(Code.data() + ValPos);
 }
 
+template <>
+void emit(Program &P, std::vector<std::byte> &Code,
+          const IntegralAP<false> &Val, bool &Success) {
+  size_t Size = Val.bytesToSerialize();
+
+  if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
+    Success = false;
+    return;
+  }
+
+  // Access must be aligned!
+  size_t ValPos = align(Code.size());
+  Size = align(Size);
+  assert(aligned(ValPos + Size));
+  Code.resize(ValPos + Size);
+  Val.serialize(Code.data() + ValPos);
+}
+
+template <>
+void emit(Program &P, std::vector<std::byte> &Code, const IntegralAP<true> &Val,
+          bool &Success) {
+  size_t Size = Val.bytesToSerialize();
+
+  if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
+    Success = false;
+    return;
+  }
+
+  // Access must be aligned!
+  size_t ValPos = align(Code.size());
+  Size = align(Size);
+  assert(aligned(ValPos + Size));
+  Code.resize(ValPos + Size);
+  Val.serialize(Code.data() + ValPos);
+}
----------------
AaronBallman wrote:

Yeah, I think that's not going to be possible without contortions; going with a templated implementation method that's called from each of these functions may be the better approach.

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


More information about the cfe-commits mailing list