Skip to content

Commit

Permalink
linker/test: add in the missing (mandatory) OpMemoryModel instructi…
Browse files Browse the repository at this point in the history
…ons.
  • Loading branch information
eddyb committed Nov 22, 2022
1 parent 970460c commit c0dde65
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions crates/rustc_codegen_spirv/src/linker/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn without_header_eq(mut result: Module, expected: &str) {
fn standard() {
let a = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Import
%2 = OpTypeFloat 32
%1 = OpVariable %2 Uniform
Expand All @@ -168,6 +169,7 @@ fn standard() {

let b = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Export
%2 = OpTypeFloat 32
%3 = OpConstant %2 42
Expand All @@ -176,7 +178,8 @@ fn standard() {
);

let result = assemble_and_link(&[&a, &b]).unwrap();
let expect = r#"%1 = OpTypeFloat 32
let expect = r#"OpMemoryModel Logical OpenCL
%1 = OpTypeFloat 32
%2 = OpVariable %1 Input
%3 = OpConstant %1 42.0
%4 = OpVariable %1 Uniform %3"#;
Expand All @@ -188,13 +191,15 @@ fn standard() {
fn not_a_lib_extra_exports() {
let a = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Export
%2 = OpTypeFloat 32
%1 = OpVariable %2 Uniform"#,
);

let result = assemble_and_link(&[&a]).unwrap();
let expect = r#"%1 = OpTypeFloat 32
let expect = r#"OpMemoryModel Logical OpenCL
%1 = OpTypeFloat 32
%2 = OpVariable %1 Uniform"#;
without_header_eq(result, expect);
}
Expand All @@ -203,12 +208,16 @@ fn not_a_lib_extra_exports() {
fn unresolved_symbol() {
let a = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Import
%2 = OpTypeFloat 32
%1 = OpVariable %2 Uniform"#,
);

let b = assemble_spirv("OpCapability Linkage");
let b = assemble_spirv(
"OpCapability Linkage
OpMemoryModel Logical OpenCL",
);

let result = assemble_and_link(&[&a, &b]);

Expand All @@ -222,6 +231,7 @@ fn unresolved_symbol() {
fn type_mismatch() {
let a = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Import
%2 = OpTypeFloat 32
%1 = OpVariable %2 Uniform
Expand All @@ -230,6 +240,7 @@ fn type_mismatch() {

let b = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Export
%2 = OpTypeInt 32 0
%3 = OpConstant %2 42
Expand All @@ -248,6 +259,7 @@ fn type_mismatch() {
fn multiple_definitions() {
let a = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Import
%2 = OpTypeFloat 32
%1 = OpVariable %2 Uniform
Expand All @@ -257,6 +269,7 @@ fn multiple_definitions() {
let b = assemble_spirv(
r#"OpCapability Linkage
OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Export
%2 = OpTypeFloat 32
%3 = OpConstant %2 42
Expand All @@ -265,6 +278,7 @@ fn multiple_definitions() {

let c = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Export
%2 = OpTypeFloat 32
%3 = OpConstant %2 -1
Expand All @@ -282,6 +296,7 @@ fn multiple_definitions() {
fn multiple_definitions_different_types() {
let a = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Import
%2 = OpTypeFloat 32
%1 = OpVariable %2 Uniform
Expand All @@ -291,6 +306,7 @@ fn multiple_definitions_different_types() {
let b = assemble_spirv(
r#"OpCapability Linkage
OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Export
%2 = OpTypeInt 32 0
%3 = OpConstant %2 42
Expand All @@ -299,6 +315,7 @@ fn multiple_definitions_different_types() {

let c = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Export
%2 = OpTypeFloat 32
%3 = OpConstant %2 12
Expand All @@ -317,6 +334,7 @@ fn multiple_definitions_different_types() {
fn decoration_mismatch() {
let a = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Import
OpDecorate %2 Constant
%2 = OpTypeFloat 32
Expand All @@ -326,6 +344,7 @@ fn decoration_mismatch() {
let b = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Export
%2 = OpTypeFloat 32
%3 = OpConstant %2 42
Expand All @@ -344,6 +363,7 @@ fn decoration_mismatch() {
fn func_ctrl() {
let a = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Import
%2 = OpTypeVoid
%3 = OpTypeFunction %2
Expand All @@ -355,6 +375,7 @@ fn func_ctrl() {

let b = assemble_spirv(
r#"OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Export
%2 = OpTypeVoid
%3 = OpTypeFunction %2
Expand All @@ -366,7 +387,8 @@ fn func_ctrl() {

let result = assemble_and_link(&[&a, &b]).unwrap();

let expect = r#"%1 = OpTypeVoid
let expect = r#"OpMemoryModel Logical OpenCL
%1 = OpTypeVoid
%2 = OpTypeFunction %1
%3 = OpTypeFloat 32
%4 = OpVariable %3 Uniform
Expand All @@ -383,6 +405,7 @@ fn use_exported_func_param_attr() {
let a = assemble_spirv(
r#"OpCapability Kernel
OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Import
OpDecorate %3 FuncParamAttr Zext
OpDecorate %4 FuncParamAttr Zext
Expand All @@ -404,6 +427,7 @@ fn use_exported_func_param_attr() {
let b = assemble_spirv(
r#"OpCapability Kernel
OpCapability Linkage
OpMemoryModel Logical OpenCL
OpDecorate %1 LinkageAttributes "foo" Export
OpDecorate %2 FuncParamAttr Sext
%3 = OpTypeVoid
Expand All @@ -421,6 +445,7 @@ fn use_exported_func_param_attr() {
let result = assemble_and_link(&[&a, &b]).unwrap();

let expect = r#"OpCapability Kernel
OpMemoryModel Logical OpenCL
OpDecorate %1 FuncParamAttr Zext
OpDecorate %2 FuncParamAttr Sext
%3 = OpTypeVoid
Expand All @@ -447,6 +472,7 @@ fn names_and_decorations() {
let a = assemble_spirv(
r#"OpCapability Kernel
OpCapability Linkage
OpMemoryModel Logical OpenCL
OpName %1 "foo"
OpName %3 "param"
OpDecorate %1 LinkageAttributes "foo" Import
Expand All @@ -472,6 +498,7 @@ fn names_and_decorations() {
let b = assemble_spirv(
r#"OpCapability Kernel
OpCapability Linkage
OpMemoryModel Logical OpenCL
OpName %1 "foo"
OpName %2 "param"
OpDecorate %1 LinkageAttributes "foo" Export
Expand All @@ -492,6 +519,7 @@ fn names_and_decorations() {
let result = assemble_and_link(&[&a, &b]).unwrap();

let expect = r#"OpCapability Kernel
OpMemoryModel Logical OpenCL
OpName %1 "foo"
OpName %2 "param"
OpDecorate %3 Restrict
Expand Down

0 comments on commit c0dde65

Please sign in to comment.