[PATCH] D59520: [WebAssembly] Address review comments on r352930

Dan Gohman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 18 16:10:09 PDT 2019


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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59520.191200.patch
Type: text/x-patch
Size: 2647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190318/a744ea69/attachment-0001.bin>


More information about the cfe-commits mailing list