History

win64: fix va_arg

fixes 5c35ba66c5ade4713bbd9c005e66889f6d7db293 Implementation was consistent within tcc but incompatible with the ABI (for example library functions vprintf etc) Also: - tccpp.c/get_tok_str() : avoid "unknown format "%llu" warning - x86_64_gen.c/gen_vla_alloc() : fix vstack leak

grischka committed 10 years ago

Commit 41349941 parent 03609055 files · +12 −5Browse files

Unified · Split

5 files
  1. include/stdarg.h +2 −1
  2. tccgen.c +1 −0
  3. tccpp.c +0 −3
  4. tests/tcctest.c +9 −0
  5. x86_64-gen.c +0 −1
include/stdarg.h+2−1
@@ -30,7 +30,8 @@ void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); · 29 unmodified lines
3030 #else /* _WIN64 */
3131 typedef char *va_list;
3232 #define va_start(ap,last) __builtin_va_start(ap,last)
33−#define va_arg(ap,type) (ap += 8, sizeof(type)<=8 ? *(type*)ap : **(type**)ap)
33+#define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \
34+ ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8))
3435 #define va_copy(dest, src) ((dest) = (src))
3536 #define va_end(ap)
3637 #endif
tccgen.c+1−0
@@ -4033,6 +4033,7 @@ ST_FUNC void unary(void) · 4032 unmodified lines
40334033 tcc_error("__builtin_va_start expects a local variable");
40344034 vtop->r &= ~(VT_LVAL | VT_REF);
40354035 vtop->type = char_pointer_type;
4036+ vtop->c.i += 8;
40364037 vstore();
40374038 }
40384039 break;
tccpp.c+0−3
@@ -464,9 +464,6 @@ ST_FUNC const char *get_tok_str(int v, CValue *cv) · 463 unmodified lines
464464 switch(v) {
465465 case TOK_CINT:
466466 case TOK_CUINT:
467− /* XXX: not quite exact, but only useful for testing */
468− sprintf(p, "%llu", (unsigned long long)cv->i);
469− break;
470467 case TOK_CLLONG:
471468 case TOK_CULLONG:
472469 /* XXX: not quite exact, but only useful for testing */
tests/tcctest.c+9−0
@@ -2116,6 +2116,14 @@ void stdarg_for_struct(struct myspace bob, ...) · 2115 unmodified lines
21162116 va_end(ap);
21172117 }
21182118
2119+void stdarg_for_libc(const char *fmt, ...)
2120+{
2121+ va_list args;
2122+ va_start(args, fmt);
2123+ vprintf(fmt, args);
2124+ va_end(args);
2125+}
2126+
21192127 void stdarg_test(void)
21202128 {
21212129 LONG_DOUBLE ld = 1234567891234LL;
@@ -2162,6 +2170,7 @@ void stdarg_test(void) · 40 unmodified lines
21622170
21632171 bob.profile = 42;
21642172 stdarg_for_struct(bob, bob, bob, bob.profile);
2173+ stdarg_for_libc("stdarg_for_libc: %s %.2f %d\n", "string", 1.23, 456);
21652174 }
21662175
21672176 void whitespace_test(void)
x86_64-gen.c+0−1
@@ -2228,7 +2228,6 @@ ST_FUNC void gen_vla_alloc(CType *type, int align) { · 2227 unmodified lines
22282228 vpush_global_sym(&func_old_type, TOK_alloca);
22292229 vswap(); /* Move alloca ref past allocation size */
22302230 gfunc_call(1);
2231− vset(type, REG_IRET, 0);
22322231 #else
22332232 int r;
22342233 r = gv(RC_INT); /* allocation size */

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