-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
[NFC] Test behavior of common global variables (#2306)
Add tests to ensure that: A common global without addrspace is reported as an error A common addrspace global is not transformed to a locally allocated variable Updated error message from "can not" to "cannot". Otherwise this is a NFC. Signed-off-by: Lu, John <[email protected]>
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
; Ensure "common global" with no addrspace is reported as an error | ||
; since the SPIR-V spec states: | ||
; | ||
; global variable declarations must always have an address space | ||
; specified and that address space cannot be `0` | ||
|
||
; RUN: llvm-as %s -o %t.bc | ||
; RUN: not llvm-spirv %t.bc 2>&1 \ | ||
; RUN: | FileCheck %s --check-prefix=CHECK-ERROR | ||
|
||
; CHECK-ERROR: InvalidInstruction: Can't translate llvm instruction: | ||
; CHECK-ERROR-NEXT: Global variable cannot have Function storage class. Consider setting a proper address space. | ||
; CHECK-ERROR-NEXT: Original LLVM value: | ||
; CHECK-ERROR-NEXT: @CG = common global i32 0, align 4 | ||
|
||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" | ||
target triple = "spir64-unknown-unknown" | ||
|
||
@CG = common global i32 0, align 4 | ||
|
||
define i32 @f() #0 { | ||
%1 = load i32, i32* @CG, align 4 | ||
ret i32 %1 | ||
} |
10 changes: 9 additions & 1 deletion
10
test/GlobalVarNoAddrspace.ll → test/negative/GlobalVarNoAddrspace.ll
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
; Ensure that a "common global" is not converted to a locally allocated | ||
; variable when translated to SPIR-V and back to LLVM. | ||
|
||
; RUN: llvm-as %s -o %t.bc | ||
; RUN: llvm-spirv %t.bc -o %t.spv | ||
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc | ||
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM | ||
|
||
; CHECK-LLVM-NOT: alloca | ||
; CHECK-LLVM: @CAG = common addrspace(1) global i32 0, align 4 | ||
; CHECK-LLVM-NOT: alloca | ||
|
||
target triple = "spir64-unknown-unknown" | ||
|
||
@CAG = common addrspace(1) global i32 0, align 4 | ||
|
||
define i32 @f() #0 { | ||
%1 = load i32, i32 addrspace(1) * @CAG, align 4 | ||
ret i32 %1 | ||
} |