[Verifier] Allow too big unused sectioned global variables with local linkage - #212733
Open
steffenlarsen wants to merge 3 commits into
Open
[Verifier] Allow too big unused sectioned global variables with local linkage#212733steffenlarsen wants to merge 3 commits into
steffenlarsen wants to merge 3 commits into
Conversation
… linkage This commit adjusts the check added in llvm#179625 to allow global variables that are too big for their address space if they are unused, have local linkage, and have a section. This allows metadata embedded in global variables, like __clang_ast, to exceed the limits. Signed-off-by: Steffen Holst Larsen <sholstla@amd.com>
|
@llvm/pr-subscribers-llvm-ir Author: Steffen Larsen (steffenlarsen) ChangesThis commit adjusts the check added in #179625 to allow global variables that are too big for their address space if they are unused, have local linkage, and have a section. This allows metadata embedded in global variables, like __clang_ast, to exceed the limits. Full diff: https://github.com/llvm/llvm-project/pull/212733.diff 2 Files Affected:
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 90ad2e5bc8f68..f523fa869a27e 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -812,10 +812,13 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
"Global @" + GV.getName() + " has illegal target extension type",
GVType);
- // Check that the the address space can hold all bits of the type, recognized
+ // Check that the address space can hold all bits of the type, recognized
// by an access in the address space being able to reach all bytes of the
// type.
+ // An exemption to this is sectioned global variables with local linkage
+ // and no uses. These are usually used for metadata.
Check(!GVType->isSized() ||
+ (GV.use_empty() && GV.hasLocalLinkage() && GV.hasSection()) ||
isUIntN(DL.getAddressSizeInBits(GV.getAddressSpace()),
GV.getGlobalSize(DL)),
"Global variable is too large to fit into the address space", &GV,
diff --git a/llvm/test/Verifier/global-var-too-big.ll b/llvm/test/Verifier/global-var-too-big.ll
index fecb021145ae1..cd5c4bba7f78c 100644
--- a/llvm/test/Verifier/global-var-too-big.ll
+++ b/llvm/test/Verifier/global-var-too-big.ll
@@ -12,10 +12,27 @@ target datalayout = "e-m:e-p1:16:16-p2:32:32-p3:64:64-i8:8-i32:32-i64:64"
@G3 = internal addrspace(1) global [65535 x i8] zeroinitializer, align 4
@G4 = internal addrspace(2) global [2147483647 x i16] zeroinitializer, align 4
+; Too large but exempt: unreferenced, local linkage, has a section.
+@G5 = internal addrspace(1) global [65536 x i8] zeroinitializer, section "some_section_1", align 4
+@G6 = private addrspace(1) global [65536 x i8] zeroinitializer, section "some_section_2", align 4
+
+; Too large, has a section, but has a use so not exempt.
+@G7 = internal addrspace(1) global [65536 x i8] zeroinitializer, section "some_section_3", align 4
+@G7_user = global ptr addrspace(1) @G7
+
+; Too large, unreferenced, has a section, but external linkage so not exempt.
+@G8 = addrspace(1) global [65536 x i8] zeroinitializer, section "some_section_4", align 4
+
; CHECK: Global variable is too large to fit into the address space
; CHECK-NEXT: ptr addrspace(1) @G1
; CHECK-NEXT: [65536 x i8]
; CHECK: Global variable is too large to fit into the address space
; CHECK-NEXT: ptr addrspace(2) @G2
; CHECK-NEXT: [2147483648 x i16]
+; CHECK: Global variable is too large to fit into the address space
+; CHECK-NEXT: ptr addrspace(1) @G7
+; CHECK-NEXT: [65536 x i8]
+; CHECK: Global variable is too large to fit into the address space
+; CHECK-NEXT: ptr addrspace(1) @G8
+; CHECK-NEXT: [65536 x i8]
; CHECK-NOT: Global variable is too large to fit into the address space
|
Signed-off-by: Steffen Holst Larsen <sholstla@amd.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit adjusts the check added in #179625 to allow global variables that are too big for their address space if they are unused, have local linkage, and have a section. This allows metadata embedded in global variables, like __clang_ast, to exceed the limits.