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 middle-end/82223] New: Incorrect optimization for lossy round trips of arithmetic types


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

            Bug ID: 82223
           Summary: Incorrect optimization for lossy round trips of
                    arithmetic types
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 02c9a08a70164b24b9f762d53a64ab at gmail dot com
  Target Milestone: ---

When the value of x in known to the compiler, GCC always returns true for x ==
static_cast<int>(static_cast<float>(x)).

I believe this behaviour is incorrect. If the round trip is lossy, these two
values should not be equal. Clang 5.0 and vc141 both return false if x is
MAX_INT.

https://godbolt.org/g/74e5ok

======================================================
Test code:
======================================================

#include <limits>

bool foo()
{
  // This function should return FALSE. You cannot
  // round trip MAX_INT to a float and back without
  // losing precision.
  constexpr auto x = std::numeric_limits<int>::max();
  return x == static_cast<int>(static_cast<float>(x));
}

======================================================
Compiler options:
======================================================
-O3 -std=c++14

======================================================
Generated assembly (x86):
======================================================
foo():
  mov eax, 1
  ret

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