On 11/18/2016 03:51 PM, Bernd Edlinger wrote:
> of the builtin (the function is not declared without attribute
> alloc_size, at least in Glibc, but GCC still expands it inline).
> This is as simple as enclosing alloca in parentheses:
>
> void *p = (alloca)(n);
>
> Ugly? Perhaps. One might say that code that does tricky or
No. I doubt that will work, unless you use -ffreestanding on the
command line.
It works because "__builtin_alloca" is distinct from "alloca" and
the warning code can simply compare the strings, just as you say
you did below. It's not ideal and I would prefer to avoid it but
I offer it as another solution if the performance overhead of
(n + 1) is thought to be too high.
Although the macro is not used in this case, even a declaraion
like
extern void *alloca (size_t __size);
goes thru the decl-anticipated path, that means it inherits
all the attributes from the builtin, unless the parameter don't
match, in that case you get a warning in C but no warning
in C++ (I am going to change the latter).
There is currently an attribute malloc but no explicit attribute
alloca, that's one of the reasons why special_function_p still
has to do a string compare of the function name aginst "alloca".
I think Jakub is right that we need a better way to fix the
warning for instance with a comment like the fall thru thing.
I don't believe this rare, corner case justifies special treatment.
There are many warnings in both -Wall and -Wextra that are orders
of magnitude noisier and that people find useful nonetheless. They
don't need a special mechanism to suppress or fine tune beyond what
GCC already provides: an option and a pragma, and neither should
this one. I certainly don't think that extending the complicated
(and controversial) machinery that was put in place to deal with
the exceedingly noisy fallthrough warning would be worth the effort
or even appropriate.
If you or others are concerned about the rate of false positives
of this warning please point me at a code base that might be a good
test bed to to try it on. Besides GCC I've built Binutils and the
Linux kernel with just the 5 instances in GCC.
Martin