Author: echuraev Date: Fri Dec 23 08:55:49 2016 New Revision: 290431 URL: http://llvm.org/viewvc/llvm-project?rev=290431&view=rev Log: Fix problems in "[OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand."
Summary: Fixed warnings in commit: https://reviews.llvm.org/rL290171 Reviewers: djasper, Anastasia Subscribers: yaxunl, cfe-commits, bader Differential Revision: https://reviews.llvm.org/D27981 Added: cfe/trunk/test/CodeGenOpenCL/null_queue.cl cfe/trunk/test/SemaOpenCL/null_queue.cl cfe/trunk/test/SemaOpenCL/queue_t_overload.cl Modified: cfe/trunk/include/clang/AST/OperationKinds.def cfe/trunk/include/clang/Sema/Initialization.h cfe/trunk/include/clang/Sema/Overload.h cfe/trunk/lib/AST/Expr.cpp cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/lib/CodeGen/CGExpr.cpp cfe/trunk/lib/CodeGen/CGExprAgg.cpp cfe/trunk/lib/CodeGen/CGExprComplex.cpp cfe/trunk/lib/CodeGen/CGExprConstant.cpp cfe/trunk/lib/CodeGen/CGExprScalar.cpp cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/lib/Sema/SemaOverload.cpp cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp Modified: cfe/trunk/include/clang/AST/OperationKinds.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OperationKinds.def?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/OperationKinds.def (original) +++ cfe/trunk/include/clang/AST/OperationKinds.def Fri Dec 23 08:55:49 2016 @@ -321,6 +321,9 @@ CAST_OPERATION(BuiltinFnToFnPtr) // Convert a zero value for OpenCL event_t initialization. CAST_OPERATION(ZeroToOCLEvent) +// Convert a zero value for OpenCL queue_t initialization. +CAST_OPERATION(ZeroToOCLQueue) + // Convert a pointer to a different address space. CAST_OPERATION(AddressSpaceConversion) Modified: cfe/trunk/include/clang/Sema/Initialization.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Initialization.h?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/Initialization.h (original) +++ cfe/trunk/include/clang/Sema/Initialization.h Fri Dec 23 08:55:49 2016 @@ -751,6 +751,8 @@ public: SK_StdInitializerListConstructorCall, /// \brief Initialize an OpenCL sampler from an integer. SK_OCLSamplerInit, + /// \brief Initialize queue_t from 0. + SK_OCLZeroQueue, /// \brief Passing zero to a function where OpenCL event_t is expected. SK_OCLZeroEvent }; @@ -1148,6 +1150,9 @@ public: /// constant. void AddOCLZeroEventStep(QualType T); + /// \brief Add a step to initialize an OpenCL queue_t from 0. + void AddOCLZeroQueueStep(QualType T); + /// \brief Add steps to unwrap a initializer list for a reference around a /// single element and rewrap it at the end. void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic); Modified: cfe/trunk/include/clang/Sema/Overload.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/Overload.h (original) +++ cfe/trunk/include/clang/Sema/Overload.h Fri Dec 23 08:55:49 2016 @@ -83,6 +83,7 @@ namespace clang { ICK_TransparentUnionConversion, ///< Transparent Union Conversions ICK_Writeback_Conversion, ///< Objective-C ARC writeback conversion ICK_Zero_Event_Conversion, ///< Zero constant to event (OpenCL1.2 6.12.10) + ICK_Zero_Queue_Conversion, ///< Zero constant to queue ICK_C_Only_Conversion, ///< Conversions allowed in C, but not C++ ICK_Incompatible_Pointer_Conversion, ///< C-only conversion between pointers /// with incompatible types Modified: cfe/trunk/lib/AST/Expr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/AST/Expr.cpp (original) +++ cfe/trunk/lib/AST/Expr.cpp Fri Dec 23 08:55:49 2016 @@ -1603,6 +1603,7 @@ bool CastExpr::CastConsistency() const { case CK_ARCReclaimReturnedObject: case CK_ARCExtendBlockObject: case CK_ZeroToOCLEvent: + case CK_ZeroToOCLQueue: case CK_IntToOCLSampler: assert(!getType()->isBooleanType() && "unheralded conversion to bool"); goto CheckNoBasePath; Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Dec 23 08:55:49 2016 @@ -8590,6 +8590,7 @@ bool IntExprEvaluator::VisitCastExpr(con case CK_IntegralComplexToFloatingComplex: case CK_BuiltinFnToFnPtr: case CK_ZeroToOCLEvent: + case CK_ZeroToOCLQueue: case CK_NonAtomicToAtomic: case CK_AddressSpaceConversion: case CK_IntToOCLSampler: @@ -9087,6 +9088,7 @@ bool ComplexExprEvaluator::VisitCastExpr case CK_CopyAndAutoreleaseBlockObject: case CK_BuiltinFnToFnPtr: case CK_ZeroToOCLEvent: + case CK_ZeroToOCLQueue: case CK_NonAtomicToAtomic: case CK_AddressSpaceConversion: case CK_IntToOCLSampler: Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Dec 23 08:55:49 2016 @@ -3781,6 +3781,8 @@ LValue CodeGenFunction::EmitCastLValue(c ConvertType(E->getType())); return MakeAddrLValue(V, E->getType(), LV.getAlignmentSource()); } + case CK_ZeroToOCLQueue: + llvm_unreachable("NULL to OpenCL queue lvalue cast is not valid"); case CK_ZeroToOCLEvent: llvm_unreachable("NULL to OpenCL event lvalue cast is not valid"); } Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Fri Dec 23 08:55:49 2016 @@ -751,6 +751,7 @@ void AggExprEmitter::VisitCastExpr(CastE case CK_CopyAndAutoreleaseBlockObject: case CK_BuiltinFnToFnPtr: case CK_ZeroToOCLEvent: + case CK_ZeroToOCLQueue: case CK_AddressSpaceConversion: case CK_IntToOCLSampler: llvm_unreachable("cast kind invalid for aggregate types"); Modified: cfe/trunk/lib/CodeGen/CGExprComplex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprComplex.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprComplex.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprComplex.cpp Fri Dec 23 08:55:49 2016 @@ -480,6 +480,7 @@ ComplexPairTy ComplexExprEmitter::EmitCa case CK_CopyAndAutoreleaseBlockObject: case CK_BuiltinFnToFnPtr: case CK_ZeroToOCLEvent: + case CK_ZeroToOCLQueue: case CK_AddressSpaceConversion: case CK_IntToOCLSampler: llvm_unreachable("invalid cast kind for complex value"); Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri Dec 23 08:55:49 2016 @@ -753,6 +753,7 @@ public: case CK_FloatingToBoolean: case CK_FloatingCast: case CK_ZeroToOCLEvent: + case CK_ZeroToOCLQueue: return nullptr; } llvm_unreachable("Invalid CastKind"); Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Dec 23 08:55:49 2016 @@ -1593,6 +1593,11 @@ Value *ScalarExprEmitter::VisitCastExpr( return llvm::Constant::getNullValue(ConvertType(DestTy)); } + case CK_ZeroToOCLQueue: { + assert(DestTy->isQueueT() && "CK_ZeroToOCLQueue cast on non queue_t type"); + return llvm::Constant::getNullValue(ConvertType(DestTy)); + } + case CK_IntToOCLSampler: return CGF.CGM.createOpenCLIntToSamplerConversion(E, CGF); Modified: cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp (original) +++ cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp Fri Dec 23 08:55:49 2016 @@ -1076,6 +1076,7 @@ static bool rewriteToNumericBoxedExpress case CK_CopyAndAutoreleaseBlockObject: case CK_BuiltinFnToFnPtr: case CK_ZeroToOCLEvent: + case CK_ZeroToOCLQueue: case CK_IntToOCLSampler: return false; Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Dec 23 08:55:49 2016 @@ -9635,6 +9635,18 @@ QualType Sema::CheckCompareOperands(Expr return ResultTy; } + if (getLangOpts().OpenCLVersion >= 200) { + if (LHSIsNull && RHSType->isQueueT()) { + LHS = ImpCastExprToType(LHS.get(), RHSType, CK_NullToPointer); + return ResultTy; + } + + if (LHSType->isQueueT() && RHSIsNull) { + RHS = ImpCastExprToType(RHS.get(), LHSType, CK_NullToPointer); + return ResultTy; + } + } + return InvalidOperands(Loc, LHS, RHS); } Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Dec 23 08:55:49 2016 @@ -3878,6 +3878,12 @@ Sema::PerformImplicitConversion(Expr *Fr From->getValueKind()).get(); break; + case ICK_Zero_Queue_Conversion: + From = ImpCastExprToType(From, ToType, + CK_ZeroToOCLQueue, + From->getValueKind()).get(); + break; + case ICK_Lvalue_To_Rvalue: case ICK_Array_To_Pointer: case ICK_Function_To_Pointer: Modified: cfe/trunk/lib/Sema/SemaInit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaInit.cpp (original) +++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 23 08:55:49 2016 @@ -3077,6 +3077,7 @@ void InitializationSequence::Step::Destr case SK_StdInitializerListConstructorCall: case SK_OCLSamplerInit: case SK_OCLZeroEvent: + case SK_OCLZeroQueue: break; case SK_ConversionSequence: @@ -3365,6 +3366,13 @@ void InitializationSequence::AddOCLZeroE Steps.push_back(S); } +void InitializationSequence::AddOCLZeroQueueStep(QualType T) { + Step S; + S.Kind = SK_OCLZeroQueue; + S.Type = T; + Steps.push_back(S); +} + void InitializationSequence::RewrapReferenceInitList(QualType T, InitListExpr *Syntactic) { assert(Syntactic->getNumInits() == 1 && @@ -5022,6 +5030,20 @@ static bool TryOCLZeroEventInitializatio return true; } +static bool TryOCLZeroQueueInitialization(Sema &S, + InitializationSequence &Sequence, + QualType DestType, + Expr *Initializer) { + if (!S.getLangOpts().OpenCL || S.getLangOpts().OpenCLVersion < 200 || + !DestType->isQueueT() || + !Initializer->isIntegerConstantExpr(S.getASTContext()) || + (Initializer->EvaluateKnownConstInt(S.getASTContext()) != 0)) + return false; + + Sequence.AddOCLZeroQueueStep(DestType); + return true; +} + InitializationSequence::InitializationSequence(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, @@ -5284,6 +5306,9 @@ void InitializationSequence::InitializeF if (TryOCLZeroEventInitialization(S, *this, DestType, Initializer)) return; + if (TryOCLZeroQueueInitialization(S, *this, DestType, Initializer)) + return; + // Handle initialization in C AddCAssignmentStep(DestType); MaybeProduceObjCObject(S, *this, Entity); @@ -6521,7 +6546,8 @@ InitializationSequence::Perform(Sema &S, case SK_ProduceObjCObject: case SK_StdInitializerList: case SK_OCLSamplerInit: - case SK_OCLZeroEvent: { + case SK_OCLZeroEvent: + case SK_OCLZeroQueue: { assert(Args.size() == 1); CurInit = Args[0]; if (!CurInit.get()) return ExprError(); @@ -7205,6 +7231,15 @@ InitializationSequence::Perform(Sema &S, CurInit.get()->getValueKind()); break; } + case SK_OCLZeroQueue: { + assert(Step->Type->isQueueT() && + "Event initialization on non queue type."); + + CurInit = S.ImpCastExprToType(CurInit.get(), Step->Type, + CK_ZeroToOCLQueue, + CurInit.get()->getValueKind()); + break; + } } } @@ -8033,6 +8068,10 @@ void InitializationSequence::dump(raw_os case SK_OCLZeroEvent: OS << "OpenCL event_t from zero"; break; + + case SK_OCLZeroQueue: + OS << "OpenCL queue_t from zero"; + break; } OS << " [" << S->Type.getAsString() << ']'; Modified: cfe/trunk/lib/Sema/SemaOverload.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaOverload.cpp (original) +++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Dec 23 08:55:49 2016 @@ -1800,6 +1800,11 @@ static bool IsStandardConversion(Sema &S From->EvaluateKnownConstInt(S.getASTContext()) == 0) { SCS.Second = ICK_Zero_Event_Conversion; FromType = ToType; + } else if (ToType->isQueueT() && + From->isIntegerConstantExpr(S.getASTContext()) && + (From->EvaluateKnownConstInt(S.getASTContext()) == 0)) { + SCS.Second = ICK_Zero_Queue_Conversion; + FromType = ToType; } else { // No second conversion required. SCS.Second = ICK_Identity; @@ -5177,6 +5182,7 @@ static bool CheckConvertedConstantConver case ICK_Function_Conversion: case ICK_Integral_Promotion: case ICK_Integral_Conversion: // Narrowing conversions are checked elsewhere. + case ICK_Zero_Queue_Conversion: return true; case ICK_Boolean_Conversion: Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=290431&r1=290430&r2=290431&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp Fri Dec 23 08:55:49 2016 @@ -397,6 +397,7 @@ void ExprEngine::VisitCast(const CastExp case CK_AnyPointerToBlockPointerCast: case CK_ObjCObjectLValueCast: case CK_ZeroToOCLEvent: + case CK_ZeroToOCLQueue: case CK_IntToOCLSampler: case CK_LValueBitCast: { state = Added: cfe/trunk/test/CodeGenOpenCL/null_queue.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/null_queue.cl?rev=290431&view=auto ============================================================================== --- cfe/trunk/test/CodeGenOpenCL/null_queue.cl (added) +++ cfe/trunk/test/CodeGenOpenCL/null_queue.cl Fri Dec 23 08:55:49 2016 @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -emit-llvm %s -o - | FileCheck %s +extern queue_t get_default_queue(); + +bool compare() { + return 0 == get_default_queue() && + get_default_queue() == 0; + // CHECK: icmp eq %opencl.queue_t* null, %{{.*}} + // CHECK: icmp eq %opencl.queue_t* %{{.*}}, null +} + +void func(queue_t q); + +void init() { + queue_t q = 0; + func(0); + // CHECK: store %opencl.queue_t* null, %opencl.queue_t** %q + // CHECK: call void @func(%opencl.queue_t* null) +} Added: cfe/trunk/test/SemaOpenCL/null_queue.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/null_queue.cl?rev=290431&view=auto ============================================================================== --- cfe/trunk/test/SemaOpenCL/null_queue.cl (added) +++ cfe/trunk/test/SemaOpenCL/null_queue.cl Fri Dec 23 08:55:49 2016 @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only +extern queue_t get_default_queue(); + +bool compare() { + return 1 == get_default_queue() && // expected-error{{invalid operands to binary expression ('int' and 'queue_t')}} + get_default_queue() == 1; // expected-error{{invalid operands to binary expression ('queue_t' and 'int')}} +} + +void init() { + queue_t q1 = 1; // expected-error{{initializing 'queue_t' with an expression of incompatible type 'int'}} + queue_t q = 0; +} Added: cfe/trunk/test/SemaOpenCL/queue_t_overload.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/queue_t_overload.cl?rev=290431&view=auto ============================================================================== --- cfe/trunk/test/SemaOpenCL/queue_t_overload.cl (added) +++ cfe/trunk/test/SemaOpenCL/queue_t_overload.cl Fri Dec 23 08:55:49 2016 @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only + +void __attribute__((overloadable)) foo(queue_t, __local char *); // expected-note {{candidate function not viable: no known conversion from 'int' to 'queue_t' for 1st argument}} // expected-note {{candidate function}} +void __attribute__((overloadable)) foo(queue_t, __local float *); // expected-note {{candidate function not viable: no known conversion from 'int' to 'queue_t' for 1st argument}} // expected-note {{candidate function}} + +void kernel ker(__local char *src1, __local float *src2, __global int *src3) { + queue_t q; + foo(q, src1); + foo(0, src2); + foo(q, src3); // expected-error {{call to 'foo' is ambiguous}} + foo(1, src3); // expected-error {{no matching function for call to 'foo'}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits