diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp | 110 | ||||
-rw-r--r-- | clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h | 16 | ||||
-rw-r--r-- | clang/lib/Sema/HLSLExternalSemaSource.cpp | 26 | ||||
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 26 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Sema/SemaHLSL.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Sema/SemaOpenACC.cpp | 30 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateDeductionGuide.cpp | 9 |
9 files changed, 183 insertions, 54 deletions
diff --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp index 97a6a7f..3c20ccd 100644 --- a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp +++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp @@ -138,7 +138,16 @@ private: // LastStmt - refers to the last statement in the method body; referencing // LastStmt will remove the statement from the method body since // it will be linked from the new expression being constructed. - enum class PlaceHolder { _0, _1, _2, _3, _4, Handle = 128, LastStmt }; + enum class PlaceHolder { + _0, + _1, + _2, + _3, + _4, + Handle = 128, + CounterHandle, + LastStmt + }; Expr *convertPlaceholder(PlaceHolder PH); Expr *convertPlaceholder(LocalVar &Var); @@ -178,10 +187,14 @@ public: template <typename ResourceT, typename ValueT> BuiltinTypeMethodBuilder &setHandleFieldOnResource(ResourceT ResourceRecord, ValueT HandleValue); + template <typename T> + BuiltinTypeMethodBuilder & + accessCounterHandleFieldOnResource(T ResourceRecord); template <typename T> BuiltinTypeMethodBuilder &returnValue(T ReturnValue); BuiltinTypeMethodBuilder &returnThis(); BuiltinTypeDeclBuilder &finalize(); Expr *getResourceHandleExpr(); + Expr *getResourceCounterHandleExpr(); private: void createDecl(); @@ -346,6 +359,8 @@ TemplateParameterListBuilder::finalizeTemplateArgs(ConceptDecl *CD) { Expr *BuiltinTypeMethodBuilder::convertPlaceholder(PlaceHolder PH) { if (PH == PlaceHolder::Handle) return getResourceHandleExpr(); + if (PH == PlaceHolder::CounterHandle) + return getResourceCounterHandleExpr(); if (PH == PlaceHolder::LastStmt) { assert(!StmtsList.empty() && "no statements in the list"); @@ -467,6 +482,18 @@ Expr *BuiltinTypeMethodBuilder::getResourceHandleExpr() { OK_Ordinary); } +Expr *BuiltinTypeMethodBuilder::getResourceCounterHandleExpr() { + ensureCompleteDecl(); + + ASTContext &AST = DeclBuilder.SemaRef.getASTContext(); + CXXThisExpr *This = CXXThisExpr::Create( + AST, SourceLocation(), Method->getFunctionObjectParameterType(), true); + FieldDecl *HandleField = DeclBuilder.getResourceCounterHandleField(); + return MemberExpr::CreateImplicit(AST, This, false, HandleField, + HandleField->getType(), VK_LValue, + OK_Ordinary); +} + BuiltinTypeMethodBuilder & BuiltinTypeMethodBuilder::declareLocalVar(LocalVar &Var) { ensureCompleteDecl(); @@ -584,6 +611,22 @@ BuiltinTypeMethodBuilder::setHandleFieldOnResource(ResourceT ResourceRecord, } template <typename T> +BuiltinTypeMethodBuilder & +BuiltinTypeMethodBuilder::accessCounterHandleFieldOnResource(T ResourceRecord) { + ensureCompleteDecl(); + + Expr *ResourceExpr = convertPlaceholder(ResourceRecord); + + ASTContext &AST = DeclBuilder.SemaRef.getASTContext(); + FieldDecl *HandleField = DeclBuilder.getResourceCounterHandleField(); + MemberExpr *HandleExpr = MemberExpr::CreateImplicit( + AST, ResourceExpr, false, HandleField, HandleField->getType(), VK_LValue, + OK_Ordinary); + StmtsList.push_back(HandleExpr); + return *this; +} + +template <typename T> BuiltinTypeMethodBuilder &BuiltinTypeMethodBuilder::returnValue(T ReturnValue) { ensureCompleteDecl(); @@ -722,8 +765,31 @@ BuiltinTypeDeclBuilder::addMemberVariable(StringRef Name, QualType Type, return *this; } +BuiltinTypeDeclBuilder & +BuiltinTypeDeclBuilder::addBufferHandles(ResourceClass RC, bool IsROV, + bool RawBuffer, bool HasCounter, + AccessSpecifier Access) { + addHandleMember(RC, IsROV, RawBuffer, Access); + if (HasCounter) + addCounterHandleMember(RC, IsROV, RawBuffer, Access); + return *this; +} + BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addHandleMember( ResourceClass RC, bool IsROV, bool RawBuffer, AccessSpecifier Access) { + return addResourceMember("__handle", RC, IsROV, RawBuffer, + /*IsCounter=*/false, Access); +} + +BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addCounterHandleMember( + ResourceClass RC, bool IsROV, bool RawBuffer, AccessSpecifier Access) { + return addResourceMember("__counter_handle", RC, IsROV, RawBuffer, + /*IsCounter=*/true, Access); +} + +BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addResourceMember( + StringRef MemberName, ResourceClass RC, bool IsROV, bool RawBuffer, + bool IsCounter, AccessSpecifier Access) { assert(!Record->isCompleteDefinition() && "record is already complete"); ASTContext &Ctx = SemaRef.getASTContext(); @@ -739,9 +805,12 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addHandleMember( ElementTypeInfo ? HLSLContainedTypeAttr::CreateImplicit(Ctx, ElementTypeInfo) : nullptr}; + if (IsCounter) + Attrs.push_back(HLSLIsCounterAttr::CreateImplicit(Ctx)); + if (CreateHLSLAttributedResourceType(SemaRef, Ctx.HLSLResourceTy, Attrs, AttributedResTy)) - addMemberVariable("__handle", AttributedResTy, {}, Access); + addMemberVariable(MemberName, AttributedResTy, {}, Access); return *this; } @@ -844,12 +913,17 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addCopyConstructor() { using PH = BuiltinTypeMethodBuilder::PlaceHolder; - return BuiltinTypeMethodBuilder(*this, /*Name=*/"", AST.VoidTy, - /*IsConst=*/false, /*IsCtor=*/true) - .addParam("other", ConstRecordRefType) + BuiltinTypeMethodBuilder MMB(*this, /*Name=*/"", AST.VoidTy, + /*IsConst=*/false, /*IsCtor=*/true); + MMB.addParam("other", ConstRecordRefType) .accessHandleFieldOnResource(PH::_0) - .assign(PH::Handle, PH::LastStmt) - .finalize(); + .assign(PH::Handle, PH::LastStmt); + + if (getResourceCounterHandleField()) + MMB.accessCounterHandleFieldOnResource(PH::_0).assign(PH::CounterHandle, + PH::LastStmt); + + return MMB.finalize(); } BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addCopyAssignmentOperator() { @@ -863,12 +937,16 @@ BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addCopyAssignmentOperator() { using PH = BuiltinTypeMethodBuilder::PlaceHolder; DeclarationName Name = AST.DeclarationNames.getCXXOperatorName(OO_Equal); - return BuiltinTypeMethodBuilder(*this, Name, RecordRefType) - .addParam("other", ConstRecordRefType) + BuiltinTypeMethodBuilder MMB(*this, Name, RecordRefType); + MMB.addParam("other", ConstRecordRefType) .accessHandleFieldOnResource(PH::_0) - .assign(PH::Handle, PH::LastStmt) - .returnThis() - .finalize(); + .assign(PH::Handle, PH::LastStmt); + + if (getResourceCounterHandleField()) + MMB.accessCounterHandleFieldOnResource(PH::_0).assign(PH::CounterHandle, + PH::LastStmt); + + return MMB.returnThis().finalize(); } BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addArraySubscriptOperators() { @@ -903,6 +981,14 @@ FieldDecl *BuiltinTypeDeclBuilder::getResourceHandleField() const { return I->second; } +FieldDecl *BuiltinTypeDeclBuilder::getResourceCounterHandleField() const { + auto I = Fields.find("__counter_handle"); + if (I == Fields.end() || + !I->second->getType()->isHLSLAttributedResourceType()) + return nullptr; + return I->second; +} + QualType BuiltinTypeDeclBuilder::getFirstTemplateTypeParam() { assert(Template && "record it not a template"); if (const auto *TTD = dyn_cast<TemplateTypeParmDecl>( diff --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h index 9448af1..a981602 100644 --- a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h +++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h @@ -72,8 +72,9 @@ public: AccessSpecifier Access = AccessSpecifier::AS_private); BuiltinTypeDeclBuilder & - addHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer, - AccessSpecifier Access = AccessSpecifier::AS_private); + addBufferHandles(ResourceClass RC, bool IsROV, bool RawBuffer, + bool HasCounter, + AccessSpecifier Access = AccessSpecifier::AS_private); BuiltinTypeDeclBuilder &addArraySubscriptOperators(); // Builtin types constructors @@ -95,7 +96,18 @@ public: BuiltinTypeDeclBuilder &addConsumeMethod(); private: + BuiltinTypeDeclBuilder &addResourceMember(StringRef MemberName, + ResourceClass RC, bool IsROV, + bool RawBuffer, bool IsCounter, + AccessSpecifier Access); + BuiltinTypeDeclBuilder & + addHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer, + AccessSpecifier Access = AccessSpecifier::AS_private); + BuiltinTypeDeclBuilder & + addCounterHandleMember(ResourceClass RC, bool IsROV, bool RawBuffer, + AccessSpecifier Access = AccessSpecifier::AS_private); FieldDecl *getResourceHandleField() const; + FieldDecl *getResourceCounterHandleField() const; QualType getFirstTemplateTypeParam(); QualType getHandleElementType(); Expr *getConstantIntExpr(int value); diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 464922b..cc43e94 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -230,9 +230,9 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() { /// Set up common members and attributes for buffer types static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, ResourceClass RC, bool IsROV, - bool RawBuffer) { + bool RawBuffer, bool HasCounter) { return BuiltinTypeDeclBuilder(S, Decl) - .addHandleMember(RC, IsROV, RawBuffer) + .addBufferHandles(RC, IsROV, RawBuffer, HasCounter) .addDefaultHandleConstructor() .addCopyConstructor() .addCopyAssignmentOperator() @@ -377,7 +377,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false, - /*RawBuffer=*/false) + /*RawBuffer=*/false, /*HasCounter=*/false) .addArraySubscriptOperators() .addLoadMethods() .completeDefinition(); @@ -389,7 +389,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false, - /*RawBuffer=*/false) + /*RawBuffer=*/false, /*HasCounter=*/false) .addArraySubscriptOperators() .addLoadMethods() .completeDefinition(); @@ -401,7 +401,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { .finalizeForwardDeclaration(); onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true, - /*RawBuffer=*/false) + /*RawBuffer=*/false, /*HasCounter=*/false) .addArraySubscriptOperators() .addLoadMethods() .completeDefinition(); @@ -412,7 +412,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { .finalizeForwardDeclaration(); onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false, - /*RawBuffer=*/true) + /*RawBuffer=*/true, /*HasCounter=*/false) .addArraySubscriptOperators() .addLoadMethods() .completeDefinition(); @@ -423,7 +423,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { .finalizeForwardDeclaration(); onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false, - /*RawBuffer=*/true) + /*RawBuffer=*/true, /*HasCounter=*/true) .addArraySubscriptOperators() .addLoadMethods() .addIncrementCounterMethod() @@ -437,7 +437,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { .finalizeForwardDeclaration(); onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false, - /*RawBuffer=*/true) + /*RawBuffer=*/true, /*HasCounter=*/true) .addAppendMethod() .completeDefinition(); }); @@ -448,7 +448,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { .finalizeForwardDeclaration(); onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false, - /*RawBuffer=*/true) + /*RawBuffer=*/true, /*HasCounter=*/true) .addConsumeMethod() .completeDefinition(); }); @@ -459,7 +459,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { .finalizeForwardDeclaration(); onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true, - /*RawBuffer=*/true) + /*RawBuffer=*/true, /*HasCounter=*/true) .addArraySubscriptOperators() .addLoadMethods() .addIncrementCounterMethod() @@ -471,14 +471,14 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { .finalizeForwardDeclaration(); onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, /*IsROV=*/false, - /*RawBuffer=*/true) + /*RawBuffer=*/true, /*HasCounter=*/false) .completeDefinition(); }); Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWByteAddressBuffer") .finalizeForwardDeclaration(); onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/false, - /*RawBuffer=*/true) + /*RawBuffer=*/true, /*HasCounter=*/false) .completeDefinition(); }); Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, @@ -486,7 +486,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { .finalizeForwardDeclaration(); onCompletion(Decl, [this](CXXRecordDecl *Decl) { setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, /*IsROV=*/true, - /*RawBuffer=*/true) + /*RawBuffer=*/true, /*HasCounter=*/false) .completeDefinition(); }); } diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 8b9e132..7ce3513 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -5954,9 +5954,6 @@ bool Sema::BuiltinAssumeAligned(CallExpr *TheCall) { if (Result > Sema::MaximumAlignment) Diag(TheCall->getBeginLoc(), diag::warn_assume_aligned_too_great) << SecondArg->getSourceRange() << Sema::MaximumAlignment; - - TheCall->setArg(1, - ConstantExpr::Create(Context, SecondArg, APValue(Result))); } if (NumArgs > 2) { @@ -14884,13 +14881,11 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, // Diag message shows element size in bits and in "bytes" (platform- // dependent CharUnits) DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr, - PDiag(DiagID) - << toString(index, 10, true) << AddrBits - << (unsigned)ASTC.toBits(*ElemCharUnits) - << toString(ElemBytes, 10, false) - << toString(MaxElems, 10, false) - << (unsigned)MaxElems.getLimitedValue(~0U) - << IndexExpr->getSourceRange()); + PDiag(DiagID) << index << AddrBits + << (unsigned)ASTC.toBits(*ElemCharUnits) + << ElemBytes << MaxElems + << MaxElems.getZExtValue() + << IndexExpr->getSourceRange()); const NamedDecl *ND = nullptr; // Try harder to find a NamedDecl to point at in the note. @@ -14973,10 +14968,10 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, unsigned CastMsg = (!ASE || BaseType == EffectiveType) ? 0 : 1; QualType CastMsgTy = ASE ? ASE->getLHS()->getType() : QualType(); - DiagRuntimeBehavior( - BaseExpr->getBeginLoc(), BaseExpr, - PDiag(DiagID) << toString(index, 10, true) << ArrayTy->desugar() - << CastMsg << CastMsgTy << IndexExpr->getSourceRange()); + DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr, + PDiag(DiagID) + << index << ArrayTy->desugar() << CastMsg + << CastMsgTy << IndexExpr->getSourceRange()); } else { unsigned DiagID = diag::warn_array_index_precedes_bounds; if (!ASE) { @@ -14985,8 +14980,7 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, } DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr, - PDiag(DiagID) << toString(index, 10, true) - << IndexExpr->getSourceRange()); + PDiag(DiagID) << index << IndexExpr->getSourceRange()); } const NamedDecl *ND = nullptr; diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 1131e1f..16d42d2 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -13660,7 +13660,7 @@ bool Sema::CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename, if (Cxx20Enumerator) { Diag(NameLoc, diag::warn_cxx17_compat_using_decl_non_member_enumerator) - << SS.getRange(); + << SS.getScopeRep() << SS.getRange(); return false; } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 06b2529..4d3c7d6 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -20107,9 +20107,10 @@ static void DoMarkVarDeclReferenced( bool NeededForConstantEvaluation = isPotentiallyConstantEvaluatedContext(SemaRef) && UsableInConstantExpr; - bool NeedDefinition = OdrUse == OdrUseContext::Used || - NeededForConstantEvaluation || - Var->getType()->isUndeducedType(); + bool NeedDefinition = + OdrUse == OdrUseContext::Used || NeededForConstantEvaluation || + (TSK != clang::TSK_Undeclared && !UsableInConstantExpr && + Var->getType()->isUndeducedType()); assert(!isa<VarTemplatePartialSpecializationDecl>(Var) && "Can't instantiate a partial template specialization."); diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 129b03c..fa30c66b 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -1810,6 +1810,13 @@ bool clang::CreateHLSLAttributedResourceType( } ResAttrs.RawBuffer = true; break; + case attr::HLSLIsCounter: + if (ResAttrs.IsCounter) { + S.Diag(A->getLocation(), diag::warn_duplicate_attribute_exact) << A; + return false; + } + ResAttrs.IsCounter = true; + break; case attr::HLSLContainedType: { const HLSLContainedTypeAttr *CTAttr = cast<HLSLContainedTypeAttr>(A); QualType Ty = CTAttr->getType(); @@ -1902,6 +1909,10 @@ bool SemaHLSL::handleResourceTypeAttr(QualType T, const ParsedAttr &AL) { A = HLSLRawBufferAttr::Create(getASTContext(), ACI); break; + case ParsedAttr::AT_HLSLIsCounter: + A = HLSLIsCounterAttr::Create(getASTContext(), ACI); + break; + case ParsedAttr::AT_HLSLContainedType: { if (AL.getNumArgs() != 1 && !AL.hasParsedType()) { Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp index a64f207..9aaf7f4 100644 --- a/clang/lib/Sema/SemaOpenACC.cpp +++ b/clang/lib/Sema/SemaOpenACC.cpp @@ -2789,7 +2789,7 @@ OpenACCPrivateRecipe SemaOpenACC::CreatePrivateInitRecipe(const Expr *VarExpr) { AllocaDecl->setInitStyle(VarDecl::CallInit); } - return OpenACCPrivateRecipe(AllocaDecl, Init.get()); + return OpenACCPrivateRecipe(AllocaDecl); } OpenACCFirstPrivateRecipe @@ -2828,7 +2828,14 @@ SemaOpenACC::CreateFirstPrivateInitRecipe(const Expr *VarExpr) { if (!ArrTy) { ExprResult Init = FinishValueInit( SemaRef.SemaRef, Entity, VarExpr->getBeginLoc(), VarTy, TemporaryDRE); - return OpenACCFirstPrivateRecipe(AllocaDecl, Init.get(), Temporary); + + // For 'no bounds' version, we can use this as a shortcut, so set the init + // anyway. + if (Init.isUsable()) { + AllocaDecl->setInit(Init.get()); + AllocaDecl->setInitStyle(VarDecl::CallInit); + } + return OpenACCFirstPrivateRecipe(AllocaDecl, Temporary); } // Arrays need to have each individual element initialized as there @@ -2875,8 +2882,16 @@ SemaOpenACC::CreateFirstPrivateInitRecipe(const Expr *VarExpr) { ExprResult Init = FinishValueInit(SemaRef.SemaRef, Entity, VarExpr->getBeginLoc(), VarTy, InitExpr); - return OpenACCFirstPrivateRecipe(AllocaDecl, Init.get(), Temporary); + // For 'no bounds' version, we can use this as a shortcut, so set the init + // anyway. + if (Init.isUsable()) { + AllocaDecl->setInit(Init.get()); + AllocaDecl->setInitStyle(VarDecl::CallInit); + } + + return OpenACCFirstPrivateRecipe(AllocaDecl, Temporary); } + OpenACCReductionRecipe SemaOpenACC::CreateReductionInitRecipe( OpenACCReductionOperator ReductionOperator, const Expr *VarExpr) { // TODO: OpenACC: This shouldn't be necessary, see PrivateInitRecipe @@ -2932,5 +2947,12 @@ OpenACCReductionRecipe SemaOpenACC::CreateReductionInitRecipe( ExprResult Init = FinishValueInit(SemaRef.SemaRef, Entity, VarExpr->getBeginLoc(), VarTy, InitExpr); - return OpenACCReductionRecipe(AllocaDecl, Init.get()); + + // For 'no bounds' version, we can use this as a shortcut, so set the init + // anyway. + if (Init.isUsable()) { + AllocaDecl->setInit(Init.get()); + AllocaDecl->setInitStyle(VarDecl::CallInit); + } + return OpenACCReductionRecipe(AllocaDecl); } diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp index 3d54d1e..fe673ea 100644 --- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp +++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp @@ -1428,10 +1428,13 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template, DeclareImplicitDeductionGuidesForTypeAlias(*this, AliasTemplate, Loc); return; } - if (CXXRecordDecl *DefRecord = - cast<CXXRecordDecl>(Template->getTemplatedDecl())->getDefinition()) { + CXXRecordDecl *DefRecord = + dyn_cast_or_null<CXXRecordDecl>(Template->getTemplatedDecl()); + if (!DefRecord) + return; + if (const CXXRecordDecl *Definition = DefRecord->getDefinition()) { if (TemplateDecl *DescribedTemplate = - DefRecord->getDescribedClassTemplate()) + Definition->getDescribedClassTemplate()) Template = DescribedTemplate; } |