This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix unsafe function attributes for special functions (PR 71876)
On 07/21/16 23:57, Bernd Edlinger wrote:
> Hi,
>
> based on the discussion here, I have updated my patch again...
>
> This is the rest of the patch, which removes outdated function names,
> and creates built-in definitions for vfork, getcontext, savectx.
> These built-ins have the return_twice attribute but not the
> leaf attribute, because we do not really know, what these functions
> do.
>
> The reason for ceating the builtin functions is, that I would like
> to get a warning about conflicting builtin definition if someone
> accidentally picks the name of one of these less well known special
> functions, which are _not_ reserved names in most environments.
>
> I do not define builtins (without __builtin_ prefix) for setjmp and
> sigsetjmp because these are like wildcards, and they fall in the
> well-known category anyways.
>
> I still retain the handling of these functions in special_function_p
> because even in a free standing environment, returning
> ECF_RETURNS_TWICE is on the safe side.
>
>
>
> Is it OK for trunk after boot-strap and regression-testing?
>
Hmm, cough...
Boot-strap and reg-test was OK, but...
I just noticed that the new built-ins do not quite work as expected.
First with C++ there is no warning in this example although the
parameters are different:
cat test2.C
extern "C"
void savectx () __attribute__((nothrow));
int test () throw()
{
savectx ();
return 0;
}
and what I do not understand at all in the moment, is:
although both the builtin and the explict header say
"nothrow" there is still eh code emitted that was not
there before.
So I would like to split that patch again, in the
cleanup of special_function_p and drop the new built-ins
in the moment, until I understand what went wrong there.
The built-in were just meant to bring up warnings, and
are therefore less important.
Sorry for all the iterations this took already :(
So here is the next version of the patch that I am gonna try.
Is it OK for trunk?
Thanks
Bernd.
2016-07-21 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR middle-end/71876
* calls.c (special_function_p): Remove special handling of
"setjmp_syscall", "qsetjmp", "longjmp", "siglongjmp" and the
prefix "__x". Recognize "savectx", "vfork" and "getcontext" only
without prefix. Remove potentially unsafe ECF_LEAF and ECF_NORETURN.
Index: gcc/calls.c
===================================================================
--- gcc/calls.c (Revision 238611)
+++ gcc/calls.c (Arbeitskopie)
@@ -468,15 +468,13 @@
anti_adjust_stack (GEN_INT (n_popped));
}
-/* Determine if the function identified by NAME and FNDECL is one with
- special properties we wish to know about.
+/* Determine if the function identified by FNDECL is one with
+ special properties we wish to know about. Modify FLAGS accordingly.
For example, if the function might return more than one time (setjmp), then
- set RETURNS_TWICE to a nonzero value.
+ set ECF_RETURNS_TWICE.
- Similarly set NORETURN if the function is in the longjmp family.
-
- Set MAY_BE_ALLOCA for any memory allocation function that might allocate
+ Set ECF_MAY_BE_ALLOCA for any memory allocation function that might allocate
space from the stack such as alloca. */
static int
@@ -491,7 +489,7 @@
name_decl = DECL_NAME (cgraph_node::get (fndecl)->orig_decl);
if (fndecl && name_decl
- && IDENTIFIER_LENGTH (name_decl) <= 17
+ && IDENTIFIER_LENGTH (name_decl) <= 11
/* Exclude functions not at the file scope, or not `extern',
since they are not the magic functions we would otherwise
think they are.
@@ -514,43 +512,22 @@
&& ! strcmp (name, "alloca"))
flags |= ECF_MAY_BE_ALLOCA;
- /* Disregard prefix _, __ or __x. */
+ /* Disregard prefix _ or __. */
if (name[0] == '_')
{
- if (name[1] == '_' && name[2] == 'x')
- tname += 3;
- else if (name[1] == '_')
+ if (name[1] == '_')
tname += 2;
else
tname += 1;
}
- if (tname[0] == 's')
- {
- if ((tname[1] == 'e'
- && (! strcmp (tname, "setjmp")
- || ! strcmp (tname, "setjmp_syscall")))
- || (tname[1] == 'i'
- && ! strcmp (tname, "sigsetjmp"))
- || (tname[1] == 'a'
- && ! strcmp (tname, "savectx")))
- flags |= ECF_RETURNS_TWICE | ECF_LEAF;
-
- if (tname[1] == 'i'
- && ! strcmp (tname, "siglongjmp"))
- flags |= ECF_NORETURN;
- }
- else if ((tname[0] == 'q' && tname[1] == 's'
- && ! strcmp (tname, "qsetjmp"))
- || (tname[0] == 'v' && tname[1] == 'f'
- && ! strcmp (tname, "vfork"))
- || (tname[0] == 'g' && tname[1] == 'e'
- && !strcmp (tname, "getcontext")))
- flags |= ECF_RETURNS_TWICE | ECF_LEAF;
-
- else if (tname[0] == 'l' && tname[1] == 'o'
- && ! strcmp (tname, "longjmp"))
- flags |= ECF_NORETURN;
+ /* ECF_RETURNS_TWICE is safe even for -ffreestanding. */
+ if (! strcmp (tname, "setjmp")
+ || ! strcmp (tname, "sigsetjmp")
+ || ! strcmp (name, "savectx")
+ || ! strcmp (name, "vfork")
+ || ! strcmp (name, "getcontext"))
+ flags |= ECF_RETURNS_TWICE;
}
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)