-
Notifications
You must be signed in to change notification settings - Fork 18.1k
[Verifier] Make verifier fail when global variable size exceeds address space size #179625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -955,6 +955,16 @@ 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 | ||
| // by an access in the address space being able to reach all bytes of the | ||
| // type. | ||
| Check(GVType->isScalableTy() || !GVType->isSized() || | ||
| GV.getGlobalSize(DL) == 0 || | ||
| isUIntN(DL.getAddressSizeInBits(GV.getAddressSpace()), | ||
| GV.getGlobalSize(DL) - 1), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strictly speaking objects can only take up half the address space. But even if we don't enforce that as an IR well-formedness requirement, I think we should at least be dropping the -1 here, otherwise we're still going to be dealing with overflow issues. |
||
| "Global variable is too large to fit into the address space", &GV, | ||
| GVType); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth noting that this doesn't catch cases that overflow during the size calculation, but that's something we can handle separately... |
||
|
|
||
| if (!GV.hasInitializer()) { | ||
| visitGlobalValue(GV); | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| ; RUN: not opt -S -passes=verify < %s 2>&1 | FileCheck %s | ||
|
|
||
| target datalayout = "e-m:e-p1:16:16-p2:32:32-p3:64:64-i8:8-i32:32-i64:64" | ||
|
|
||
| ; Too large for 16-bit address space. | ||
| @G1 = internal addrspace(1) global [65537 x i8] zeroinitializer, align 4 | ||
|
|
||
| ; Too large for 32-bit address space. | ||
| @G2 = internal addrspace(2) global [2147483649 x i16] zeroinitializer, align 4 | ||
|
|
||
| ; Fit within the address spaces | ||
| @G3 = internal addrspace(1) global [65536 x i8] zeroinitializer, align 4 | ||
| @G4 = internal addrspace(2) global [2147483648 x i16] zeroinitializer, align 4 | ||
|
|
||
| ; CHECK: Global variable is too large to fit into the address space | ||
| ; CHECK-NEXT: ptr addrspace(1) @G1 | ||
| ; CHECK-NEXT: [65537 x i8] | ||
| ; CHECK: Global variable is too large to fit into the address space | ||
| ; CHECK-NEXT: ptr addrspace(2) @G2 | ||
| ; CHECK-NEXT: [2147483649 x i16] | ||
| ; CHECK-NOT: Global variable is too large to fit into the address space |
Uh oh!
There was an error while loading. Please reload this page.