@@ -3883,8 +3883,11 @@ OpMemoryModel Logical GLSL450
3883
3883
%void = OpTypeVoid
3884
3884
%bool = OpTypeBool
3885
3885
%int = OpTypeInt 32 0
3886
+ %float = OpTypeFloat 32
3886
3887
%ptr_int = OpTypePointer Private %int
3887
3888
%var = OpVariable %ptr_int Private
3889
+ %ptr_float = OpTypePointer Private %float
3890
+ %var2 = OpVariable %ptr_float Private
3888
3891
%func_ty = OpTypeFunction %void
3889
3892
%func = OpFunction %void None %func_ty
3890
3893
%1 = OpLabel
@@ -3897,7 +3900,7 @@ OpMemoryModel Logical GLSL450
3897
3900
spirv += " %bool " ;
3898
3901
}
3899
3902
3900
- spirv += R"( %var %ld
3903
+ spirv += R"( %var %var2
3901
3904
OpReturn
3902
3905
OpFunctionEnd
3903
3906
)" ;
@@ -3908,6 +3911,223 @@ OpFunctionEnd
3908
3911
HasSubstr (" The types of Operand 1 and Operand 2 must match" ));
3909
3912
}
3910
3913
3914
+ TEST_P (ValidatePointerComparisons, GoodUntypedPointerSameType) {
3915
+ const std::string operation = GetParam ();
3916
+
3917
+ std::string spirv = R"(
3918
+ OpCapability Shader
3919
+ OpCapability Linkage
3920
+ OpCapability VariablePointersStorageBuffer
3921
+ OpCapability UntypedPointersKHR
3922
+ OpExtension "SPV_KHR_untyped_pointers"
3923
+ OpMemoryModel Logical GLSL450
3924
+ %void = OpTypeVoid
3925
+ %bool = OpTypeBool
3926
+ %int = OpTypeInt 32 0
3927
+ %ptr = OpTypeUntypedPointerKHR StorageBuffer
3928
+ %var = OpUntypedVariableKHR %ptr StorageBuffer
3929
+ %func_ty = OpTypeFunction %void
3930
+ %func = OpFunction %void None %func_ty
3931
+ %1 = OpLabel
3932
+ %equal = )" + operation;
3933
+
3934
+ if (operation == " OpPtrDiff" ) {
3935
+ spirv += " %int " ;
3936
+ } else {
3937
+ spirv += " %bool " ;
3938
+ }
3939
+
3940
+ spirv += R"( %var %var
3941
+ OpReturn
3942
+ OpFunctionEnd
3943
+ )" ;
3944
+
3945
+ CompileSuccessfully (spirv, SPV_ENV_UNIVERSAL_1_4);
3946
+ EXPECT_EQ (SPV_SUCCESS, ValidateInstructions (SPV_ENV_UNIVERSAL_1_4));
3947
+ }
3948
+
3949
+ TEST_P (ValidatePointerComparisons, GoodUntypedPointerSameStorageClass) {
3950
+ const std::string operation = GetParam ();
3951
+
3952
+ std::string spirv = R"(
3953
+ OpCapability Shader
3954
+ OpCapability Linkage
3955
+ OpCapability VariablePointersStorageBuffer
3956
+ OpCapability UntypedPointersKHR
3957
+ OpExtension "SPV_KHR_untyped_pointers"
3958
+ OpMemoryModel Logical GLSL450
3959
+ %void = OpTypeVoid
3960
+ %bool = OpTypeBool
3961
+ %int = OpTypeInt 32 0
3962
+ %ptr1 = OpTypeUntypedPointerKHR StorageBuffer
3963
+ %var = OpUntypedVariableKHR %ptr1 StorageBuffer
3964
+ %ptr2 = OpTypeUntypedPointerKHR StorageBuffer
3965
+ %var2 = OpUntypedVariableKHR %ptr2 StorageBuffer
3966
+ %func_ty = OpTypeFunction %void
3967
+ %func = OpFunction %void None %func_ty
3968
+ %1 = OpLabel
3969
+ %equal = )" + operation;
3970
+
3971
+ if (operation == " OpPtrDiff" ) {
3972
+ spirv += " %int " ;
3973
+ } else {
3974
+ spirv += " %bool " ;
3975
+ }
3976
+
3977
+ spirv += R"( %var %var2
3978
+ OpReturn
3979
+ OpFunctionEnd
3980
+ )" ;
3981
+
3982
+ CompileSuccessfully (spirv, SPV_ENV_UNIVERSAL_1_4);
3983
+ if (operation == " OpPtrDiff" ) {
3984
+ EXPECT_EQ (SPV_ERROR_INVALID_ID,
3985
+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4));
3986
+ EXPECT_THAT (getDiagnosticString (),
3987
+ HasSubstr (" The types of Operand 1 and Operand 2 must match" ));
3988
+ } else {
3989
+ EXPECT_EQ (SPV_SUCCESS, ValidateInstructions (SPV_ENV_UNIVERSAL_1_4));
3990
+ }
3991
+ }
3992
+
3993
+ TEST_P (ValidatePointerComparisons, BadUntypedPointerDiffStorageClass) {
3994
+ const std::string operation = GetParam ();
3995
+
3996
+ std::string spirv = R"(
3997
+ OpCapability Shader
3998
+ OpCapability Linkage
3999
+ OpCapability VariablePointers
4000
+ OpCapability UntypedPointersKHR
4001
+ OpExtension "SPV_KHR_untyped_pointers"
4002
+ OpMemoryModel Logical GLSL450
4003
+ %void = OpTypeVoid
4004
+ %bool = OpTypeBool
4005
+ %int = OpTypeInt 32 0
4006
+ %ptr1 = OpTypeUntypedPointerKHR StorageBuffer
4007
+ %var1 = OpUntypedVariableKHR %ptr1 StorageBuffer
4008
+ %ptr2 = OpTypeUntypedPointerKHR Workgroup
4009
+ %var2 = OpUntypedVariableKHR %ptr2 Workgroup %int
4010
+ %func_ty = OpTypeFunction %void
4011
+ %func = OpFunction %void None %func_ty
4012
+ %1 = OpLabel
4013
+ %equal = )" + operation;
4014
+
4015
+ if (operation == " OpPtrDiff" ) {
4016
+ spirv += " %int " ;
4017
+ } else {
4018
+ spirv += " %bool " ;
4019
+ }
4020
+
4021
+ spirv += R"( %var1 %var2
4022
+ OpReturn
4023
+ OpFunctionEnd
4024
+ )" ;
4025
+
4026
+ CompileSuccessfully (spirv, SPV_ENV_UNIVERSAL_1_4);
4027
+ if (operation == " OpPtrDiff" ) {
4028
+ EXPECT_EQ (SPV_ERROR_INVALID_ID,
4029
+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4));
4030
+ EXPECT_THAT (getDiagnosticString (),
4031
+ HasSubstr (" The types of Operand 1 and Operand 2 must match" ));
4032
+ } else {
4033
+ EXPECT_EQ (SPV_ERROR_INVALID_ID,
4034
+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4));
4035
+ EXPECT_THAT (getDiagnosticString (),
4036
+ HasSubstr (" Pointer storage classes must match" ));
4037
+ }
4038
+ }
4039
+
4040
+ TEST_P (ValidatePointerComparisons, GoodMixedPointerSameStorageClass) {
4041
+ const std::string operation = GetParam ();
4042
+
4043
+ std::string spirv = R"(
4044
+ OpCapability Shader
4045
+ OpCapability Linkage
4046
+ OpCapability VariablePointersStorageBuffer
4047
+ OpCapability UntypedPointersKHR
4048
+ OpExtension "SPV_KHR_untyped_pointers"
4049
+ OpMemoryModel Logical GLSL450
4050
+ %void = OpTypeVoid
4051
+ %bool = OpTypeBool
4052
+ %int = OpTypeInt 32 0
4053
+ %ptr1 = OpTypeUntypedPointerKHR StorageBuffer
4054
+ %var = OpUntypedVariableKHR %ptr1 StorageBuffer
4055
+ %ptr2 = OpTypePointer StorageBuffer %int
4056
+ %var2 = OpVariable %ptr2 StorageBuffer
4057
+ %func_ty = OpTypeFunction %void
4058
+ %func = OpFunction %void None %func_ty
4059
+ %1 = OpLabel
4060
+ %equal = )" + operation;
4061
+
4062
+ if (operation == " OpPtrDiff" ) {
4063
+ spirv += " %int " ;
4064
+ } else {
4065
+ spirv += " %bool " ;
4066
+ }
4067
+
4068
+ spirv += R"( %var %var2
4069
+ OpReturn
4070
+ OpFunctionEnd
4071
+ )" ;
4072
+
4073
+ CompileSuccessfully (spirv, SPV_ENV_UNIVERSAL_1_4);
4074
+ if (operation == " OpPtrDiff" ) {
4075
+ EXPECT_EQ (SPV_ERROR_INVALID_ID,
4076
+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4));
4077
+ EXPECT_THAT (getDiagnosticString (),
4078
+ HasSubstr (" The types of Operand 1 and Operand 2 must match" ));
4079
+ } else {
4080
+ EXPECT_EQ (SPV_SUCCESS, ValidateInstructions (SPV_ENV_UNIVERSAL_1_4));
4081
+ }
4082
+ }
4083
+
4084
+ TEST_P (ValidatePointerComparisons, BadMixedPointerDiffStorageClass) {
4085
+ const std::string operation = GetParam ();
4086
+
4087
+ std::string spirv = R"(
4088
+ OpCapability Shader
4089
+ OpCapability Linkage
4090
+ OpCapability VariablePointers
4091
+ OpCapability UntypedPointersKHR
4092
+ OpExtension "SPV_KHR_untyped_pointers"
4093
+ OpMemoryModel Logical GLSL450
4094
+ %void = OpTypeVoid
4095
+ %bool = OpTypeBool
4096
+ %int = OpTypeInt 32 0
4097
+ %ptr1 = OpTypeUntypedPointerKHR StorageBuffer
4098
+ %var1 = OpUntypedVariableKHR %ptr1 StorageBuffer
4099
+ %ptr2 = OpTypePointer Workgroup %int
4100
+ %var2 = OpVariable %ptr2 Workgroup
4101
+ %func_ty = OpTypeFunction %void
4102
+ %func = OpFunction %void None %func_ty
4103
+ %1 = OpLabel
4104
+ %equal = )" + operation;
4105
+
4106
+ if (operation == " OpPtrDiff" ) {
4107
+ spirv += " %int " ;
4108
+ } else {
4109
+ spirv += " %bool " ;
4110
+ }
4111
+
4112
+ spirv += R"( %var1 %var2
4113
+ OpReturn
4114
+ OpFunctionEnd
4115
+ )" ;
4116
+
4117
+ CompileSuccessfully (spirv, SPV_ENV_UNIVERSAL_1_4);
4118
+ if (operation == " OpPtrDiff" ) {
4119
+ EXPECT_EQ (SPV_ERROR_INVALID_ID,
4120
+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4));
4121
+ EXPECT_THAT (getDiagnosticString (),
4122
+ HasSubstr (" The types of Operand 1 and Operand 2 must match" ));
4123
+ } else {
4124
+ EXPECT_EQ (SPV_ERROR_INVALID_ID,
4125
+ ValidateInstructions (SPV_ENV_UNIVERSAL_1_4));
4126
+ EXPECT_THAT (getDiagnosticString (),
4127
+ HasSubstr (" Pointer storage classes must match" ));
4128
+ }
4129
+ }
4130
+
3911
4131
INSTANTIATE_TEST_SUITE_P (PointerComparisons, ValidatePointerComparisons,
3912
4132
Values (" OpPtrEqual" , " OpPtrNotEqual" , " OpPtrDiff" ));
3913
4133
0 commit comments