Skip to content

Commit

Permalink
Use \n as delimiter for stripping OpenCL features
Browse files Browse the repository at this point in the history
The previous regex was matching a semicolon to end the string to be
removed, which was nuking many additional lines when matching macro
definitions like as_type().

Fixes google#166
  • Loading branch information
jrprice authored and dneto0 committed Aug 10, 2018
1 parent 3a0df83 commit 7654291
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 19 deletions.
35 changes: 16 additions & 19 deletions cmake/strip_banned_opencl_features.cmakescript
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,23 @@ endif()

file(READ "${STRIP_BANNED_OPENCL_FEATURES_INPUT_FILE}" lines)

string(REGEX REPLACE "\n[^;\n]*char8[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*char16[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*short8[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*short16[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*int8[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*int16[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*long8[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*long16[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*float8[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*float16[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*double8[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*double16[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*half8[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*half16[^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*char8[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*char16[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*short8[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*short16[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*int8[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*int16[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*long8[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*long16[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*float8[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*float16[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*double8[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*double16[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*half8[^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*half16[^\n]*" "" lines "${lines}")

string(REGEX REPLACE "\n[^;\n]*_rt[pn][^;]*;" "" lines "${lines}")
string(REGEX REPLACE "\n[^;\n]*_sat[^;]*;" "" lines "${lines}")

# get_work_dim gets stripped out, lets fudge it back in
string(REPLACE "#define __cnfn __attribute__((const))" "#define __cnfn __attribute__((const))\nunsigned int __ovld __cnfn get_work_dim(void);" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*_rt[pn][^\n]*" "" lines "${lines}")
string(REGEX REPLACE "\n[^\n]*_sat[^\n]*" "" lines "${lines}")

# Declare the invalid vector types so we can issue better error messages
set(BANNED_VECTOR_TYPES "")
Expand Down
70 changes: 70 additions & 0 deletions test/as_float.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Test for https://github.com/google/clspv/issues/166
// Function declarations were missing from builtin header.

// RUN: clspv %s -S -o %t.spvasm
// RUN: FileCheck %s < %t.spvasm
// RUN: clspv %s -o %t.spv
// RUN: spirv-dis -o %t2.spvasm %t.spv
// RUN: FileCheck %s < %t2.spvasm
// RUN: spirv-val --target-env vulkan1.0 %t.spv


kernel void foo(global float *A, uint a) {
*A = as_float(a);
}

// CHECK: ; SPIR-V
// CHECK: ; Version: 1.0
// CHECK: ; Generator: Codeplay; 0
// CHECK: ; Bound: 28
// CHECK: ; Schema: 0
// CHECK: OpCapability Shader
// CHECK: OpCapability VariablePointers
// CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
// CHECK: OpExtension "SPV_KHR_variable_pointers"
// CHECK: OpMemoryModel Logical GLSL450
// CHECK: OpEntryPoint GLCompute [[_22:%[0-9a-zA-Z_]+]] "foo"
// CHECK: OpSource OpenCL_C 120
// CHECK: OpDecorate [[_15:%[0-9a-zA-Z_]+]] SpecId 0
// CHECK: OpDecorate [[_16:%[0-9a-zA-Z_]+]] SpecId 1
// CHECK: OpDecorate [[_17:%[0-9a-zA-Z_]+]] SpecId 2
// CHECK: OpDecorate [[__runtimearr_float:%[0-9a-zA-Z_]+]] ArrayStride 4
// CHECK: OpMemberDecorate [[__struct_3:%[0-9a-zA-Z_]+]] 0 Offset 0
// CHECK: OpDecorate [[__struct_3]] Block
// CHECK: OpMemberDecorate [[__struct_6:%[0-9a-zA-Z_]+]] 0 Offset 0
// CHECK: OpDecorate [[__struct_6]] Block
// CHECK: OpDecorate [[_gl_WorkGroupSize:%[0-9a-zA-Z_]+]] BuiltIn WorkgroupSize
// CHECK: OpDecorate [[_20:%[0-9a-zA-Z_]+]] DescriptorSet 0
// CHECK: OpDecorate [[_20]] Binding 0
// CHECK: OpDecorate [[_21:%[0-9a-zA-Z_]+]] DescriptorSet 0
// CHECK: OpDecorate [[_21]] Binding 1
// CHECK: [[_float:%[0-9a-zA-Z_]+]] = OpTypeFloat 32
// CHECK: [[__runtimearr_float]] = OpTypeRuntimeArray [[_float]]
// CHECK: [[__struct_3]] = OpTypeStruct [[__runtimearr_float]]
// CHECK: [[__ptr_StorageBuffer__struct_3:%[0-9a-zA-Z_]+]] = OpTypePointer StorageBuffer [[__struct_3]]
// CHECK: [[_uint:%[0-9a-zA-Z_]+]] = OpTypeInt 32 0
// CHECK: [[__struct_6]] = OpTypeStruct [[_uint]]
// CHECK: [[__ptr_StorageBuffer__struct_6:%[0-9a-zA-Z_]+]] = OpTypePointer StorageBuffer [[__struct_6]]
// CHECK: [[_void:%[0-9a-zA-Z_]+]] = OpTypeVoid
// CHECK: [[_9:%[0-9a-zA-Z_]+]] = OpTypeFunction [[_void]]
// CHECK: [[__ptr_StorageBuffer_uint:%[0-9a-zA-Z_]+]] = OpTypePointer StorageBuffer [[_uint]]
// CHECK: [[__ptr_StorageBuffer_float:%[0-9a-zA-Z_]+]] = OpTypePointer StorageBuffer [[_float]]
// CHECK: [[_v3uint:%[0-9a-zA-Z_]+]] = OpTypeVector [[_uint]] 3
// CHECK: [[__ptr_Private_v3uint:%[0-9a-zA-Z_]+]] = OpTypePointer Private [[_v3uint]]
// CHECK: [[_uint_0:%[0-9a-zA-Z_]+]] = OpConstant [[_uint]] 0
// CHECK: [[_15]] = OpSpecConstant [[_uint]] 1
// CHECK: [[_16]] = OpSpecConstant [[_uint]] 1
// CHECK: [[_17]] = OpSpecConstant [[_uint]] 1
// CHECK: [[_gl_WorkGroupSize]] = OpSpecConstantComposite [[_v3uint]] [[_15]] [[_16]] [[_17]]
// CHECK: [[_19:%[0-9a-zA-Z_]+]] = OpVariable [[__ptr_Private_v3uint]] Private [[_gl_WorkGroupSize]]
// CHECK: [[_20]] = OpVariable [[__ptr_StorageBuffer__struct_3]] StorageBuffer
// CHECK: [[_21]] = OpVariable [[__ptr_StorageBuffer__struct_6]] StorageBuffer
// CHECK: [[_22]] = OpFunction [[_void]] None [[_9]]
// CHECK: [[_23:%[0-9a-zA-Z_]+]] = OpLabel
// CHECK: [[_24:%[0-9a-zA-Z_]+]] = OpAccessChain [[__ptr_StorageBuffer_uint]] [[_21]] [[_uint_0]]
// CHECK: [[_25:%[0-9a-zA-Z_]+]] = OpLoad [[_uint]] [[_24]]
// CHECK: [[_26:%[0-9a-zA-Z_]+]] = OpBitcast [[_float]] [[_25]]
// CHECK: [[_27:%[0-9a-zA-Z_]+]] = OpAccessChain [[__ptr_StorageBuffer_float]] [[_20]] [[_uint_0]] [[_uint_0]]
// CHECK: OpStore [[_27]] [[_26]]
// CHECK: OpReturn
// CHECK: OpFunctionEnd

0 comments on commit 7654291

Please sign in to comment.