diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 0fdebe207b555..1e844017f5718 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9774,10 +9774,6 @@ class Sema { AssignmentAction Action, CheckedConversionKind CCK); - ExprResult PerformQualificationConversion( - Expr *E, QualType Ty, ExprValueKind VK = VK_RValue, - CheckedConversionKind CCK = CCK_ImplicitConversion); - /// the following "Check" methods will return a valid/converted QualType /// or a null QualType (indicating an error diagnostic was issued). diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 11191c4682d9a..c7d6bcf02de35 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1660,18 +1660,13 @@ bool CastExpr::CastConsistency() const { assert(getSubExpr()->getType()->isFunctionType()); goto CheckNoBasePath; - case CK_AddressSpaceConversion: { - auto Ty = getType(); - auto SETy = getSubExpr()->getType(); - assert(getValueKindForType(Ty) == Expr::getValueKindForType(SETy)); - if (!isGLValue()) - Ty = Ty->getPointeeType(); - if (!isGLValue()) - SETy = SETy->getPointeeType(); - assert(!Ty.isNull() && !SETy.isNull() && - Ty.getAddressSpace() != SETy.getAddressSpace()); - goto CheckNoBasePath; - } + case CK_AddressSpaceConversion: + assert(getType()->isPointerType() || getType()->isBlockPointerType()); + assert(getSubExpr()->getType()->isPointerType() || + getSubExpr()->getType()->isBlockPointerType()); + assert(getType()->getPointeeType().getAddressSpace() != + getSubExpr()->getType()->getPointeeType().getAddressSpace()); + LLVM_FALLTHROUGH; // These should not have an inheritance path. case CK_Dynamic: case CK_ToUnion: diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 6ef1091cc0ddb..e2c9362c45529 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -4168,6 +4168,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { case CK_ARCReclaimReturnedObject: case CK_ARCExtendBlockObject: case CK_CopyAndAutoreleaseBlockObject: + case CK_AddressSpaceConversion: case CK_IntToOCLSampler: case CK_FixedPointCast: case CK_FixedPointToBoolean: @@ -4264,15 +4265,6 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { return MakeAddrLValue(V, E->getType(), LV.getBaseInfo(), CGM.getTBAAInfoForSubobject(LV, E->getType())); } - case CK_AddressSpaceConversion: { - LValue LV = EmitLValue(E->getSubExpr()); - QualType DestTy = getContext().getPointerType(E->getType()); - llvm::Value *V = getTargetHooks().performAddrSpaceCast( - *this, LV.getPointer(), E->getSubExpr()->getType().getAddressSpace(), - E->getType().getAddressSpace(), ConvertType(DestTy)); - return MakeAddrLValue(Address(V, LV.getAddress().getAlignment()), - E->getType(), LV.getBaseInfo(), LV.getTBAAInfo()); - } case CK_ObjCObjectLValueCast: { LValue LV = EmitLValue(E->getSubExpr()); Address V = Builder.CreateElementBitCast(LV.getAddress(), diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp index 2efa0a7fd1d2f..ea8c4ec40d8ff 100644 --- a/clang/lib/Sema/DeclSpec.cpp +++ b/clang/lib/Sema/DeclSpec.cpp @@ -566,16 +566,14 @@ bool DeclSpec::SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, // these storage-class specifiers. // OpenCL v1.2 s6.8 changes this to "The auto and register storage-class // specifiers are not supported." - // OpenCL C++ v1.0 s2.9 restricts register. if (S.getLangOpts().OpenCL && !S.getOpenCLOptions().isEnabled("cl_clang_storage_class_specifiers")) { switch (SC) { case SCS_extern: case SCS_private_extern: case SCS_static: - if (S.getLangOpts().OpenCLVersion < 120 && - !S.getLangOpts().OpenCLCPlusPlus) { - DiagID = diag::err_opencl_unknown_type_specifier; + if (S.getLangOpts().OpenCLVersion < 120) { + DiagID = diag::err_opencl_unknown_type_specifier; PrevSpec = getSpecifierName(SC); return true; } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 80cafbedf5e14..4746a198fe69c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -7359,23 +7359,19 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) { return; } } - // OpenCL C v1.2 s6.5 - All program scope variables must be declared in the + // OpenCL v1.2 s6.5 - All program scope variables must be declared in the // __constant address space. - // OpenCL C v2.0 s6.5.1 - Variables defined at program scope and static + // OpenCL v2.0 s6.5.1 - Variables defined at program scope and static // variables inside a function can also be declared in the global // address space. - // OpenCL C++ v1.0 s2.5 inherits rule from OpenCL C v2.0 and allows local - // address space additionally. - // FIXME: Add local AS for OpenCL C++. if (NewVD->isFileVarDecl() || NewVD->isStaticLocal() || NewVD->hasExternalStorage()) { if (!T->isSamplerT() && !(T.getAddressSpace() == LangAS::opencl_constant || (T.getAddressSpace() == LangAS::opencl_global && - (getLangOpts().OpenCLVersion == 200 || - getLangOpts().OpenCLCPlusPlus)))) { + getLangOpts().OpenCLVersion == 200))) { int Scope = NewVD->isStaticLocal() | NewVD->hasExternalStorage() << 1; - if (getLangOpts().OpenCLVersion == 200 || getLangOpts().OpenCLCPlusPlus) + if (getLangOpts().OpenCLVersion == 200) Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space) << Scope << "global or constant"; else diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 730c426076fae..ffd74656fa968 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -4276,24 +4276,10 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, case ICK_Qualification: { // The qualification keeps the category of the inner expression, unless the // target type isn't a reference. - ExprValueKind VK = - ToType->isReferenceType() ? From->getValueKind() : VK_RValue; - - CastKind CK = CK_NoOp; - - if (ToType->isReferenceType() && - ToType->getPointeeType().getAddressSpace() != - From->getType().getAddressSpace()) - CK = CK_AddressSpaceConversion; - - if (ToType->isPointerType() && - ToType->getPointeeType().getAddressSpace() != - From->getType()->getPointeeType().getAddressSpace()) - CK = CK_AddressSpaceConversion; - - From = ImpCastExprToType(From, ToType.getNonLValueExprType(Context), CK, VK, - /*BasePath=*/nullptr, CCK) - .get(); + ExprValueKind VK = ToType->isReferenceType() ? + From->getValueKind() : VK_RValue; + From = ImpCastExprToType(From, ToType.getNonLValueExprType(Context), + CK_NoOp, VK, /*BasePath=*/nullptr, CCK).get(); if (SCS.DeprecatedStringLiteralToCharPtr && !getLangOpts().WritableStrings) { diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 80cc4617eb5db..9d15ac0354e35 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -7261,20 +7261,12 @@ ExprResult Sema::TemporaryMaterializationConversion(Expr *E) { return CreateMaterializeTemporaryExpr(E->getType(), E, false); } -ExprResult Sema::PerformQualificationConversion(Expr *E, QualType Ty, - ExprValueKind VK, - CheckedConversionKind CCK) { - CastKind CK = (Ty.getAddressSpace() != E->getType().getAddressSpace()) - ? CK_AddressSpaceConversion - : CK_NoOp; - return ImpCastExprToType(E, Ty, CK, VK, /*BasePath=*/nullptr, CCK); -} - -ExprResult InitializationSequence::Perform(Sema &S, - const InitializedEntity &Entity, - const InitializationKind &Kind, - MultiExprArg Args, - QualType *ResultType) { +ExprResult +InitializationSequence::Perform(Sema &S, + const InitializedEntity &Entity, + const InitializationKind &Kind, + MultiExprArg Args, + QualType *ResultType) { if (Failed()) { Diagnose(S, Entity, Kind, Args); return ExprError(); @@ -7662,11 +7654,12 @@ ExprResult InitializationSequence::Perform(Sema &S, case SK_QualificationConversionRValue: { // Perform a qualification conversion; these can never go wrong. ExprValueKind VK = - Step->Kind == SK_QualificationConversionLValue - ? VK_LValue - : (Step->Kind == SK_QualificationConversionXValue ? VK_XValue - : VK_RValue); - CurInit = S.PerformQualificationConversion(CurInit.get(), Step->Type, VK); + Step->Kind == SK_QualificationConversionLValue ? + VK_LValue : + (Step->Kind == SK_QualificationConversionXValue ? + VK_XValue : + VK_RValue); + CurInit = S.ImpCastExprToType(CurInit.get(), Step->Type, CK_NoOp, VK); break; } diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 489eb9ee616d4..d9942e1c517e8 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -7255,8 +7255,7 @@ static void deduceOpenCLImplicitAddrSpace(TypeProcessingState &State, bool IsPointee = ChunkIndex > 0 && (D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Pointer || - D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer || - D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Reference); + D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::BlockPointer); bool IsFuncReturnType = ChunkIndex > 0 && D.getTypeObject(ChunkIndex - 1).Kind == DeclaratorChunk::Function;