[nasm:nasm-2.15.xx] clang: add -ftrivial-auto-var-init=zero

nasm-bot for H. Peter Anvin (Intel) hpa at zytor.com
Mon Jul 6 10:21:08 PDT 2020


Commit-ID:  0da8a88c62181c8e6d3cddead762befbc0e9b45a
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=0da8a88c62181c8e6d3cddead762befbc0e9b45a
Author:     H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Mon, 6 Jul 2020 10:15:11 -0700
Committer:  H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Mon, 6 Jul 2020 10:19:38 -0700

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 at zytor.com>


---
 config/unconfig.h | 13 +++++++++++++
 configure.ac      | 20 +++++++++++++++-----
 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__])


More information about the Nasm-commits mailing list