This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/52304] New: Gcc does not notice missing header instead it shows a warning. The compiled code may work or not.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]