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

            Bug ID: 98474
           Summary: incorrect results using __uint128_t
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeffhurchalla at gmail dot com
  Target Milestone: ---

g++ version: g++-10 (Ubuntu 10.1.0-2ubuntu1~18.04) 10.1.0
x64 CPU: Intel(R) Core(TM) i5-4570S CPU @ 2.90GH

Compile command used:
g++-10 -O3 -std="gnu++11" -v -save-temps -fsanitize=undefined -Wall -Wextra
-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations test.cpp -o
testbug

It compiles cleanly for me, with no warnings or errors.  After compiling, I use
the following commands:
./testbug
echo $?

Echo prints 2 for me, but the result should be 0.
The preprocessed version of test.cpp is the same as the non-preprocessed
version.  It follows here:

__attribute__ ((noinline))
__uint128_t foo(__uint128_t& x)
{
    return x;
}

int main()
{
    using T = __uint128_t;
    T two65 = static_cast<T>(1) << 65;
    T two65_copy = two65;

    foo(two65_copy);
    T n = two65_copy;

    while (n >= two65)
        n -= two65;

    return static_cast<int>(n >> 64);
}

Reply via email to