From: Matthias Braun Date: Tue, 12 Oct 2010 22:17:53 +0000 (+0000) Subject: initial implementation of builtin_object_size X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=261c839b6e7f5700601ea91b3620fe0d7bea1c73;p=cparser initial implementation of builtin_object_size [r28112] --- diff --git a/ast2firm.c b/ast2firm.c index fe9aa08..6082e67 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -1884,6 +1884,22 @@ static ir_node *process_builtin_call(const call_expression_t *call) set_store(new_Proj(irn, mode_M, pn_Builtin_M)); return NULL; } + case bk_gnu_builtin_object_size: { + /* determine value of "type" */ + expression_t *type_expression = call->arguments->next->expression; + long type_val = fold_constant_to_int(type_expression); + type_t *type = function_type->function.return_type; + ir_mode *mode = get_ir_mode_arithmetic(type); + ir_tarval *result; + + /* just produce a "I don't know" result */ + if (type_val & 2) + result = new_tarval_from_long(0, mode); + else + result = new_tarval_from_long(-1, mode); + + return new_d_Const(dbgi, result); + } case bk_gnu_builtin_trap: case bk_ms__ud2: { diff --git a/parser.c b/parser.c index 0174b5b..e0a7cc4 100644 --- a/parser.c +++ b/parser.c @@ -7421,8 +7421,21 @@ static void handle_builtin_argument_restrictions(call_expression_t *call) { } break; } - case bk_gnu_builtin_prefetch: { + case bk_gnu_builtin_object_size: + if (call->arguments == NULL) + break; + + call_argument_t *arg = call->arguments->next; + if (arg != NULL && ! is_constant_expression(arg->expression)) { + errorf(&call->base.source_position, + "second argument of '%Y' must be a constant expression", + call->function->reference.entity->base.symbol); + } + break; + case bk_gnu_builtin_prefetch: /* second and third argument must be constant if existent */ + if (call->arguments == NULL) + break; call_argument_t *rw = call->arguments->next; call_argument_t *locality = NULL; @@ -7443,7 +7456,6 @@ static void handle_builtin_argument_restrictions(call_expression_t *call) { locality = rw->next; } break; - } default: break; }