svenvh created this revision. svenvh added a reviewer: Anastasia. Herald added subscribers: cfe-commits, yaxunl. Herald added a project: clang.
The sampler handling logic in SemaInit.cpp would inadvertently treat parentheses around sampler arguments as an implicit cast, leading to an unreachable "can't implicitly cast lvalue to rvalue with this cast kind". Fix by ignoring parentheses once we are in the sampler initializer case. Repository: rC Clang https://reviews.llvm.org/D66080 Files: clang/lib/Sema/SemaInit.cpp clang/test/SemaOpenCL/sampler_t.cl Index: clang/test/SemaOpenCL/sampler_t.cl =================================================================== --- clang/test/SemaOpenCL/sampler_t.cl +++ clang/test/SemaOpenCL/sampler_t.cl @@ -10,6 +10,9 @@ #define CLK_FILTER_NEAREST 0x10 #define CLK_FILTER_LINEAR 0x20 +typedef float float4 __attribute__((ext_vector_type(4))); +float4 read_imagef(read_only image1d_t, sampler_t, float); + constant sampler_t glb_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR; constant sampler_t glb_smp2; // expected-error{{variable in constant address space must be initialized}} global sampler_t glb_smp3 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST; // expected-error{{sampler type cannot be used with the __local and __global address space qualifiers}} expected-error {{global sampler requires a const or constant address space qualifier}} @@ -74,3 +77,7 @@ foo(smp1+1); //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}} } +void smp_args(read_only image1d_t image) { + // Test that parentheses around sampler arguments are ignored. + float4 res = read_imagef(image, (glb_smp10), 0.0f); +} Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -8248,7 +8248,7 @@ // argument passing. assert(Step->Type->isSamplerT() && "Sampler initialization on non-sampler type."); - Expr *Init = CurInit.get(); + Expr *Init = CurInit.get()->IgnoreParens(); QualType SourceType = Init->getType(); // Case 1 if (Entity.isParameterKind()) {
Index: clang/test/SemaOpenCL/sampler_t.cl =================================================================== --- clang/test/SemaOpenCL/sampler_t.cl +++ clang/test/SemaOpenCL/sampler_t.cl @@ -10,6 +10,9 @@ #define CLK_FILTER_NEAREST 0x10 #define CLK_FILTER_LINEAR 0x20 +typedef float float4 __attribute__((ext_vector_type(4))); +float4 read_imagef(read_only image1d_t, sampler_t, float); + constant sampler_t glb_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR; constant sampler_t glb_smp2; // expected-error{{variable in constant address space must be initialized}} global sampler_t glb_smp3 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST; // expected-error{{sampler type cannot be used with the __local and __global address space qualifiers}} expected-error {{global sampler requires a const or constant address space qualifier}} @@ -74,3 +77,7 @@ foo(smp1+1); //expected-error{{invalid operands to binary expression ('sampler_t' and 'int')}} } +void smp_args(read_only image1d_t image) { + // Test that parentheses around sampler arguments are ignored. + float4 res = read_imagef(image, (glb_smp10), 0.0f); +} Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -8248,7 +8248,7 @@ // argument passing. assert(Step->Type->isSamplerT() && "Sampler initialization on non-sampler type."); - Expr *Init = CurInit.get(); + Expr *Init = CurInit.get()->IgnoreParens(); QualType SourceType = Init->getType(); // Case 1 if (Entity.isParameterKind()) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits