[llvm] Don't rely on undefined behavior to store how a `User` object's allocation is laid out (PR #105714)
Daniel Paoliello via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 9 17:29:29 PDT 2024
================
@@ -454,6 +453,9 @@ GlobalVariable::GlobalVariable(Type *Ty, bool constant, LinkageTypes Link,
assert(InitVal->getType() == Ty &&
"Initializer should be the same type as the GlobalVariable!");
Op<0>() = InitVal;
+ } else {
+ // HACK: This is incorrect, we should have allocated less memory.
----------------
dpaoliello wrote:
Ah, I didn't see that `operator delete` fixed this!
I moved the fixup into the destructor, and moved `setGlobalVariableNumOperands` into `GlobalVariable` and made it private (as it's only used in `GlobalVariable`).
I also removed my comment in the ctor as I'm now calling `setGlobalVariableNumOperands` and that (and the dtor) have comments to explain what's happening.
https://github.com/llvm/llvm-project/pull/105714
More information about the llvm-commits
mailing list