[Bug lto/51806] New: -flto ignores -Werror

DeusExSophismata at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Jan 10 01:28:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51806

             Bug #: 51806
           Summary: -flto ignores -Werror
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: lto
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: DeusExSophismata@gmail.com


If a program triggers a warning that is only discovered during link time
optimization (such as a potential use of an uninitialized variable that crosses
compilation unit boundaries), the flag -Werror is ignored.

[david@david-desktop gcc error]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.6.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-gnu-unique-object
--enable-linker-build-id
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin
--enable-java-awt=gtk --disable-dssi
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-ppl --with-cloog --with-tune=generic --with-arch_32=i686
--build=x86_64-redhat-linux
Thread model: posix
gcc version 4.6.2 20111027 (Red Hat 4.6.2-1) (GCC) 


==============================================
main.cpp
==============================================
void f1 (int & x);

int main () {
    int x;
    f1 (x);
    return 0;
}
==============================================
werror.cpp
==============================================
void f1 (int & x) {
    volatile int y = x;
}
==============================================

[david@david-desktop gcc error]$ g++ main.cpp werror.cpp -Wuninitialized
-Werror -O1 -flto
In file included from :0:0:
main.cpp: In function ‘main’:
werror.cpp:2:19: warning: ‘x’ is used uninitialized in this function
[-Wuninitialized]
main.cpp:4:6: note: ‘x’ was declared here


Compilation is seen as successful and a.out exists.

The expected behavior is that the warning would be converted to an error by
-Werror and stop the linking / compiling final stage. The effect of this is
that automated build tools believe that the compiling was a success (and the
warning may be buried deep in the middle of the output when compiling multiple
programs), so the user may not know that there was a problem found despite
having -Werror selected.



More information about the Gcc-bugs mailing list