diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -642,6 +642,13 @@ let Documentation = [Undocumented]; } +def BuiltinAlias : Attr { + let Spellings = [Clang<"clang_builtin_alias">]; + let Args = [IdentifierArgument<"BuiltinName">]; + let Subjects = SubjectList<[Function], ErrorDiag>; + let Documentation = [BuiltinAliasDocs]; +} + def ArmBuiltinAlias : InheritableAttr, TargetSpecificAttr { let Spellings = [Clang<"__clang_arm_builtin_alias">]; let Args = [IdentifierArgument<"BuiltinName">]; @@ -1767,13 +1774,6 @@ let Documentation = [RISCVInterruptDocs]; } -def RISCVBuiltinAlias : InheritableAttr, TargetSpecificAttr { - let Spellings = [Clang<"__clang_riscv_builtin_alias">]; - let Subjects = SubjectList<[Function], ErrorDiag>; - let Args = [IdentifierArgument<"BuiltinName">]; - let Documentation = [RISCVBuiltinAliasDocs]; -} - // This is not a TargetSpecificAttr so that is silently accepted and // ignored on other targets as encouraged by the OpenCL spec. // 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 @@ -2132,25 +2132,6 @@ }]; } -def RISCVBuiltinAliasDocs : Documentation { - let Category = DocCatFunction; - let Content = [{ -This attribute is used in the implementation of the RVV C intrinsics. -It allows the C intrinsic functions to be declared using the names defined -in RVV builtins, and still be recognized as clang builtins equivalent to the -underlying name. For example, ``riscv_vector.h`` declares the function ``vadd`` -with ``__attribute__((__clang_riscv_builtin_alias(__builtin_rvv_vadd_vv_i8m1)))``. -This ensures that both functions are recognized as that clang builtin, -and in the latter case, the choice of which builtin to identify the -function as can be deferred until after overload resolution. - -This attribute can only be used to set up the aliases for certain RISC-V -C intrinsic functions; it is intended for use only inside ``riscv_*.h`` -and is not a general mechanism for declaring arbitrary aliases for -clang builtin functions. - }]; -} - def AVRInterruptDocs : Documentation { let Category = DocCatFunction; let Heading = "interrupt (AVR)"; @@ -4706,6 +4687,20 @@ }]; } +def BuiltinAliasDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +This attribute is used in the implementation of the C intrinsics. +It allows the C intrinsic functions to be declared using the names defined +in target builtins, and still be recognized as clang builtins equivalent to the +underlying name. For example, ``riscv_vector.h`` declares the function ``vadd`` +with ``__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv_i8m1)))``. +This ensures that both functions are recognized as that clang builtin, +and in the latter case, the choice of which builtin to identify the +function as can be deferred until after overload resolution. + }]; +} + def PreferredNameDocs : Documentation { let Category = DocCatDecl; let Content = [{ diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -4017,6 +4017,9 @@ def err_attribute_preferred_name_arg_invalid : Error< "argument %0 to 'preferred_name' attribute is not a typedef for " "a specialization of %1">; +def err_attribute_builtin_alias : Error< + "'clang_builtin_alias' attribute can only be applied to a target " + "builtin">; // called-once attribute diagnostics. def err_called_once_attribute_wrong_type : Error< @@ -11249,7 +11252,4 @@ // RISC-V builtin required extension warning def err_riscv_builtin_requires_extension : Error< "builtin requires '%0' extension support to be enabled">; -def err_attribute_riscv_builtin_alias : Error< - "'__clang_riscv_builtin_alias' attribute can only be applied to a RISC-V " - "builtin">; } // end of sema component. diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -3265,8 +3265,8 @@ if (const auto *ABAA = getAttr()) { BuiltinID = ABAA->getBuiltinName()->getBuiltinID(); - } else if (const auto *RBAA = getAttr()) { - BuiltinID = RBAA->getBuiltinName()->getBuiltinID(); + } else if (const auto *BAA = getAttr()) { + BuiltinID = BAA->getBuiltinName()->getBuiltinID(); } else if (const auto *A = getAttr()) { BuiltinID = A->getID(); } @@ -3277,7 +3277,7 @@ // If the function is marked "overloadable", it has a different mangled name // and is not the C library function. if (!ConsiderWrapperFunctions && hasAttr() && - (!hasAttr() && !hasAttr())) + (!hasAttr() && !hasAttr())) return 0; ASTContext &Context = getASTContext(); diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -5147,7 +5147,7 @@ D->addAttr(::new (S.Context) ArmBuiltinAliasAttr(S.Context, AL, Ident)); } -static bool RISCVVAliasValid(unsigned BuiltinID, StringRef AliasName) { +static bool AliasValid(unsigned BuiltinID, StringRef AliasName) { switch (BuiltinID) { default: return false; @@ -5158,7 +5158,7 @@ } } -static void handleRISCVBuiltinAliasAttr(Sema &S, Decl *D, +static void handleBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (!AL.isArgIdent(0)) { S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) @@ -5170,12 +5170,12 @@ unsigned BuiltinID = Ident->getBuiltinID(); StringRef AliasName = cast(D)->getIdentifier()->getName(); - if (!RISCVVAliasValid(BuiltinID, AliasName)) { - S.Diag(AL.getLoc(), diag::err_attribute_riscv_builtin_alias); + if (!AliasValid(BuiltinID, AliasName)) { + S.Diag(AL.getLoc(), diag::err_attribute_builtin_alias); return; } - D->addAttr(::new (S.Context) RISCVBuiltinAliasAttr(S.Context, AL, Ident)); + D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); } //===----------------------------------------------------------------------===// @@ -8276,8 +8276,8 @@ handleEnforceTCBAttr(S, D, AL); break; - case ParsedAttr::AT_RISCVBuiltinAlias: - handleRISCVBuiltinAliasAttr(S, D, AL); + case ParsedAttr::AT_BuiltinAlias: + handleBuiltinAliasAttr(S, D, AL); break; } } diff --git a/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c b/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c --- a/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c +++ b/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias-err.c @@ -9,7 +9,7 @@ static inline __attribute__((__always_inline__, __nodebug__)) __rvv_generic -__attribute__((__clang_riscv_builtin_alias(__builtin_rvv_vadd_vv_i8m1))) +__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv_i8m1))) vint8m1_t vadd_generic (vint8m1_t op0, vint8m1_t op1, size_t op2); // CHECK: passing 'vint8m2_t' (aka '__rvv_int8m2_t') to parameter of incompatible type 'vint8m1_t' diff --git a/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c b/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c --- a/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c +++ b/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c @@ -10,7 +10,7 @@ static inline __attribute__((__always_inline__, __nodebug__)) __rvv_generic -__attribute__((__clang_riscv_builtin_alias(__builtin_rvv_vadd_vv_i8m1))) +__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv_i8m1))) vint8m1_t vadd_generic (vint8m1_t op0, vint8m1_t op1, size_t op2); // CHECK-LABEL: @test( diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test --- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -142,7 +142,7 @@ // CHECK-NEXT: PassObjectSize (SubjectMatchRule_variable_is_parameter) // CHECK-NEXT: PatchableFunctionEntry (SubjectMatchRule_function, SubjectMatchRule_objc_method) // CHECK-NEXT: Pointer (SubjectMatchRule_record_not_is_union) -// CHECK-NEXT: RISCVBuiltinAlias (SubjectMatchRule_function) +// CHECK-NEXT: BuiltinAlias (SubjectMatchRule_function) // CHECK-NEXT: ReleaseHandle (SubjectMatchRule_variable_is_parameter) // CHECK-NEXT: RenderScriptKernel (SubjectMatchRule_function) // CHECK-NEXT: ReqdWorkGroupSize (SubjectMatchRule_function) diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp b/clang/utils/TableGen/RISCVVEmitter.cpp --- a/clang/utils/TableGen/RISCVVEmitter.cpp +++ b/clang/utils/TableGen/RISCVVEmitter.cpp @@ -885,7 +885,7 @@ void RVVIntrinsic::emitMangledFuncDef(raw_ostream &OS) const { bool UseAliasAttr = !isMask() && !isOperandReordered(); if (UseAliasAttr) { - OS << "__attribute__((__clang_riscv_builtin_alias("; + OS << "__attribute__((clang_builtin_alias("; OS << "__builtin_rvv_" << getName() << ")))\n"; } OS << OutputType->getTypeStr() << " " << getMangledName() << "(";