From 748ae0fc25c51316d741afd9b9dfd479ffdf3250 Mon Sep 17 00:00:00 2001 From: Cheyenne Wills Date: Tue, 7 Jun 2022 11:14:55 -0600 Subject: [PATCH] lwp: Ignore dangling-pointer warning in process.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In lwp/process.c the address of a stack variable is saved as part of creating a new context. GCC-12 is flagging the statement with a diagnostic: ./process.c:46:24: error: storing the address of local variable ‘stackvar’ in ‘*savearea.topstack’ [-Werror=dangling-pointer=] 46 | savearea->topstack = (char *)&stackvar; | ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ In this particular case, the code is meaning to save the address of the stack in preparation of setting up a new context, which requires knowing the address the current stack. The diagnostic is changed from a warning to an error when configured with --enable-checking. Set the env variable CFLAGS_NODANGLING_POINTER to '-Wno-dangling-pointer' if the compiler supports the option and update the src/lwp/Makefile.in to use the flag when compiling process.c Change-Id: Ibec956b505c0edad9b74d63b9bb7805f6f0cba01 Reviewed-on: https://gerrit.openafs.org/14957 Reviewed-by: Andrew Deason Reviewed-by: Michael Meffie Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- CODING | 4 +++- src/cf/osconf.m4 | 4 ++++ src/lwp/Makefile.in | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CODING b/CODING index fef643d6b6..e0a81f89e4 100644 --- a/CODING +++ b/CODING @@ -351,4 +351,6 @@ rxkad/ticket5.c : format-truncation : inside included file v5der.c in the function _heim_time2generalizedtime, the two snprintf calls raise format-truncation warnings due to the - arithmetic on tm_year and tm_mon fields \ No newline at end of file + arithmetic on tm_year and tm_mon fields +lwp/process.c : dangling-pointer : Ignore the legitimate use of saving + the address of a stack variable diff --git a/src/cf/osconf.m4 b/src/cf/osconf.m4 index 2805ab604e..482d5adfe4 100644 --- a/src/cf/osconf.m4 +++ b/src/cf/osconf.m4 @@ -631,6 +631,7 @@ CFLAGS_NOUNUSED= CFLAGS_NOOLDSTYLE= CFLAGS_NOIMPLICIT_FALLTHROUGH= CFLAGS_NOCAST_FUNCTION_TYPE= +CFLAGS_NODANGLING_POINTER= XCFLAGS_NOCHECKING="$XCFLAGS" if test "x$GCC" = "xyes"; then @@ -648,6 +649,8 @@ if test "x$GCC" = "xyes"; then [CFLAGS_NOIMPLICIT_FALLTHROUGH], [-Werror]) AX_APPEND_COMPILE_FLAGS([-Wno-cast-function-type], [CFLAGS_NOCAST_FUNCTION_TYPE], [-Werror]) + AX_APPEND_COMPILE_FLAGS([-Wno-dangling-pointer], + [CFLAGS_NODANGLING_POINTER], [-Werror]) AC_DEFINE(IGNORE_SOME_GCC_WARNINGS, 1, [define to disable some gcc warnings in warnings-as-errors mode]) else CFLAGS_NOSTRICT= @@ -732,6 +735,7 @@ AC_SUBST(CFLAGS_NOUNUSED) AC_SUBST(CFLAGS_NOOLDSTYLE) AC_SUBST(CFLAGS_NOIMPLICIT_FALLTHROUGH) AC_SUBST(CFLAGS_NOCAST_FUNCTION_TYPE) +AC_SUBST(CFLAGS_NODANGLING_POINTER) AC_SUBST(CFLAGS_WERROR) AC_SUBST(XCFLAGS64) AC_SUBST(XLDFLAGS) diff --git a/src/lwp/Makefile.in b/src/lwp/Makefile.in index 39d7402bed..7a5419602c 100644 --- a/src/lwp/Makefile.in +++ b/src/lwp/Makefile.in @@ -60,6 +60,7 @@ process.default.s: # Making process.o for $(SYS_NAME) # The files "process.s" and "process.S" may be used internally, # but will be removed after building the .o +CFLAGS_process.o = @CFLAGS_NODANGLING_POINTER@ process.o : process.default.s process.i386.s process.amd64.s process.c lwp.o @set -x; case "$(SYS_NAME)" in \ sun4c_51 | sun4c_52 | sun4m_51 | sun4m_52 | sun4c_53 | sun4m_53 | sun4_53 | sun4_52 | sun4_54 | sun4c_54 | sun4m_54 | sun4x_5* | arm_linux* ) \