sunfish created this revision.
sunfish added a reviewer: aaron.ballman.
Herald added subscribers: aheejin, jgravelle-google, sbc100, dschuff.
Herald added a project: clang.

This patch addresses the review comments on r352930:

- Removes redundant diagnostic checking code
- Removes errnoneous use of `diag::err_alias_is_definition`, which turned out 
to be ineffective anyway since functions can be defined later in the 
translation unit and avoid detection.
- Adds a test for various invalid cases for `import_name` and `import_module`.


Repository:
  rC Clang

https://reviews.llvm.org/D59520

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-wasm.c


Index: test/Sema/attr-wasm.c
===================================================================
--- test/Sema/attr-wasm.c
+++ test/Sema/attr-wasm.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fsyntax-only -verify %s
+
+void name_a() {}
+
+void name_b() __attribute__((import_name)); //expected-error {{'import_name' 
attribute takes one argument}}
+
+int name_c __attribute__((import_name("foo"))); //expected-error 
{{'import_name' attribute only applies to functions}}
+
+void name_d() __attribute__((import_name("foo", "bar"))); //expected-error 
{{'import_name' attribute takes one argument}}
+
+void name_e() __attribute__((import_name("foo", "bar", "qux"))); 
//expected-error {{'import_name' attribute takes one argument}}
+
+void name_z() __attribute__((import_name("foo")));
+
+void module_a() {}
+
+void module_b() __attribute__((import_module)); //expected-error 
{{'import_module' attribute takes one argument}}
+
+int module_c __attribute__((import_module("foo"))); //expected-error 
{{'import_module' attribute only applies to functions}}
+
+void module_d() __attribute__((import_module("foo", "bar"))); //expected-error 
{{'import_module' attribute takes one argument}}
+
+void module_e() __attribute__((import_module("foo", "bar", "qux"))); 
//expected-error {{'import_module' attribute takes one argument}}
+
+void module_z() __attribute__((import_module("foo")));
+
+void both() __attribute__((import_name("foo"), import_module("bar")));
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5754,17 +5754,7 @@
 }
 
 static void handleWebAssemblyImportModuleAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
-  if (!isFunctionOrMethod(D)) {
-    S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type)
-        << "'import_module'" << ExpectedFunction;
-    return;
-  }
-
   auto *FD = cast<FunctionDecl>(D);
-  if (FD->isThisDeclarationADefinition()) {
-    S.Diag(D->getLocation(), diag::err_alias_is_definition) << FD << 0;
-    return;
-  }
 
   StringRef Str;
   SourceLocation ArgLoc;
@@ -5777,17 +5767,7 @@
 }
 
 static void handleWebAssemblyImportNameAttr(Sema &S, Decl *D, const ParsedAttr 
&AL) {
-  if (!isFunctionOrMethod(D)) {
-    S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type)
-        << "'import_name'" << ExpectedFunction;
-    return;
-  }
-
   auto *FD = cast<FunctionDecl>(D);
-  if (FD->isThisDeclarationADefinition()) {
-    S.Diag(D->getLocation(), diag::err_alias_is_definition) << FD << 0;
-    return;
-  }
 
   StringRef Str;
   SourceLocation ArgLoc;


Index: test/Sema/attr-wasm.c
===================================================================
--- test/Sema/attr-wasm.c
+++ test/Sema/attr-wasm.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fsyntax-only -verify %s
+
+void name_a() {}
+
+void name_b() __attribute__((import_name)); //expected-error {{'import_name' attribute takes one argument}}
+
+int name_c __attribute__((import_name("foo"))); //expected-error {{'import_name' attribute only applies to functions}}
+
+void name_d() __attribute__((import_name("foo", "bar"))); //expected-error {{'import_name' attribute takes one argument}}
+
+void name_e() __attribute__((import_name("foo", "bar", "qux"))); //expected-error {{'import_name' attribute takes one argument}}
+
+void name_z() __attribute__((import_name("foo")));
+
+void module_a() {}
+
+void module_b() __attribute__((import_module)); //expected-error {{'import_module' attribute takes one argument}}
+
+int module_c __attribute__((import_module("foo"))); //expected-error {{'import_module' attribute only applies to functions}}
+
+void module_d() __attribute__((import_module("foo", "bar"))); //expected-error {{'import_module' attribute takes one argument}}
+
+void module_e() __attribute__((import_module("foo", "bar", "qux"))); //expected-error {{'import_module' attribute takes one argument}}
+
+void module_z() __attribute__((import_module("foo")));
+
+void both() __attribute__((import_name("foo"), import_module("bar")));
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5754,17 +5754,7 @@
 }
 
 static void handleWebAssemblyImportModuleAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
-  if (!isFunctionOrMethod(D)) {
-    S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type)
-        << "'import_module'" << ExpectedFunction;
-    return;
-  }
-
   auto *FD = cast<FunctionDecl>(D);
-  if (FD->isThisDeclarationADefinition()) {
-    S.Diag(D->getLocation(), diag::err_alias_is_definition) << FD << 0;
-    return;
-  }
 
   StringRef Str;
   SourceLocation ArgLoc;
@@ -5777,17 +5767,7 @@
 }
 
 static void handleWebAssemblyImportNameAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
-  if (!isFunctionOrMethod(D)) {
-    S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type)
-        << "'import_name'" << ExpectedFunction;
-    return;
-  }
-
   auto *FD = cast<FunctionDecl>(D);
-  if (FD->isThisDeclarationADefinition()) {
-    S.Diag(D->getLocation(), diag::err_alias_is_definition) << FD << 0;
-    return;
-  }
 
   StringRef Str;
   SourceLocation ArgLoc;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to