Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) ||
Comment thread
steffenlarsen marked this conversation as resolved.
Outdated
isUIntN(DL.getAddressSizeInBits(GV.getAddressSpace()),
GV.getGlobalSize(DL)),
"Global variable is too large to fit into the address space", &GV,
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/Verifier/global-var-too-big.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading