configure: Check for and -Wuse-after-free=3 when available
authorMark Wielaard <mark@klomp.org>
Tue, 21 Feb 2023 12:12:38 +0000 (13:12 +0100)
committerMark Wielaard <mark@klomp.org>
Tue, 21 Feb 2023 12:12:38 +0000 (13:12 +0100)
gcc already includes -Wuse-after-free=2 in -Wall. -Wuse-after-free=3
also warns for indeterminate pointers in equality expressions.

Signed-off-by: Mark Wielaard <mark@klomp.org>
ChangeLog
config/ChangeLog
config/eu.am
configure.ac

index d99d837..5da4f35 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2023-02-21  Mark Wielaard  <mark@klomp.org>
+
+       * configure.ac: Check for -Wuse-after-free=3
+
 2023-02-15  Mark Wielaard  <mark@klomp.org>
 
        * configure.ac: Error out when demangler is enabled, but
index c63caa0..ce1f74f 100644 (file)
@@ -1,3 +1,8 @@
+2023-02-21  Mark Wielaard  <mark@klomp.org>
+
+       * eu.am (USE_AFTER_FREE3_WARNING): Define.
+       (AM_CFLAGS): Use USE_AFTER_FREE3_WARNING.
+
 2022-10-02  Mark Wielaard  <mark@klomp.org>
 
        * elfutils.spec.in: Update for 0.188.
index c3cefe7..e6c241f 100644 (file)
@@ -1,6 +1,7 @@
 ## Common automake fragments for elfutils subdirectory makefiles.
 ##
 ## Copyright (C) 2010, 2014, 2016 Red Hat, Inc.
+## Copyright (C) 2023, Mark J. Wielaard <mark@klomp.org>
 ##
 ## This file is part of elfutils.
 ##
@@ -87,10 +88,17 @@ else
 NO_PACKED_NOT_ALIGNED_WARNING=
 endif
 
+if HAVE_USE_AFTER_FREE3_WARNING
+USE_AFTER_FREE3_WARNING=-Wuse-after-free=3
+else
+USE_AFTER_FREE3_WARNING=
+endif
+
 AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \
            -Wold-style-definition -Wstrict-prototypes $(TRAMPOLINES_WARNING) \
            $(LOGICAL_OP_WARNING) $(DUPLICATED_COND_WARNING) \
            $(NULL_DEREFERENCE_WARNING) $(IMPLICIT_FALLTHROUGH_WARNING) \
+           $(USE_AFTER_FREE3_WARNING) \
            $(if $($(*F)_no_Werror),,-Werror) \
            $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \
            $(if $($(*F)_no_Wstack_usage),,$(STACK_USAGE_WARNING)) \
index 4c8a4c3..142a89f 100644 (file)
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
 dnl Configure input file for elfutils.                     -*-autoconf-*-
 dnl
 dnl Copyright (C) 1996-2019 Red Hat, Inc.
-dnl Copyright (C) 2022 Mark J. Wielaard <mark@klomp.org>
+dnl Copyright (C) 2022, 2023 Mark J. Wielaard <mark@klomp.org>
 dnl
 dnl This file is part of elfutils.
 dnl
@@ -618,6 +618,15 @@ CFLAGS="$old_CFLAGS"])
 AM_CONDITIONAL(HAVE_NO_PACKED_NOT_ALIGNED_WARNING,
               [test "x$ac_cv_no_packed_not_aligned" != "xno"])
 
+AC_CACHE_CHECK([whether the compiler accepts -Wuse-after-free=3], ac_cv_use_after_free3, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wuse-after-free=3 -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
+                 ac_cv_use_after_free3=yes, ac_cv_use_after_free3=no)
+CFLAGS="$old_CFLAGS"])
+AM_CONDITIONAL(HAVE_USE_AFTER_FREE3_WARNING,
+              [test "x$ac_cv_use_after_free3" != "xno"])
+
 AC_CACHE_CHECK([whether the compiler accepts -fno-addrsig], ac_cv_fno_addrsig, [dnl
 old_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -fno-addrsig -Werror"