[LLVMbugs] [Bug 8126] New: Strange behaviour with integer promotion on x86-64
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Sep 10 10:06:12 PDT 2010
http://llvm.org/bugs/show_bug.cgi?id=8126
Summary: Strange behaviour with integer promotion on x86-64
Product: clang
Version: trunk
Platform: PC
OS/Version: FreeBSD
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: csdavec at swan.ac.uk
CC: llvmbugs at cs.uiuc.edu
I have some code in a simple inline function:
static INLINE void
GSIMapRightSizeMap(GSIMapTable map, uintptr_t capacity)
{
if (3 * capacity >= 4 * map->bucketCount)
{
GSIMapResize(map, (3 * capacity)/4 + 1);
}
}
This code crashes while evaluating the 4 * map->bucketCount expression with a
segfault. I've eliminated the possibility that map is an invalid pointer and
added some debugging statements:
printf("Map: %p\n", map);
printf("Map: %lx\n", map->bucketCount);
printf("Map: %lx\n", (uintptr_t)(4 * (int)map->bucketCount));
printf("Map: %lx\n", (4 * map->bucketCount));
Here, map is a pointer to a structure and the bucketCount field is an
uintptr_t, which is a 64-bit quantity on the target architecture (x86-64). The
output from this is:
Map: 0x802008b10
Map: 0
Map: 0
Program received signal SIGBUS, Bus error.
The first line was just sanity checking, to see if the debugger was getting the
same address for map as the code - it was. Inspecting this pointer in the
debugger shows that map is a valid value.
The value of the field is 0 - both the debugger and the second print statement
agree on this.
The value of the field cast to an int and multiplied by 4 is 0.
Attempting to multiply the field by a 4, either as the literal 4 or as
((uintptr_t) 4), crashes.
Similarly, this line generates a crash:
uintptr_t p = 4 * map->bucketCount;
However, this works correctly:
uintptr_t p = map->bucketCount * 4;
I therefore assume that something is going a bit wrong with the integer
promotion code.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list