[llvm-dev] Is a global without definitive initializer not "sized"?

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 10 11:46:10 PST 2021


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.


More information about the llvm-dev mailing list