Message150278
Here's a minimal test case for #define bug in LLVM GCC.
If the base struct is 8-byte long or smaller, the code runs correctly.
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
========
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int padding; /* remove this and the sizes will be the same */
int type;
int attr;
} struct_a;
typedef struct {
struct_a base;
int junk;
} struct_b;
#define BUG(op) \
((((struct_a*)(op))->type) ? (void*)((struct_a*)(op) + 1) : \
(void*)((struct_b*)(op) + 1))
static void* func(void* op)
{
if (((struct_a*)(op))->type)
{
return (void*)((struct_a*)(op) + 1);
}
return (void*)((struct_b*)(op) + 1);
}
int main(int argc, char** argv)
{
struct_b* b = malloc(sizeof(struct_b) + 2);
struct_a* a = (struct_a*)b;
char* p;
a->type = 0;
p = BUG(b);
printf("expected: %d, actual: %d, b = %p, p = %p\n",
sizeof(struct_b), p - (char*)b, b, p);
p = func(b);
printf("expected: %d, actual: %d, b = %p, p = %p\n",
sizeof(struct_b), p - (char*)b, b, p);
return 0;
}
========
$ ./bug
expected: 16, actual: 12, b = 0x10d7008b0, p = 0x10d7008bc
expected: 16, actual: 16, b = 0x10d7008b0, p = 0x10d7008c0 |
|
Date |
User |
Action |
Args |
2011-12-28 02:47:44 | Nam.Nguyen | set | recipients:
+ Nam.Nguyen, barry, ronaldoussoren, vstinner, ned.deily, ezio.melotti, michael.foord, Yury.Selivanov, Julian, Oleg.Plakhotnyuk, xapple |
2011-12-28 02:47:44 | Nam.Nguyen | set | messageid: <1325040464.29.0.697880015673.issue13241@psf.upfronthosting.co.za> |
2011-12-28 02:47:43 | Nam.Nguyen | link | issue13241 messages |
2011-12-28 02:47:42 | Nam.Nguyen | create | |
|