On Mon, Jan 27, 2014 at 06:04:06AM -0700, EBo wrote:
> Hmmm... it might be a good idea to write a filter and search for large
> constants and review them not only for simplifying, but also for
> appropriate size.
It's worth noting that gcc 4.7 compiles both of these to the same code
when -O or higher optimization is used:
int fn(int x) { return x * 1000 * 1000 * 1000; }
int gn(int x) { return x * 1000000000; }
Object code is the same on x86-64 and i386:
imull $1000000000, %edi, %eax
ret
Building the software with clang 3.5 -fsanitize=integer on a 32-bit
platform might have turned up this bug at runtime, as it does in this
simple program:
$ cat tvs.c
#include <sys/time.h>
#include <stdio.h>
int main() {
struct timeval tv;
gettimeofday(&tv, 0);
long long u = tv.tv_sec * 1000 * 1000 * 1000 + tv.tv_usec * 1000;
printf("%lld\n", u);
return 0;
}
$ clang -g -m32 -fsanitize=integer ./tvs.c
$ ./a.out
./tvs.c:7:29: runtime error: signed integer overflow: 1390838542 * 1000 cannot
be represented in type 'long'
./tvs.c:7:36: runtime error: signed integer overflow: -730861904 * 1000 cannot
be represented in type 'long'
./tvs.c:7:43: runtime error: signed integer overflow: -717463680 * 1000 cannot
be represented in type 'long'
(interestingly, with -fsanitize=integer clang doesn't
perform the optimization due to the associative property of
multiplication)
Jeff
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers