diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -3679,6 +3679,7 @@ match_any match_none disable_implicit_base + allow_templates The match extensions change when the *entire* context selector is considered a match for an OpenMP context. The default is ``all``, with ``none`` no trait in the @@ -3690,6 +3691,11 @@ introduce an implicit base function for a variant if no base function was found. The variant is still generated but will never be called, due to the absence of a base function and consequently calls to a base function. +The allow extensions change when the ``begin declare variant`` effect is +applied to a definition. If ``allow_templates`` is given, template function +definitions are considered as specializations of existing or assumed template +declarations with the same name. The template parameters for the base functions +are used to instantiate the specialization. }]; } diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -10031,15 +10031,15 @@ /// The declarator \p D defines a function in the scope \p S which is nested /// in an `omp begin/end declare variant` scope. In this method we create a /// declaration for \p D and rename \p D according to the OpenMP context - /// selector of the surrounding scope. - FunctionDecl * - ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(Scope *S, - Declarator &D); + /// selector of the surrounding scope. Return all base functions in \p Bases. + void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( + Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, + SmallVectorImpl &Bases); - /// Register \p FD as specialization of \p BaseFD in the current `omp - /// begin/end declare variant` scope. + /// Register \p D as specialization of all base functions in \p Bases in the + /// current `omp begin/end declare variant` scope. void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope( - FunctionDecl *FD, FunctionDecl *BaseFD); + Decl *D, SmallVectorImpl &Bases); public: diff --git a/clang/lib/Headers/openmp_wrappers/cmath b/clang/lib/Headers/openmp_wrappers/cmath --- a/clang/lib/Headers/openmp_wrappers/cmath +++ b/clang/lib/Headers/openmp_wrappers/cmath @@ -24,8 +24,11 @@ // which might live in cstdlib. #include +// We need limits because __clang_cuda_cmath.h below uses `std::numeric_limit`. +#include + #pragma omp begin declare variant match( \ - device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)}) + device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any, allow_templates)}) #define __CUDA__ #define __OPENMP_NVPTX__ diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -939,6 +939,10 @@ TraitProperty::implementation_extension_disable_implicit_base) return true; + if (TIProperty.Kind == + TraitProperty::implementation_extension_allow_templates) + return true; + auto IsMatchExtension = [](OMPTraitProperty &TP) { return (TP.Kind == llvm::omp::TraitProperty::implementation_extension_match_all || diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -13757,19 +13757,17 @@ // variant` annotation which specifies the mangled definition as a // specialization function under the OpenMP context defined as part of the // `omp begin declare variant`. - FunctionDecl *BaseFD = nullptr; - if (LangOpts.OpenMP && isInOpenMPDeclareVariantScope() && - TemplateParameterLists.empty()) - BaseFD = ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( - ParentScope, D); + SmallVector Bases; + if (LangOpts.OpenMP && isInOpenMPDeclareVariantScope()) + ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( + ParentScope, D, TemplateParameterLists, Bases); D.setFunctionDefinitionKind(FDK_Definition); Decl *DP = HandleDeclarator(ParentScope, D, TemplateParameterLists); Decl *Dcl = ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody); - if (BaseFD) - ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope( - cast(Dcl), BaseFD); + if (!Bases.empty()) + ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(Dcl, Bases); return Dcl; } diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -5868,10 +5868,21 @@ Sema::OMPDeclareVariantScope::OMPDeclareVariantScope(OMPTraitInfo &TI) : TI(&TI), NameSuffix(TI.getMangledName()) {} -FunctionDecl * -Sema::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(Scope *S, - Declarator &D) { +void Sema::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( + Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParamLists, + SmallVectorImpl &Bases) { + if (!D.getIdentifier()) + return; + OMPDeclareVariantScope &DVScope = OMPDeclareVariantScopes.back(); + + // Template specialization is an extension, check if we do it. + bool IsTemplated = !TemplateParamLists.empty(); + if (IsTemplated & + !DVScope.TI->isExtensionActive( + llvm::omp::TraitProperty::implementation_extension_allow_templates)) + return; + IdentifierInfo *BaseII = D.getIdentifier(); LookupResult Lookup(*this, DeclarationName(BaseII), D.getIdentifierLoc(), LookupOrdinaryName); @@ -5883,9 +5894,13 @@ bool IsConstexpr = D.getDeclSpec().getConstexprSpecifier() == CSK_constexpr; bool IsConsteval = D.getDeclSpec().getConstexprSpecifier() == CSK_consteval; - FunctionDecl *BaseFD = nullptr; for (auto *Candidate : Lookup) { - auto *UDecl = dyn_cast(Candidate->getUnderlyingDecl()); + auto *CandidateDecl = Candidate->getUnderlyingDecl(); + FunctionDecl *UDecl = nullptr; + if (IsTemplated && isa(CandidateDecl)) + UDecl = cast(CandidateDecl)->getTemplatedDecl(); + else if (!IsTemplated) + UDecl = dyn_cast(CandidateDecl); if (!UDecl) continue; @@ -5896,23 +5911,31 @@ if (UDecl->isConsteval() && !IsConsteval) continue; - QualType NewType = Context.mergeFunctionTypes( - FType, UDecl->getType(), /* OfBlockPointer */ false, - /* Unqualified */ false, /* AllowCXX */ true); - if (NewType.isNull()) - continue; + QualType UDeclTy = UDecl->getType(); + // TODO: Verify types for templates eventually. + if (!UDeclTy->isDependentType()) { + QualType NewType = Context.mergeFunctionTypes( + FType, UDeclTy, /* OfBlockPointer */ false, + /* Unqualified */ false, /* AllowCXX */ true); + if (NewType.isNull()) + continue; + } // Found a base! - BaseFD = UDecl; - break; + Bases.push_back(UDecl); } bool UseImplicitBase = !DVScope.TI->isExtensionActive( llvm::omp::TraitProperty::implementation_extension_disable_implicit_base); // If no base was found we create a declaration that we use as base. - if (!BaseFD && UseImplicitBase) { - BaseFD = cast(ActOnDeclarator(S, D)); - BaseFD->setImplicit(true); + if (Bases.empty() && UseImplicitBase) { + D.setFunctionDefinitionKind(FDK_Declaration); + Decl *BaseD = HandleDeclarator(S, D, TemplateParamLists); + BaseD->setImplicit(true); + if (auto *BaseTemplD = dyn_cast(BaseD)) + Bases.push_back(BaseTemplD->getTemplatedDecl()); + else + Bases.push_back(cast(BaseD)); } std::string MangledName; @@ -5923,17 +5946,21 @@ VariantII.setMangledOpenMPVariantName(true); D.SetIdentifier(&VariantII, D.getBeginLoc()); - return BaseFD; } void Sema::ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope( - FunctionDecl *FD, FunctionDecl *BaseFD) { + Decl *D, SmallVectorImpl &Bases) { // Do not mark function as is used to prevent its emission if this is the // only place where it is used. EnterExpressionEvaluationContext Unevaluated( *this, Sema::ExpressionEvaluationContext::Unevaluated); - Expr *VariantFuncRef = DeclRefExpr::Create( + FunctionDecl *FD = nullptr; + if (auto *UTemplDecl = dyn_cast(D)) + FD = UTemplDecl->getTemplatedDecl(); + else + FD = cast(D); + auto *VariantFuncRef = DeclRefExpr::Create( Context, NestedNameSpecifierLoc(), SourceLocation(), FD, /* RefersToEnclosingVariableOrCapture */ false, /* NameLoc */ FD->getLocation(), FD->getType(), ExprValueKind::VK_RValue); @@ -5941,7 +5968,8 @@ OMPDeclareVariantScope &DVScope = OMPDeclareVariantScopes.back(); auto *OMPDeclareVariantA = OMPDeclareVariantAttr::CreateImplicit( Context, VariantFuncRef, DVScope.TI); - BaseFD->addAttr(OMPDeclareVariantA); + for (FunctionDecl *BaseFD : Bases) + BaseFD->addAttr(OMPDeclareVariantA); } ExprResult Sema::ActOnOpenMPCall(ExprResult Call, Scope *Scope, @@ -6129,7 +6157,7 @@ // Convert VariantRef expression to the type of the original function to // resolve possible conflicts. - ExprResult VariantRefCast; + ExprResult VariantRefCast = VariantRef; if (LangOpts.CPlusPlus) { QualType FnPtrType; auto *Method = dyn_cast(FD); @@ -6154,25 +6182,27 @@ } else { FnPtrType = Context.getPointerType(FD->getType()); } - ImplicitConversionSequence ICS = - TryImplicitConversion(VariantRef, FnPtrType.getUnqualifiedType(), - /*SuppressUserConversions=*/false, - AllowedExplicit::None, - /*InOverloadResolution=*/false, - /*CStyle=*/false, - /*AllowObjCWritebackConversion=*/false); - if (ICS.isFailure()) { - Diag(VariantRef->getExprLoc(), - diag::err_omp_declare_variant_incompat_types) - << VariantRef->getType() - << ((Method && !Method->isStatic()) ? FnPtrType : FD->getType()) - << VariantRef->getSourceRange(); - return None; + QualType VarianPtrType = Context.getPointerType(VariantRef->getType()); + if (VarianPtrType.getUnqualifiedType() != FnPtrType.getUnqualifiedType()) { + ImplicitConversionSequence ICS = TryImplicitConversion( + VariantRef, FnPtrType.getUnqualifiedType(), + /*SuppressUserConversions=*/false, AllowedExplicit::None, + /*InOverloadResolution=*/false, + /*CStyle=*/false, + /*AllowObjCWritebackConversion=*/false); + if (ICS.isFailure()) { + Diag(VariantRef->getExprLoc(), + diag::err_omp_declare_variant_incompat_types) + << VariantRef->getType() + << ((Method && !Method->isStatic()) ? FnPtrType : FD->getType()) + << VariantRef->getSourceRange(); + return None; + } + VariantRefCast = PerformImplicitConversion( + VariantRef, FnPtrType.getUnqualifiedType(), AA_Converting); + if (!VariantRefCast.isUsable()) + return None; } - VariantRefCast = PerformImplicitConversion( - VariantRef, FnPtrType.getUnqualifiedType(), AA_Converting); - if (!VariantRefCast.isUsable()) - return None; // Drop previously built artificial addr_of unary op for member functions. if (Method && !Method->isStatic()) { Expr *PossibleAddrOfVariantRef = VariantRefCast.get(); @@ -6180,8 +6210,6 @@ PossibleAddrOfVariantRef->IgnoreImplicit())) VariantRefCast = UO->getSubExpr(); } - } else { - VariantRefCast = VariantRef; } ExprResult ER = CheckPlaceholderExpr(VariantRefCast.get()); diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -417,7 +417,9 @@ if (TI.anyScoreOrCondition(SubstScoreOrConditionExpr)) return; - // Check function/variant ref. + Expr *E = VariantFuncRef.get(); + // Check function/variant ref for `omp declare variant` but not for `omp + // begin declare variant` (which use implicit attributes). Optional> DeclVarData = S.checkOpenMPDeclareVariantFunction(S.ConvertDeclToDeclGroup(New), VariantFuncRef.get(), TI, @@ -426,9 +428,36 @@ if (!DeclVarData) return; - S.ActOnOpenMPDeclareVariantDirective(DeclVarData.getValue().first, - DeclVarData.getValue().second, TI, - Attr.getRange()); + E = DeclVarData.getValue().second; + FD = DeclVarData.getValue().first; + + if (auto *VariantDRE = dyn_cast(E->IgnoreParenImpCasts())) { + if (auto *VariantFD = dyn_cast(VariantDRE->getDecl())) { + if (auto *VariantFTD = VariantFD->getDescribedFunctionTemplate()) { + if (!VariantFTD->isThisDeclarationADefinition()) + return; + Sema::TentativeAnalysisScope Trap(S); + const TemplateArgumentList *TAL = TemplateArgumentList::CreateCopy( + S.Context, TemplateArgs.getInnermost()); + + auto *SubstFD = S.InstantiateFunctionDeclaration(VariantFTD, TAL, + New->getLocation()); + if (!SubstFD) + return; + S.InstantiateFunctionDefinition( + New->getLocation(), SubstFD, /* Recursive */ true, + /* DefinitionRequired */ false, /* AtEndOfTU */ false); + SubstFD->setInstantiationIsPending(!SubstFD->isDefined()); + E = DeclRefExpr::Create(S.Context, NestedNameSpecifierLoc(), + SourceLocation(), SubstFD, + /* RefersToEnclosingVariableOrCapture */ false, + /* NameLoc */ SubstFD->getLocation(), + SubstFD->getType(), ExprValueKind::VK_RValue); + } + } + } + + S.ActOnOpenMPDeclareVariantDirective(FD, E, TI, Attr.getRange()); } static void instantiateDependentAMDGPUFlatWorkGroupSizeAttr( diff --git a/clang/test/AST/ast-dump-openmp-begin-declare-variant_template_2.cpp b/clang/test/AST/ast-dump-openmp-begin-declare-variant_template_2.cpp new file mode 100644 --- /dev/null +++ b/clang/test/AST/ast-dump-openmp-begin-declare-variant_template_2.cpp @@ -0,0 +1,264 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s -x c++ | FileCheck %s +// expected-no-diagnostics + +template +int also_before(T) { + return 1; +} +template +int also_before_mismatch(void) { + return 0; +} +int also_before_non_template(void) { + return 0; +} + +#pragma omp begin declare variant match(implementation = {extension(allow_templates)}) +template +int also_before(T) { + return 0; +} +template +int also_after(T) { + return 0; +} +template +int also_after_mismatch(T, Q) { + return 2; +} +template +int also_before_mismatch(T) { + return 3; +} +template +int also_before_non_template(T) { + return 4; +} +template +int only_def(void) { + return 0; +} +#pragma omp end declare variant + +template +int also_after(T) { + return 6; +} +template +int also_after_mismatch(T) { + return 0; +} + +int test() { + // Should return 0. + return also_before(0.) + also_before_mismatch<0>() + also_before_non_template() + also_after(0) + also_after_mismatch(0) + only_def<0>(); +} + +// CHECK: |-FunctionTemplateDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:7:1> line:5:5 also_before +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_1:0x[a-z0-9]*]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | |-FunctionDecl [[ADDR_2:0x[a-z0-9]*]] line:5:5 also_before 'int (T)' +// CHECK-NEXT: | | |-ParmVarDecl [[ADDR_3:0x[a-z0-9]*]] col:18 'T' +// CHECK-NEXT: | | |-CompoundStmt [[ADDR_4:0x[a-z0-9]*]] +// CHECK-NEXT: | | | `-ReturnStmt [[ADDR_5:0x[a-z0-9]*]] +// CHECK-NEXT: | | | `-IntegerLiteral [[ADDR_6:0x[a-z0-9]*]] 'int' 1 +// CHECK-NEXT: | | `-OMPDeclareVariantAttr [[ADDR_7:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)} +// CHECK-NEXT: | | `-DeclRefExpr [[ADDR_8:0x[a-z0-9]*]] 'int (T)' {{.*}}Function [[ADDR_9:0x[a-z0-9]*]] 'also_before[implementation={extension(allow_templates)}]' 'int (T)' +// CHECK-NEXT: | `-FunctionDecl [[ADDR_10:0x[a-z0-9]*]] line:5:5 used also_before 'int (double)' +// CHECK-NEXT: | |-TemplateArgument type 'double' +// CHECK-NEXT: | | `-BuiltinType [[ADDR_11:0x[a-z0-9]*]] 'double' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_12:0x[a-z0-9]*]] col:18 'double':'double' +// CHECK-NEXT: | |-CompoundStmt [[ADDR_13:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-ReturnStmt [[ADDR_14:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_6]] 'int' 1 +// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_15:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)} +// CHECK-NEXT: | `-DeclRefExpr [[ADDR_16:0x[a-z0-9]*]] 'int (double)' {{.*}}Function [[ADDR_17:0x[a-z0-9]*]] 'also_before[implementation={extension(allow_templates)}]' 'int (double)' +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_18:0x[a-z0-9]*]] line:9:5 also_before_mismatch +// CHECK-NEXT: | |-NonTypeTemplateParmDecl [[ADDR_19:0x[a-z0-9]*]] col:15 'int' depth 0 index 0 V +// CHECK-NEXT: | |-FunctionDecl [[ADDR_20:0x[a-z0-9]*]] line:9:5 also_before_mismatch 'int ({{.*}})' +// CHECK-NEXT: | | `-CompoundStmt [[ADDR_21:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-ReturnStmt [[ADDR_22:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_23:0x[a-z0-9]*]] 'int' 0 +// CHECK-NEXT: | `-FunctionDecl [[ADDR_24:0x[a-z0-9]*]] line:9:5 used also_before_mismatch 'int ({{.*}})' +// CHECK-NEXT: | |-TemplateArgument integral 0 +// CHECK-NEXT: | `-CompoundStmt [[ADDR_25:0x[a-z0-9]*]] +// CHECK-NEXT: | `-ReturnStmt [[ADDR_26:0x[a-z0-9]*]] +// CHECK-NEXT: | `-IntegerLiteral [[ADDR_23]] 'int' 0 +// CHECK-NEXT: |-FunctionDecl [[ADDR_27:0x[a-z0-9]*]] line:12:5 used also_before_non_template 'int ({{.*}})' +// CHECK-NEXT: | `-CompoundStmt [[ADDR_28:0x[a-z0-9]*]] +// CHECK-NEXT: | `-ReturnStmt [[ADDR_29:0x[a-z0-9]*]] +// CHECK-NEXT: | `-IntegerLiteral [[ADDR_30:0x[a-z0-9]*]] 'int' 0 +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_31:0x[a-z0-9]*]] line:18:1 also_before[implementation={extension(allow_templates)}] +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_32:0x[a-z0-9]*]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | |-FunctionDecl [[ADDR_9]] line:18:1 referenced also_before[implementation={extension(allow_templates)}] 'int (T)' +// CHECK-NEXT: | | |-ParmVarDecl [[ADDR_33:0x[a-z0-9]*]] col:18 'T' +// CHECK-NEXT: | | `-CompoundStmt [[ADDR_34:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-ReturnStmt [[ADDR_35:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_36:0x[a-z0-9]*]] 'int' 0 +// CHECK-NEXT: | `-FunctionDecl [[ADDR_17]] line:18:1 also_before[implementation={extension(allow_templates)}] 'int (double)' +// CHECK-NEXT: | |-TemplateArgument type 'double' +// CHECK-NEXT: | | `-BuiltinType [[ADDR_11]] 'double' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_37:0x[a-z0-9]*]] col:18 'double':'double' +// CHECK-NEXT: | `-CompoundStmt [[ADDR_38:0x[a-z0-9]*]] +// CHECK-NEXT: | `-ReturnStmt [[ADDR_39:0x[a-z0-9]*]] +// CHECK-NEXT: | `-IntegerLiteral [[ADDR_36]] 'int' 0 +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_40:0x[a-z0-9]*]] col:5 implicit also_after +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_41:0x[a-z0-9]*]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | |-FunctionDecl [[ADDR_42:0x[a-z0-9]*]] col:5 also_after 'int (T)' +// CHECK-NEXT: | | |-ParmVarDecl [[ADDR_43:0x[a-z0-9]*]] col:17 'T' +// CHECK-NEXT: | | `-OMPDeclareVariantAttr [[ADDR_44:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)} +// CHECK-NEXT: | | `-DeclRefExpr [[ADDR_45:0x[a-z0-9]*]] 'int (T)' {{.*}}Function [[ADDR_46:0x[a-z0-9]*]] 'also_after[implementation={extension(allow_templates)}]' 'int (T)' +// CHECK-NEXT: | `-FunctionDecl [[ADDR_47:0x[a-z0-9]*]] line:44:5 used also_after 'int (char)' +// CHECK-NEXT: | |-TemplateArgument type 'char' +// CHECK-NEXT: | | `-BuiltinType [[ADDR_48:0x[a-z0-9]*]] 'char' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_49:0x[a-z0-9]*]] col:17 'char':'char' +// CHECK-NEXT: | |-CompoundStmt [[ADDR_50:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-ReturnStmt [[ADDR_51:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_52:0x[a-z0-9]*]] 'int' 6 +// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_53:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)} +// CHECK-NEXT: | `-DeclRefExpr [[ADDR_54:0x[a-z0-9]*]] 'int (char)' {{.*}}Function [[ADDR_55:0x[a-z0-9]*]] 'also_after[implementation={extension(allow_templates)}]' 'int (char)' +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_56:0x[a-z0-9]*]] line:22:1 also_after[implementation={extension(allow_templates)}] +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_41]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | |-FunctionDecl [[ADDR_46]] line:22:1 referenced also_after[implementation={extension(allow_templates)}] 'int (T)' +// CHECK-NEXT: | | |-ParmVarDecl [[ADDR_43]] col:17 'T' +// CHECK-NEXT: | | `-CompoundStmt [[ADDR_57:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-ReturnStmt [[ADDR_58:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_59:0x[a-z0-9]*]] 'int' 0 +// CHECK-NEXT: | `-FunctionDecl [[ADDR_55]] line:22:1 also_after[implementation={extension(allow_templates)}] 'int (char)' +// CHECK-NEXT: | |-TemplateArgument type 'char' +// CHECK-NEXT: | | `-BuiltinType [[ADDR_48]] 'char' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_60:0x[a-z0-9]*]] col:17 'char':'char' +// CHECK-NEXT: | `-CompoundStmt [[ADDR_61:0x[a-z0-9]*]] +// CHECK-NEXT: | `-ReturnStmt [[ADDR_62:0x[a-z0-9]*]] +// CHECK-NEXT: | `-IntegerLiteral [[ADDR_59]] 'int' 0 +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_63:0x[a-z0-9]*]] col:5 implicit also_after_mismatch +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_64:0x[a-z0-9]*]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_65:0x[a-z0-9]*]] col:32 referenced typename depth 0 index 1 Q +// CHECK-NEXT: | `-FunctionDecl [[ADDR_66:0x[a-z0-9]*]] col:5 also_after_mismatch 'int (T, Q)' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_67:0x[a-z0-9]*]] col:26 'T' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_68:0x[a-z0-9]*]] col:29 'Q' +// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_69:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)} +// CHECK-NEXT: | `-DeclRefExpr [[ADDR_70:0x[a-z0-9]*]] 'int (T, Q)' {{.*}}Function [[ADDR_71:0x[a-z0-9]*]] 'also_after_mismatch[implementation={extension(allow_templates)}]' 'int (T, Q)' +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_72:0x[a-z0-9]*]] line:26:1 also_after_mismatch[implementation={extension(allow_templates)}] +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_64]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_65]] col:32 referenced typename depth 0 index 1 Q +// CHECK-NEXT: | `-FunctionDecl [[ADDR_71]] line:26:1 also_after_mismatch[implementation={extension(allow_templates)}] 'int (T, Q)' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_67]] col:26 'T' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_68]] col:29 'Q' +// CHECK-NEXT: | `-CompoundStmt [[ADDR_73:0x[a-z0-9]*]] +// CHECK-NEXT: | `-ReturnStmt [[ADDR_74:0x[a-z0-9]*]] +// CHECK-NEXT: | `-IntegerLiteral [[ADDR_75:0x[a-z0-9]*]] 'int' 2 +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_76:0x[a-z0-9]*]] col:5 implicit also_before_mismatch +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_77:0x[a-z0-9]*]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | `-FunctionDecl [[ADDR_78:0x[a-z0-9]*]] col:5 also_before_mismatch 'int (T)' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_79:0x[a-z0-9]*]] col:27 'T' +// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_80:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)} +// CHECK-NEXT: | `-DeclRefExpr [[ADDR_81:0x[a-z0-9]*]] 'int (T)' {{.*}}Function [[ADDR_82:0x[a-z0-9]*]] 'also_before_mismatch[implementation={extension(allow_templates)}]' 'int (T)' +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_83:0x[a-z0-9]*]] line:30:1 also_before_mismatch[implementation={extension(allow_templates)}] +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_77]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | `-FunctionDecl [[ADDR_82]] line:30:1 also_before_mismatch[implementation={extension(allow_templates)}] 'int (T)' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_79]] col:27 'T' +// CHECK-NEXT: | `-CompoundStmt [[ADDR_84:0x[a-z0-9]*]] +// CHECK-NEXT: | `-ReturnStmt [[ADDR_85:0x[a-z0-9]*]] +// CHECK-NEXT: | `-IntegerLiteral [[ADDR_86:0x[a-z0-9]*]] 'int' 3 +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_87:0x[a-z0-9]*]] col:5 implicit also_before_non_template +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_88:0x[a-z0-9]*]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | `-FunctionDecl [[ADDR_89:0x[a-z0-9]*]] col:5 also_before_non_template 'int (T)' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_90:0x[a-z0-9]*]] col:31 'T' +// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_91:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)} +// CHECK-NEXT: | `-DeclRefExpr [[ADDR_92:0x[a-z0-9]*]] 'int (T)' {{.*}}Function [[ADDR_93:0x[a-z0-9]*]] 'also_before_non_template[implementation={extension(allow_templates)}]' 'int (T)' +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_94:0x[a-z0-9]*]] line:34:1 also_before_non_template[implementation={extension(allow_templates)}] +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_88]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | `-FunctionDecl [[ADDR_93]] line:34:1 also_before_non_template[implementation={extension(allow_templates)}] 'int (T)' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_90]] col:31 'T' +// CHECK-NEXT: | `-CompoundStmt [[ADDR_95:0x[a-z0-9]*]] +// CHECK-NEXT: | `-ReturnStmt [[ADDR_96:0x[a-z0-9]*]] +// CHECK-NEXT: | `-IntegerLiteral [[ADDR_97:0x[a-z0-9]*]] 'int' 4 +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_98:0x[a-z0-9]*]] col:5 implicit only_def +// CHECK-NEXT: | |-NonTypeTemplateParmDecl [[ADDR_99:0x[a-z0-9]*]] col:15 'int' depth 0 index 0 V +// CHECK-NEXT: | |-FunctionDecl [[ADDR_100:0x[a-z0-9]*]] col:5 only_def 'int ({{.*}})' +// CHECK-NEXT: | | `-OMPDeclareVariantAttr [[ADDR_101:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)} +// CHECK-NEXT: | | `-DeclRefExpr [[ADDR_102:0x[a-z0-9]*]] 'int ({{.*}})' {{.*}}Function [[ADDR_103:0x[a-z0-9]*]] 'only_def[implementation={extension(allow_templates)}]' 'int ({{.*}})' +// CHECK-NEXT: | `-FunctionDecl [[ADDR_104:0x[a-z0-9]*]] col:5 used only_def 'int ({{.*}})' +// CHECK-NEXT: | |-TemplateArgument integral 0 +// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_105:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)} +// CHECK-NEXT: | `-DeclRefExpr [[ADDR_106:0x[a-z0-9]*]] 'int ({{.*}})' {{.*}}Function [[ADDR_107:0x[a-z0-9]*]] 'only_def[implementation={extension(allow_templates)}]' 'int ({{.*}})' +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_108:0x[a-z0-9]*]] line:38:1 only_def[implementation={extension(allow_templates)}] +// CHECK-NEXT: | |-NonTypeTemplateParmDecl [[ADDR_99]] col:15 'int' depth 0 index 0 V +// CHECK-NEXT: | |-FunctionDecl [[ADDR_103]] line:38:1 referenced only_def[implementation={extension(allow_templates)}] 'int ({{.*}})' +// CHECK-NEXT: | | `-CompoundStmt [[ADDR_109:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-ReturnStmt [[ADDR_110:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_111:0x[a-z0-9]*]] 'int' 0 +// CHECK-NEXT: | `-FunctionDecl [[ADDR_107]] line:38:1 only_def[implementation={extension(allow_templates)}] 'int ({{.*}})' +// CHECK-NEXT: | |-TemplateArgument integral 0 +// CHECK-NEXT: | `-CompoundStmt [[ADDR_112:0x[a-z0-9]*]] +// CHECK-NEXT: | `-ReturnStmt [[ADDR_113:0x[a-z0-9]*]] +// CHECK-NEXT: | `-IntegerLiteral [[ADDR_111]] 'int' 0 +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_114:0x[a-z0-9]*]] prev [[ADDR_40]] line:44:5 also_after +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_115:0x[a-z0-9]*]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | |-FunctionDecl [[ADDR_116:0x[a-z0-9]*]] prev [[ADDR_42]] line:44:5 also_after 'int (T)' +// CHECK-NEXT: | | |-ParmVarDecl [[ADDR_117:0x[a-z0-9]*]] col:17 'T' +// CHECK-NEXT: | | |-CompoundStmt [[ADDR_118:0x[a-z0-9]*]] +// CHECK-NEXT: | | | `-ReturnStmt [[ADDR_119:0x[a-z0-9]*]] +// CHECK-NEXT: | | | `-IntegerLiteral [[ADDR_52]] 'int' 6 +// CHECK-NEXT: | | `-OMPDeclareVariantAttr [[ADDR_120:0x[a-z0-9]*]] <> Inherited Implicit implementation={extension(allow_templates)} +// CHECK-NEXT: | | `-DeclRefExpr [[ADDR_45]] 'int (T)' {{.*}}Function [[ADDR_46]] 'also_after[implementation={extension(allow_templates)}]' 'int (T)' +// CHECK-NEXT: | `-Function [[ADDR_47]] 'also_after' 'int (char)' +// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_121:0x[a-z0-9]*]] line:48:5 also_after_mismatch +// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_122:0x[a-z0-9]*]] col:20 referenced typename depth 0 index 0 T +// CHECK-NEXT: | |-FunctionDecl [[ADDR_123:0x[a-z0-9]*]] line:48:5 also_after_mismatch 'int (T)' +// CHECK-NEXT: | | |-ParmVarDecl [[ADDR_124:0x[a-z0-9]*]] col:26 'T' +// CHECK-NEXT: | | `-CompoundStmt [[ADDR_125:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-ReturnStmt [[ADDR_126:0x[a-z0-9]*]] +// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_127:0x[a-z0-9]*]] 'int' 0 +// CHECK-NEXT: | `-FunctionDecl [[ADDR_128:0x[a-z0-9]*]] line:48:5 used also_after_mismatch 'int (int)' +// CHECK-NEXT: | |-TemplateArgument type 'int' +// CHECK-NEXT: | | `-BuiltinType [[ADDR_129:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | |-ParmVarDecl [[ADDR_130:0x[a-z0-9]*]] col:26 'int':'int' +// CHECK-NEXT: | `-CompoundStmt [[ADDR_131:0x[a-z0-9]*]] +// CHECK-NEXT: | `-ReturnStmt [[ADDR_132:0x[a-z0-9]*]] +// CHECK-NEXT: | `-IntegerLiteral [[ADDR_127]] 'int' 0 +// CHECK-NEXT: `-FunctionDecl [[ADDR_133:0x[a-z0-9]*]] line:52:5 test 'int ({{.*}})' +// CHECK-NEXT: `-CompoundStmt [[ADDR_134:0x[a-z0-9]*]] +// CHECK-NEXT: `-ReturnStmt [[ADDR_135:0x[a-z0-9]*]] +// CHECK-NEXT: `-BinaryOperator [[ADDR_136:0x[a-z0-9]*]] 'int' '+' +// CHECK-NEXT: |-BinaryOperator [[ADDR_137:0x[a-z0-9]*]] 'int' '+' +// CHECK-NEXT: | |-BinaryOperator [[ADDR_138:0x[a-z0-9]*]] 'int' '+' +// CHECK-NEXT: | | |-BinaryOperator [[ADDR_139:0x[a-z0-9]*]] 'int' '+' +// CHECK-NEXT: | | | |-BinaryOperator [[ADDR_140:0x[a-z0-9]*]] 'int' '+' +// CHECK-NEXT: | | | | |-PseudoObjectExpr [[ADDR_141:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | | | | | |-CallExpr [[ADDR_142:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | | | | | | |-ImplicitCastExpr [[ADDR_143:0x[a-z0-9]*]] 'int (*)(double)' +// CHECK-NEXT: | | | | | | | `-DeclRefExpr [[ADDR_144:0x[a-z0-9]*]] 'int (double)' {{.*}}Function [[ADDR_10]] 'also_before' 'int (double)' (FunctionTemplate [[ADDR_0]] 'also_before') +// CHECK-NEXT: | | | | | | `-FloatingLiteral [[ADDR_145:0x[a-z0-9]*]] 'double' 0.000000e+00 +// CHECK-NEXT: | | | | | `-CallExpr [[ADDR_146:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | | | | | |-ImplicitCastExpr [[ADDR_147:0x[a-z0-9]*]] 'int (*)(double)' +// CHECK-NEXT: | | | | | | `-DeclRefExpr [[ADDR_16]] 'int (double)' {{.*}}Function [[ADDR_17]] 'also_before[implementation={extension(allow_templates)}]' 'int (double)' +// CHECK-NEXT: | | | | | `-FloatingLiteral [[ADDR_145]] 'double' 0.000000e+00 +// CHECK-NEXT: | | | | `-CallExpr [[ADDR_148:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | | | | `-ImplicitCastExpr [[ADDR_149:0x[a-z0-9]*]] 'int (*)({{.*}})' +// CHECK-NEXT: | | | | `-DeclRefExpr [[ADDR_150:0x[a-z0-9]*]] 'int ({{.*}})' {{.*}}Function [[ADDR_24]] 'also_before_mismatch' 'int ({{.*}})' (FunctionTemplate [[ADDR_18]] 'also_before_mismatch') +// CHECK-NEXT: | | | `-CallExpr [[ADDR_151:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | | | `-ImplicitCastExpr [[ADDR_152:0x[a-z0-9]*]] 'int (*)({{.*}})' +// CHECK-NEXT: | | | `-DeclRefExpr [[ADDR_153:0x[a-z0-9]*]] 'int ({{.*}})' {{.*}}Function [[ADDR_27]] 'also_before_non_template' 'int ({{.*}})' +// CHECK-NEXT: | | `-PseudoObjectExpr [[ADDR_154:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | | |-CallExpr [[ADDR_155:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | | | |-ImplicitCastExpr [[ADDR_156:0x[a-z0-9]*]] 'int (*)(char)' +// CHECK-NEXT: | | | | `-DeclRefExpr [[ADDR_157:0x[a-z0-9]*]] 'int (char)' {{.*}}Function [[ADDR_47]] 'also_after' 'int (char)' (FunctionTemplate [[ADDR_114]] 'also_after') +// CHECK-NEXT: | | | `-ImplicitCastExpr [[ADDR_158:0x[a-z0-9]*]] 'char':'char' +// CHECK-NEXT: | | | `-IntegerLiteral [[ADDR_159:0x[a-z0-9]*]] 'int' 0 +// CHECK-NEXT: | | `-CallExpr [[ADDR_160:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | | |-ImplicitCastExpr [[ADDR_161:0x[a-z0-9]*]] 'int (*)(char)' +// CHECK-NEXT: | | | `-DeclRefExpr [[ADDR_54]] 'int (char)' {{.*}}Function [[ADDR_55]] 'also_after[implementation={extension(allow_templates)}]' 'int (char)' +// CHECK-NEXT: | | `-ImplicitCastExpr [[ADDR_162:0x[a-z0-9]*]] 'char':'char' +// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_159]] 'int' 0 +// CHECK-NEXT: | `-CallExpr [[ADDR_163:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | |-ImplicitCastExpr [[ADDR_164:0x[a-z0-9]*]] 'int (*)(int)' +// CHECK-NEXT: | | `-DeclRefExpr [[ADDR_165:0x[a-z0-9]*]] 'int (int)' {{.*}}Function [[ADDR_128]] 'also_after_mismatch' 'int (int)' (FunctionTemplate [[ADDR_121]] 'also_after_mismatch') +// CHECK-NEXT: | `-IntegerLiteral [[ADDR_166:0x[a-z0-9]*]] 'int' 0 +// CHECK-NEXT: `-PseudoObjectExpr [[ADDR_167:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: |-CallExpr [[ADDR_168:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: | `-ImplicitCastExpr [[ADDR_169:0x[a-z0-9]*]] 'int (*)({{.*}})' +// CHECK-NEXT: | `-DeclRefExpr [[ADDR_170:0x[a-z0-9]*]] 'int ({{.*}})' {{.*}}Function [[ADDR_104]] 'only_def' 'int ({{.*}})' (FunctionTemplate [[ADDR_98]] 'only_def') +// CHECK-NEXT: `-CallExpr [[ADDR_171:0x[a-z0-9]*]] 'int' +// CHECK-NEXT: `-ImplicitCastExpr [[ADDR_172:0x[a-z0-9]*]] 'int (*)({{.*}})' +// CHECK-NEXT: `-DeclRefExpr [[ADDR_106]] 'int ({{.*}})' {{.*}}Function [[ADDR_107]] 'only_def[implementation={extension(allow_templates)}]' 'int ({{.*}})' diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def --- a/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def +++ b/llvm/include/llvm/Frontend/OpenMP/OMPKinds.def @@ -1119,6 +1119,7 @@ __OMP_TRAIT_PROPERTY(implementation, extension, match_any) __OMP_TRAIT_PROPERTY(implementation, extension, match_none) __OMP_TRAIT_PROPERTY(implementation, extension, disable_implicit_base) +__OMP_TRAIT_PROPERTY(implementation, extension, allow_templates) __OMP_TRAIT_SET(user)