[llvm] 2e9549d - [LangRef] Global variable declarations imply minimum size

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 13 23:23:45 PST 2023


Author: Nikita Popov
Date: 2023-02-14T08:23:37+01:00
New Revision: 2e9549db268645accb83ebf031fbb1de84b00ca9

URL: https://github.com/llvm/llvm-project/commit/2e9549db268645accb83ebf031fbb1de84b00ca9
DIFF: https://github.com/llvm/llvm-project/commit/2e9549db268645accb83ebf031fbb1de84b00ca9.diff

LOG: [LangRef] Global variable declarations imply minimum size

Adjust the wording added in 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

Differential Revision: https://reviews.llvm.org/D143057

Added: 
    

Modified: 
    llvm/docs/LangRef.rst

Removed: 
    


################################################################################
diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 16e20293a622..cd51a42de24f 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -721,12 +721,11 @@ limits the alignment to the given value. Optimizers are not allowed to
 impose a stronger alignment on these variables. 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>`,


        


More information about the llvm-commits mailing list