On 07/20/16 12:46, Richard Biener wrote: > On Wed, 20 Jul 2016, Richard Biener wrote: > >> On Tue, 19 Jul 2016, Bernd Edlinger wrote: >> >>> Hi! >>> >>> As discussed at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71876, >>> we have a _very_ old hack in gcc, that recognizes certain functions by >>> name, and inserts in some cases unsafe attributes, that don't work for >>> a freestanding environment. >>> >>> It is unsafe to return ECF_MAY_BE_ALLOCA, ECF_LEAF and ECF_NORETURN >>> from special_function_p, just by the name of the function, especially >>> for less well known functions, like "getcontext" or "savectx", which >>> could easily used for something completely different. >> >> Returning ECF_MAY_BE_ALLOCA is safe. Just wanted to mention this, >> regardless of the followups you already received. > > Oh, and maybe you can factor out the less controversical parts, > namely ignoring the __builtin_ prefix. I don't think that > calling __builtin_setjmp in an environment where setjmp is not a > builtin should beave like setjmp (it will call a function named > '__builtin_setjmp').
I wonder how I manage to dig out such contriversical things ;) But you are right, that would at least be a start. So this patch is what you requested: Remove the handling of the __builtin_ prefix from special_function_p and add the returns_twice attribute to the __builtin_setjmp declaration instead. Is it OK after boot-strap and regression-testing? Thanks Bernd.
2016-07-19 Bernd Edlinger <bernd.edlin...@hotmail.de> PR middle-end/71876 * builtin-attrs.def (ATTR_RT_NOTHROW_LEAF_LIST): New return twice attribute. * builtins.def (BUILT_IN_SETJMP): Use ATTR_RT_NOTHROW_LEAF_LIST here. * calls.c (special_function_p): Remove the special handling of the "__builtin_" prefix. Index: gcc/builtin-attrs.def =================================================================== --- gcc/builtin-attrs.def (Revision 238382) +++ gcc/builtin-attrs.def (Arbeitskopie) @@ -131,6 +131,8 @@ DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, AT ATTR_NULL, ATTR_NOTHROW_LIST) DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LEAF_LIST, ATTR_NORETURN,\ ATTR_NULL, ATTR_NOTHROW_LEAF_LIST) +DEF_ATTR_TREE_LIST (ATTR_RT_NOTHROW_LEAF_LIST, ATTR_RETURNS_TWICE,\ + ATTR_NULL, ATTR_NOTHROW_LEAF_LIST) DEF_ATTR_TREE_LIST (ATTR_COLD_NOTHROW_LEAF_LIST, ATTR_COLD,\ ATTR_NULL, ATTR_NOTHROW_LEAF_LIST) DEF_ATTR_TREE_LIST (ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST, ATTR_COLD,\ Index: gcc/builtins.def =================================================================== --- gcc/builtins.def (Revision 238382) +++ gcc/builtins.def (Arbeitskopie) @@ -837,7 +837,7 @@ DEF_LIB_BUILTIN (BUILT_IN_REALLOC, "realloc DEF_GCC_BUILTIN (BUILT_IN_RETURN, "return", BT_FN_VOID_PTR, ATTR_NORETURN_NOTHROW_LEAF_LIST) DEF_GCC_BUILTIN (BUILT_IN_RETURN_ADDRESS, "return_address", BT_FN_PTR_UINT, ATTR_LEAF_LIST) DEF_GCC_BUILTIN (BUILT_IN_SAVEREGS, "saveregs", BT_FN_PTR_VAR, ATTR_NULL) -DEF_GCC_BUILTIN (BUILT_IN_SETJMP, "setjmp", BT_FN_INT_PTR, ATTR_NOTHROW_LEAF_LIST) +DEF_GCC_BUILTIN (BUILT_IN_SETJMP, "setjmp", BT_FN_INT_PTR, ATTR_RT_NOTHROW_LEAF_LIST) DEF_EXT_LIB_BUILTIN (BUILT_IN_STRFMON, "strfmon", BT_FN_SSIZE_STRING_SIZE_CONST_STRING_VAR, ATTR_FORMAT_STRFMON_NOTHROW_3_4) DEF_LIB_BUILTIN (BUILT_IN_STRFTIME, "strftime", BT_FN_SIZE_STRING_SIZE_CONST_STRING_CONST_PTR, ATTR_FORMAT_STRFTIME_NOTHROW_3_0) DEF_GCC_BUILTIN (BUILT_IN_TRAP, "trap", BT_FN_VOID, ATTR_NORETURN_NOTHROW_LEAF_LIST) Index: gcc/calls.c =================================================================== --- gcc/calls.c (Revision 238382) +++ gcc/calls.c (Arbeitskopie) @@ -514,14 +514,10 @@ special_function_p (const_tree fndecl, int flags) && ! strcmp (name, "alloca")) flags |= ECF_MAY_BE_ALLOCA; - /* Disregard prefix _, __, __x or __builtin_. */ + /* Disregard prefix _, __ or __x. */ if (name[0] == '_') { - if (name[1] == '_' - && name[2] == 'b' - && !strncmp (name + 3, "uiltin_", 7)) - tname += 10; - else if (name[1] == '_' && name[2] == 'x') + if (name[1] == '_' && name[2] == 'x') tname += 3; else if (name[1] == '_') tname += 2;