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>
This commit is contained in:
H. Peter Anvin (Intel) 2020-07-06 10:15:11 -07:00
parent ecb9b773f2
commit 0da8a88c62
2 changed files with 28 additions and 5 deletions

View file

@ -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 */

View file

@ -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__])