homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Nam.Nguyen
Recipients Julian, Nam.Nguyen, Oleg.Plakhotnyuk, Yury.Selivanov, barry, ezio.melotti, michael.foord, ned.deily, ronaldoussoren, vstinner, xapple
Date 2011年12月28日.02:47:42
SpamBayes Score 1.1337544e-08
Marked as misclassified No
Message-id <1325040464.29.0.697880015673.issue13241@psf.upfronthosting.co.za>
In-reply-to
Content
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 2336100)
========
#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
History
Date User Action Args
2011年12月28日 02:47:44Nam.Nguyensetrecipients: + Nam.Nguyen, barry, ronaldoussoren, vstinner, ned.deily, ezio.melotti, michael.foord, Yury.Selivanov, Julian, Oleg.Plakhotnyuk, xapple
2011年12月28日 02:47:44Nam.Nguyensetmessageid: <1325040464.29.0.697880015673.issue13241@psf.upfronthosting.co.za>
2011年12月28日 02:47:43Nam.Nguyenlinkissue13241 messages
2011年12月28日 02:47:42Nam.Nguyencreate

AltStyle によって変換されたページ (->オリジナル) /