Opened 15 years ago

Closed 15 years ago

#23 closed defect (fixed)

strict-aliasing warnings from gcc 4.4.1 on Linux x86_64

Reported by: Christian Franke Owned by: somebody
Priority: minor Milestone: Experimental Release 5.39
Component: all Version:
Keywords: Cc: manfred99

Description

Build from smartmontools-5.39-rc.tar.gz (r2990) with gcc 4.4.1:

g++ [...] -g -O2 -Wall -W [...] -c -o os_linux.o os_linux.cpp
os_linux.cpp: In member function 'bool os_linux::linux_megaraid_device::megasas_cmd(int, void*, int, void*, int, void*, int)':
os_linux.cpp:1108: warning: dereferencing pointer 'pthru' does break strict-aliasing rules
[...]
os_linux.cpp:1079: warning: dereferencing pointer 'pthru' does break strict-aliasing rules
os_linux.cpp:1078: note: initialized from here

(source:trunk/smartmontools/os_linux.cpp@2990#L1069)

Change History (2)

comment:1 by manfred99, 15 years ago

how about just disabling aliasing optimization?
Smartmontools is not an high performance application, after all.
Something like:

--- configure.in (Revision 2990)
+++ configure.in (Arbeitskopie)
@@ -310,7 +310,7 @@

AM_CONDITIONAL(OS_WIN32_MINGW, [echo $host_os | grep 'mingw' > /dev/null])
AM_CONDITIONAL(OS_FREEBSD, [echo $host_os | grep '
freebsd' > /dev/null])

-dnl Add -Wall and -W if using gcc and its not already specified.
+dnl Add -Wall and -W if using g++ and its not already specified.

if test "x$GCC" = "xyes"; then

if test -z "echo "$CXXFLAGS" | grep "\-Wall" 2> /dev/null" ; then

CXXFLAGS="$CXXFLAGS -Wall"

@@ -319,6 +319,18 @@

if test -z "echo "$CXXFLAGS " | grep "\-W " 2> /dev/null" ; then

CXXFLAGS="$CXXFLAGS -W"

fi

+ ac_save_CXXFLAGS=$CXXFLAGS
+ CXXFLAGS="-fno-strict-aliasing"
+ AC_MSG_CHECKING([whether g++ supports -fno-strict-aliasing])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
+ [gcc_have_fno_strict_aliasing=yes], [gcc_have_fno_strict_aliasing=no])
+ AC_MSG_RESULT([$gcc_have_fno_strict_aliasing])
+ AC_SUBST(gcc_have_fno_strict_aliasing)
+ if test "$gcc_have_fno_strict_aliasing" = "yes"; then
+ CXXFLAGS="$ac_save_CXXFLAGS -fno-strict-aliasing"
+ else
+ CXXFLAGS="$ac_save_CXXFLAGS"
+ fi

case "${host}" in

*-*-mingw*)

# MinGW uses MSVCRT.DLL which uses printf format "%I64d" and not "%lld" for int64_t

in reply to:  1 comment:2 by Christian Franke, 15 years ago

Milestone: RC1 5.40Experimental Release 5.39
Resolution: fixed
Status: newclosed

r2992.
Option '-fno-strict-aliasing' set if supported. Patch slightly enhanced such that this can be overridden with CXXFLAGS='-fstrict-aliasing' configure argument.

Note: See TracTickets for help on using tickets.