[clang] [clang][bytecode][NFC] Code size is always aligned (PR #151824)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 2 22:28:25 PDT 2025


================
@@ -137,21 +137,21 @@ int32_t ByteCodeEmitter::getOffset(LabelTy Label) {
 template <typename T>
 static void emit(Program &P, std::vector<std::byte> &Code, const T &Val,
                  bool &Success) {
+  size_t ValPos = Code.size();
   size_t Size;
 
   if constexpr (std::is_pointer_v<T>)
-    Size = sizeof(uint32_t);
+    Size = align(sizeof(uint32_t));
   else
-    Size = sizeof(T);
+    Size = align(sizeof(T));
 
-  if (Code.size() + Size > std::numeric_limits<unsigned>::max()) {
+  if (ValPos + Size > std::numeric_limits<unsigned>::max()) {
----------------
tbaederr wrote:

That test was pre-existing so I haven't touched it at all. I thought it works because the LHS is 64 bits and the RHS only 32, so LHS can't overflow.

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


More information about the cfe-commits mailing list