Skip to content

Commit

Permalink
Merge branch 'warn-address-builtin' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
lucvoo committed Oct 19, 2020
2 parents 6746138 + e5fcbca commit efa1869
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions evaluate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,8 @@ static struct symbol *degenerate(struct expression *expr)
expression_error(expr, "strange non-value function or array");
return &bad_ctype;
}
if (ctype->builtin)
sparse_error(expr->pos, "taking the address of built-in function '%s'", show_ident(ctype->ident));
*expr = *expr->unop;
ctype = create_pointer(expr, ctype, 1);
expr->ctype = ctype;
Expand All @@ -1807,6 +1809,8 @@ static struct symbol *evaluate_addressof(struct expression *expr)
return NULL;
}
ctype = op->ctype;
if (ctype->builtin)
sparse_error(expr->pos, "taking the address of built-in function '%s'", show_ident(ctype->ident));
*expr = *op->unop;

mark_addressable(expr);
Expand Down
25 changes: 15 additions & 10 deletions validation/builtin-arith.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,27 @@ void test(void (*fun)(void))
/*
* check-name: builtin arithmetic
* check-command: sparse -Wno-decl $file
* check-known-to-fail
*
* check-error-start
builtin-arith.c:10:xx: error: ...
builtin-arith.c:11:xx: error: ...
builtin-arith.c:10:14: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:11:13: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:12:14: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:13:14: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:13:29: error: arithmetics on pointers to functions
builtin-arith.c:14:14: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:14:29: error: arithmetics on pointers to functions
builtin-arith.c:15:14: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:15:29: error: arithmetics on pointers to functions
builtin-arith.c:18:xx: error: ...
builtin-arith.c:19:xx: error: ...
builtin-arith.c:21:xx: error: ...
builtin-arith.c:22:xx: error: ...
builtin-arith.c:23:xx: error: ...
builtin-arith.c:24:xx: error: ...
builtin-arith.c:25:xx: error: ...
builtin-arith.c:18:21: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:19:29: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:21:14: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:22:14: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:23:14: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:24:21: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:25:21: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:27:9: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:27:24: error: subtraction of functions? Share your drugs
builtin-arith.c:28:15: error: taking the address of built-in function '__builtin_trap'
builtin-arith.c:28:13: error: subtraction of functions? Share your drugs
* check-error-end
*/

0 comments on commit efa1869

Please sign in to comment.