| View previous topic :: View next topic |
| Author |
Message |
delph
Joined: 10 Nov 2010 Posts: 1
|
Posted: Thu Feb 14, 2013 2:47 am Post subject: Compiler bug in pgcpp |
|
|
Hi,
I found a compiler bug in pgcpp 13.2-0 64-bit target on x86-64 Windows. The bug is caused due to erroneous optimization. Here is a test program that reproduces the bug:
| Code: |
/// Usage:
/// $ pgcpp bug.cpp -o bug
/// $ ./bug 10
/// $ pgcpp -fast bug.cpp -o bug
/// $ ./bug 10
#include <iostream>
#include <limits>
#include <cstdlib>
#include <stdint.h>
int main(int, char* argv[])
{
if (argv[1]) {
uint64_t MAX_UINT32 = std::numeric_limits<uint32_t>::max();
uint64_t MAX_UINT64 = std::numeric_limits<uint64_t>::max();
int factor = atoi(argv[1]);
uint64_t result = MAX_UINT64 - MAX_UINT32 * factor;
std::cout << result << std::endl;
}
}
|
The non optimized version prints the correct result '18446744030759878665' while the optimized version (-fast or -O2) prints '9' which is an error. |
|
| Back to top |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Thu Feb 14, 2013 10:21 am Post subject: |
|
|
Thanks Delph, I have sent a report to our engineers (TPR#19133) who will investigate this further.
The two quick work arounds that I see are to add the "volatile" attribute to MAX_UINT32 or disable auto-inlining (-Mnoautoinline).
- Mat |
|
| Back to top |
|
 |
|