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

* [Bug c/52304] Gcc does not notice missing header instead it shows a warning. The compiled code may work or not.
  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 ` redi at gcc dot gnu.org
  2012-02-18  9:56 ` viniciustinti at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-18  4:57 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |normal

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-18 02:54:24 UTC ---
you couldn't show this with a testcase that has fewer than 50 files?!
did you read http://gcc.gnu.org/bugs/ ?

I think you are complaining about a feature of the C language, but I tried to
build your example and 'cmake' isn't enough to do it so I gave up.


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

* [Bug c/52304] Gcc does not notice missing header instead it shows a warning. The compiled code may work or not.
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: viniciustinti at gmail dot com @ 2012-02-18  9:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Vinicius Tinti <viniciustinti at gmail dot com> 2012-02-18 09:54:19 UTC ---
Hello Jonathan,

Sorry my mistake, I forget to remove the build folder content. There are only
things generated by CMake. Please just do rm -rf build/* and try to run CMake
again inside the build folder.

Thus:
  rm -rf build/*
  cd build
  cmake ..
  make

The only important files are: test.c test_included.c test_included.h
test_not_included.c test_not_included.h.

CMake does not allow you to change the path of the project after running it. So
it is necessary to clean the build folder.

Another very strange point is that if you run the code inside valgrind it works
like a charm. In gdb it crashes also.

Regards,
Vinicius

==6562== Memcheck, a memory error detector
==6562== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==6562== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==6562== Command: ./main
==6562== 
b0 [OK]
==6562== Warning: set address range perms: large range [0x393ce040, 0x793ce040)
(undefined)
==6562== Warning: set address range perms: large range [0x393ce030, 0x793ce050)
(noaccess)
b1 [OK]
b2 [OK]
==6562== Warning: set address range perms: large range [0x393ce040, 0x793ce040)
(undefined)
==6562== Warning: set address range perms: large range [0x393ce030, 0x793ce050)
(noaccess)
b3 [OK]
==6562== 
==6562== HEAP SUMMARY:
==6562==     in use at exit: 0 bytes in 0 blocks
==6562==   total heap usage: 4 allocs, 4 frees, 2,147,485,696 bytes allocated
==6562== 
==6562== All heap blocks were freed -- no leaks are possible
==6562== 
==6562== For counts of detected and suppressed errors, rerun with: -v
==6562== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)


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

* [Bug c/52304] Gcc does not notice missing header instead it shows a warning. The compiled code may work or not.
  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
  4 siblings, 0 replies; 6+ messages in thread
From: viniciustinti at gmail dot com @ 2012-02-18 10:00 UTC (permalink / raw)
  To: gcc-bugs

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

Vinicius Tinti <viniciustinti at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #26697|0                           |1
        is obsolete|                            |

--- Comment #3 from Vinicius Tinti <viniciustinti at gmail dot com> 2012-02-18 09:56:11 UTC ---
Created attachment 26698
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26698
CMake project to reproduce the problem (fixed)

Cleaned cmake cache folder.


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

* [Bug c/52304] Gcc does not notice missing header instead it shows a warning. The compiled code may work or not.
  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
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-18 14:08 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |4.5.2

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-18 14:01:15 UTC ---
So basically without all the cmake cruft it's just this:

$ gcc -g -Wall -Wextra test_included.c test_not_included.c test.c -o main

Which gives these warnings telling you about the problem:

test.c: In function ‘main’:
test.c:22:3: warning: implicit declaration of function
‘not_included_get_buffer’ [-Wimplicit-function-declaration]
test.c:22:14: warning: initialization makes pointer from integer without a cast
[enabled by default]
test.c:29:14: warning: initialization makes pointer from integer without a cast
[enabled by default]
test.c:7:14: warning: unused parameter ‘argc’ [-Wunused-parameter]
test.c:7:27: warning: unused parameter ‘argv’ [-Wunused-parameter]

This is how C works, if you dno't declare a function it is assumed to return
'int' and a pointer can't fit in an int.

If you don't like it you should fix the warnings or use
-Werror=implicit-function-declaration to make it an error.

This is not a bug in gcc


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

* [Bug c/52304] Gcc does not notice missing header instead it shows a warning. The compiled code may work or not.
  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
                   ` (3 preceding siblings ...)
  2012-02-18 14:08 ` redi at gcc dot gnu.org
@ 2012-02-20 12:07 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-02-20 12:07 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-02-20 12:03:40 UTC ---
indeed


^ 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).