[PATCH] D13280: Adding reserved operator logical xor for OpenCL
neil.hickey created this revision. neil.hickey added a reviewer: cfe-commits. This patch adds the reserved operator ^^ when compiling for OpenCL, which results in a more meaningful error message. http://reviews.llvm.org/D13280 Files: include/clang/Basic/DiagnosticParseKinds.td include/clang/Basic/TokenKinds.def lib/Basic/OperatorPrecedence.cpp lib/Lex/Lexer.cpp lib/Parse/ParseExpr.cpp test/SemaOpenCL/unsupported.cl Index: test/SemaOpenCL/unsupported.cl === --- test/SemaOpenCL/unsupported.cl +++ test/SemaOpenCL/unsupported.cl @@ -7,3 +7,7 @@ void no_vla(int n) { int a[n]; // expected-error {{variable length arrays are not supported in OpenCL}} } + +void no_logxor(int n) { + int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in OpenCL}} +} Index: lib/Parse/ParseExpr.cpp === --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -261,6 +261,9 @@ Token OpToken = Tok; ConsumeToken(); +if (OpToken.is(tok::caretcaret)) { + return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or)); +} // Bail out when encountering a comma followed by a token which can't // possibly be the start of an expression. For instance: // int f() { return 1, } Index: lib/Lex/Lexer.cpp === --- lib/Lex/Lexer.cpp +++ lib/Lex/Lexer.cpp @@ -3473,6 +3473,9 @@ if (Char == '=') { CurPtr = ConsumeChar(CurPtr, SizeTmp, Result); Kind = tok::caretequal; +} else if (LangOpts.OpenCL && Char == '^') { + CurPtr = ConsumeChar(CurPtr, SizeTmp, Result); + Kind = tok::caretcaret; } else { Kind = tok::caret; } Index: lib/Basic/OperatorPrecedence.cpp === --- lib/Basic/OperatorPrecedence.cpp +++ lib/Basic/OperatorPrecedence.cpp @@ -53,6 +53,7 @@ case tok::pipeequal:return prec::Assignment; case tok::question: return prec::Conditional; case tok::pipepipe: return prec::LogicalOr; + case tok::caretcaret: case tok::ampamp: return prec::LogicalAnd; case tok::pipe: return prec::InclusiveOr; case tok::caret:return prec::ExclusiveOr; Index: include/clang/Basic/TokenKinds.def === --- include/clang/Basic/TokenKinds.def +++ include/clang/Basic/TokenKinds.def @@ -219,6 +219,9 @@ PUNCTUATOR(lesslessless, "<<<") PUNCTUATOR(greatergreatergreater, ">>>") +// CL support +PUNCTUATOR(caretcaret,"^^") + // C99 6.4.1: Keywords. These turn into kw_* tokens. // Flags allowed: // KEYALL - This is a keyword in all variants of C and C++, or it Index: include/clang/Basic/DiagnosticParseKinds.td === --- include/clang/Basic/DiagnosticParseKinds.td +++ include/clang/Basic/DiagnosticParseKinds.td @@ -964,6 +964,8 @@ // OpenCL Section 6.8.g def err_opencl_unknown_type_specifier : Error< "OpenCL does not support the '%0' %select{type qualifier|storage class specifier}1">; +def err_opencl_logical_exclusive_or : Error< + "^^ is a reserved operator in OpenCL">; // OpenCL EXTENSION pragma (OpenCL 1.1 [9.1]) def warn_pragma_expected_colon : Warning< Index: test/SemaOpenCL/unsupported.cl === --- test/SemaOpenCL/unsupported.cl +++ test/SemaOpenCL/unsupported.cl @@ -7,3 +7,7 @@ void no_vla(int n) { int a[n]; // expected-error {{variable length arrays are not supported in OpenCL}} } + +void no_logxor(int n) { + int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in OpenCL}} +} Index: lib/Parse/ParseExpr.cpp === --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -261,6 +261,9 @@ Token OpToken = Tok; ConsumeToken(); +if (OpToken.is(tok::caretcaret)) { + return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or)); +} // Bail out when encountering a comma followed by a token which can't // possibly be the start of an expression. For instance: // int f() { return 1, } Index: lib/Lex/Lexer.cpp === --- lib/Lex/Lexer.cpp +++ lib/Lex/Lexer.cpp @@ -3473,6 +3473,9 @@ if (Char == '=') { CurPtr = ConsumeChar(CurPtr, SizeTmp, Result); Kind = tok::caretequal; +} else if (LangOpts.OpenCL && Char == '^') { + CurPtr = ConsumeChar(CurPtr, SizeTmp, Result); + Kind = tok::caretcaret; } else { Kind = tok::caret; } Index: lib/Basic/OperatorPrecedence.cpp === ---
[PATCH] D13349: Casting boolean to an integer vector in OpenCL should set all bits if boolean is true
neil.hickey created this revision. neil.hickey added a reviewer: cfe-commits. Changing behaviour of casting a true boolean to an integer vector for OpenCL. The spec (6.2.2) states that if the boolean is true, every bit in the result vector should be set. This change will treat the i1 value as signed for the purposes of performing the cast to integer, and therefore sign extend into the result. http://reviews.llvm.org/D13349 Files: lib/CodeGen/CGExprScalar.cpp test/CodeGenOpenCL/bool_cast.cl Index: test/CodeGenOpenCL/bool_cast.cl === --- /dev/null +++ test/CodeGenOpenCL/bool_cast.cl @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -O0 | FileCheck %s + +typedef unsigned char uchar4 __attribute((ext_vector_type(4))); +typedef unsigned int int4 __attribute((ext_vector_type(4))); + +void kernel ker() { + bool t = true; + int4 vec4 = (int4)t; +// CHECK: {{%.*}} = load i8, i8* %t, align 1 +// CHECK: {{%.*}} = trunc i8 {{%.*}} to i1 +// CHECK: {{%.*}} = sext i1 {{%.*}} to i32 +// CHECK: {{%.*}} = insertelement <4 x i32> undef, i32 {{%.*}}, i32 0 +// CHECK: {{%.*}} = shufflevector <4 x i32> {{%.*}}, <4 x i32> undef, <4 x i32> zeroinitializer +// CHECK: store <4 x i32> {{%.*}}, <4 x i32>* %vec4, align 16 + int i = (int)t; +// CHECK: {{%.*}} = load i8, i8* %t, align 1 +// CHECK: {{%.*}} = trunc i8 {{%.*}} to i1 +// CHECK: {{%.*}} = zext i1 {{%.*}} to i32 +// CHECK: store i32 {{%.*}}, i32* %i, align 4 + + uchar4 vc; + vc = (uchar4)true; +// CHECK: store <4 x i8> , <4 x i8>* %vc, align 4 + unsigned char c; + c = (unsigned char)true; +// CHECK: store i8 1, i8* %c, align 1 +} Index: lib/CodeGen/CGExprScalar.cpp === --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -151,6 +151,9 @@ Value *EmitScalarConversion(Value *Src, QualType SrcTy, QualType DstTy, SourceLocation Loc); + Value *EmitScalarConversion(Value *Src, QualType SrcTy, QualType DstTy, + SourceLocation Loc, bool TreatBooleanAsSigned); + /// Emit a conversion from the specified complex type to the specified /// destination type, where the destination type is an LLVM scalar type. Value *EmitComplexToScalarConversion(CodeGenFunction::ComplexPairTy Src, @@ -733,6 +736,13 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, QualType DstType, SourceLocation Loc) { + return EmitScalarConversion(Src, SrcType, DstType, Loc, false); +} + +Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, + QualType DstType, + SourceLocation Loc, + bool TreatBooleanAsSigned) { SrcType = CGF.getContext().getCanonicalType(SrcType); DstType = CGF.getContext().getCanonicalType(DstType); if (SrcType == DstType) return Src; @@ -807,7 +817,7 @@ if (DstType->isExtVectorType() && !SrcType->isVectorType()) { // Cast the scalar to element type QualType EltTy = DstType->getAs()->getElementType(); -llvm::Value *Elt = EmitScalarConversion(Src, SrcType, EltTy, Loc); +llvm::Value *Elt = EmitScalarConversion(Src, SrcType, EltTy, Loc, CGF.getContext().getLangOpts().OpenCL); // Splat the element across to all elements unsigned NumElements = cast(DstTy)->getNumElements(); @@ -847,6 +857,9 @@ if (isa(SrcTy)) { bool InputSigned = SrcType->isSignedIntegerOrEnumerationType(); +if (SrcType->isBooleanType() && TreatBooleanAsSigned) { + InputSigned = true; +} if (isa(DstTy)) Res = Builder.CreateIntCast(Src, DstTy, InputSigned, "conv"); else if (InputSigned) @@ -1531,10 +1544,14 @@ } case CK_VectorSplat: { llvm::Type *DstTy = ConvertType(DestTy); -Value *Elt = Visit(const_cast(E)); -Elt = EmitScalarConversion(Elt, E->getType(), +// Need an IgnoreImpCasts here as by default a boolean will be promoted to +// an int, which will not perform the sign extension, so if we know we are +// going to cast to a vector we have to strip the implicit cast off. +Value *Elt = Visit(const_cast (E->IgnoreImpCasts())); +Elt = EmitScalarConversion(Elt, E->IgnoreImpCasts()->getType(), DestTy->getAs()->getElementType(), - CE->getExprLoc()); + CE->getExprLoc(), + CGF.getContext().getLangOpts().OpenCL); // Splat the element across to all elements unsigned NumElements = cast(DstTy)->getNumElements(); Index: test/CodeGenOpenCL/bool_cast.cl === --- /dev/null +++
Re: [PATCH] D13349: [OpenCL] Casting boolean to an integer vector in OpenCL should set all bits if boolean is true
neil.hickey updated this revision to Diff 36348. neil.hickey added a comment. Fixing formatting problems. http://reviews.llvm.org/D13349 Files: lib/CodeGen/CGExprScalar.cpp test/CodeGenOpenCL/bool_cast.cl Index: test/CodeGenOpenCL/bool_cast.cl === --- /dev/null +++ test/CodeGenOpenCL/bool_cast.cl @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -O0 | FileCheck %s + +typedef unsigned char uchar4 __attribute((ext_vector_type(4))); +typedef unsigned int int4 __attribute((ext_vector_type(4))); + +void kernel ker() { + bool t = true; + int4 vec4 = (int4)t; +// CHECK: {{%.*}} = load i8, i8* %t, align 1 +// CHECK: {{%.*}} = trunc i8 {{%.*}} to i1 +// CHECK: {{%.*}} = sext i1 {{%.*}} to i32 +// CHECK: {{%.*}} = insertelement <4 x i32> undef, i32 {{%.*}}, i32 0 +// CHECK: {{%.*}} = shufflevector <4 x i32> {{%.*}}, <4 x i32> undef, <4 x i32> zeroinitializer +// CHECK: store <4 x i32> {{%.*}}, <4 x i32>* %vec4, align 16 + int i = (int)t; +// CHECK: {{%.*}} = load i8, i8* %t, align 1 +// CHECK: {{%.*}} = trunc i8 {{%.*}} to i1 +// CHECK: {{%.*}} = zext i1 {{%.*}} to i32 +// CHECK: store i32 {{%.*}}, i32* %i, align 4 + + uchar4 vc; + vc = (uchar4)true; +// CHECK: store <4 x i8> , <4 x i8>* %vc, align 4 + unsigned char c; + c = (unsigned char)true; +// CHECK: store i8 1, i8* %c, align 1 +} Index: lib/CodeGen/CGExprScalar.cpp === --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -151,6 +151,9 @@ Value *EmitScalarConversion(Value *Src, QualType SrcTy, QualType DstTy, SourceLocation Loc); + Value *EmitScalarConversion(Value *Src, QualType SrcTy, QualType DstTy, + SourceLocation Loc, bool TreatBooleanAsSigned); + /// Emit a conversion from the specified complex type to the specified /// destination type, where the destination type is an LLVM scalar type. Value *EmitComplexToScalarConversion(CodeGenFunction::ComplexPairTy Src, @@ -733,6 +736,13 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, QualType DstType, SourceLocation Loc) { + return EmitScalarConversion(Src, SrcType, DstType, Loc, false); +} + +Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, + QualType DstType, + SourceLocation Loc, + bool TreatBooleanAsSigned) { SrcType = CGF.getContext().getCanonicalType(SrcType); DstType = CGF.getContext().getCanonicalType(DstType); if (SrcType == DstType) return Src; @@ -807,7 +817,8 @@ if (DstType->isExtVectorType() && !SrcType->isVectorType()) { // Cast the scalar to element type QualType EltTy = DstType->getAs()->getElementType(); -llvm::Value *Elt = EmitScalarConversion(Src, SrcType, EltTy, Loc); +llvm::Value *Elt = EmitScalarConversion( +Src, SrcType, EltTy, Loc, CGF.getContext().getLangOpts().OpenCL); // Splat the element across to all elements unsigned NumElements = cast(DstTy)->getNumElements(); @@ -847,6 +858,9 @@ if (isa(SrcTy)) { bool InputSigned = SrcType->isSignedIntegerOrEnumerationType(); +if (SrcType->isBooleanType() && TreatBooleanAsSigned) { + InputSigned = true; +} if (isa(DstTy)) Res = Builder.CreateIntCast(Src, DstTy, InputSigned, "conv"); else if (InputSigned) @@ -1531,10 +1545,14 @@ } case CK_VectorSplat: { llvm::Type *DstTy = ConvertType(DestTy); -Value *Elt = Visit(const_cast(E)); -Elt = EmitScalarConversion(Elt, E->getType(), +// Need an IgnoreImpCasts here as by default a boolean will be promoted to +// an int, which will not perform the sign extension, so if we know we are +// going to cast to a vector we have to strip the implicit cast off. +Value *Elt = Visit(const_cast (E->IgnoreImpCasts())); +Elt = EmitScalarConversion(Elt, E->IgnoreImpCasts()->getType(), DestTy->getAs()->getElementType(), - CE->getExprLoc()); + CE->getExprLoc(), + CGF.getContext().getLangOpts().OpenCL); // Splat the element across to all elements unsigned NumElements = cast(DstTy)->getNumElements(); Index: test/CodeGenOpenCL/bool_cast.cl === --- /dev/null +++ test/CodeGenOpenCL/bool_cast.cl @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -O0 | FileCheck %s + +typedef unsigned char uchar4 __attribute((ext_vector_type(4))); +typedef unsigned int int4 __attribute((ext_vector_type(4))); + +void kernel ker() { + bool t = true; + int4 vec4 = (int4)t; +//
[PATCH] D15691: [OpenCL] Improving OpenCL function pointer error checking to catch lone function designator
neil.hickey created this revision. neil.hickey added a reviewer: cfe-commits. An undecorated function designator implies taking the address of a function, which is illegal in OpenCL. Implementing a check for this earlier to allow the error to be reported even in the presence of other more obvious errors. http://reviews.llvm.org/D15691 Files: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseExpr.cpp test/SemaOpenCL/cond.cl test/SemaOpenCL/func_ptr.cl Index: test/SemaOpenCL/func_ptr.cl === --- test/SemaOpenCL/func_ptr.cl +++ test/SemaOpenCL/func_ptr.cl @@ -11,6 +11,9 @@ foo((void*)foo); // expected-error{{taking address of function is not allowed}} foo(); // expected-error{{taking address of function is not allowed}} + // initializing an array with the address of functions is an error + void* vptrarr[2] = {foo, }; // expected-error{{taking address of function is not allowed}} expected-error{{taking address of function is not allowed}} + // just calling a function is correct foo(0); } Index: test/SemaOpenCL/cond.cl === --- test/SemaOpenCL/cond.cl +++ test/SemaOpenCL/cond.cl @@ -128,5 +128,5 @@ unsigned int ntest12(int2 C) { - return (unsigned int)(C ? foo1 : foo2); // expected-error {{taking address of function is not allowed}} + return (unsigned int)(C ? foo1 : foo2); // expected-error {{taking address of function is not allowed}} expected-error {{taking address of function is not allowed}} } Index: lib/Parse/ParseExpr.cpp === --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -1334,8 +1334,23 @@ return ExprError(); } + // check to see whether Res is a function designator only. If it is and we + // are compiling for OpenCL, we need to return an error as this implies + // that the address of the function is being taken, which is illegal in CL + // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res); + Res = ParsePostfixExpressionSuffix(Res); + Expr *PostfixExpr = Res.get(); + if (PostfixExpr) { +QualType Ty = PostfixExpr->getType(); +if (!Ty.isNull() && Ty->isFunctionType() && getLangOpts().OpenCL) { + Diag(PostfixExpr->getExprLoc(), + diag::err_opencl_taking_function_address_parser); + return ExprError(); +} + } + + return Res; } /// \brief Once the leading part of a postfix-expression is parsed, this Index: include/clang/Basic/DiagnosticParseKinds.td === --- include/clang/Basic/DiagnosticParseKinds.td +++ include/clang/Basic/DiagnosticParseKinds.td @@ -910,6 +910,10 @@ def warn_pragma_unknown_extension : Warning< "unknown OpenCL extension %0 - ignoring">, InGroup; +// OpenCL error +def err_opencl_taking_function_address_parser : Error< + "taking address of function is not allowed">; + // OpenMP support. def warn_pragma_omp_ignored : Warning< "unexpected '#pragma omp ...' in program">, InGroup, DefaultIgnore; Index: test/SemaOpenCL/func_ptr.cl === --- test/SemaOpenCL/func_ptr.cl +++ test/SemaOpenCL/func_ptr.cl @@ -11,6 +11,9 @@ foo((void*)foo); // expected-error{{taking address of function is not allowed}} foo(); // expected-error{{taking address of function is not allowed}} + // initializing an array with the address of functions is an error + void* vptrarr[2] = {foo, }; // expected-error{{taking address of function is not allowed}} expected-error{{taking address of function is not allowed}} + // just calling a function is correct foo(0); } Index: test/SemaOpenCL/cond.cl === --- test/SemaOpenCL/cond.cl +++ test/SemaOpenCL/cond.cl @@ -128,5 +128,5 @@ unsigned int ntest12(int2 C) { - return (unsigned int)(C ? foo1 : foo2); // expected-error {{taking address of function is not allowed}} + return (unsigned int)(C ? foo1 : foo2); // expected-error {{taking address of function is not allowed}} expected-error {{taking address of function is not allowed}} } Index: lib/Parse/ParseExpr.cpp === --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -1334,8 +1334,23 @@ return ExprError(); } + // check to see whether Res is a function designator only. If it is and we + // are compiling for OpenCL, we need to return an error as this implies + // that the address of the function is being taken, which is illegal in CL + // These can be followed by postfix-expr pieces. - return ParsePostfixExpressionSuffix(Res); + Res = ParsePostfixExpressionSuffix(Res); + Expr *PostfixExpr = Res.get(); + if (PostfixExpr) { +QualType Ty = PostfixExpr->getType(); +if
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey updated this revision to Diff 70527. neil.hickey added a comment. Added a CodeGen test as well as fixed an issue with vararg type promotion https://reviews.llvm.org/D24235 Files: lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/fpmath.cl test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -1,13 +1,16 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -21,16 +24,22 @@ #endif (void) 1.0; +#ifdef FP64 +// expected-no-diagnostics +#endif + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: test/CodeGenOpenCL/fpmath.cl === --- test/CodeGenOpenCL/fpmath.cl +++ test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,22 @@ return a / b; } -#pragma OPENCL EXTENSION cl_khr_fp64 : enable +void printf(constant char* fmt, ...); + +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1413,7 +1413,8 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || +!((S.getLangOpts().OpenCLVersion >= 120 + && S.Context.getTargetInfo().getSupportedOpenCLOpts().cl_khr_fp64) || S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -829,7 +829,20 @@ const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || BTy->getKind() == BuiltinType::Float)) -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + { +if (getLangOpts().OpenCL && +!((getLangOpts().OpenCLVersion >= 120 && + Context.getTargetInfo() + .getSupportedOpenCLOpts() + .cl_khr_fp64) || + getOpenCLOptions().cl_khr_fp64)) { +E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get(); +} +else +{ + E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); +} + } // C++ performs lvalue-to-rvalue conversion as a default argument // promotion, even on class types, but note: @@ -3406,8 +3419,14 @@ if (getLangOpts().SinglePrecisionConstants) { Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); } else if (getLangOpts().OpenCL && - !((getLangOpts().OpenCLVersion >= 120) || + !((getLangOpts().OpenCLVersion >=
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey closed this revision. neil.hickey added a comment. Commit merged to trunk https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey added a comment. committed @ 281714 https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r281711 - Testing commit rights. Removing trailing white space from test file.
Author: neil.hickey Date: Fri Sep 16 04:38:11 2016 New Revision: 281711 URL: http://llvm.org/viewvc/llvm-project?rev=281711=rev Log: Testing commit rights. Removing trailing white space from test file. Modified: cfe/trunk/test/SemaCXX/attr-noreturn.cpp Modified: cfe/trunk/test/SemaCXX/attr-noreturn.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-noreturn.cpp?rev=281711=281710=281711=diff == --- cfe/trunk/test/SemaCXX/attr-noreturn.cpp (original) +++ cfe/trunk/test/SemaCXX/attr-noreturn.cpp Fri Sep 16 04:38:11 2016 @@ -167,7 +167,7 @@ namespace destructor_tests { // PR5620 void f0() __attribute__((__noreturn__)); -void f1(void (*)()); +void f1(void (*)()); void f2() { f1(f0); } // Taking the address of a noreturn function ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r281714 - Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64
Author: neil.hickey Date: Fri Sep 16 05:15:06 2016 New Revision: 281714 URL: http://llvm.org/viewvc/llvm-project?rev=281714=rev Log: Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64 https://reviews.llvm.org/D24235 Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/CodeGenOpenCL/fpmath.cl cfe/trunk/test/SemaOpenCL/extensions.cl Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=281714=281713=281714=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Sep 16 05:15:06 2016 @@ -828,8 +828,18 @@ ExprResult Sema::DefaultArgumentPromotio // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || - BTy->getKind() == BuiltinType::Float)) -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + BTy->getKind() == BuiltinType::Float)) { +if (getLangOpts().OpenCL && +!((getLangOpts().OpenCLVersion >= 120 && + Context.getTargetInfo() + .getSupportedOpenCLOpts() + .cl_khr_fp64) || + getOpenCLOptions().cl_khr_fp64)) { +E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get(); +} else { + E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); +} + } // C++ performs lvalue-to-rvalue conversion as a default argument // promotion, even on class types, but note: @@ -3406,8 +3416,14 @@ ExprResult Sema::ActOnNumericConstant(co if (getLangOpts().SinglePrecisionConstants) { Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); } else if (getLangOpts().OpenCL && - !((getLangOpts().OpenCLVersion >= 120) || + !((getLangOpts().OpenCLVersion >= 120 && +Context.getTargetInfo() +.getSupportedOpenCLOpts() +.cl_khr_fp64) || getOpenCLOptions().cl_khr_fp64)) { +// Impose single-precision float type when: +// - in CL 1.2 or above and cl_khr_fp64 is not supported, or +// - in CL 1.1 or below and cl_khr_fp64 is not enabled. Diag(Tok.getLocation(), diag::warn_double_const_requires_fp64); Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); } Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=281714=281713=281714=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Fri Sep 16 05:15:06 2016 @@ -1401,7 +1401,8 @@ static QualType ConvertDeclSpecToType(Ty Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || +!((S.getLangOpts().OpenCLVersion >= 120 + && S.Context.getTargetInfo().getSupportedOpenCLOpts().cl_khr_fp64) || S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; Modified: cfe/trunk/test/CodeGenOpenCL/fpmath.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/fpmath.cl?rev=281714=281713=281714=diff == --- cfe/trunk/test/CodeGenOpenCL/fpmath.cl (original) +++ cfe/trunk/test/CodeGenOpenCL/fpmath.cl Fri Sep 16 05:15:06 2016 @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,26 @@ float4 spvectordiv(float4 a, float4 b) { return a / b; } +void printf(constant char* fmt, ...); + +#ifndef NOFP64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + // CHECK: double 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Modified: cfe/trunk/test/SemaOpenCL/extensions.cl URL:
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey added inline comments. Comment at: lib/Sema/SemaExpr.cpp:837 @@ +836,3 @@ + .getSupportedOpenCLOpts() + .cl_khr_fp64) || + getOpenCLOptions().cl_khr_fp64)) { Anastasia wrote: > Could we merge this and two lines above into one? This was the result when I ran this through clang-format so I'd rather keep it as it is. https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r281899 - Reverting r281714 due to causing an assert when calling builtins that expect a double, from CL
Author: neil.hickey Date: Mon Sep 19 06:42:14 2016 New Revision: 281899 URL: http://llvm.org/viewvc/llvm-project?rev=281899=rev Log: Reverting r281714 due to causing an assert when calling builtins that expect a double, from CL Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/CodeGenOpenCL/fpmath.cl cfe/trunk/test/SemaOpenCL/extensions.cl Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=281899=281898=281899=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 19 06:42:14 2016 @@ -828,18 +828,8 @@ ExprResult Sema::DefaultArgumentPromotio // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || - BTy->getKind() == BuiltinType::Float)) { -if (getLangOpts().OpenCL && -!((getLangOpts().OpenCLVersion >= 120 && - Context.getTargetInfo() - .getSupportedOpenCLOpts() - .cl_khr_fp64) || - getOpenCLOptions().cl_khr_fp64)) { -E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get(); -} else { - E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); -} - } + BTy->getKind() == BuiltinType::Float)) +E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); // C++ performs lvalue-to-rvalue conversion as a default argument // promotion, even on class types, but note: @@ -3416,14 +3406,8 @@ ExprResult Sema::ActOnNumericConstant(co if (getLangOpts().SinglePrecisionConstants) { Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); } else if (getLangOpts().OpenCL && - !((getLangOpts().OpenCLVersion >= 120 && -Context.getTargetInfo() -.getSupportedOpenCLOpts() -.cl_khr_fp64) || + !((getLangOpts().OpenCLVersion >= 120) || getOpenCLOptions().cl_khr_fp64)) { -// Impose single-precision float type when: -// - in CL 1.2 or above and cl_khr_fp64 is not supported, or -// - in CL 1.1 or below and cl_khr_fp64 is not enabled. Diag(Tok.getLocation(), diag::warn_double_const_requires_fp64); Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); } Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=281899=281898=281899=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Sep 19 06:42:14 2016 @@ -1401,8 +1401,7 @@ static QualType ConvertDeclSpecToType(Ty Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120 - && S.Context.getTargetInfo().getSupportedOpenCLOpts().cl_khr_fp64) || +!((S.getLangOpts().OpenCLVersion >= 120) || S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; Modified: cfe/trunk/test/CodeGenOpenCL/fpmath.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/fpmath.cl?rev=281899=281898=281899=diff == --- cfe/trunk/test/CodeGenOpenCL/fpmath.cl (original) +++ cfe/trunk/test/CodeGenOpenCL/fpmath.cl Mon Sep 19 06:42:14 2016 @@ -1,6 +1,5 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s -// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -22,26 +21,14 @@ float4 spvectordiv(float4 a, float4 b) { return a / b; } -void printf(constant char* fmt, ...); - -#ifndef NOFP64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable -#endif -void testdbllit(long *val) { - // CHECK-DBL: float 2.00e+01 - // CHECK: double 2.00e+01 - printf("%f", 20.0); -} -#ifndef NOFP64 -#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } -#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Modified: cfe/trunk/test/SemaOpenCL/extensions.cl URL:
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey added a reviewer: tstellarAMD. neil.hickey updated this revision to Diff 71837. neil.hickey added a comment. Herald added subscribers: yaxunl, wdng. There was a bug whereby an implicitcast was being applied from float to float, this caused issues later on in builin processing which caused an assertion. This changed patch removes the duplicate, superfluous, cast. https://reviews.llvm.org/D24235 Files: lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/fpmath.cl test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -1,13 +1,16 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -21,16 +24,22 @@ #endif (void) 1.0; +#ifdef FP64 +// expected-no-diagnostics +#endif + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: test/CodeGenOpenCL/fpmath.cl === --- test/CodeGenOpenCL/fpmath.cl +++ test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,26 @@ return a / b; } +void printf(constant char* fmt, ...); + +#ifndef NOFP64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + // CHECK: double 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1401,7 +1401,8 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || +!((S.getLangOpts().OpenCLVersion >= 120 + && S.Context.getTargetInfo().getSupportedOpenCLOpts().cl_khr_fp64) || S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -716,9 +716,13 @@ if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + if ( T != E->getType()) { +Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, + nullptr, VK_RValue); + } // C11 6.3.2.1p2: // ... if the lvalue has atomic type, the value has the non-atomic version @@ -828,8 +832,20 @@ // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || - BTy->getKind() == BuiltinType::Float)) -E =
Re: [PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey added inline comments. Comment at: lib/Sema/SemaExpr.cpp:3431 @@ -3410,1 +3430,3 @@ +.getSupportedOpenCLOpts() +.cl_khr_fp64) || getOpenCLOptions().cl_khr_fp64)) { yaxunl wrote: > This check > (getLangOpts().OpenCLVersion >= 120 && > Context.getTargetInfo() > .getSupportedOpenCLOpts() > .cl_khr_fp64) > > is redundant since for CL 1.2 and above getOpenCLOptions().cl_khr_fp64 is set > to be true by default. This is get**Supported**OpenCLOpts(). Some hardware may not support doubles https://reviews.llvm.org/D24235 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey updated this revision to Diff 77600. neil.hickey added a comment. Improving now confusing comment. https://reviews.llvm.org/D24235 Files: lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/fpmath.cl test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -1,13 +1,20 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 +#ifdef FP64 +// expected-no-diagnostics +#endif + +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -21,16 +28,19 @@ #endif (void) 1.0; + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: test/CodeGenOpenCL/fpmath.cl === --- test/CodeGenOpenCL/fpmath.cl +++ test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,26 @@ return a / b; } +void printf(constant char* fmt, ...); + +#ifndef NOFP64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + // CHECK: double 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1401,8 +1401,7 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || - S.getOpenCLOptions().cl_khr_fp64)) { +!(S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -705,9 +705,13 @@ if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + if ( T != E->getType()) { +Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, + nullptr, VK_RValue); + } // C11 6.3.2.1p2: // ... if the lvalue has atomic type, the value has the non-atomic version @@ -817,8 +821,16 @@ // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || - BTy->getKind() == BuiltinType::Float)) -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + BTy->getKind() == BuiltinType::Float)) { +if (getLangOpts().OpenCL && +!(getOpenCLOptions().cl_khr_fp64)) { +if (BTy->getKind() == BuiltinType::Half) { +E = ImpCastExprToType(E, Context.FloatTy,
r286815 - Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64.
Author: neil.hickey Date: Mon Nov 14 05:15:51 2016 New Revision: 286815 URL: http://llvm.org/viewvc/llvm-project?rev=286815=rev Log: Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64. This change makes sure single-precision floating point types are used if the cl_fp64 extension is not supported by the target. Also removed the check to see whether the OpenCL version is >= 1.2, as this has been incorporated into the extension setting code. Differential Revision: https://reviews.llvm.org/D24235 Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/CodeGenOpenCL/fpmath.cl cfe/trunk/test/SemaOpenCL/extensions.cl Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=286815=286814=286815=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Nov 14 05:15:51 2016 @@ -705,9 +705,13 @@ ExprResult Sema::DefaultLvalueConversion if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + if ( T != E->getType()) { +Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, + nullptr, VK_RValue); + } // C11 6.3.2.1p2: // ... if the lvalue has atomic type, the value has the non-atomic version @@ -817,8 +821,16 @@ ExprResult Sema::DefaultArgumentPromotio // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || - BTy->getKind() == BuiltinType::Float)) -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + BTy->getKind() == BuiltinType::Float)) { +if (getLangOpts().OpenCL && +!(getOpenCLOptions().cl_khr_fp64)) { +if (BTy->getKind() == BuiltinType::Half) { +E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get(); +} +} else { + E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); +} + } // C++ performs lvalue-to-rvalue conversion as a default argument // promotion, even on class types, but note: @@ -3397,10 +3409,13 @@ ExprResult Sema::ActOnNumericConstant(co if (Ty == Context.DoubleTy) { if (getLangOpts().SinglePrecisionConstants) { -Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); +const BuiltinType *BTy = Ty->getAs(); +if (BTy->getKind() != BuiltinType::Float) { + Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); +} } else if (getLangOpts().OpenCL && - !((getLangOpts().OpenCLVersion >= 120) || - getOpenCLOptions().cl_khr_fp64)) { + !(getOpenCLOptions().cl_khr_fp64)) { +// Impose single-precision float type when cl_khr_fp64 is not enabled. Diag(Tok.getLocation(), diag::warn_double_const_requires_fp64); Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); } Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=286815=286814=286815=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Nov 14 05:15:51 2016 @@ -1402,8 +1402,7 @@ static QualType ConvertDeclSpecToType(Ty Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || - S.getOpenCLOptions().cl_khr_fp64)) { +!(S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); Modified: cfe/trunk/test/CodeGenOpenCL/fpmath.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/fpmath.cl?rev=286815=286814=286815=diff == --- cfe/trunk/test/CodeGenOpenCL/fpmath.cl (original) +++ cfe/trunk/test/CodeGenOpenCL/fpmath.cl Mon Nov 14 05:15:51 2016 @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s
[PATCH] D24235: [OpenCL] Improve double literal handling
This revision was automatically updated to reflect the committed changes. Closed by commit rL286815: Improve handling of floating point literals in OpenCL to only use double… (authored by neil.hickey). Changed prior to commit: https://reviews.llvm.org/D24235?vs=77600=77783#toc Repository: rL LLVM https://reviews.llvm.org/D24235 Files: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/CodeGenOpenCL/fpmath.cl cfe/trunk/test/SemaOpenCL/extensions.cl Index: cfe/trunk/test/SemaOpenCL/extensions.cl === --- cfe/trunk/test/SemaOpenCL/extensions.cl +++ cfe/trunk/test/SemaOpenCL/extensions.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 -DNOFP16 @@ -21,12 +22,16 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64 -cl-ext=+cl_khr_fp16 -cl-ext=-cl_khr_fp64 -DNOFP64 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-ext=-all -cl-ext=+cl_khr_fp64,-cl_khr_fp64,+cl_khr_fp16 -DNOFP64 +#ifdef FP64 +// expected-no-diagnostics +#endif - +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -45,16 +50,19 @@ #endif (void) 1.0; + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: cfe/trunk/test/CodeGenOpenCL/fpmath.cl === --- cfe/trunk/test/CodeGenOpenCL/fpmath.cl +++ cfe/trunk/test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,26 @@ return a / b; } +void printf(constant char* fmt, ...); + +#ifndef NOFP64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + // CHECK: double 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: cfe/trunk/lib/Sema/SemaType.cpp === --- cfe/trunk/lib/Sema/SemaType.cpp +++ cfe/trunk/lib/Sema/SemaType.cpp @@ -1402,8 +1402,7 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || - S.getOpenCLOptions().cl_khr_fp64)) { +!(S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); Index: cfe/trunk/lib/Sema/SemaExpr.cpp === --- cfe/trunk/lib/Sema/SemaExpr.cpp +++ cfe/trunk/lib/Sema/SemaExpr.cpp @@ -705,9 +705,13 @@ if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + if ( T != E->getType()) { +Res = ImplicitCastExpr::Create(Context, T,
RE: r286815 - Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64.
It would be valuable to perform that test, if clang tests don't already do this, though I'm not sure it should be part of this particular commit as all this commit should do is change the casts if the target doesn't support double. Neil > -Original Message- > From: sca...@apple.com [mailto:sca...@apple.com] > Sent: 14 November 2016 16:01 > To: Neil Hickey > Cc: cfe-commits@lists.llvm.org > Subject: Re: r286815 - Improve handling of floating point literals in OpenCL > to > only use double precision if the target supports fp64. > > Can you add some non-trivial test cases that exercise double-rounding, > especially near the overflow boundary? > > e.g. What is the expected value of x if the target does not support fp64?: > > float x = 340282356779733661637539395458142568447.0; > > – Steve > > > On Nov 14, 2016, at 6:15 AM, Neil Hickey via cfe-commits comm...@lists.llvm.org> wrote: > > > > Author: neil.hickey > > Date: Mon Nov 14 05:15:51 2016 > > New Revision: 286815 > > > > URL: http://llvm.org/viewvc/llvm-project?rev=286815=rev > > Log: > > Improve handling of floating point literals in OpenCL to only use double > precision if the target supports fp64. > > > > This change makes sure single-precision floating point types are used > > if the > > cl_fp64 extension is not supported by the target. > > > > Also removed the check to see whether the OpenCL version is >= 1.2, as > > this has been incorporated into the extension setting code. > > > > Differential Revision: https://reviews.llvm.org/D24235 > > > > > > Modified: > > cfe/trunk/lib/Sema/SemaExpr.cpp > > cfe/trunk/lib/Sema/SemaType.cpp > > cfe/trunk/test/CodeGenOpenCL/fpmath.cl > > cfe/trunk/test/SemaOpenCL/extensions.cl > > > > Modified: cfe/trunk/lib/Sema/SemaExpr.cpp > > URL: > > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?re > > v=286815=286814=286815=diff > > > == > > > > > --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) > > +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Nov 14 05:15:51 2016 > > @@ -705,9 +705,13 @@ ExprResult Sema::DefaultLvalueConversion if > > (getLangOpts().ObjCAutoRefCount && > > E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) > >Cleanup.setExprNeedsCleanups(true); > > + > > + ExprResult Res = E; > > > > - ExprResult Res = ImplicitCastExpr::Create(Context, T, > CK_LValueToRValue, E, > > -nullptr, VK_RValue); > > + if ( T != E->getType()) { > > +Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, > > + nullptr, VK_RValue); } > > > > // C11 6.3.2.1p2: > > // ... if the lvalue has atomic type, the value has the non-atomic > > version > > @@ -817,8 +821,16 @@ ExprResult Sema::DefaultArgumentPromotio // > > double. > > const BuiltinType *BTy = Ty->getAs(); if (BTy && > > (BTy->getKind() == BuiltinType::Half || > > - BTy->getKind() == BuiltinType::Float)) > > -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); > > + BTy->getKind() == BuiltinType::Float)) { > > +if (getLangOpts().OpenCL && > > +!(getOpenCLOptions().cl_khr_fp64)) { > > +if (BTy->getKind() == BuiltinType::Half) { > > +E = ImpCastExprToType(E, Context.FloatTy, > > CK_FloatingCast).get(); > > +} > > +} else { > > + E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); > > +} > > + } > > > > // C++ performs lvalue-to-rvalue conversion as a default argument // > > promotion, even on class types, but note: > > @@ -3397,10 +3409,13 @@ ExprResult Sema::ActOnNumericConstant(co > > > >if (Ty == Context.DoubleTy) { > > if (getLangOpts().SinglePrecisionConstants) { > > -Res = ImpCastExprToType(Res, Context.FloatTy, > CK_FloatingCast).get(); > > +const BuiltinType *BTy = Ty->getAs(); > > +if (BTy->getKind() != BuiltinType::Float) { > > + Res = ImpCastExprToType(Res, Context.FloatTy, > CK_FloatingCast).get(); > > +} > > } else if (getLangOpts().OpenCL && > > - !((getLangOpts().OpenCLVersion >= 120) || > > - getOpenCLOptions().cl_khr_fp64)) { > > + !(getOpenCLOptions().cl_khr_fp64)) { > &g
[PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey removed rL LLVM as the repository for this revision. neil.hickey updated this revision to Diff 77961. neil.hickey added a comment. Fixes to tests and removal of incorrect check to stop float to float casts if types match. This was still needed as it was an lvalue to rvalue cast. Added extra code in SemaChecking to allow a float to float cast to appear and be handled. https://reviews.llvm.org/D24235 Files: lib/Sema/SemaChecking.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/fpmath.cl test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -1,13 +1,20 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 +#ifdef FP64 +// expected-no-diagnostics +#endif + +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -21,16 +28,19 @@ #endif (void) 1.0; + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-3{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: test/CodeGenOpenCL/fpmath.cl === --- test/CodeGenOpenCL/fpmath.cl +++ test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,7 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.2 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-FLT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DFP64 -cl-std=CL1.2 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +23,26 @@ return a / b; } -#pragma OPENCL EXTENSION cl_khr_fp64 : enable +#if __OPENCL_C_VERSION__ >=120 +void printf(constant char* fmt, ...); + +void testdbllit(long *val) { + // CHECK-FLT: float 2.00e+01 + // CHECK-DBL: double 2.00e+01 + printf("%f", 20.0); +} +#endif + +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1401,8 +1401,7 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || - S.getOpenCLOptions().cl_khr_fp64)) { +!(S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -705,9 +705,11 @@ if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, + nullptr, VK_RValue); // C11 6.3.2.1p2: // ... if the lvalue has atomic type, the value has the non-atomic version @@ -817,8 +819,16 @@ // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() ==
[PATCH] D24235: [OpenCL] Improve double literal handling
neil.hickey updated this revision to Diff 76587. neil.hickey added a comment. Sorry for the delay. It looks like the code to handle extensions was changed since Neil Henning added the check against opencl 1.2. Perhaps the best approach is just to remove the check. https://reviews.llvm.org/D24235 Files: lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/fpmath.cl test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -1,13 +1,16 @@ // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only // RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1 +// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64 // Test with a target not supporting fp64. // RUN: %clang_cc1 %s -triple r600-unknown-unknown -target-cpu r600 -verify -pedantic -fsyntax-only -DNOFP64 +#if __OPENCL_C_VERSION__ < 120 void f1(double da) { // expected-error {{type 'double' requires cl_khr_fp64 extension}} double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} (void) 1.0; // expected-warning {{double precision constant requires cl_khr_fp64}} } +#endif #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 @@ -21,16 +24,22 @@ #endif (void) 1.0; +#ifdef FP64 +// expected-no-diagnostics +#endif + #ifdef NOFP64 -// expected-warning@-2{{double precision constant requires cl_khr_fp64, casting to single precision}} +// expected-warning@-6{{double precision constant requires cl_khr_fp64, casting to single precision}} #endif } #pragma OPENCL EXTENSION cl_khr_fp64 : disable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} #endif +#if __OPENCL_C_VERSION__ < 120 void f3(void) { double d; // expected-error {{type 'double' requires cl_khr_fp64 extension}} } +#endif Index: test/CodeGenOpenCL/fpmath.cl === --- test/CodeGenOpenCL/fpmath.cl +++ test/CodeGenOpenCL/fpmath.cl @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.1 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; @@ -21,14 +22,26 @@ return a / b; } +void printf(constant char* fmt, ...); + +#ifndef NOFP64 #pragma OPENCL EXTENSION cl_khr_fp64 : enable +#endif +void testdbllit(long *val) { + // CHECK-DBL: float 2.00e+01 + // CHECK: double 2.00e+01 + printf("%f", 20.0); +} +#ifndef NOFP64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable double dpscalardiv(double a, double b) { // CHECK: @dpscalardiv // CHECK: #[[ATTR]] // CHECK-NOT: !fpmath return a / b; } +#endif // CHECK: attributes #[[ATTR]] = { // NODIVOPT: "correctly-rounded-divide-sqrt-fp-math"="false" Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1401,8 +1401,7 @@ Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || - S.getOpenCLOptions().cl_khr_fp64)) { +!(S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -705,9 +705,13 @@ if (getLangOpts().ObjCAutoRefCount && E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); + + ExprResult Res = E; - ExprResult Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, -nullptr, VK_RValue); + if ( T != E->getType()) { +Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, + nullptr, VK_RValue); + } // C11 6.3.2.1p2: // ... if the lvalue has atomic type, the value has the non-atomic version @@ -817,8 +821,16 @@ // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || - BTy->getKind() == BuiltinType::Float)) -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + BTy->getKind() == BuiltinType::Float)) { +if (getLangOpts().OpenCL && +
r289650 - Fixing cast condition for removing casts from builtin FPClassification.
Author: neil.hickey Date: Wed Dec 14 07:18:48 2016 New Revision: 289650 URL: http://llvm.org/viewvc/llvm-project?rev=289650=rev Log: Fixing cast condition for removing casts from builtin FPClassification. The function SemaBuiltinFPClassification removed superfluous float to double casts, this was changed to also remove float to float casts but this isn't valid in all cases, for example when doing an rvaluetolvalue cast. Added a check to only remove if this was a conventional floating cast. Added additional tests into SemaOpenCL/extensions to cover these cases Modified: cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/SemaOpenCL/extensions.cl Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=289650=289649=289650=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Dec 14 07:18:48 2016 @@ -3750,13 +3750,16 @@ bool Sema::SemaBuiltinFPClassification(C // If this is an implicit conversion from float -> float or double, remove it. if (ImplicitCastExpr *Cast = dyn_cast(OrigArg)) { -Expr *CastArg = Cast->getSubExpr(); -if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Float)) { -assert((Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) || -Cast->getType()->isSpecificBuiltinType(BuiltinType::Float)) && - "promotion from float to either float or double is the only expected cast here"); - Cast->setSubExpr(nullptr); - TheCall->setArg(NumArgs-1, CastArg); +// Only remove standard FloatCasts, leaving other casts inplace +if (Cast->getCastKind() == CK_FloatingCast) { + Expr *CastArg = Cast->getSubExpr(); + if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Float)) { + assert((Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) || + Cast->getType()->isSpecificBuiltinType(BuiltinType::Float)) && + "promotion from float to either float or double is the only expected cast here"); +Cast->setSubExpr(nullptr); +TheCall->setArg(NumArgs-1, CastArg); + } } } Modified: cfe/trunk/test/SemaOpenCL/extensions.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extensions.cl?rev=289650=289649=289650=diff == --- cfe/trunk/test/SemaOpenCL/extensions.cl (original) +++ cfe/trunk/test/SemaOpenCL/extensions.cl Wed Dec 14 07:18:48 2016 @@ -35,6 +35,14 @@ void f1(double da) { // expected-error { } #endif +int isnan(float x) { +return __builtin_isnan(x); +} + +int isfinite(float x) { +return __builtin_isfinite(x); +} + #pragma OPENCL EXTENSION cl_khr_fp64 : enable #ifdef NOFP64 // expected-warning@-2{{unsupported OpenCL extension 'cl_khr_fp64' - ignoring}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r289544 - Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64.
Author: neil.hickey Date: Tue Dec 13 10:22:50 2016 New Revision: 289544 URL: http://llvm.org/viewvc/llvm-project?rev=289544=rev Log: Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64. This change makes sure single-precision floating point types are used if the cl_fp64 extension is not supported by the target. Also removed the check to see whether the OpenCL version is >= 1.2, as this has been incorporated into the extension setting code. Differential Revision: https://reviews.llvm.org/D24235 Modified: cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/test/CodeGenOpenCL/fpmath.cl cfe/trunk/test/SemaOpenCL/extensions.cl Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=289544=289543=289544=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Dec 13 10:22:50 2016 @@ -3748,12 +3748,13 @@ bool Sema::SemaBuiltinFPClassification(C diag::err_typecheck_call_invalid_unary_fp) << OrigArg->getType() << OrigArg->getSourceRange(); - // If this is an implicit conversion from float -> double, remove it. + // If this is an implicit conversion from float -> float or double, remove it. if (ImplicitCastExpr *Cast = dyn_cast(OrigArg)) { Expr *CastArg = Cast->getSubExpr(); if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Float)) { - assert(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) && - "promotion from float to double is the only expected cast here"); +assert((Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) || +Cast->getType()->isSpecificBuiltinType(BuiltinType::Float)) && + "promotion from float to either float or double is the only expected cast here"); Cast->setSubExpr(nullptr); TheCall->setArg(NumArgs-1, CastArg); } Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=289544=289543=289544=diff == --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Dec 13 10:22:50 2016 @@ -817,8 +817,16 @@ ExprResult Sema::DefaultArgumentPromotio // double. const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || - BTy->getKind() == BuiltinType::Float)) -E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); + BTy->getKind() == BuiltinType::Float)) { +if (getLangOpts().OpenCL && +!(getOpenCLOptions().cl_khr_fp64)) { +if (BTy->getKind() == BuiltinType::Half) { +E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get(); +} +} else { + E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); +} + } // C++ performs lvalue-to-rvalue conversion as a default argument // promotion, even on class types, but note: @@ -3397,10 +3405,13 @@ ExprResult Sema::ActOnNumericConstant(co if (Ty == Context.DoubleTy) { if (getLangOpts().SinglePrecisionConstants) { -Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); +const BuiltinType *BTy = Ty->getAs(); +if (BTy->getKind() != BuiltinType::Float) { + Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); +} } else if (getLangOpts().OpenCL && - !((getLangOpts().OpenCLVersion >= 120) || - getOpenCLOptions().cl_khr_fp64)) { + !(getOpenCLOptions().cl_khr_fp64)) { +// Impose single-precision float type when cl_khr_fp64 is not enabled. Diag(Tok.getLocation(), diag::warn_double_const_requires_fp64); Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get(); } Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=289544=289543=289544=diff == --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Tue Dec 13 10:22:50 2016 @@ -1403,8 +1403,7 @@ static QualType ConvertDeclSpecToType(Ty Result = Context.DoubleTy; if (S.getLangOpts().OpenCL && -!((S.getLangOpts().OpenCLVersion >= 120) || - S.getOpenCLOptions().cl_khr_fp64)) { +!(S.getOpenCLOptions().cl_khr_fp64)) { S.Diag(DS.getTypeSpecTypeLoc(), diag::err_type_requires_extension) << Result << "cl_khr_fp64"; declarator.setInvalidType(true); Modified: cfe/trunk/test/CodeGenOpenCL/fpmath.cl URL:
r289552 - Fixing build failure by adding triple option to new test condition.
Author: neil.hickey Date: Tue Dec 13 11:04:33 2016 New Revision: 289552 URL: http://llvm.org/viewvc/llvm-project?rev=289552=rev Log: Fixing build failure by adding triple option to new test condition. Adding -triple option to ensure target supports double for fpmath test. Modified: cfe/trunk/test/CodeGenOpenCL/fpmath.cl Modified: cfe/trunk/test/CodeGenOpenCL/fpmath.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/fpmath.cl?rev=289552=289551=289552=diff == --- cfe/trunk/test/CodeGenOpenCL/fpmath.cl (original) +++ cfe/trunk/test/CodeGenOpenCL/fpmath.cl Tue Dec 13 11:04:33 2016 @@ -1,7 +1,7 @@ // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck --check-prefix=CHECK --check-prefix=NODIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown -cl-fp32-correctly-rounded-divide-sqrt | FileCheck --check-prefix=CHECK --check-prefix=DIVOPT %s // RUN: %clang_cc1 %s -emit-llvm -o - -DNOFP64 -cl-std=CL1.2 -triple r600-unknown-unknown -target-cpu r600 -pedantic | FileCheck --check-prefix=CHECK-FLT %s -// RUN: %clang_cc1 %s -emit-llvm -o - -DFP64 -cl-std=CL1.2 -pedantic | FileCheck --check-prefix=CHECK-DBL %s +// RUN: %clang_cc1 %s -emit-llvm -o - -DFP64 -cl-std=CL1.2 -triple spir-unknown-unknown -pedantic | FileCheck --check-prefix=CHECK-DBL %s typedef __attribute__(( ext_vector_type(4) )) float float4; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
RE: r286815 - Improve handling of floating point literals in OpenCL to only use double precision if the target supports fp64.
I looked into this, and for C, clang converts the literal to inf in the first case. OpenCL spec doesn't mention anything different so I presume the behaviour should match Cs behaviour, which is does with this change. More exhaustive tests could be implemented to ensure this though. Neil > -Original Message- > From: sca...@apple.com [mailto:sca...@apple.com] > Sent: 15 November 2016 13:20 > To: Neil Hickey > Cc: cfe-commits@lists.llvm.org; nd > Subject: Re: r286815 - Improve handling of floating point literals in OpenCL > to > only use double precision if the target supports fp64. > > The reason these commits bring it up is that I don’t see it clearly documented > whether: > > float x = 340282356779733661637539395458142568447.0; > > is interpreted as > > float x = 340282356779733661637539395458142568447.0f; // x is > FLT_MAX > > or as > > float x = (float)(340282356779733661637539395458142568447.0); // x > is INFINITY > > when the no-fp64 mode is active. I assume that only one of these is the > correct behavior, and we should have a regression test that will flag the > error > if it changes. > > – Steve > > > On Nov 15, 2016, at 4:51 AM, Neil Hickey <neil.hic...@arm.com> wrote: > > > > It would be valuable to perform that test, if clang tests don't already do > this, though I'm not sure it should be part of this particular commit as all > this > commit should do is change the casts if the target doesn't support double. > > > > Neil > > > >> -Original Message- > >> From: sca...@apple.com [mailto:sca...@apple.com] > >> Sent: 14 November 2016 16:01 > >> To: Neil Hickey > >> Cc: cfe-commits@lists.llvm.org > >> Subject: Re: r286815 - Improve handling of floating point literals in > >> OpenCL to only use double precision if the target supports fp64. > >> > >> Can you add some non-trivial test cases that exercise > >> double-rounding, especially near the overflow boundary? > >> > >> e.g. What is the expected value of x if the target does not support fp64?: > >> > >>float x = 340282356779733661637539395458142568447.0; > >> > >> – Steve > >> > >>> On Nov 14, 2016, at 6:15 AM, Neil Hickey via cfe-commits >> comm...@lists.llvm.org> wrote: > >>> > >>> Author: neil.hickey > >>> Date: Mon Nov 14 05:15:51 2016 > >>> New Revision: 286815 > >>> > >>> URL: http://llvm.org/viewvc/llvm-project?rev=286815=rev > >>> Log: > >>> Improve handling of floating point literals in OpenCL to only use > >>> double > >> precision if the target supports fp64. > >>> > >>> This change makes sure single-precision floating point types are > >>> used if the > >>> cl_fp64 extension is not supported by the target. > >>> > >>> Also removed the check to see whether the OpenCL version is >= 1.2, > >>> as this has been incorporated into the extension setting code. > >>> > >>> Differential Revision: https://reviews.llvm.org/D24235 > >>> > >>> > >>> Modified: > >>> cfe/trunk/lib/Sema/SemaExpr.cpp > >>> cfe/trunk/lib/Sema/SemaType.cpp > >>> cfe/trunk/test/CodeGenOpenCL/fpmath.cl > >>> cfe/trunk/test/SemaOpenCL/extensions.cl > >>> > >>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp > >>> URL: > >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp? > >>> re v=286815=286814=286815=diff > >>> > >> > == > >> > >>> > >>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) > >>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Nov 14 05:15:51 2016 > >>> @@ -705,9 +705,13 @@ ExprResult Sema::DefaultLvalueConversion if > >>> (getLangOpts().ObjCAutoRefCount && > >>> E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) > >>> Cleanup.setExprNeedsCleanups(true); > >>> + > >>> + ExprResult Res = E; > >>> > >>> - ExprResult Res = ImplicitCastExpr::Create(Context, T, > >> CK_LValueToRValue, E, > >>> -nullptr, VK_RValue); > >>> + if ( T != E->getType()) { > >>> +Res = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue, E, > >&g
r366212 - [OpenCL] Fixing sampler initialisations for C++ mode.
Author: neil.hickey Date: Tue Jul 16 07:57:32 2019 New Revision: 366212 URL: http://llvm.org/viewvc/llvm-project?rev=366212=rev Log: [OpenCL] Fixing sampler initialisations for C++ mode. Allow conversions between integer and sampler type. Differential Revision: https://reviews.llvm.org/D64791 Modified: cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/lib/Sema/SemaOverload.cpp cfe/trunk/test/CodeGenOpenCL/sampler.cl Modified: cfe/trunk/lib/Sema/SemaInit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=366212=366211=366212=diff == --- cfe/trunk/lib/Sema/SemaInit.cpp (original) +++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Jul 16 07:57:32 2019 @@ -5640,6 +5640,9 @@ void InitializationSequence::InitializeF bool allowObjCWritebackConversion = S.getLangOpts().ObjCAutoRefCount && Entity.isParameterKind(); + if (TryOCLSamplerInitialization(S, *this, DestType, Initializer)) +return; + // We're at the end of the line for C: it's either a write-back conversion // or it's a C assignment. There's no need to check anything else. if (!S.getLangOpts().CPlusPlus) { @@ -5649,9 +5652,6 @@ void InitializationSequence::InitializeF return; } -if (TryOCLSamplerInitialization(S, *this, DestType, Initializer)) - return; - if (TryOCLZeroOpaqueTypeInitialization(S, *this, DestType, Initializer)) return; Modified: cfe/trunk/lib/Sema/SemaOverload.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=366212=366211=366212=diff == --- cfe/trunk/lib/Sema/SemaOverload.cpp (original) +++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Jul 16 07:57:32 2019 @@ -1851,6 +1851,10 @@ static bool IsStandardConversion(Sema (From->EvaluateKnownConstInt(S.getASTContext()) == 0)) { SCS.Second = ICK_Zero_Queue_Conversion; FromType = ToType; + } else if (ToType->isSamplerT() && + From->isIntegerConstantExpr(S.getASTContext())) { +SCS.Second = ICK_Compatible_Conversion; +FromType = ToType; } else { // No second conversion required. SCS.Second = ICK_Identity; Modified: cfe/trunk/test/CodeGenOpenCL/sampler.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/sampler.cl?rev=366212=366211=366212=diff == --- cfe/trunk/test/CodeGenOpenCL/sampler.cl (original) +++ cfe/trunk/test/CodeGenOpenCL/sampler.cl Tue Jul 16 07:57:32 2019 @@ -1,5 +1,6 @@ // RUN: %clang_cc1 %s -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s // RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s +// RUN: %clang_cc1 %s -cl-std=c++ -emit-llvm -triple spir-unknown-unknown -o - -O0 | FileCheck %s // // This test covers 5 cases of sampler initialzation: // 1. function argument passing @@ -29,7 +30,7 @@ const sampler_t glb_smp_const = CLK_ADDR int get_sampler_initializer(void); void fnc4smp(sampler_t s) {} -// CHECK: define spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* % +// CHECK: define spir_func void [[FUNCNAME:@.*fnc4smp.*]](%opencl.sampler_t addrspace(2)* % kernel void foo(sampler_t smp_par) { // CHECK-LABEL: define spir_kernel void @foo(%opencl.sampler_t addrspace(2)* %smp_par) @@ -45,32 +46,32 @@ kernel void foo(sampler_t smp_par) { fnc4smp(smp); // CHECK-NOT: call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19) // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_ptr]] - // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]]) + // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]]) // Case 1b fnc4smp(smp); // CHECK-NOT: call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19) // CHECK: [[SAMP:%[0-9]+]] = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** [[smp_ptr]] - // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]]) + // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]]) // Case 1a/2a fnc4smp(glb_smp); // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35) - // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]]) + // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t addrspace(2)* [[SAMP]]) // Case 1a/2c fnc4smp(glb_smp_const); // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 35) - // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]]) + // CHECK: call spir_func void [[FUNCNAME]](%opencl.sampler_t