History

tcctest.c: sizeof (long) != 8

Bad assumption make bad things happen: long d3; asm(..."1:\tdec %3\n\t" : ... "=&c" (d3) Which wants 'dec RDI' but did 'dec EDI' on _WIN64. Also: - tcctest.c: enable more asm tests for win64 - configure: show errors if any with 'gcc conftest.c' - tccgen.c: remove decl0(x, y, z)

grischka committed 4 years ago

Commit bb80cbe1 parent c60f1d93 files · +46 −47Browse files

Unified · Split

3 files
  1. configure +1 −1
  2. tccgen.c +20 −23
  3. tests/tcctest.c +25 −23
configure+1−1
@@ -357,7 +357,7 @@ fi · 356 unmodified lines
357357
358358 if test -z "$cross_prefix" ; then
359359 CONFTEST=./conftest$EXESUF
360− if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
360+ if ! $cc -o $CONFTEST $source_path/conftest.c ; then
361361 echo "configure: error: '$cc' failed to compile conftest.c."
362362 else
363363 cc_name="$($CONFTEST compiler)"
tccgen.c+20−23
@@ -130,8 +130,7 @@ static void init_putv(init_params *p, CType *type, unsigned long c); · 129 unmodified lines
130130 static void decl_initializer(init_params *p, CType *type, unsigned long c, int flags);
131131 static void block(int is_expr);
132132 static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope);
133−static void decl(int l);
134−static int decl0(int l, int is_for_loop_init, Sym *);
133+static int decl(int l);
135134 static void expr_eq(void);
136135 static void vpush_type_size(CType *type, int *a);
137136 static int is_compatible_unqualified_types(CType *type1, CType *type2);
@@ -6881,7 +6880,7 @@ again: · 6743 unmodified lines
68816880 skip('(');
68826881 if (tok != ';') {
68836882 /* c99 for-loop init decl? */
6884− if (!decl0(VT_LOCAL, 1, NULL)) {
6883+ if (!decl(VT_JMP)) {
68856884 /* no, regular for-loop init expr */
68866885 gexpr();
68876886 vpop();
@@ -7795,7 +7794,7 @@ static void decl_initializer(init_params *p, CType *type, unsigned long c, int f · 907 unmodified lines
77957794 is put in the value stack. If 'has_init' is 2, a special parsing
77967795 is done to handle string constants. */
77977796 static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
7798− int has_init, int v, int scope)
7797+ int has_init, int v, int global)
77997798 {
78007799 int size, align, addr;
78017800 TokenString *init_str = NULL;
@@ -7932,7 +7931,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 130 unmodified lines
79327931 }
79337932 } else {
79347933 sym = NULL;
7935− if (v && scope == VT_CONST) {
7934+ if (v && global) {
79367935 /* see if the symbol was already defined */
79377936 sym = sym_find(v);
79387937 if (sym) {
@@ -8198,9 +8197,10 @@ static void free_inline_functions(TCCState *s) · 259 unmodified lines
81988197 dynarray_reset(&s->inline_fns, &s->nb_inline_fns);
81998198 }
82008199
8201−/* 'l' is VT_LOCAL or VT_CONST to define default storage type, or VT_CMP
8202− if parsing old style parameter decl list (and FUNC_SYM is set then) */
8203−static int decl0(int l, int is_for_loop_init, Sym *func_sym)
8200+/* 'l' is VT_LOCAL or VT_CONST to define default storage type
8201+ or VT_CMP if parsing old style parameter list
8202+ or VT_JMP if parsing c99 for decl: for (int i = 0, ...) */
8203+static int decl(int l)
82048204 {
82058205 int v, has_init, r, oldint;
82068206 CType type, btype;
@@ -8236,7 +8236,7 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) · 29 unmodified lines
82368236
82378237 oldint = 0;
82388238 if (!parse_btype(&btype, &adbase, l == VT_LOCAL)) {
8239− if (is_for_loop_init)
8239+ if (l == VT_JMP)
82408240 return 0;
82418241 /* skip redundant ';' if not in old parameter decl scope */
82428242 if (tok == ';' && l != VT_CMP) {
@@ -8288,13 +8288,15 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) · 45 unmodified lines
82888288 }
82898289 #endif
82908290 if ((type.t & VT_BTYPE) == VT_FUNC) {
8291− if ((type.t & VT_STATIC) && (l == VT_LOCAL))
8291+ if ((type.t & VT_STATIC) && (l != VT_CONST))
82928292 tcc_error("function without file scope cannot be static");
82938293 /* if old style function prototype, we accept a
82948294 declaration list */
82958295 sym = type.ref;
8296− if (sym->f.func_type == FUNC_OLD && l == VT_CONST)
8297− decl0(VT_CMP, 0, sym);
8296+ if (sym->f.func_type == FUNC_OLD && l == VT_CONST) {
8297+ func_vt = type;
8298+ decl(VT_CMP);
8299+ }
82988300 #if defined TCC_TARGET_MACHO || defined TARGETOS_ANDROID
82998301 if (sym->f.func_alwinl
83008302 && ((type.t & (VT_EXTERN | VT_INLINE))
@@ -8388,12 +8390,12 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) · 87 unmodified lines
83888390 } else {
83898391 if (l == VT_CMP) {
83908392 /* find parameter in function parameter list */
8391− for (sym = func_sym->next; sym; sym = sym->next)
8393+ for (sym = func_vt.ref->next; sym; sym = sym->next)
83928394 if ((sym->v & ~SYM_FIELD) == v)
83938395 goto found;
83948396 tcc_error("declaration for parameter '%s' but no such parameter",
83958397 get_tok_str(v, NULL));
8396−found:
8398+ found:
83978399 if (type.t & VT_STORAGE) /* 'register' is okay */
83988400 tcc_error("storage class specified for '%s'",
83998401 get_tok_str(v, NULL));
@@ -8460,20 +8462,20 @@ found: · 60 unmodified lines
84608462 esym->st_value, esym->st_size, 1);
84618463 }
84628464 } else {
8463− if (type.t & VT_STATIC)
8465+ if (l == VT_CONST || (type.t & VT_STATIC))
84648466 r |= VT_CONST;
84658467 else
8466− r |= l;
8468+ r |= VT_LOCAL;
84678469 if (has_init)
84688470 next();
84698471 else if (l == VT_CONST)
84708472 /* uninitialized global variables may be overridden */
84718473 type.t |= VT_EXTERN;
8472− decl_initializer_alloc(&type, &ad, r, has_init, v, l);
8474+ decl_initializer_alloc(&type, &ad, r, has_init, v, l == VT_CONST);
84738475 }
84748476 }
84758477 if (tok != ',') {
8476− if (is_for_loop_init)
8478+ if (l == VT_JMP)
84778479 return 1;
84788480 skip(';');
84798481 break;
@@ -8485,11 +8487,6 @@ found: · 5 unmodified lines
84858487 return 0;
84868488 }
84878489
8488−static void decl(int l)
8489−{
8490− decl0(l, 0, NULL);
8491−}
8492−
84938490 /* ------------------------------------------------------------------------- */
84948491 #undef gjmp_addr
84958492 #undef gjmp
tests/tcctest.c+25−23
@@ -3251,10 +3251,12 @@ void local_label_test(void) · 3250 unmodified lines
32513251 /* inline assembler test */
32523252 #if defined(__i386__) || defined(__x86_64__)
32533253
3254+typedef __SIZE_TYPE__ word;
3255+
32543256 /* from linux kernel */
32553257 static char * strncat1(char * dest,const char * src,size_t count)
32563258 {
3257−long d0, d1, d2, d3;
3259+word d0, d1, d2, d3;
32583260 __asm__ __volatile__(
32593261 "repne\n\t"
32603262 "scasb\n\t"
@@ -3276,7 +3278,7 @@ return dest; · 15 unmodified lines
32763278
32773279 static char * strncat2(char * dest,const char * src,size_t count)
32783280 {
3279−long d0, d1, d2, d3;
3281+word d0, d1, d2, d3;
32803282 __asm__ __volatile__(
32813283 "repne scasb\n\t" /* one-line repne prefix + string op */
32823284 "dec %1\n\t"
@@ -3297,7 +3299,7 @@ return dest; · 14 unmodified lines
32973299
32983300 static inline void * memcpy1(void * to, const void * from, size_t n)
32993301 {
3300−size_t d0, d1, d2;
3302+word d0, d1, d2;
33013303 __asm__ __volatile__(
33023304 "rep ; movsl\n\t"
33033305 "testb $2,%b4\n\t"
@@ -3308,14 +3310,14 @@ __asm__ __volatile__( · 4 unmodified lines
33083310 "movsb\n"
33093311 "2:"
33103312 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
3311− :"0" (n/4), "q" (n),"1" ((size_t) to),"2" ((size_t) from)
3313+ :"0" (n/4), "q" (n),"1" ((word) to),"2" ((word) from)
33123314 : "memory");
33133315 return (to);
33143316 }
33153317
33163318 static inline void * memcpy2(void * to, const void * from, size_t n)
33173319 {
3318−size_t d0, d1, d2;
3320+word d0, d1, d2;
33193321 __asm__ __volatile__(
33203322 "rep movsl\n\t" /* one-line rep prefix + string op */
33213323 "testb $2,%b4\n\t"
@@ -3326,7 +3328,7 @@ __asm__ __volatile__( · 4 unmodified lines
33263328 "movsb\n"
33273329 "2:"
33283330 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
3329− :"0" (n/4), "q" (n),"1" ((size_t) to),"2" ((size_t) from)
3331+ :"0" (n/4), "q" (n),"1" ((word) to),"2" ((word) from)
33303332 : "memory");
33313333 return (to);
33323334 }
@@ -3395,12 +3397,12 @@ struct struct123 { · 62 unmodified lines
33953397 int b;
33963398 };
33973399 struct struct1231 {
3398− unsigned long addr;
3400+ word addr;
33993401 };
34003402
3401−unsigned long mconstraint_test(struct struct1231 *r)
3403+word mconstraint_test(struct struct1231 *r)
34023404 {
3403− unsigned long ret;
3405+ word ret;
34043406 unsigned int a[2];
34053407 a[0] = 0;
34063408 __asm__ volatile ("lea %2,%0; movl 4(%0),%k0; addl %2,%k0; movl $51,%2; movl $52,4%2; movl $63,%1"
@@ -3422,11 +3424,11 @@ int fls64(unsigned long long x) · 15 unmodified lines
34223424
34233425 void other_constraints_test(void)
34243426 {
3425− unsigned long ret;
3427+ word ret;
34263428 int var;
3427−#if !defined(_WIN64) && CC_NAME != CC_clang
3429+#if CC_NAME != CC_clang
34283430 __asm__ volatile ("mov %P1,%0" : "=r" (ret) : "p" (&var));
3429− printf ("oc1: %d\n", ret == (unsigned long)&var);
3431+ printf ("oc1: %d\n", ret == (word)&var);
34303432 #endif
34313433 }
34323434
@@ -3510,6 +3512,7 @@ void asm_local_label_diff (void) · 77 unmodified lines
35103512 printf ("asm_local_label_diff: %d %d\n", alld_stuff[0], alld_stuff[1]);
35113513 }
35123514 #endif
3515+#endif
35133516
35143517 /* This checks that static local variables are available from assembler. */
35153518 void asm_local_statics (void)
@@ -3518,7 +3521,6 @@ void asm_local_statics (void) · 2 unmodified lines
35183521 asm("incl %0" : "+m" (localint));
35193522 printf ("asm_local_statics: %d\n", localint);
35203523 }
3521−#endif
35223524
35233525 static
35243526 unsigned int set;
@@ -3533,7 +3535,7 @@ void fancy_copy2 (unsigned *in, unsigned *out) · 8 unmodified lines
35333535 asm volatile ("mov %0,(%1)" : : "r" (*in), "r" (out) : "memory");
35343536 }
35353537
3536−#if defined __x86_64__ && !defined _WIN64
3538+#if defined __x86_64__
35373539 void clobber_r12(void)
35383540 {
35393541 asm volatile("mov $1, %%r12" ::: "r12");
@@ -3542,9 +3544,9 @@ void clobber_r12(void) · 2 unmodified lines
35423544
35433545 void test_high_clobbers_really(void)
35443546 {
3545−#if defined __x86_64__ && !defined _WIN64
3546− register long val asm("r12");
3547− long val2;
3547+#if defined __x86_64__
3548+ register word val asm("r12");
3549+ word val2;
35483550 /* This tests if asm clobbers correctly save/restore callee saved
35493551 registers if they are clobbered and if it's the high 8 x86-64
35503552 registers. This is fragile for GCC as the constraints do not
@@ -3558,8 +3560,8 @@ void test_high_clobbers_really(void) · 7 unmodified lines
35583560
35593561 void test_high_clobbers(void)
35603562 {
3561−#if defined __x86_64__ && !defined _WIN64
3562− long x1, x2;
3563+#if defined __x86_64__
3564+ word x1, x2;
35633565 asm volatile("mov %%r12,%0" :: "m" (x1)); /* save r12 */
35643566 test_high_clobbers_really();
35653567 asm volatile("mov %%r12,%0" :: "m" (x2)); /* new r12 */
@@ -3625,7 +3627,7 @@ void trace_console(long len, long len2) · 59 unmodified lines
36253627
36263628 void test_asm_dead_code(void)
36273629 {
3628− long rdi;
3630+ word rdi;
36293631 /* Try to make sure that xdi contains a zero, and hence will
36303632 lead to a segfault if the next asm is evaluated without
36313633 arguments being set up. */
@@ -3727,12 +3729,12 @@ void asm_test(void) · 95 unmodified lines
37273729 char buf[128];
37283730 unsigned int val, val2;
37293731 struct struct123 s1;
3730− struct struct1231 s2 = { (unsigned long)&s1 };
3732+ struct struct1231 s2 = { (word)&s1 };
37313733 /* Hide the outer base_func, but check later that the inline
37323734 asm block gets the outer one. */
37333735 int base_func = 42;
37343736 void override_func3 (void);
3735− unsigned long asmret;
3737+ word asmret;
37363738 #ifdef BOOL_ISOC99
37373739 _Bool somebool;
37383740 #endif
@@ -3783,8 +3785,8 @@ void asm_test(void) · 44 unmodified lines
37833785 printf("asmstr: %s\n", get_asm_string());
37843786 asm_local_label_diff();
37853787 #endif
3786− asm_local_statics();
37873788 #endif
3789+ asm_local_statics();
37883790 #ifndef __clang__
37893791 /* clang can't deal with the type change */
37903792 /* Check that we can also load structs of appropriate layout

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t