From 2e9549db268645accb83ebf031fbb1de84b00ca9 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 1 Feb 2023 11:18:47 +0100 Subject: [PATCH] [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 --- llvm/docs/LangRef.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 16e2029..cd51a42 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 `, an optional :ref:`runtime preemption specifier `, -- 2.7.4