r352539 - Revert "OpenCL: Extend argument promotion rules to vector types"

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 29 13:30:36 PST 2019


Merged to 8.0 in r352547.

On Tue, Jan 29, 2019 at 3:49 PM Matt Arsenault via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
>
> Author: arsenm
> Date: Tue Jan 29 12:49:47 2019
> New Revision: 352539
>
> URL: http://llvm.org/viewvc/llvm-project?rev=352539&view=rev
> Log:
> Revert "OpenCL: Extend argument promotion rules to vector types"
>
> This reverts r348083. This was based on a misreading of the spec
> for printf specifiers.
>
> Also revert r343653, as without a subsequent patch, a correctly
> specified format for a vector will incorrectly warn.
>
> Fixes bug 40491.
>
> Modified:
>     cfe/trunk/lib/Headers/opencl-c.h
>     cfe/trunk/lib/Sema/SemaExpr.cpp
>     cfe/trunk/test/CodeGenOpenCL/printf.cl
>     cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl
>     cfe/trunk/test/SemaOpenCL/printf-format-strings.cl
>
> Modified: cfe/trunk/lib/Headers/opencl-c.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=352539&r1=352538&r2=352539&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Headers/opencl-c.h (original)
> +++ cfe/trunk/lib/Headers/opencl-c.h Tue Jan 29 12:49:47 2019
> @@ -14469,7 +14469,7 @@ half16 __ovld __cnfn shuffle2(half16 x,
>  #if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
>  // OpenCL v1.2 s6.12.13, v2.0 s6.13.13 - printf
>
> -int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 2)));
> +int printf(__constant const char* st, ...);
>  #endif
>
>  // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write Functions
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=352539&r1=352538&r2=352539&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan 29 12:49:47 2019
> @@ -737,33 +737,20 @@ ExprResult Sema::DefaultArgumentPromotio
>      return ExprError();
>    E = Res.get();
>
> -  QualType ScalarTy = Ty;
> -  unsigned NumElts = 0;
> -  if (const ExtVectorType *VecTy = Ty->getAs<ExtVectorType>()) {
> -    NumElts = VecTy->getNumElements();
> -    ScalarTy = VecTy->getElementType();
> -  }
> -
>    // If this is a 'float'  or '__fp16' (CVR qualified or typedef)
>    // promote to double.
>    // Note that default argument promotion applies only to float (and
>    // half/fp16); it does not apply to _Float16.
> -  const BuiltinType *BTy = ScalarTy->getAs<BuiltinType>();
> +  const BuiltinType *BTy = Ty->getAs<BuiltinType>();
>    if (BTy && (BTy->getKind() == BuiltinType::Half ||
>                BTy->getKind() == BuiltinType::Float)) {
>      if (getLangOpts().OpenCL &&
>          !getOpenCLOptions().isEnabled("cl_khr_fp64")) {
> -      if (BTy->getKind() == BuiltinType::Half) {
> -        QualType Ty = Context.FloatTy;
> -        if (NumElts != 0)
> -          Ty = Context.getExtVectorType(Ty, NumElts);
> -        E = ImpCastExprToType(E, Ty, CK_FloatingCast).get();
> -      }
> +        if (BTy->getKind() == BuiltinType::Half) {
> +            E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get();
> +        }
>      } else {
> -      QualType Ty = Context.DoubleTy;
> -      if (NumElts != 0)
> -        Ty = Context.getExtVectorType(Ty, NumElts);
> -      E = ImpCastExprToType(E, Ty, CK_FloatingCast).get();
> +      E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get();
>      }
>    }
>
>
> Modified: cfe/trunk/test/CodeGenOpenCL/printf.cl
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/printf.cl?rev=352539&r1=352538&r2=352539&view=diff
> ==============================================================================
> --- cfe/trunk/test/CodeGenOpenCL/printf.cl (original)
> +++ cfe/trunk/test/CodeGenOpenCL/printf.cl Tue Jan 29 12:49:47 2019
> @@ -12,28 +12,26 @@ int printf(__constant const char* st, ..
>
>
>  // ALL-LABEL: @test_printf_float2(
> -// FP64: %conv = fpext <2 x float> %0 to <2 x double>
> -// FP64: %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([5 x i8], [5 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x double> %conv)
> +// FP64: %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([7 x i8], [7 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %0)
>
> -// NOFP64:  call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([5 x i8], [5 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %0)
> +
> +// NOFP64:  call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([7 x i8], [7 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %0)
>  kernel void test_printf_float2(float2 arg) {
> -  printf("%v2f", arg);
> +  printf("%v2hlf", arg);
>  }
>
>  // ALL-LABEL: @test_printf_half2(
> -// FP64: %conv = fpext <2 x half> %0 to <2 x double>
> -// FP64:  %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([5 x i8], [5 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x double> %conv) #2
> +// FP64:  %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str.1, i32 0, i32 0), <2 x half> %0)
>
> -// NOFP64: %conv = fpext <2 x half> %0 to <2 x float>
> -// NOFP64:  %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([5 x i8], [5 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x float> %conv) #2
> +// NOFP64:  %call = call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str.1, i32 0, i32 0), <2 x half> %0)
>  kernel void test_printf_half2(half2 arg) {
> -  printf("%v2f", arg);
> +  printf("%v2hf", arg);
>  }
>
>  #ifdef cl_khr_fp64
>  // FP64-LABEL: @test_printf_double2(
> -// FP64: call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([5 x i8], [5 x i8] addrspace(2)* @.str, i32 0, i32 0), <2 x double> %0) #2
> +// FP64: call spir_func i32 (i8 addrspace(2)*, ...) @printf(i8 addrspace(2)* getelementptr inbounds ([6 x i8], [6 x i8] addrspace(2)* @.str.2, i32 0, i32 0), <2 x double> %0)
>  kernel void test_printf_double2(double2 arg) {
> -  printf("%v2f", arg);
> +  printf("%v2lf", arg);
>  }
>  #endif
>
> Modified: cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl?rev=352539&r1=352538&r2=352539&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl (original)
> +++ cfe/trunk/test/SemaOpenCL/printf-format-string-warnings.cl Tue Jan 29 12:49:47 2019
> @@ -1,13 +1,14 @@
>  // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 -finclude-default-header
>
> -// Make sure warnings are produced based on printf format strings.
> +// FIXME: Make sure warnings are produced based on printf format strings.
>
> +// expected-no-diagnostics
>
>  kernel void format_string_warnings(__constant char* arg) {
>
> -  printf("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type '__constant char *'}}
> +  printf("%d", arg);
>
> -  printf("not enough arguments %d %d", 4); // expected-warning {{more '%' conversions than data arguments}}
> +  printf("not enough arguments %d %d", 4);
>
> -  printf("too many arguments", 4); // expected-warning {{data argument not used by format string}}
> +  printf("too many arguments", 4);
>  }
>
> Modified: cfe/trunk/test/SemaOpenCL/printf-format-strings.cl
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/printf-format-strings.cl?rev=352539&r1=352538&r2=352539&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaOpenCL/printf-format-strings.cl (original)
> +++ cfe/trunk/test/SemaOpenCL/printf-format-strings.cl Tue Jan 29 12:49:47 2019
> @@ -13,10 +13,10 @@ int printf(__constant const char* st, ..
>  kernel void format_v4f32(float4 arg)
>  {
>  #ifdef cl_khr_fp64
> -    printf("%v4f\n", arg);
> +    printf("%v4f\n", arg); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
>
>      // Precision modifier
> -    printf("%.2v4f\n", arg);
> +    printf("%.2v4f\n", arg); // expected-warning{{format specifies type 'double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
>  #else
>      // FIXME: These should not warn, and the type should be expected to be float.
>      printf("%v4f\n", arg);  // expected-warning {{double __attribute__((ext_vector_type(4)))' but the argument has type 'float4' (vector of 4 'float' values)}}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list