http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56420
Bug #: 56420
Summary: Arithmetic error in computation with compile time
unsigned __int128 constant
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
With GCC 4.8 (x86-64, snapshot 20130203 on Linux) the following simple test
case demonstrates an arithmetic bug for code involving a static unsigned
__int128 constant. This seems to be a regression from GCC 4.7.
#include <iostream>
typedef unsigned __int128 uint128_t;
static const uint128_t c = ((uint128_t)-1ULL << 64) + (1ULL << 63);
int main() {
// use volatile to prevent optimizer from optimizing the test
volatile uint128_t a = (uint128_t)1 << 127;
volatile uint128_t b = 1;
volatile uint128_t cc = c;
uint128_t result1 = a - b*c;
uint128_t result2 = a - b*cc;
if (result1 != result2) {
std::cout << "Error: results differ.\n";
return 1;
} else {
std::cout << "No error.\n";
return 0;
}
}