diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-15 00:06:14 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-15 01:42:54 +0100 |
| commit | 233d4e17c544e1de252aed8f409630599104dbc7 (patch) | |
| tree | 83f39dd2618b8656d342a8a0bd946452e8d1f010 /validation | |
| parent | fd3528aa0409874386610ce63bb647fff8312fd9 (diff) | |
| download | sparse-dev-233d4e17c544e1de252aed8f409630599104dbc7.tar.gz | |
function attributes apply to the function declaration
Function attributes relate to the function declaration they
appear in. Sparse ignore most these attributes but a few ones
have a semantic value: 'pure', 'noreturn' & 'externally_visible'.
Due to how Sparse parse attributes and how these attributes
are stored for functions, the attributes 'pure' & 'noreturn'
are applied not to the function itself but its return type
if the function returns a pointer.
Fix this by extracting these attributes from the declaration
context and ensure they're applied to the declarator.
Reported-by: John Levon <john.levon@joyent.com>
Reported-by: Alex Kogan <alex.kogan@oracle.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/function-attribute.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/validation/function-attribute.c b/validation/function-attribute.c new file mode 100644 index 00000000..0f2c7592 --- /dev/null +++ b/validation/function-attribute.c @@ -0,0 +1,19 @@ +#define __pure __attribute__((pure)) + +struct s { + int x; +}; + +static __pure struct s *grab(struct s *ptr) +{ + return ptr; +} + +static void foo(struct s *ptr) +{ + struct s *ptr = grab(ptr); +} + +/* + * check-name: function-attribute + */ |
