public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Help diagnosing a GCC 10.2 problem :  error: 'removed_return.213' may be used uninitialized in this function
       [not found] <1044085695.4037783.1609882274366.ref@mail.yahoo.com>
@ 2021-01-05 21:31 ` Nick Savoiu
  2021-01-06 17:20   ` Martin Sebor
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Savoiu @ 2021-01-05 21:31 UTC (permalink / raw)
  To: gcc-help

Hi all, I'm trying to upgrade a codebase from GCC 9.1 to GCC 10.2 and running into weird warning/error messages in the optimized build (-O2).

  error: 'removed_return.213' may be used uninitialized in this function [-Werror=maybe-uninitialized]

I thought that I can just downgrade the -Werror and go on but the code actually crashes on that statement.

The problem code seems to be around a macro that looks like this:

extern bool IsDebugOn();
#define debug IsDebugOn() && std::cout

and that's used like this:

  debug << "print something" << std::endl;

The error goes away if I use

   if (IsDebugOn())
     debug << "print something" << endl;

so I guess the shortcircuited && somehow makes a difference. Unfortunately this happens way deep in the code and any attempts so far to extract the code such that it still exhibits the problem have failed.

I'd appreciate any pointers.

Regards,
Nick

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

* Re: Help diagnosing a GCC 10.2 problem : error: 'removed_return.213' may be used uninitialized in this function
  2021-01-05 21:31 ` Help diagnosing a GCC 10.2 problem : error: 'removed_return.213' may be used uninitialized in this function Nick Savoiu
@ 2021-01-06 17:20   ` Martin Sebor
  2021-01-06 18:25     ` Nick Savoiu
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Sebor @ 2021-01-06 17:20 UTC (permalink / raw)
  To: Nick Savoiu, gcc-help

On 1/5/21 2:31 PM, Nick Savoiu via Gcc-help wrote:
> Hi all, I'm trying to upgrade a codebase from GCC 9.1 to GCC 10.2 and running into weird warning/error messages in the optimized build (-O2).
> 
>    error: 'removed_return.213' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> 
> I thought that I can just downgrade the -Werror and go on but the code actually crashes on that statement.

Do you mean to say the compiler crashes or the program crashes at
runtime?  The former would be a bug in the compiler.  The latter
likely a bug in the program.

The removed_return.213 name refers to a variable GCC synthesizes
internally from one called removed_return in the code.  It just
means that GCC can't prove the variable is initialized when it's
used.  Initializing it on declaration should avoid the warning.

> 
> The problem code seems to be around a macro that looks like this:
> 
> extern bool IsDebugOn();
> #define debug IsDebugOn() && std::cout
> 
> and that's used like this:
> 
>    debug << "print something" << std::endl;
> 
> The error goes away if I use
> 
>     if (IsDebugOn())
>       debug << "print something" << endl;
> 
> so I guess the shortcircuited && somehow makes a difference. Unfortunately this happens way deep in the code and any attempts so far to extract the code such that it still exhibits the problem have failed.
> 
> I'd appreciate any pointers.

If you suspect a bug in GCC then, at a minimum, we need to see
the full GCC output (the warning/error, followed by any informational
notes and stack trace if GCC dies with an ICE).  Better yet would be
a translation unit (the result of preprocessing the file with -E) and
the full command line so we can reproduce the problem.  Since you
mentioned <iostream> it's probably going to be too big for the list
so opening a bug report and attaching the translation unit to it
would be preferable.

Martin

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

* Re: Help diagnosing a GCC 10.2 problem : error: 'removed_return.213' may be used uninitialized in this function
  2021-01-06 17:20   ` Martin Sebor
@ 2021-01-06 18:25     ` Nick Savoiu
  2021-01-06 19:32       ` Segher Boessenkool
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Savoiu @ 2021-01-06 18:25 UTC (permalink / raw)
  To: gcc-help, Martin Sebor

Hi Martin, the program crashes, not GCC.

My code does not contain any 'removed_return'. I suspect that it's a GCC thing so it would probably not appear in a -E output.

I'll try again to extract the behavior from the codebase.

Nick



On Wednesday, January 6, 2021, 9:20:19 AM PST, Martin Sebor <msebor@gmail.com> wrote: 





On 1/5/21 2:31 PM, Nick Savoiu via Gcc-help wrote:
> Hi all, I'm trying to upgrade a codebase from GCC 9.1 to GCC 10.2 and running into weird warning/error messages in the optimized build (-O2).
> 
>    error: 'removed_return.213' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> 
> I thought that I can just downgrade the -Werror and go on but the code actually crashes on that statement.

Do you mean to say the compiler crashes or the program crashes at
runtime?  The former would be a bug in the compiler.  The latter
likely a bug in the program.

The removed_return.213 name refers to a variable GCC synthesizes
internally from one called removed_return in the code.  It just
means that GCC can't prove the variable is initialized when it's
used.  Initializing it on declaration should avoid the warning.


> 
> The problem code seems to be around a macro that looks like this:
> 
> extern bool IsDebugOn();
> #define debug IsDebugOn() && std::cout
> 
> and that's used like this:
> 
>    debug << "print something" << std::endl;
> 
> The error goes away if I use
> 
>     if (IsDebugOn())
>       debug << "print something" << endl;
> 
> so I guess the shortcircuited && somehow makes a difference. Unfortunately this happens way deep in the code and any attempts so far to extract the code such that it still exhibits the problem have failed.
> 
> I'd appreciate any pointers.


If you suspect a bug in GCC then, at a minimum, we need to see
the full GCC output (the warning/error, followed by any informational
notes and stack trace if GCC dies with an ICE).  Better yet would be
a translation unit (the result of preprocessing the file with -E) and
the full command line so we can reproduce the problem.  Since you
mentioned <iostream> it's probably going to be too big for the list
so opening a bug report and attaching the translation unit to it
would be preferable.

Martin

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

* Re: Help diagnosing a GCC 10.2 problem : error: 'removed_return.213' may be used uninitialized in this function
  2021-01-06 18:25     ` Nick Savoiu
@ 2021-01-06 19:32       ` Segher Boessenkool
  2021-01-13 23:13         ` Nick Savoiu
  0 siblings, 1 reply; 8+ messages in thread
From: Segher Boessenkool @ 2021-01-06 19:32 UTC (permalink / raw)
  To: Nick Savoiu; +Cc: gcc-help, Martin Sebor

On Wed, Jan 06, 2021 at 06:25:32PM +0000, Nick Savoiu via Gcc-help wrote:
> Hi Martin, the program crashes, not GCC.
> 
> My code does not contain any 'removed_return'. I suspect that it's a GCC thing so it would probably not appear in a -E output.

It's an artificial name GCC makes up (in IPA)


Segher

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

* Re: Help diagnosing a GCC 10.2 problem : error: 'removed_return.213' may be used uninitialized in this function
  2021-01-06 19:32       ` Segher Boessenkool
@ 2021-01-13 23:13         ` Nick Savoiu
  2021-01-14 19:43           ` Nick Savoiu
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Savoiu @ 2021-01-13 23:13 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-help, Martin Sebor

Hi all, after some work I was able to extract a reproducible case:

This is the code:

#include <ostream>

extern std::ostream* the_dout;

namespace Debug
{
    bool IsEnabled();
}

class MyClass
{
    MyClass();
    ~MyClass();
    int value;
};

MyClass:: MyClass() : value(0)
{
    if (Debug::IsEnabled()) (*the_dout) << value << std::endl;
}

MyClass::~MyClass()
{
    Debug::IsEnabled() && (*the_dout) << value << std::endl;
}

This is the command line:

g++ -c -fnon-call-exceptions -Wmaybe-uninitialized -O2 gcc10bug.cpp

And this is the error:

gcc10bug.cpp: In destructor 'MyClass::~MyClass()':
gcc10bug.cpp:24:56: warning: 'removed_return.24' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     Debug::IsEnabled() && (*the_dout) << value << std::endl;
      |                                                        ^~~~

A few notes:

1. the ^~~~ is pointing at endl
2. the almost similar code in the constructor does not error out
2. there is no error if -fnon-call-exceptions is removed

Nick



On Wednesday, January 6, 2021, 11:35:01 AM PST, Segher Boessenkool <segher@kernel.crashing.org> wrote: 





On Wed, Jan 06, 2021 at 06:25:32PM +0000, Nick Savoiu via Gcc-help wrote:

> Hi Martin, the program crashes, not GCC.
> 
> My code does not contain any 'removed_return'. I suspect that it's a GCC thing so it would probably not appear in a -E output.


It's an artificial name GCC makes up (in IPA)


Segher


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

* Re: Help diagnosing a GCC 10.2 problem : error: 'removed_return.213' may be used uninitialized in this function
  2021-01-13 23:13         ` Nick Savoiu
@ 2021-01-14 19:43           ` Nick Savoiu
  2021-01-15 11:03             ` Jonathan Wakely
  0 siblings, 1 reply; 8+ messages in thread
From: Nick Savoiu @ 2021-01-14 19:43 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1906 bytes --]

Here's a fully contained testcase that crashes on the offending line.

Command line: g++ -g -fnon-call-exceptions -Wmaybe-uninitialized -O2 gcc10bug.cpp gcc10bug_main.cpp

Nick




On Wednesday, January 13, 2021, 3:14:06 PM PST, Nick Savoiu via Gcc-help <gcc-help@gcc.gnu.org> wrote: 





Hi all, after some work I was able to extract a reproducible case:

This is the code:

#include <ostream>

extern std::ostream* the_dout;

namespace Debug
{
    bool IsEnabled();
}

class MyClass
{
    MyClass();
    ~MyClass();
    int value;
};

MyClass:: MyClass() : value(0)
{
    if (Debug::IsEnabled()) (*the_dout) << value << std::endl;
}

MyClass::~MyClass()
{
    Debug::IsEnabled() && (*the_dout) << value << std::endl;
}

This is the command line:

g++ -c -fnon-call-exceptions -Wmaybe-uninitialized -O2 gcc10bug.cpp

And this is the error:

gcc10bug.cpp: In destructor 'MyClass::~MyClass()':
gcc10bug.cpp:24:56: warning: 'removed_return.24' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     Debug::IsEnabled() && (*the_dout) << value << std::endl;
      |                                                        ^~~~

A few notes:

1. the ^~~~ is pointing at endl
2. the almost similar code in the constructor does not error out
2. there is no error if -fnon-call-exceptions is removed

Nick



On Wednesday, January 6, 2021, 11:35:01 AM PST, Segher Boessenkool <segher@kernel.crashing.org> wrote: 





On Wed, Jan 06, 2021 at 06:25:32PM +0000, Nick Savoiu via Gcc-help wrote:

> Hi Martin, the program crashes, not GCC.
> 
> My code does not contain any 'removed_return'. I suspect that it's a GCC thing so it would probably not appear in a -E output.


It's an artificial name GCC makes up (in IPA)


Segher

[-- Attachment #2: GCC_10_bug.zip --]
[-- Type: application/x-zip-compressed, Size: 873 bytes --]

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

* Re: Help diagnosing a GCC 10.2 problem : error: 'removed_return.213' may be used uninitialized in this function
  2021-01-14 19:43           ` Nick Savoiu
@ 2021-01-15 11:03             ` Jonathan Wakely
  2021-01-15 16:34               ` Nick Savoiu
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2021-01-15 11:03 UTC (permalink / raw)
  To: Nick Savoiu; +Cc: Segher Boessenkool, gcc-help

On Thu, 14 Jan 2021, 19:51 Nick Savoiu via Gcc-help, <gcc-help@gcc.gnu.org>
wrote:

> Here's a fully contained testcase that crashes on the offending line.
>
> Command line: g++ -g -fnon-call-exceptions -Wmaybe-uninitialized -O2
> gcc10bug.cpp gcc10bug_main.cpp
>

Please report it to bugzilla.





>
>

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

* Re: Help diagnosing a GCC 10.2 problem : error: 'removed_return.213' may be used uninitialized in this function
  2021-01-15 11:03             ` Jonathan Wakely
@ 2021-01-15 16:34               ` Nick Savoiu
  0 siblings, 0 replies; 8+ messages in thread
From: Nick Savoiu @ 2021-01-15 16:34 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Segher Boessenkool, gcc-help

Done already: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98690


Nick



On Friday, January 15, 2021, 3:04:03 AM PST, Jonathan Wakely <jwakely.gcc@gmail.com> wrote: 







On Thu, 14 Jan 2021, 19:51 Nick Savoiu via Gcc-help, <gcc-help@gcc.gnu.org> wrote:
> Here's a fully contained testcase that crashes on the offending line.
> 
> Command line: g++ -g -fnon-call-exceptions -Wmaybe-uninitialized -O2 gcc10bug.cpp gcc10bug_main.cpp
> 

Please report it to bugzilla.




>  
> 


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

end of thread, other threads:[~2021-01-15 16:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1044085695.4037783.1609882274366.ref@mail.yahoo.com>
2021-01-05 21:31 ` Help diagnosing a GCC 10.2 problem : error: 'removed_return.213' may be used uninitialized in this function Nick Savoiu
2021-01-06 17:20   ` Martin Sebor
2021-01-06 18:25     ` Nick Savoiu
2021-01-06 19:32       ` Segher Boessenkool
2021-01-13 23:13         ` Nick Savoiu
2021-01-14 19:43           ` Nick Savoiu
2021-01-15 11:03             ` Jonathan Wakely
2021-01-15 16:34               ` Nick Savoiu

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