summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2020-07-06 10:15:11 -0700
committerH. Peter Anvin (Intel) <hpa@zytor.com>2020-07-06 10:19:38 -0700
commit0da8a88c62181c8e6d3cddead762befbc0e9b45a (patch)
tree811fb90c4ef08207d57e1f98c28ad8cd8baf3491
parentecb9b773f2280c636fc37fd03ea1f622915d09ce (diff)
downloadnasm-0da8a88c62181c8e6d3cddead762befbc0e9b45a.tar.gz
clang: add -ftrivial-auto-var-init=zero
The clang behavior is sometimes really weird, and extremely hard to debug, when uninitialized variables are used even if the value cancels out in an expression. It also depends on optimization level, etc. -ftrivial-auto-var-init=zero makes the behavior predictable. Unfortunately it also needs a really weird "enable" option, and it issues a warning about an unused command line option on link, which may get promoted to error, so silence the warning before doing anything else. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
-rw-r--r--config/unconfig.h13
-rw-r--r--configure.ac20
2 files changed, 28 insertions, 5 deletions
diff --git a/config/unconfig.h b/config/unconfig.h
index c7d900fc..5972a302 100644
--- a/config/unconfig.h
+++ b/config/unconfig.h
@@ -6,6 +6,11 @@
/* Define if building universal (internal helper macro) */
/* #undef AC_APPLE_UNIVERSAL_BUILD */
+/* Define to 1 if compiled with the
+ `-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang'
+ compiler flag */
+/* #undef CFLAGS_ENABLE_TRIVIAL_AUTO_VAR_INIT_ZERO_KNOWING_IT_WILL_BE_REMOVED_FROM_CLANG */
+
/* Define to 1 if compiled with the `-fdata-sections' compiler flag */
/* #undef CFLAGS_FDATA_SECTIONS */
@@ -30,6 +35,10 @@
/* Define to 1 if compiled with the `-fsanitize=undefined' compiler flag */
/* #undef CFLAGS_FSANITIZE_UNDEFINED */
+/* Define to 1 if compiled with the `-ftrivial-auto-var-init=zero' compiler
+ flag */
+/* #undef CFLAGS_FTRIVIAL_AUTO_VAR_INIT_ZERO */
+
/* Define to 1 if compiled with the `-fvisibility=hidden' compiler flag */
/* #undef CFLAGS_FVISIBILITY_HIDDEN */
@@ -112,6 +121,10 @@
/* Define to 1 if compiled with the `-Wlong-long' compiler flag */
/* #undef CFLAGS_WLONG_LONG */
+/* Define to 1 if compiled with the `-Wno-unused-command-line-argument'
+ compiler flag */
+/* #undef CFLAGS_WNO_UNUSED_COMMAND_LINE_ARGUMENT */
+
/* Define to 1 if compiled with the `-Wpedantic-ms-format' compiler flag */
/* #undef CFLAGS_WPEDANTIC_MS_FORMAT */
diff --git a/configure.ac b/configure.ac
index d9d45837..1e69c4d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,11 +30,6 @@ PA_ARG_DISABLED([optimization],
[compile without optimization (-O0) to help debugging],
[pa_no_optimize=true])
-dnl LLVM doesn't error out on invalid -W options unless this option is
-dnl specified first. Enable this so this script can actually discover
-dnl which -W options are possible for this compiler.
-PA_ADD_CFLAGS([-Werror=unknown-warning-option])
-
dnl Other programs
AC_PROG_LN_S
AC_PROG_MAKE_SET
@@ -81,10 +76,25 @@ AH_TEMPLATE(WORDS_LITTLEENDIAN,
[Define to 1 if your processor stores words with the least significant
byte first (like Intel and VAX, unlike Motorola and SPARC).])
+dnl LLVM doesn't error out on invalid -W options unless this option is
+dnl specified first. Enable this so this script can actually discover
+dnl which -W options are possible for this compiler.
+PA_ADD_CFLAGS([-Werror=unknown-warning-option])
+
+dnl Without this option, clang sometimes fail to link if LDFLAGS is
+dnl a superset of CFLAGS, which is the normal thing...
+PA_ADD_CFLAGS([-Wno-unused-command-line-argument])
+
dnl Force gcc and gcc-compatible compilers treat signed integers
dnl as 2's complement
PA_ADD_CFLAGS([-fwrapv])
+dnl Force clang to behave in a predictable manner, in order to make bugs
+dnl possible to track down. gcc appears to have this behavior by default.
+dnl Needing the -enable-... option is kind of a bizarre thing.
+PA_ADD_CFLAGS([-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang])
+PA_ADD_CFLAGS([-ftrivial-auto-var-init=zero])
+
dnl Some environments abuse __STRICT_ANSI__ to disable some
dnl function declarations
PA_ADD_CFLAGS([-U__STRICT_ANSI__])