@@ -5892,75 +5892,45 @@ static void handleWebAssemblyExportNameAttr(Sema &S, Decl *D, const ParsedAttr &
58925892 D->addAttr (UsedAttr::CreateImplicit (S.Context ));
58935893}
58945894
5895- WebAssemblyImportModuleAttr *
5896- Sema::mergeImportModuleAttr (Decl *D, const WebAssemblyImportModuleAttr &AL) {
5897- auto *FD = cast<FunctionDecl>(D);
5898-
5899- if (const auto *ExistingAttr = FD->getAttr <WebAssemblyImportModuleAttr>()) {
5900- if (ExistingAttr->getImportModule () == AL.getImportModule ())
5901- return nullptr ;
5902- Diag (ExistingAttr->getLocation (), diag::warn_mismatched_import) << 0
5903- << ExistingAttr->getImportModule () << AL.getImportModule ();
5904- Diag (AL.getLoc (), diag::note_previous_attribute);
5905- return nullptr ;
5906- }
5907- if (FD->hasBody ()) {
5908- Diag (AL.getLoc (), diag::warn_import_on_definition) << 0 ;
5909- return nullptr ;
5895+ static void handleWebAssemblyImportModuleAttr (Sema &S, Decl *D, const ParsedAttr &AL) {
5896+ if (!isFunctionOrMethod (D)) {
5897+ S.Diag (D->getLocation (), diag::warn_attribute_wrong_decl_type)
5898+ << " 'import_module'" << ExpectedFunction;
5899+ return ;
59105900 }
5911- return ::new (Context) WebAssemblyImportModuleAttr (Context, AL,
5912- AL.getImportModule ());
5913- }
59145901
5915- WebAssemblyImportNameAttr *
5916- Sema::mergeImportNameAttr (Decl *D, const WebAssemblyImportNameAttr &AL) {
59175902 auto *FD = cast<FunctionDecl>(D);
5918-
5919- if (const auto *ExistingAttr = FD->getAttr <WebAssemblyImportNameAttr>()) {
5920- if (ExistingAttr->getImportName () == AL.getImportName ())
5921- return nullptr ;
5922- Diag (ExistingAttr->getLocation (), diag::warn_mismatched_import) << 1
5923- << ExistingAttr->getImportName () << AL.getImportName ();
5924- Diag (AL.getLoc (), diag::note_previous_attribute);
5925- return nullptr ;
5926- }
5927- if (FD->hasBody ()) {
5928- Diag (AL.getLoc (), diag::warn_import_on_definition) << 1 ;
5929- return nullptr ;
5903+ if (FD->isThisDeclarationADefinition ()) {
5904+ S.Diag (D->getLocation (), diag::err_alias_is_definition) << FD << 0 ;
5905+ return ;
59305906 }
5931- return ::new (Context) WebAssemblyImportNameAttr (Context, AL,
5932- AL.getImportName ());
5933- }
5934-
5935- static void
5936- handleWebAssemblyImportModuleAttr (Sema &S, Decl *D, const ParsedAttr &AL) {
5937- auto *FD = cast<FunctionDecl>(D);
59385907
59395908 StringRef Str;
59405909 SourceLocation ArgLoc;
59415910 if (!S.checkStringLiteralArgumentAttr (AL, 0 , Str, &ArgLoc))
59425911 return ;
5943- if (FD->hasBody ()) {
5944- S.Diag (AL.getLoc (), diag::warn_import_on_definition) << 0 ;
5945- return ;
5946- }
59475912
59485913 FD->addAttr (::new (S.Context )
59495914 WebAssemblyImportModuleAttr (S.Context , AL, Str));
59505915}
59515916
5952- static void
5953- handleWebAssemblyImportNameAttr (Sema &S, Decl *D, const ParsedAttr &AL) {
5917+ static void handleWebAssemblyImportNameAttr (Sema &S, Decl *D, const ParsedAttr &AL) {
5918+ if (!isFunctionOrMethod (D)) {
5919+ S.Diag (D->getLocation (), diag::warn_attribute_wrong_decl_type)
5920+ << " 'import_name'" << ExpectedFunction;
5921+ return ;
5922+ }
5923+
59545924 auto *FD = cast<FunctionDecl>(D);
5925+ if (FD->isThisDeclarationADefinition ()) {
5926+ S.Diag (D->getLocation (), diag::err_alias_is_definition) << FD << 0 ;
5927+ return ;
5928+ }
59555929
59565930 StringRef Str;
59575931 SourceLocation ArgLoc;
59585932 if (!S.checkStringLiteralArgumentAttr (AL, 0 , Str, &ArgLoc))
59595933 return ;
5960- if (FD->hasBody ()) {
5961- S.Diag (AL.getLoc (), diag::warn_import_on_definition) << 1 ;
5962- return ;
5963- }
59645934
59655935 FD->addAttr (::new (S.Context ) WebAssemblyImportNameAttr (S.Context , AL, Str));
59665936}
0 commit comments