Linkage type was only referenced for functions, not for global variables.
Clarify that LLVM doesn't make assumption about the allocation size when no definitive initializer for a global variable is known.
Differential D78952
[LangRef] Describe linkage types, allocation size of declarations for global variables NeoRaider on Apr 27 2020, 12:21 PM. Authored by
Details Linkage type was only referenced for functions, not for global variables. Clarify that LLVM doesn't make assumption about the allocation size when no definitive initializer for a global variable is known.
Diff Detail Event TimelineComment Actions I don't want to take this too far off track, but there are some additional caveats which might not be obvious to someone reading this rule:
Not sure if it makes sense to modify the language here.
Comment Actions Makes sense, I'll add this.
Question regarding alignment: I would expect that a variable declaration with lower alignment than the definition it refers to should be fine. For example, when declaring an extern global variable of a forward-declared struct type in C, clang will use an opaque type with alignment 1 for the declaration.
Comment Actions
Sure, the alignment specified on a declaration can be lower than the alignment on the definition. Comment Actions In getPointerDereferenceableBytes(), we currently assume that non-extern_weak globals are dereferenceable up to their type store size: https://github.com/llvm/llvm-project/blob/2153544865a9733b06579823814c981f735e4201/llvm/lib/IR/Value.cpp#L907 In ConstantFoldGetElementPtr(), we currently assume that GEPs without notional overindexing are inbounds of non-extern_weak globals: https://github.com/llvm/llvm-project/blob/2153544865a9733b06579823814c981f735e4201/llvm/lib/IR/ConstantFold.cpp#L2283 (Note that this code is broken for other reasons, it's missing a pointee type check -- this is why I'm looking into this in the first place.) In getObjectSize() we do check for a definitive initializer: https://github.com/llvm/llvm-project/blob/a6f66d57e1d626a9b676f6e3ec0e084bdca3a934/llvm/lib/Analysis/MemoryBuiltins.cpp#L821 So I wanted to double check what the intended semantics here are. For a global without definitive initializer, do we assume that the global is *at least* as large as the value type, or do we allow it to be smaller? If the latter, then we need to fix our dereferencability assumptions. Comment Actions I've put up D142970 as an incomplete patch to remove the dereferencability assumption. Not sure this is a good idea. |
Not sure the italics are necessary.