sunfish created this revision.
sunfish added a reviewer: sbc100.
Herald added subscribers: llvm-commits, aheejin, jfb.

WebAssembly, the architecture, is not designed to support unprototyped calling 
conventions. For example, clang tends to assume that it can use varargs to 
implement parts of the unprototyped function rules, which works on most other 
architectures, however WebAssembly has no straightforward way of allowing 
functions to be callable as both varargs and non-varargs. LLVM's backend does 
find ways to make things work in some cases, however the support is incomplete. 
To protect users from accidentally trying to compile such code and encountering 
bugs, this patch enables -Werror=strict-prototypes by default for the 
WebAssembly target.


Repository:
  rL LLVM

https://reviews.llvm.org/D43540

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/wasm-toolchain.c


Index: test/Driver/wasm-toolchain.c
===================================================================
--- test/Driver/wasm-toolchain.c
+++ test/Driver/wasm-toolchain.c
@@ -1,15 +1,21 @@
 // A basic clang -cc1 command-line. WebAssembly is somewhat special in
-// enabling -fvisibility=hidden by default.
+// enabling -fvisibility=hidden and -Werror-strict-prototypes by default.
 
 // RUN: %clang %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 
2>&1 | FileCheck -check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} 
"-fvisibility" "hidden" {{.*}}
+// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} 
"-Werror=strict-prototypes" "-fvisibility" "hidden" {{.*}}
 
 // Ditto, but ensure that a user -fvisibility=default disables the default
 // -fvisibility=hidden.
 
 // RUN: %clang %s -### -target wasm32-unknown-unknown -fvisibility=default 
2>&1 | FileCheck -check-prefix=FVISIBILITY_DEFAULT %s
 // FVISIBILITY_DEFAULT-NOT: hidden
 
+// Ensure that a user -Wno-strict-prototypes disabled the default
+// -Werror=strict-prototypes.
+
+// RUN: %clang %s -### -target wasm32-unknown-unknown -Wno-strict-prototypes 
2>&1 | FileCheck -check-prefix=WNO_STRICT_PROTOTYPES %s
+// WNO_STRICT_PROTOTYPES: "-Werror=strict-prototypes" {{.*}} 
"-Wno-strict-prototypes"
+
 // A basic C link command-line.
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -1820,6 +1820,9 @@
 
 void Clang::AddWebAssemblyTargetArgs(const ArgList &Args,
                                      ArgStringList &CmdArgs) const {
+  // WebAssembly doesn't fully support code without prototypes.
+  CmdArgs.push_back("-Werror=strict-prototypes");
+
   // Default to "hidden" visibility.
   if (!Args.hasArg(options::OPT_fvisibility_EQ,
                    options::OPT_fvisibility_ms_compat)) {


Index: test/Driver/wasm-toolchain.c
===================================================================
--- test/Driver/wasm-toolchain.c
+++ test/Driver/wasm-toolchain.c
@@ -1,15 +1,21 @@
 // A basic clang -cc1 command-line. WebAssembly is somewhat special in
-// enabling -fvisibility=hidden by default.
+// enabling -fvisibility=hidden and -Werror-strict-prototypes by default.
 
 // RUN: %clang %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 2>&1 | FileCheck -check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} "-fvisibility" "hidden" {{.*}}
+// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} "-Werror=strict-prototypes" "-fvisibility" "hidden" {{.*}}
 
 // Ditto, but ensure that a user -fvisibility=default disables the default
 // -fvisibility=hidden.
 
 // RUN: %clang %s -### -target wasm32-unknown-unknown -fvisibility=default 2>&1 | FileCheck -check-prefix=FVISIBILITY_DEFAULT %s
 // FVISIBILITY_DEFAULT-NOT: hidden
 
+// Ensure that a user -Wno-strict-prototypes disabled the default
+// -Werror=strict-prototypes.
+
+// RUN: %clang %s -### -target wasm32-unknown-unknown -Wno-strict-prototypes 2>&1 | FileCheck -check-prefix=WNO_STRICT_PROTOTYPES %s
+// WNO_STRICT_PROTOTYPES: "-Werror=strict-prototypes" {{.*}} "-Wno-strict-prototypes"
+
 // A basic C link command-line.
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -1820,6 +1820,9 @@
 
 void Clang::AddWebAssemblyTargetArgs(const ArgList &Args,
                                      ArgStringList &CmdArgs) const {
+  // WebAssembly doesn't fully support code without prototypes.
+  CmdArgs.push_back("-Werror=strict-prototypes");
+
   // Default to "hidden" visibility.
   if (!Args.hasArg(options::OPT_fvisibility_EQ,
                    options::OPT_fvisibility_ms_compat)) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to