aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/function-attribute-inner.c
AgeCommit message (Collapse)AuthorFilesLines
2019-11-20propagate function modifiers only to functionsLuc Van Oostenryck1-1/+0
Function attributes need to be parsed differently than the usual specifiers: For example, in code like: #define __noreturn __attribute__((noreturn)) __noreturn void foo(int a); the __noreturn attribute should apply to the function type while a specifier like 'const' would apply to its return type. The situation is quite similar to how storage specifiers must not be handled by alloc_indirect_symbol(). However, the solution used for storage specifiers (apply the modifier bits only after the declarator is reached: cfr.commit 233d4e17c ("function attributes apply to the function declaration")) can't be used here (because the storage modifiers can be applied to the outermost declarator and function attributes may be applied more deeply if function pointers are present). Fix this by: 1) reverting the previous storage-specifier-like solution 2) collect function specifiers MODs in a new separate field in the declaration context (f_modifiers) 3) apply these modifiers when the declarator for the function type is reached (note: it must not be applied to the SYM_FN itself since this correspond to the function's return type; it must be applied to the parent node which can be a SYM_NODE or a SYM_PTR). 4) also apply these modifiers to the declared symbol, if this symbol is a function declaration, to take into account attributes which are placed at the end of the declaration and not in front. Reported-by: Ramsay Jones <ramsay@ramsayjones.plus.com> Fixes: 233d4e17c544e1de252aed8f409630599104dbc7 Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
2019-11-19add tests for function attributesLuc Van Oostenryck1-0/+10
Function attributes need to be parsed differently than the usual specifiers. For example, in code like: #define __noreturn __attribute__((noreturn)) __noreturn void foo(int a); the __noreturn attribute should apply to the function type, while a specifier like 'const' would apply to its return type. It's even more clear when function pointers are involved: __noreturn void (*fptr)(void); here too, the attribute should be applied to the function type, not the its return type, nor to the declared pointer type. Add some testcases to cover some of the situations concerning the parsing of these function pointers. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>