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 target/69789] g++ -O2 is removing tests against a variable that can be changed


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69789

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Thomas Markwalder from comment #5)
> A bit more digging reveals that in the logic expression which fails:
> 
> {{{
>     // Check if we need to run the operation again.
>     if (ec == boost::asio::error::would_block
>         || ec == boost::asio::error::try_again)
>       return false;
> }}}
> 
> The value for error_category:m_cat differs between the implicitly created
> instances for would_block and try_again.

Do you mean that error_code(boost::asio::error::would_block) !=
error_code(boost::asio::error::try_again) ?

I don't see how that's possible, since in the optimized GIMPLE dump they both
use the same constructor, which isn't inlined. The two enums have the same
value, and the constructor will call the same asio::make_error_code() overload
that sets the category to boost::system_category().

             
boost::system::error_code::error_code<boost::asio::error::basic_errors>
(&D.94931, 11, 0B);
              cleanup.88 = 1;
              D.165192 = boost::system::operator== (ec, &D.94931);
              if (D.165192 != 0) goto <D.165186>; else goto <D.165193>;
              <D.165193>:
             
boost::system::error_code::error_code<boost::asio::error::basic_errors>
(&D.94932, 11, 0B);
              cleanup.89 = 1;
              D.165197 = boost::system::operator== (ec, &D.94932);
              if (D.165197 != 0) goto <D.165186>; else goto <D.165187>;
              <D.165186>:
              iftmp.87 = 1;
              goto <D.165188>;
              <D.165187>:
              iftmp.87 = 0;
              <D.165188>:
              retval.86 = iftmp.87;


So what exactly are you seeing? What digging have you done? Stepped through
with the debugger?

The most likely explanation seems to be that ec.category() !=
boost::system::system_category() and so the comparisons are always false.


> If one splits the if into two separate if statements,  the values for m_cat
> are the same.  This looks a like the behavior described under "Static
> Variables in Inline Functions" described here:
> 
> http://processors.wiki.ti.com/index.php/C++_Inlining_Issues

This function has nothing to do with static variables.

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