Johannes Doerfert via llvm-dev
2021-Mar-10 17:16 UTC
[llvm-dev] Is a global without definitive initializer not "sized"?
Why do we require a definitive initializer for global variables to be able to determine their size? The code in question is in `SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalVariable`, `llvm/lib/Analysis/MemoryBuiltins.cpp`. ~ Johannes -- ─────────────────── ∽ Johannes (he/his)
Tim Northover via llvm-dev
2021-Mar-10 19:46 UTC
[llvm-dev] Is a global without definitive initializer not "sized"?
On Wed, 10 Mar 2021 at 17:16, Johannes Doerfert via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Why do we require a definitive initializer for global variables to be > able to determine their size?Pragmatically it's probably because we allow different modules to declare globals with different types, as long as two don't claim to provide canonical yet different versions. Once you decide that's meaningful you pretty much have to say that a global that could end up with a different type has unknown size (or you might speculate an invalid load for example). I don't know why that decision was made though, it seems very old. I've never personally seen it exploited. From C, I *think* you might be able to legitimately get the situation with a `static` variable inside a C99 `inline` function. It'd be weird code though, and doesn't actually motivate the size assumption part itself. Cheers. Tim.