Skip to content

Commit

Permalink
Suppress taking reference for va_start macro
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Nov 24, 2024
1 parent 083daf2 commit 33a7f10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions include/stdarg.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ typedef __gnuc_va_list va_list;
#elif defined(__APPLE__) && defined(__aarch64__)
typedef void **va_list;

#define va_start(ap,p) __builtin_va_start(ap,&(p))
#define va_start(ap,p) __builtin_va_start(ap,p)
#define va_end(ap) /*(void)*/(ap = 0)
#define va_arg(ap, type) (*(type*)(ap)++) // Assume little endian
#define va_copy(dst,src) (dst = src)

#elif defined(__riscv)
typedef void **va_list;

#define va_start(ap,p) __builtin_va_start(ap,&(p))
#define va_start(ap,p) __builtin_va_start(ap,p)
#define va_end(ap) /*(void)*/(ap = 0)
#define va_arg(ap, type) ((ap) += 1, *(type*)((ap) - 1)) // Assume little endian
#define va_copy(dst,src) (dst = src)
Expand All @@ -46,7 +46,7 @@ typedef struct __va_elem __builtin_va_list[1];
typedef __builtin_va_list __gnuc_va_list;
typedef __gnuc_va_list va_list;

#define va_start(ap,p) __builtin_va_start(ap,&(p))
#define va_start(ap,p) __builtin_va_start(ap,p)
#define va_end(ap) __builtin_va_end(ap)
#define va_arg(ap,ty) __builtin_va_arg(ap,ty)
#define va_copy(dst,src) __builtin_va_copy(dst,src)
Expand Down
12 changes: 6 additions & 6 deletions src/cc/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ static VReg *gen_builtin_va_start(Expr *expr) {
}

Expr *var = strip_cast(args->data[1]);
if (var->kind == EX_REF)
var = var->unary.sub;
// if (var->kind == EX_REF)
// var = var->unary.sub;

const Vector *params = curfunc->params;
assert(params != NULL);
Expand Down Expand Up @@ -135,8 +135,8 @@ static VReg *gen_builtin_va_start(Expr *expr) {
assert(args->len == 2);
assert(curfunc != NULL);
Expr *var = strip_cast(args->data[1]);
if (var->kind == EX_REF)
var = var->unary.sub;
// if (var->kind == EX_REF)
// var = var->unary.sub;

const Vector *params = curfunc->params;
assert(params != NULL);
Expand Down Expand Up @@ -317,8 +317,8 @@ void install_builtins(void) {
Type *rettype = &tyVoid;
Vector *params = new_vector();
vec_push(params, tyVaList);
vec_push(params, &tyVoidPtr);
Type *type = new_func_type(rettype, params, false);
// vec_push(params, &tyVoidPtr);
Type *type = new_func_type(rettype, params, true); // To accept any types, pretend the function as variadic.

add_builtin_function("__builtin_va_start", type, &p_va_start, true);
}
Expand Down

0 comments on commit 33a7f10

Please sign in to comment.