[PATCH] D143057: [LangRef] Global variable declarations imply minimum size

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 1 02:22:20 PST 2023


nikic created this revision.
nikic added reviewers: efriedma, jdoerfert, arsenm.
Herald added a subscriber: StephenFan.
Herald added a project: All.
nikic requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

Adjust the wording added in D78952 <https://reviews.llvm.org/D78952> to say that global variable declarations (and interposable definitions) do imply a minimum size (and alignment) on the global. They just don't imply a maximum size.

We rely on these semantics in at least two places:

- Global dereferenceability: https://github.com/llvm/llvm-project/blob/2153544865a9733b06579823814c981f735e4201/llvm/lib/IR/Value.cpp#L907
- Global inbounds GEP: https://github.com/llvm/llvm-project/blob/2153544865a9733b06579823814c981f735e4201/llvm/lib/IR/ConstantFold.cpp#L2283


https://reviews.llvm.org/D143057

Files:
  llvm/docs/LangRef.rst


Index: llvm/docs/LangRef.rst
===================================================================
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -717,12 +717,11 @@
 iterate over them as an array, alignment padding would break this
 iteration. The maximum alignment is ``1 << 32``.
 
-For global variables declarations, as well as definitions that may be
+For global variable declarations, as well as definitions that may be
 replaced at link time (``linkonce``, ``weak``, ``extern_weak`` and ``common``
-linkage types), LLVM makes no assumptions about the allocation size of the
-variables, except that they may not overlap. The alignment of a global variable
-declaration or replaceable definition must not be greater than the alignment of
-the definition it resolves to.
+linkage types), the allocation size and alignment of the definition it resolves
+to must be greater than or equal to that of the declaration or replaceable
+definition, otherwise the behavior is undefined.
 
 Globals can also have a :ref:`DLL storage class <dllstorageclass>`,
 an optional :ref:`runtime preemption specifier <runtime_preemption_model>`,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143057.493879.patch
Type: text/x-patch
Size: 1135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230201/abf99ac6/attachment.bin>


More information about the llvm-commits mailing list