public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/52304] New: Gcc does not notice missing header instead it shows a warning. The compiled code may work or not.
@ 2012-02-18  2:54 viniciustinti at gmail dot com
  2012-02-18  4:57 ` [Bug c/52304] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: viniciustinti at gmail dot com @ 2012-02-18  2:54 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52304
           Summary: Gcc does not notice missing header instead it shows a
                    warning. The compiled code may work or not.
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: viniciustinti@gmail.com


Created attachment 26697
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26697
CMake project to reproduce the problem

By creating a shared/static library that contains two functions that returns
pointers to allocated memory and forgetting to add the proper headers for one
gcc produces an unstable code.

For example:
  char* foo(int size) {
    return malloc(size);
  }
  char* boo(int size) {
    return malloc(size);
  }

And your main file:
  #incldue "foo.h"
  // #include "bar.h"

You get just a warning:
  warning: initialization makes pointer from integer without a cast

And if you access the allocated memory it may work or generate a segmentation
fault. In my tests for large malloc's it does not work for fewer bytes it
works. It is more verbose using -Wall -Werror and detects the missing prototype
but still compiles the code.

In my opinion the compiler should notice that it has not the correct prototype
for the function instead of guessing it. It should either not compile the code
or give a verbose error even without -Wall -Werror.

COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.5.2-8ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.5 --enable-shared --enable-multiarch
--with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/x86_64-linux-gnu
--enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default
--with-plugin-ld=ld.gold --enable-objc-gc --disable-werror --with-arch-32=i686
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)

There is a simple demo code for reproducing it. Just got to build and run cmake
.. and after make. The main code works up to b2 but not with b3. Adding the
header corrects the code.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-02-20 12:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-18  2:54 [Bug c/52304] New: Gcc does not notice missing header instead it shows a warning. The compiled code may work or not viniciustinti at gmail dot com
2012-02-18  4:57 ` [Bug c/52304] " redi at gcc dot gnu.org
2012-02-18  9:56 ` viniciustinti at gmail dot com
2012-02-18 10:00 ` viniciustinti at gmail dot com
2012-02-18 14:08 ` redi at gcc dot gnu.org
2012-02-20 12:07 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).