Skip to content

Commit

Permalink
redecl: add test for attribute placement in function declarators
Browse files Browse the repository at this point in the history
Add a new test file which demonstrates some problems which can be
seen on the git codebase. gcc does not complain about this file:

  $ gcc -Wall -c validation/function-redecl2.c
  $

... but sparse does:

  $ sparse validation/function-redecl2.c
  validation/function-redecl2.c:6:5: error: symbol 'func0' redeclared with different type (originally declared at validation/function-redecl2.c:3) - different modifiers
  validation/function-redecl2.c:13:6: error: symbol 'func1' redeclared with different type (originally declared at validation/function-redecl2.c:11) - different modifiers
  validation/function-redecl2.c:21:6: error: symbol 'func2' redeclared with different type (originally declared at validation/function-redecl2.c:18) - different modifiers
  $

Note that func0 and func2 are essentially the same example, apart from
the attribute used, to demonstrate that the issue isn't caused by the
'pure' attribute. Also, examples like func1 have occurred several times
in git and, although they can be worked around (eg. See [1]), it would
be preferable if this were not necessary.

[1] (git) commit 3d7dd2d3b6 ("usage: add NORETURN to BUG() function
definitions", 2017-05-21).

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
  • Loading branch information
ramsay-jones authored and lucvoo committed Feb 7, 2019
1 parent 4ba10f2 commit ec2c615
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions validation/function-redecl2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
extern void exit (int __status) __attribute__ ((__noreturn__));

int func0(int a) __attribute__ ((pure));

__attribute__ ((pure))
int func0(int a)
{
return 0;
}

__attribute__ ((noreturn)) void func1(int a);

void func1(int a)
{
exit(0);
}

void func2(int a) __attribute__ ((noreturn));

__attribute__ ((noreturn))
void func2(int a)
{
exit(0);
}

/*
* check-name: function-redecl2
*
* check-known-to-fail
*
*/

0 comments on commit ec2c615

Please sign in to comment.