public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/36833]  New: unexpected warning: guard 13936 owner may be used uninitialized in this function
@ 2008-07-15  9:08 gcc at dpinol dot com
  2008-07-15  9:12 ` [Bug c++/36833] " gcc at dpinol dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: gcc at dpinol dot com @ 2008-07-15  9:08 UTC (permalink / raw)
  To: gcc-bugs

Hi,

When compiling the code below with 
gcc -c  -O2   -Wall main.cpp -I/opt/ACE_wrappers
, I get the warning 
/opt/ACE_wrappers/ace/Guard_T.inl:24: unexpected warning: guard 13936 owner may
be used uninitialized in this function

The warning refers to a guard's field, where the mutex passed in this line
  ACE_Write_Guard< MUTEX > guard (_mutex);

I've done a thousand tests but I have been unable to reproduce the warning
without using ACE. Even trimming the ACE headers made the warning to go away. 

What convinces me that the problem is in the compiler and not in ACE, or in my
code, is that removing some lines which have nothing to do with the mutex makes
the warning to disappear. Also commenting out the throw at the constructor
disables the warning

If you comment out any of these 3 lines, the warning disappears.
      c_pBufferStart( new int[ 10 ]),
      c_pBufferEnd( c_pBufferStart+10),
      m_pRead( (int*)c_pBufferStart ),

I can see the warning with both ACE 5.5 and latest ACE 5.6.5 available at
ftp://download.dre.vanderbilt.edu/previous_versions/ACE-src-5.6.5.tar.gz (only
9Mb)

I could also cut & paste the .ii file, but it's 38Kb

thanks

#include <ace/Thread_Mutex.h>
#include <ace/Guard_T.h>


      template<  class MUTEX = ACE_Thread_Mutex>
      class CircularBuffer
      {
         // Construction/Destruction
      public:
         CircularBuffer(MUTEX *mutex = NULL);

         unsigned long write( );

      protected:
         const int* c_pBufferStart;
         const int* c_pBufferEnd;
         int* m_pRead;
         MUTEX _nullMutex;
         MUTEX &_mutex;
      };


    template< class MUTEX >
      CircularBuffer<  MUTEX >::CircularBuffer(MUTEX *mutex):
      c_pBufferStart( new int[ 10 ]),
      c_pBufferEnd( c_pBufferStart+10),
      m_pRead( (int*)c_pBufferStart ),
      _mutex(mutex == NULL ? _nullMutex : *mutex)
    {
      if (mutex == NULL) throw "hjhk";
    }

    template< class MUTEX >
      unsigned long CircularBuffer<  MUTEX >::write( )
    {
       ACE_Write_Guard< MUTEX > guard (_mutex);
        return 0;
    }


      int main()
      {
         CircularBuffer<ACE_Thread_Mutex> buffer2;
         buffer2.write();
      }


-- 
           Summary: unexpected warning: guard 13936 owner may be used
                    uninitialized in this function
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcc at dpinol dot com


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


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

* [Bug c++/36833] unexpected warning: guard 13936 owner may be used uninitialized in this function
  2008-07-15  9:08 [Bug c++/36833] New: unexpected warning: guard 13936 owner may be used uninitialized in this function gcc at dpinol dot com
@ 2008-07-15  9:12 ` gcc at dpinol dot com
  2008-08-11  0:46 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gcc at dpinol dot com @ 2008-07-15  9:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from gcc at dpinol dot com  2008-07-15 09:11 -------
Created an attachment (id=15910)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15910&action=view)
File generated by -save-temps

I didn't know you could upload files.
I attach file generated by -save-temps so that you don't need ACE to compile my
testcase


-- 


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


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

* [Bug c++/36833] unexpected warning: guard 13936 owner may be used uninitialized in this function
  2008-07-15  9:08 [Bug c++/36833] New: unexpected warning: guard 13936 owner may be used uninitialized in this function gcc at dpinol dot com
  2008-07-15  9:12 ` [Bug c++/36833] " gcc at dpinol dot com
@ 2008-08-11  0:46 ` pinskia at gcc dot gnu dot org
  2008-08-11  6:34 ` gcc at dpinol dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-08-11  0:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2008-08-11 00:44 -------
This warning is valid as far as I can tell as the compiler does not know
ACE_OS::mutex_lock does not throw.


-- 


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


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

* [Bug c++/36833] unexpected warning: guard 13936 owner may be used uninitialized in this function
  2008-07-15  9:08 [Bug c++/36833] New: unexpected warning: guard 13936 owner may be used uninitialized in this function gcc at dpinol dot com
  2008-07-15  9:12 ` [Bug c++/36833] " gcc at dpinol dot com
  2008-08-11  0:46 ` pinskia at gcc dot gnu dot org
@ 2008-08-11  6:34 ` gcc at dpinol dot com
  2008-08-23  2:31 ` manu at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gcc at dpinol dot com @ 2008-08-11  6:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from gcc at dpinol dot com  2008-08-11 06:33 -------
(In reply to comment #2)
> This warning is valid as far as I can tell as the compiler does not know
> ACE_OS::mutex_lock does not throw.
> 

Hi,
then why removing any of these 3 lines from CircularBuffer's constructor causes
the warning to disappear?
      c_pBufferStart( new int[ 10 ]),
      c_pBufferEnd( c_pBufferStart+10),
      m_pRead( (int*)c_pBufferStart ),

thanks


-- 


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


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

* [Bug c++/36833] unexpected warning: guard 13936 owner may be used uninitialized in this function
  2008-07-15  9:08 [Bug c++/36833] New: unexpected warning: guard 13936 owner may be used uninitialized in this function gcc at dpinol dot com
                   ` (2 preceding siblings ...)
  2008-08-11  6:34 ` gcc at dpinol dot com
@ 2008-08-23  2:31 ` manu at gcc dot gnu dot org
  2008-08-27 10:07 ` gcc at dpinol dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-23  2:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2008-08-23 02:30 -------
I cannot compile this with GCC 4.3.1 or GCC 4.4. I get several errors similar
to:

In file included from /opt/ACE_wrappers/ace/Global_Macros.h:927,
                 from /opt/ACE_wrappers/ace/OS_NS_Thread.h:29,
                 from /opt/ACE_wrappers/ace/Thread_Mutex.h:32,
                 from CircularBufferTest.cpp:2:
/opt/gcc431/lib/gcc/i686-pc-linux-gnu/4.3.1/../../../../include/c++/4.3.1/new:95:
error: 'operator new' takes type 'size_t' ('long unsigned int') as first
parameter

What is the output of g++ -v ?


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org


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


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

* [Bug c++/36833] unexpected warning: guard 13936 owner may be used uninitialized in this function
  2008-07-15  9:08 [Bug c++/36833] New: unexpected warning: guard 13936 owner may be used uninitialized in this function gcc at dpinol dot com
                   ` (3 preceding siblings ...)
  2008-08-23  2:31 ` manu at gcc dot gnu dot org
@ 2008-08-27 10:07 ` gcc at dpinol dot com
  2008-08-27 11:04 ` manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gcc at dpinol dot com @ 2008-08-27 10:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from gcc at dpinol dot com  2008-08-27 10:05 -------
(In reply to comment #4)
> error: 'operator new' takes type 'size_t' ('long unsigned int') as first
> parameter

I don't understand why you get this error

> 
> What is the output of g++ -v ?
> 

See below. It eventually fails when linking because ACE libraries are not
added, but it compiles find

Thanks

$CXX -v main.ii
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.3.1src/configure --prefix=/opt/gcc431
--exec-prefix=/opt/gcc431
Thread model: posix
gcc version 4.3.1 (GCC)
COLLECT_GCC_OPTIONS='-v' '-mtune=generic'
 /opt/gcc431/libexec/gcc/i686-pc-linux-gnu/4.3.1/cc1plus -fpreprocessed main.ii
-quiet -dumpbase main.                                                       
ii -mtune=generic -auxbase main -version -o /tmp/ccXxeyeY.s
GNU C++ (GCC) version 4.3.1 (i686-pc-linux-gnu)
        compiled by GNU C version 4.3.1, GMP version 4.2.1, MPFR version 2.3.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 2292e490ef57b0cdb59146a5820a2e88
COLLECT_GCC_OPTIONS='-v' '-mtune=generic'
 as -V -Qy -o /tmp/ccwWCoNY.o /tmp/ccXxeyeY.s
GNU assembler version 2.17.50.0.5 (i586-suse-linux) using BFD version
2.17.50.0.5 20060927 (SUSE Linux                                               
        )
COMPILER_PATH=/opt/gcc431/libexec/gcc/i686-pc-linux-gnu/4.3.1/:/opt/gcc431/libexec/gcc/i686-pc-linux-g
                                                      
nu/4.3.1/:/opt/gcc431/libexec/gcc/i686-pc-linux-gnu/:/opt/gcc431/lib/gcc/i686-pc-linux-gnu/4.3.1/:/opt
                                                      
/gcc431/lib/gcc/i686-pc-linux-gnu/
LIBRARY_PATH=/opt/gcc431/lib/gcc/i686-pc-linux-gnu/4.3.1/:/opt/gcc431/lib/gcc/i686-pc-linux-gnu/4.3.1/
                                                      
../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mtune=generic'
 /opt/gcc431/libexec/gcc/i686-pc-linux-gnu/4.3.1/collect2 --eh-frame-hdr -m
elf_i386 -dynamic-linker /                                                     
  lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
/opt/gcc431/lib/gcc/i686-pc-linux-gnu/4.3.1/crtbegin                           
                            .o -L/opt/gcc431/lib/gcc/i686-pc-linux-gnu/4.3.1
-L/opt/gcc431/lib/gcc/i686-pc-linux-gnu/4.3.1/../../.                          
                             . /tmp/ccwWCoNY.o -lgcc --as-needed -lgcc_s
--no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-neede                     
                                  d
/opt/gcc431/lib/gcc/i686-pc-linux-gnu/4.3.1/crtend.o /usr/lib/crtn.o
/tmp/ccwWCoNY.o: In function
`CircularBuffer<ACE_Thread_Mutex>::CircularBuffer(ACE_Thread_Mutex*)':
CircularBufferTest.cpp:(.text._ZN14CircularBufferI16ACE_Thread_MutexEC1EPS0_[CircularBuffer<ACE_Thread
                                                      
_Mutex>::CircularBuffer(ACE_Thread_Mutex*)]+0x10): undefined reference to
`operator new[](unsigned int                                                   
    )'
CircularBufferTest.cpp:(.text._ZN14CircularBufferI16ACE_Thread_MutexEC1EPS0_[CircularBuffer<ACE_Thread
                                                      
_Mutex>::CircularBuffer(ACE_Thread_Mutex*)]+0x50): undefined reference to
`ACE_Thread_Mutex::ACE_Threa                                                   
    d_Mutex(char const*, pthread_mutexattr_t*)'
CircularBufferTest.cpp:(.text._ZN14CircularBufferI16ACE_Thread_MutexEC1EPS0_[CircularBuffer<ACE_Thread
                                                      
_Mutex>::CircularBuffer(ACE_Thread_Mutex*)]+0x82): undefined reference to
`__cxa_allocate_exception'
CircularBufferTest.cpp:(.text._ZN14CircularBufferI16ACE_Thread_MutexEC1EPS0_[CircularBuffer<ACE_Thread
                                                      
_Mutex>::CircularBuffer(ACE_Thread_Mutex*)]+0x9c): undefined reference to
`typeinfo for int'
CircularBufferTest.cpp:(.text._ZN14CircularBufferI16ACE_Thread_MutexEC1EPS0_[CircularBuffer<ACE_Thread
                                                      
_Mutex>::CircularBuffer(ACE_Thread_Mutex*)]+0xa4): undefined reference to
`__cxa_throw'
CircularBufferTest.cpp:(.text._ZN14CircularBufferI16ACE_Thread_MutexEC1EPS0_[CircularBuffer<ACE_Thread
                                                      
_Mutex>::CircularBuffer(ACE_Thread_Mutex*)]+0xba): undefined reference to
`ACE_Thread_Mutex::~ACE_Thre                                                   
    ad_Mutex()'
/tmp/ccwWCoNY.o: In function
`CircularBuffer<ACE_Thread_Mutex>::~CircularBuffer()':
CircularBufferTest.cpp:(.text._ZN14CircularBufferI16ACE_Thread_MutexED1Ev[CircularBuffer<ACE_Thread_Mu
                                                      
tex>::~CircularBuffer()]+0x10): undefined reference to
`ACE_Thread_Mutex::~ACE_Thread_Mutex()'
/tmp/ccwWCoNY.o: In function `ACE_OS::thread_mutex_lock(pthread_mutex_t*)':
CircularBufferTest.cpp:(.text._ZN6ACE_OS17thread_mutex_lockEP15pthread_mutex_t[ACE_OS::thread_mutex_lo
                                                      
ck(pthread_mutex_t*)]+0xd): undefined reference to
`ACE_OS::mutex_lock(pthread_mutex_t*)'
/tmp/ccwWCoNY.o: In function `ACE_OS::thread_mutex_unlock(pthread_mutex_t*)':
CircularBufferTest.cpp:(.text._ZN6ACE_OS19thread_mutex_unlockEP15pthread_mutex_t[ACE_OS::thread_mutex_
                                                      
unlock(pthread_mutex_t*)]+0xd): undefined reference to
`ACE_OS::mutex_unlock(pthread_mutex_t*)'
/tmp/ccwWCoNY.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status


-- 


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


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

* [Bug c++/36833] unexpected warning: guard 13936 owner may be used uninitialized in this function
  2008-07-15  9:08 [Bug c++/36833] New: unexpected warning: guard 13936 owner may be used uninitialized in this function gcc at dpinol dot com
                   ` (4 preceding siblings ...)
  2008-08-27 10:07 ` gcc at dpinol dot com
@ 2008-08-27 11:04 ` manu at gcc dot gnu dot org
  2008-08-27 11:14 ` manu at gcc dot gnu dot org
  2009-07-07 22:43 ` manu at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-27 11:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from manu at gcc dot gnu dot org  2008-08-27 11:03 -------
(In reply to comment #5)
> (In reply to comment #4)
> > error: 'operator new' takes type 'size_t' ('long unsigned int') as first
> > parameter
> 
> I don't understand why you get this error
> 

Because I am using a 64bit target and you are using a 32bit to generate the .ii
file. I can reproduce the testcase fine now.


This is a two-fold bug:

* Printing guard$13936$owner is no-no. We rather not print anything and miss a
warning than print something like that. Not sure how to detect that this is not
a user-variable. It is not marked as compiler-generated.

* I don't know if the throw is explicit or compiler-generated (the dumps are a
bit useless).

  # BLOCK 4, starting at line 0
  # PRED: 2 (ab,eh,exec)
<L2>:
  save_filt.157D.15292_7 = [filter_expr] <<<filter object>>>;
  save_eptr.156D.15293_8 = [exc_ptr_expr] <<<exception object>>>;
  [/opt/ACE_wrappers/ace/Guard_T.inl : 24] D.15294_9 =
guard$D15120$owner_D.15311_16(D);
  [/opt/ACE_wrappers/ace/Guard_T.inl : 24] if (D.15294_9 == -1)
    goto <bb 6>;
  else
    goto <bb 5>;
  # SUCC: 6 [48.8%]  (true,exec) 5 [51.2%]  (false,exec)

If it is compiler-generated, we should never warn.

The enclosing function is defined as:

long unsigned int CircularBuffer<MUTEX>::write() [with MUTEX =
ACE_Thread_Mutex] (struct CircularBufferD.14893 * const thisD.14900)
Eh tree:
   1 cleanup
   3 must_not_throw tree_label:<L3>
   2 cleanup tree_label:<L2>


The must_not_throw is not an indication that this function doesn't throw?

Perhaps we should just never warn about anything within EH BB, since they are
not properly marked as compiler-generated by the front-end and the middle-end
has problems dealing with them. That would fix a few bugs.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-08-27 11:03:18
               date|                            |


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


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

* [Bug c++/36833] unexpected warning: guard 13936 owner may be used uninitialized in this function
  2008-07-15  9:08 [Bug c++/36833] New: unexpected warning: guard 13936 owner may be used uninitialized in this function gcc at dpinol dot com
                   ` (5 preceding siblings ...)
  2008-08-27 11:04 ` manu at gcc dot gnu dot org
@ 2008-08-27 11:14 ` manu at gcc dot gnu dot org
  2009-07-07 22:43 ` manu at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-27 11:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from manu at gcc dot gnu dot org  2008-08-27 11:13 -------
(In reply to comment #6)
> 
> Perhaps we should just never warn about anything within EH BB, since they are
> not properly marked as compiler-generated by the front-end and the middle-end
> has problems dealing with them. That would fix a few bugs.

For example: PR 31246.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |31246


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


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

* [Bug c++/36833] unexpected warning: guard 13936 owner may be used uninitialized in this function
  2008-07-15  9:08 [Bug c++/36833] New: unexpected warning: guard 13936 owner may be used uninitialized in this function gcc at dpinol dot com
                   ` (6 preceding siblings ...)
  2008-08-27 11:14 ` manu at gcc dot gnu dot org
@ 2009-07-07 22:43 ` manu at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-07-07 22:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from manu at gcc dot gnu dot org  2009-07-07 22:42 -------
I cannot reproduce this in GCC 4.4.0 or GCC 4.5 revision 149265. This was
probably FIXED at some moment but the testcase is too large for the testsuite.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2009-07-07 22:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-15  9:08 [Bug c++/36833] New: unexpected warning: guard 13936 owner may be used uninitialized in this function gcc at dpinol dot com
2008-07-15  9:12 ` [Bug c++/36833] " gcc at dpinol dot com
2008-08-11  0:46 ` pinskia at gcc dot gnu dot org
2008-08-11  6:34 ` gcc at dpinol dot com
2008-08-23  2:31 ` manu at gcc dot gnu dot org
2008-08-27 10:07 ` gcc at dpinol dot com
2008-08-27 11:04 ` manu at gcc dot gnu dot org
2008-08-27 11:14 ` manu at gcc dot gnu dot org
2009-07-07 22:43 ` manu at gcc dot gnu dot 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).