Make gcc use C99 inline semantics in c99 and gnu99 mode. This was the
original intent, but the functionality wasn't implemented until after gcc 4.2 was released. However, if you compiled a program that would behave differently before and after this change, gcc 4.2 would have warned you; hence, everything currently in the base system is unaffected by this change. This patch also adds additional warnings about certain inline function-related bogosity, e.g., using a static non-const local variable in an inline function. These changes were merged from a snapshot of gcc mainline from March 2007, prior to the GPLv3 switch. I then ran the regression test suite from a more recent gcc snapshot and fixed the important bugs it found. I also squelched the following warning unless -pedantic is specified: foo is static but used in inline function bar which is not static This is consistent with LLVM's behavior, but not consistent with gcc 4.3. Reviewed by: arch@
This commit is contained in:
parent
34d3ac5921
commit
d5ed956300
@ -1,5 +1,6 @@
|
|||||||
/* Define builtin-in macros for the C family front ends.
|
/* Define builtin-in macros for the C family front ends.
|
||||||
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of GCC.
|
This file is part of GCC.
|
||||||
|
|
||||||
@ -484,7 +485,10 @@ c_cpp_builtins (cpp_reader *pfile)
|
|||||||
/* Misc. */
|
/* Misc. */
|
||||||
builtin_define_with_value ("__VERSION__", version_string, 1);
|
builtin_define_with_value ("__VERSION__", version_string, 1);
|
||||||
|
|
||||||
cpp_define (pfile, "__GNUC_GNU_INLINE__");
|
if (flag_gnu89_inline)
|
||||||
|
cpp_define (pfile, "__GNUC_GNU_INLINE__");
|
||||||
|
else
|
||||||
|
cpp_define (pfile, "__GNUC_STDC_INLINE__");
|
||||||
|
|
||||||
/* Definitions for LP64 model. */
|
/* Definitions for LP64 model. */
|
||||||
if (TYPE_PRECISION (long_integer_type_node) == 64
|
if (TYPE_PRECISION (long_integer_type_node) == 64
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* Process declarations and variables for C compiler.
|
/* Process declarations and variables for C compiler.
|
||||||
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
|
Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
|
||||||
2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of GCC.
|
This file is part of GCC.
|
||||||
|
|
||||||
@ -20,6 +20,9 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
|||||||
02110-1301, USA. */
|
02110-1301, USA. */
|
||||||
|
|
||||||
/* $FreeBSD$ */
|
/* $FreeBSD$ */
|
||||||
|
/* Merged C99 inline changes from gcc trunk 122565 2007-03-05 */
|
||||||
|
/* Fixed problems with compiling inline-25.c and inline-26.c */
|
||||||
|
/* XXX still fails inline-29.c, inline-31.c, and inline-32.c */
|
||||||
|
|
||||||
/* Process declarations and symbol lookup for C front end.
|
/* Process declarations and symbol lookup for C front end.
|
||||||
Also constructs types; the standard scalar types at initialization,
|
Also constructs types; the standard scalar types at initialization,
|
||||||
@ -156,10 +159,6 @@ int current_function_returns_abnormally;
|
|||||||
|
|
||||||
static int warn_about_return_type;
|
static int warn_about_return_type;
|
||||||
|
|
||||||
/* Nonzero when starting a function declared `extern inline'. */
|
|
||||||
|
|
||||||
static int current_extern_inline;
|
|
||||||
|
|
||||||
/* Nonzero when the current toplevel function contains a declaration
|
/* Nonzero when the current toplevel function contains a declaration
|
||||||
of a nested function which is never defined. */
|
of a nested function which is never defined. */
|
||||||
|
|
||||||
@ -804,6 +803,15 @@ pop_scope (void)
|
|||||||
error ("nested function %q+D declared but never defined", p);
|
error ("nested function %q+D declared but never defined", p);
|
||||||
undef_nested_function = true;
|
undef_nested_function = true;
|
||||||
}
|
}
|
||||||
|
/* C99 6.7.4p6: "a function with external linkage... declared
|
||||||
|
with an inline function specifier ... shall also be defined in the
|
||||||
|
same translation unit." */
|
||||||
|
else if (DECL_DECLARED_INLINE_P (p)
|
||||||
|
&& TREE_PUBLIC (p)
|
||||||
|
&& !DECL_INITIAL (p)
|
||||||
|
&& !flag_gnu89_inline)
|
||||||
|
pedwarn ("inline function %q+D declared but never defined", p);
|
||||||
|
|
||||||
goto common_symbol;
|
goto common_symbol;
|
||||||
|
|
||||||
case VAR_DECL:
|
case VAR_DECL:
|
||||||
@ -1294,10 +1302,11 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
|
|||||||
|
|
||||||
/* Function declarations can either be 'static' or 'extern' (no
|
/* Function declarations can either be 'static' or 'extern' (no
|
||||||
qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
|
qualifier is equivalent to 'extern' - C99 6.2.2p5) and therefore
|
||||||
can never conflict with each other on account of linkage (6.2.2p4).
|
can never conflict with each other on account of linkage
|
||||||
Multiple definitions are not allowed (6.9p3,5) but GCC permits
|
(6.2.2p4). Multiple definitions are not allowed (6.9p3,5) but
|
||||||
two definitions if one is 'extern inline' and one is not. The non-
|
gnu89 mode permits two definitions if one is 'extern inline' and
|
||||||
extern-inline definition supersedes the extern-inline definition. */
|
one is not. The non- extern-inline definition supersedes the
|
||||||
|
extern-inline definition. */
|
||||||
|
|
||||||
else if (TREE_CODE (newdecl) == FUNCTION_DECL)
|
else if (TREE_CODE (newdecl) == FUNCTION_DECL)
|
||||||
{
|
{
|
||||||
@ -1323,16 +1332,18 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
|
|||||||
{
|
{
|
||||||
/* If both decls are in the same TU and the new declaration
|
/* If both decls are in the same TU and the new declaration
|
||||||
isn't overriding an extern inline reject the new decl.
|
isn't overriding an extern inline reject the new decl.
|
||||||
When we handle c99 style inline rules we'll want to reject
|
In c99, no overriding is allowed in the same translation
|
||||||
the following:
|
unit. */
|
||||||
|
if ((!DECL_EXTERN_INLINE (olddecl)
|
||||||
DECL_EXTERN_INLINE (olddecl)
|
|| DECL_EXTERN_INLINE (newdecl)
|
||||||
&& !DECL_EXTERN_INLINE (newdecl)
|
|| (!flag_gnu89_inline
|
||||||
|
&& (!DECL_DECLARED_INLINE_P (olddecl)
|
||||||
if they're in the same translation unit. Until we implement
|
|| !lookup_attribute ("gnu_inline",
|
||||||
the full semantics we accept the construct. */
|
DECL_ATTRIBUTES (olddecl)))
|
||||||
if (!(DECL_EXTERN_INLINE (olddecl)
|
&& (!DECL_DECLARED_INLINE_P (newdecl)
|
||||||
&& !DECL_EXTERN_INLINE (newdecl))
|
|| !lookup_attribute ("gnu_inline",
|
||||||
|
DECL_ATTRIBUTES (newdecl))))
|
||||||
|
)
|
||||||
&& same_translation_unit_p (newdecl, olddecl))
|
&& same_translation_unit_p (newdecl, olddecl))
|
||||||
{
|
{
|
||||||
error ("redefinition of %q+D", newdecl);
|
error ("redefinition of %q+D", newdecl);
|
||||||
@ -1392,6 +1403,23 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
|
|||||||
warned = true;
|
warned = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Make sure gnu_inline attribute is either not present, or
|
||||||
|
present on all inline decls. */
|
||||||
|
if (DECL_DECLARED_INLINE_P (olddecl)
|
||||||
|
&& DECL_DECLARED_INLINE_P (newdecl))
|
||||||
|
{
|
||||||
|
bool newa = lookup_attribute ("gnu_inline",
|
||||||
|
DECL_ATTRIBUTES (newdecl)) != NULL;
|
||||||
|
bool olda = lookup_attribute ("gnu_inline",
|
||||||
|
DECL_ATTRIBUTES (olddecl)) != NULL;
|
||||||
|
if (newa != olda)
|
||||||
|
{
|
||||||
|
error ("%<gnu_inline%> attribute present on %q+D",
|
||||||
|
newa ? newdecl : olddecl);
|
||||||
|
error ("%Jbut not here", newa ? olddecl : newdecl);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (TREE_CODE (newdecl) == VAR_DECL)
|
else if (TREE_CODE (newdecl) == VAR_DECL)
|
||||||
{
|
{
|
||||||
@ -1523,9 +1551,13 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
|
|||||||
??? Should we still warn about this now we have unit-at-a-time
|
??? Should we still warn about this now we have unit-at-a-time
|
||||||
mode and can get it right?
|
mode and can get it right?
|
||||||
Definitely don't complain if the decls are in different translation
|
Definitely don't complain if the decls are in different translation
|
||||||
units. */
|
units.
|
||||||
|
C99 permits this, so don't warn in that case. (The function
|
||||||
|
may not be inlined everywhere in function-at-a-time mode, but
|
||||||
|
we still shouldn't warn.) */
|
||||||
if (DECL_DECLARED_INLINE_P (newdecl) && !DECL_DECLARED_INLINE_P (olddecl)
|
if (DECL_DECLARED_INLINE_P (newdecl) && !DECL_DECLARED_INLINE_P (olddecl)
|
||||||
&& same_translation_unit_p (olddecl, newdecl))
|
&& same_translation_unit_p (olddecl, newdecl)
|
||||||
|
&& flag_gnu89_inline)
|
||||||
{
|
{
|
||||||
if (TREE_USED (olddecl))
|
if (TREE_USED (olddecl))
|
||||||
{
|
{
|
||||||
@ -1602,12 +1634,13 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
|
|||||||
static void
|
static void
|
||||||
merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
|
merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
|
||||||
{
|
{
|
||||||
int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
|
bool new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
|
||||||
&& DECL_INITIAL (newdecl) != 0);
|
&& DECL_INITIAL (newdecl) != 0);
|
||||||
int new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
|
bool new_is_prototype = (TREE_CODE (newdecl) == FUNCTION_DECL
|
||||||
&& TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0);
|
&& TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0);
|
||||||
int old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
|
bool old_is_prototype = (TREE_CODE (olddecl) == FUNCTION_DECL
|
||||||
&& TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0);
|
&& TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0);
|
||||||
|
bool extern_changed = false;
|
||||||
|
|
||||||
/* For real parm decl following a forward decl, rechain the old decl
|
/* For real parm decl following a forward decl, rechain the old decl
|
||||||
in its new location and clear TREE_ASM_WRITTEN (it's not a
|
in its new location and clear TREE_ASM_WRITTEN (it's not a
|
||||||
@ -1750,6 +1783,20 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* In c99, 'extern' declaration before (or after) 'inline' means this
|
||||||
|
function is not DECL_EXTERNAL, unless 'gnu_inline' attribute
|
||||||
|
is present. */
|
||||||
|
if (TREE_CODE (newdecl) == FUNCTION_DECL
|
||||||
|
&& !flag_gnu89_inline
|
||||||
|
&& (DECL_DECLARED_INLINE_P (newdecl)
|
||||||
|
|| DECL_DECLARED_INLINE_P (olddecl))
|
||||||
|
&& (!DECL_DECLARED_INLINE_P (newdecl)
|
||||||
|
|| !DECL_DECLARED_INLINE_P (olddecl)
|
||||||
|
|| !DECL_EXTERNAL (olddecl))
|
||||||
|
&& DECL_EXTERNAL (newdecl)
|
||||||
|
&& !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (newdecl)))
|
||||||
|
DECL_EXTERNAL (newdecl) = 0;
|
||||||
|
|
||||||
if (DECL_EXTERNAL (newdecl))
|
if (DECL_EXTERNAL (newdecl))
|
||||||
{
|
{
|
||||||
TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
|
TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
|
||||||
@ -1842,6 +1889,8 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl);
|
||||||
|
|
||||||
/* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
|
/* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
|
||||||
But preserve OLDDECL's DECL_UID and DECL_CONTEXT. */
|
But preserve OLDDECL's DECL_UID and DECL_CONTEXT. */
|
||||||
{
|
{
|
||||||
@ -1884,6 +1933,13 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
|
|||||||
|| (TREE_CODE (olddecl) == VAR_DECL
|
|| (TREE_CODE (olddecl) == VAR_DECL
|
||||||
&& TREE_STATIC (olddecl))))
|
&& TREE_STATIC (olddecl))))
|
||||||
make_decl_rtl (olddecl);
|
make_decl_rtl (olddecl);
|
||||||
|
|
||||||
|
/* If we changed a function from DECL_EXTERNAL to !DECL_EXTERNAL,
|
||||||
|
and the definition is coming from the old version, cgraph needs
|
||||||
|
to be called again. */
|
||||||
|
if (extern_changed && !new_is_definition
|
||||||
|
&& TREE_CODE (olddecl) == FUNCTION_DECL && DECL_INITIAL (olddecl))
|
||||||
|
cgraph_finalize_function (olddecl, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle when a new declaration NEWDECL has the same name as an old
|
/* Handle when a new declaration NEWDECL has the same name as an old
|
||||||
@ -3274,6 +3330,18 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
|
|||||||
/* Set attributes here so if duplicate decl, will have proper attributes. */
|
/* Set attributes here so if duplicate decl, will have proper attributes. */
|
||||||
decl_attributes (&decl, attributes, 0);
|
decl_attributes (&decl, attributes, 0);
|
||||||
|
|
||||||
|
/* Handle gnu_inline attribute. */
|
||||||
|
if (declspecs->inline_p
|
||||||
|
&& !flag_gnu89_inline
|
||||||
|
&& TREE_CODE (decl) == FUNCTION_DECL
|
||||||
|
&& lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl)))
|
||||||
|
{
|
||||||
|
if (declspecs->storage_class == csc_auto && current_scope != file_scope)
|
||||||
|
;
|
||||||
|
else if (declspecs->storage_class != csc_static)
|
||||||
|
DECL_EXTERNAL (decl) = !DECL_EXTERNAL (decl);
|
||||||
|
}
|
||||||
|
|
||||||
if (TREE_CODE (decl) == FUNCTION_DECL
|
if (TREE_CODE (decl) == FUNCTION_DECL
|
||||||
&& targetm.calls.promote_prototypes (TREE_TYPE (decl)))
|
&& targetm.calls.promote_prototypes (TREE_TYPE (decl)))
|
||||||
{
|
{
|
||||||
@ -3301,6 +3369,18 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
|
|||||||
warning (OPT_Wattributes, "inline function %q+D given attribute noinline",
|
warning (OPT_Wattributes, "inline function %q+D given attribute noinline",
|
||||||
decl);
|
decl);
|
||||||
|
|
||||||
|
/* C99 6.7.4p3: An inline definition of a function with external
|
||||||
|
linkage shall not contain a definition of a modifiable object
|
||||||
|
with static storage duration... */
|
||||||
|
if (TREE_CODE (decl) == VAR_DECL
|
||||||
|
&& current_scope != file_scope
|
||||||
|
&& TREE_STATIC (decl)
|
||||||
|
&& !TREE_READONLY (decl)
|
||||||
|
&& DECL_DECLARED_INLINE_P (current_function_decl)
|
||||||
|
&& DECL_EXTERNAL (current_function_decl))
|
||||||
|
pedwarn ("%q+D is static but declared in inline function %qD "
|
||||||
|
"which is not static", decl, current_function_decl);
|
||||||
|
|
||||||
/* Add this decl to the current scope.
|
/* Add this decl to the current scope.
|
||||||
TEM may equal DECL or it may be a previous decl of the same name. */
|
TEM may equal DECL or it may be a previous decl of the same name. */
|
||||||
tem = pushdecl (decl);
|
tem = pushdecl (decl);
|
||||||
@ -4755,8 +4835,16 @@ grokdeclarator (const struct c_declarator *declarator,
|
|||||||
GCC to signify a forward declaration of a nested function. */
|
GCC to signify a forward declaration of a nested function. */
|
||||||
if (storage_class == csc_auto && current_scope != file_scope)
|
if (storage_class == csc_auto && current_scope != file_scope)
|
||||||
DECL_EXTERNAL (decl) = 0;
|
DECL_EXTERNAL (decl) = 0;
|
||||||
|
/* In C99, a function which is declared 'inline' with 'extern'
|
||||||
|
is not an external reference (which is confusing). It
|
||||||
|
means that the later definition of the function must be output
|
||||||
|
in this file, C99 6.7.4p6. In GNU C89, a function declared
|
||||||
|
'extern inline' is an external reference. */
|
||||||
|
else if (declspecs->inline_p && storage_class != csc_static)
|
||||||
|
DECL_EXTERNAL (decl) = ((storage_class == csc_extern)
|
||||||
|
== flag_gnu89_inline);
|
||||||
else
|
else
|
||||||
DECL_EXTERNAL (decl) = 1;
|
DECL_EXTERNAL (decl) = !initialized;
|
||||||
|
|
||||||
/* Record absence of global scope for `static' or `auto'. */
|
/* Record absence of global scope for `static' or `auto'. */
|
||||||
TREE_PUBLIC (decl)
|
TREE_PUBLIC (decl)
|
||||||
@ -4786,11 +4874,7 @@ grokdeclarator (const struct c_declarator *declarator,
|
|||||||
the abstract origin pointing between the declarations,
|
the abstract origin pointing between the declarations,
|
||||||
which will confuse dwarf2out. */
|
which will confuse dwarf2out. */
|
||||||
if (initialized)
|
if (initialized)
|
||||||
{
|
DECL_INLINE (decl) = 1;
|
||||||
DECL_INLINE (decl) = 1;
|
|
||||||
if (storage_class == csc_extern)
|
|
||||||
current_extern_inline = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* If -finline-functions, assume it can be inlined. This does
|
/* If -finline-functions, assume it can be inlined. This does
|
||||||
two things: let the function be deferred until it is actually
|
two things: let the function be deferred until it is actually
|
||||||
@ -5288,12 +5372,15 @@ start_struct (enum tree_code code, tree name)
|
|||||||
error ("nested redefinition of %<union %E%>", name);
|
error ("nested redefinition of %<union %E%>", name);
|
||||||
else
|
else
|
||||||
error ("nested redefinition of %<struct %E%>", name);
|
error ("nested redefinition of %<struct %E%>", name);
|
||||||
|
/* Don't create structures that contain themselves. */
|
||||||
|
ref = NULL_TREE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Otherwise create a forward-reference just so the tag is in scope. */
|
|
||||||
|
|
||||||
|
/* Otherwise create a forward-reference just so the tag is in scope. */
|
||||||
|
|
||||||
|
if (ref == NULL_TREE || TREE_CODE (ref) != code)
|
||||||
|
{
|
||||||
ref = make_node (code);
|
ref = make_node (code);
|
||||||
pushtag (name, ref);
|
pushtag (name, ref);
|
||||||
}
|
}
|
||||||
@ -5985,7 +6072,6 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
|
|||||||
current_function_returns_null = 0;
|
current_function_returns_null = 0;
|
||||||
current_function_returns_abnormally = 0;
|
current_function_returns_abnormally = 0;
|
||||||
warn_about_return_type = 0;
|
warn_about_return_type = 0;
|
||||||
current_extern_inline = 0;
|
|
||||||
c_switch_stack = NULL;
|
c_switch_stack = NULL;
|
||||||
|
|
||||||
nstack_se = XOBNEW (&parser_obstack, struct c_label_context_se);
|
nstack_se = XOBNEW (&parser_obstack, struct c_label_context_se);
|
||||||
@ -6025,6 +6111,16 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
|
|||||||
warning (OPT_Wattributes, "inline function %q+D given attribute noinline",
|
warning (OPT_Wattributes, "inline function %q+D given attribute noinline",
|
||||||
decl1);
|
decl1);
|
||||||
|
|
||||||
|
/* Handle gnu_inline attribute. */
|
||||||
|
if (declspecs->inline_p
|
||||||
|
&& !flag_gnu89_inline
|
||||||
|
&& TREE_CODE (decl1) == FUNCTION_DECL
|
||||||
|
&& lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1)))
|
||||||
|
{
|
||||||
|
if (declspecs->storage_class != csc_static)
|
||||||
|
DECL_EXTERNAL (decl1) = !DECL_EXTERNAL (decl1);
|
||||||
|
}
|
||||||
|
|
||||||
announce_function (decl1);
|
announce_function (decl1);
|
||||||
|
|
||||||
if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
|
if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl1))))
|
||||||
@ -6137,36 +6233,6 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
|
|||||||
warning (OPT_Wmissing_declarations,
|
warning (OPT_Wmissing_declarations,
|
||||||
"%q+D was used with no declaration before its definition", decl1);
|
"%q+D was used with no declaration before its definition", decl1);
|
||||||
|
|
||||||
/* This is a definition, not a reference.
|
|
||||||
So normally clear DECL_EXTERNAL.
|
|
||||||
However, `extern inline' acts like a declaration
|
|
||||||
except for defining how to inline. So set DECL_EXTERNAL in that case. */
|
|
||||||
DECL_EXTERNAL (decl1) = current_extern_inline;
|
|
||||||
|
|
||||||
/* C99 specified different behaviour for non-static inline
|
|
||||||
functions, compared with the traditional GNU behaviour. We don't
|
|
||||||
support the C99 behaviour, but we do warn about non-static inline
|
|
||||||
functions here. The warning can be disabled via an explicit use
|
|
||||||
of -fgnu89-inline, or by using the gnu_inline attribute. */
|
|
||||||
if (DECL_DECLARED_INLINE_P (decl1)
|
|
||||||
&& TREE_PUBLIC (decl1)
|
|
||||||
&& flag_isoc99
|
|
||||||
&& flag_gnu89_inline != 1
|
|
||||||
&& !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl1))
|
|
||||||
&& diagnostic_report_warnings_p ())
|
|
||||||
{
|
|
||||||
static bool info = false;
|
|
||||||
|
|
||||||
warning (0, "C99 inline functions are not supported; using GNU89");
|
|
||||||
if (!info)
|
|
||||||
{
|
|
||||||
warning (0,
|
|
||||||
"to disable this warning use -fgnu89-inline or "
|
|
||||||
"the gnu_inline function attribute");
|
|
||||||
info = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This function exists in static storage.
|
/* This function exists in static storage.
|
||||||
(This does not mean `static' in the C sense!) */
|
(This does not mean `static' in the C sense!) */
|
||||||
TREE_STATIC (decl1) = 1;
|
TREE_STATIC (decl1) = 1;
|
||||||
@ -6942,7 +7008,6 @@ c_push_function_context (struct function *f)
|
|||||||
p->returns_null = current_function_returns_null;
|
p->returns_null = current_function_returns_null;
|
||||||
p->returns_abnormally = current_function_returns_abnormally;
|
p->returns_abnormally = current_function_returns_abnormally;
|
||||||
p->warn_about_return_type = warn_about_return_type;
|
p->warn_about_return_type = warn_about_return_type;
|
||||||
p->extern_inline = current_extern_inline;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore the variables used during compilation of a C function. */
|
/* Restore the variables used during compilation of a C function. */
|
||||||
@ -6971,7 +7036,6 @@ c_pop_function_context (struct function *f)
|
|||||||
current_function_returns_null = p->returns_null;
|
current_function_returns_null = p->returns_null;
|
||||||
current_function_returns_abnormally = p->returns_abnormally;
|
current_function_returns_abnormally = p->returns_abnormally;
|
||||||
warn_about_return_type = p->warn_about_return_type;
|
warn_about_return_type = p->warn_about_return_type;
|
||||||
current_extern_inline = p->extern_inline;
|
|
||||||
|
|
||||||
f->language = NULL;
|
f->language = NULL;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
|||||||
02110-1301, USA. */
|
02110-1301, USA. */
|
||||||
|
|
||||||
/* $FreeBSD$ */
|
/* $FreeBSD$ */
|
||||||
|
/* Merged C99 inline changes from gcc trunk 122565 2007-03-05 */
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
@ -1008,11 +1009,12 @@ c_common_post_options (const char **pfilename)
|
|||||||
if (flag_inline_functions)
|
if (flag_inline_functions)
|
||||||
flag_inline_trees = 2;
|
flag_inline_trees = 2;
|
||||||
|
|
||||||
/* We recognize -fgnu89-inline in preparation for 4.3 where the
|
/* By default we use C99 inline semantics in GNU99 or C99 mode. C99
|
||||||
option will be meaningful. Here we just reject
|
inline semantics are not supported in GNU89 or C89 mode. */
|
||||||
-fno-gnu89-inline, since we don't support it. */
|
if (flag_gnu89_inline == -1)
|
||||||
if (!flag_gnu89_inline)
|
flag_gnu89_inline = !flag_isoc99;
|
||||||
error ("-fno-gnu89-inline is not supported");
|
else if (!flag_gnu89_inline && !flag_isoc99)
|
||||||
|
error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode");
|
||||||
|
|
||||||
/* If we are given more than one input file, we must use
|
/* If we are given more than one input file, we must use
|
||||||
unit-at-a-time mode. */
|
unit-at-a-time mode. */
|
||||||
|
@ -384,7 +384,6 @@ struct language_function GTY(())
|
|||||||
int returns_null;
|
int returns_null;
|
||||||
int returns_abnormally;
|
int returns_abnormally;
|
||||||
int warn_about_return_type;
|
int warn_about_return_type;
|
||||||
int extern_inline;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Save lists of labels used or defined in particular contexts.
|
/* Save lists of labels used or defined in particular contexts.
|
||||||
|
@ -2109,6 +2109,19 @@ build_external_ref (tree id, int fun, location_t loc)
|
|||||||
if (context != 0 && context != current_function_decl)
|
if (context != 0 && context != current_function_decl)
|
||||||
DECL_NONLOCAL (ref) = 1;
|
DECL_NONLOCAL (ref) = 1;
|
||||||
}
|
}
|
||||||
|
/* C99 6.7.4p3: An inline definition of a function with external
|
||||||
|
linkage ... shall not contain a reference to an identifier with
|
||||||
|
internal linkage. */
|
||||||
|
else if (current_function_decl != 0
|
||||||
|
&& DECL_DECLARED_INLINE_P (current_function_decl)
|
||||||
|
&& DECL_EXTERNAL (current_function_decl)
|
||||||
|
&& VAR_OR_FUNCTION_DECL_P (ref)
|
||||||
|
&& DECL_FILE_SCOPE_P (ref)
|
||||||
|
&& pedantic
|
||||||
|
&& (TREE_CODE (ref) != VAR_DECL || TREE_STATIC (ref))
|
||||||
|
&& ! TREE_PUBLIC (ref))
|
||||||
|
pedwarn ("%H%qD is static but used in inline function %qD "
|
||||||
|
"which is not static", &loc, ref, current_function_decl);
|
||||||
|
|
||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
|
@ -3829,33 +3829,45 @@ These attributes mainly are intended to support the @code{__vector},
|
|||||||
@cindex open coding
|
@cindex open coding
|
||||||
@cindex macros, inline alternative
|
@cindex macros, inline alternative
|
||||||
|
|
||||||
By declaring a function @code{inline}, you can direct GCC to
|
By declaring a function inline, you can direct GCC to make
|
||||||
|
calls to that function faster. One way GCC can achieve this is to
|
||||||
integrate that function's code into the code for its callers. This
|
integrate that function's code into the code for its callers. This
|
||||||
makes execution faster by eliminating the function-call overhead; in
|
makes execution faster by eliminating the function-call overhead; in
|
||||||
addition, if any of the actual argument values are constant, their known
|
addition, if any of the actual argument values are constant, their
|
||||||
values may permit simplifications at compile time so that not all of the
|
known values may permit simplifications at compile time so that not
|
||||||
inline function's code needs to be included. The effect on code size is
|
all of the inline function's code needs to be included. The effect on
|
||||||
less predictable; object code may be larger or smaller with function
|
code size is less predictable; object code may be larger or smaller
|
||||||
inlining, depending on the particular case. Inlining of functions is an
|
with function inlining, depending on the particular case. You can
|
||||||
optimization and it really ``works'' only in optimizing compilation. If
|
also direct GCC to try to integrate all ``simple enough'' functions
|
||||||
you don't use @option{-O}, no function is really inline.
|
into their callers with the option @option{-finline-functions}.
|
||||||
|
|
||||||
Inline functions are included in the ISO C99 standard, but there are
|
GCC implements three different semantics of declaring a function
|
||||||
currently substantial differences between what GCC implements and what
|
inline. One is available with @option{-std=gnu89}, another when
|
||||||
the ISO C99 standard requires. GCC will fully support C99 inline
|
@option{-std=c99} or @option{-std=gnu99}, and the third is used when
|
||||||
functions in version 4.3. The traditional GCC handling of inline
|
compiling C++.
|
||||||
functions will still be available with @option{-std=gnu89},
|
|
||||||
@option{-fgnu89-inline} or when @code{gnu_inline} attribute is present
|
|
||||||
on all inline declarations. The preprocessor macros
|
|
||||||
@code{__GNUC_GNU_INLINE__} and @code{__GNUC_STDC_INLINE__} may be used
|
|
||||||
to determine the handling of @code{inline} during a particular
|
|
||||||
compilation (@pxref{Common Predefined Macros,,,cpp,The C
|
|
||||||
Preprocessor}).
|
|
||||||
|
|
||||||
To declare a function inline, use the @code{inline} keyword in its
|
To declare a function inline, use the @code{inline} keyword in its
|
||||||
declaration, like this:
|
declaration, like this:
|
||||||
|
|
||||||
@smallexample
|
@smallexample
|
||||||
|
static inline int
|
||||||
|
inc (int *a)
|
||||||
|
@{
|
||||||
|
(*a)++;
|
||||||
|
@}
|
||||||
|
@end smallexample
|
||||||
|
|
||||||
|
If you are writing a header file to be included in ISO C89 programs, write
|
||||||
|
@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.
|
||||||
|
|
||||||
|
The three types of inlining behave similarly in two important cases:
|
||||||
|
when the @code{inline} keyword is used on a @code{static} function,
|
||||||
|
like the example above, and when a function is first declared without
|
||||||
|
using the @code{inline} keyword and then is defined with
|
||||||
|
@code{inline}, like this:
|
||||||
|
|
||||||
|
@smallexample
|
||||||
|
extern int inc (int *a);
|
||||||
inline int
|
inline int
|
||||||
inc (int *a)
|
inc (int *a)
|
||||||
@{
|
@{
|
||||||
@ -3863,32 +3875,8 @@ inc (int *a)
|
|||||||
@}
|
@}
|
||||||
@end smallexample
|
@end smallexample
|
||||||
|
|
||||||
(If you are writing a header file to be included in ISO C programs, write
|
In both of these common cases, the program behaves the same as if you
|
||||||
@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.)
|
had not used the @code{inline} keyword, except for its speed.
|
||||||
You can also make all ``simple enough'' functions inline with the option
|
|
||||||
@option{-finline-functions}.
|
|
||||||
|
|
||||||
@opindex Winline
|
|
||||||
Note that certain usages in a function definition can make it unsuitable
|
|
||||||
for inline substitution. Among these usages are: use of varargs, use of
|
|
||||||
alloca, use of variable sized data types (@pxref{Variable Length}),
|
|
||||||
use of computed goto (@pxref{Labels as Values}), use of nonlocal goto,
|
|
||||||
and nested functions (@pxref{Nested Functions}). Using @option{-Winline}
|
|
||||||
will warn when a function marked @code{inline} could not be substituted,
|
|
||||||
and will give the reason for the failure.
|
|
||||||
|
|
||||||
Note that in C and Objective-C, unlike C++, the @code{inline} keyword
|
|
||||||
does not affect the linkage of the function.
|
|
||||||
|
|
||||||
@cindex automatic @code{inline} for C++ member fns
|
|
||||||
@cindex @code{inline} automatic for C++ member fns
|
|
||||||
@cindex member fns, automatically @code{inline}
|
|
||||||
@cindex C++ member fns, automatically @code{inline}
|
|
||||||
@opindex fno-default-inline
|
|
||||||
GCC automatically inlines member functions defined within the class
|
|
||||||
body of C++ programs even if they are not explicitly declared
|
|
||||||
@code{inline}. (You can override this with @option{-fno-default-inline};
|
|
||||||
@pxref{C++ Dialect Options,,Options Controlling C++ Dialect}.)
|
|
||||||
|
|
||||||
@cindex inline functions, omission of
|
@cindex inline functions, omission of
|
||||||
@opindex fkeep-inline-functions
|
@opindex fkeep-inline-functions
|
||||||
@ -3904,6 +3892,27 @@ nonintegrated call, then the function is compiled to assembler code as
|
|||||||
usual. The function must also be compiled as usual if the program
|
usual. The function must also be compiled as usual if the program
|
||||||
refers to its address, because that can't be inlined.
|
refers to its address, because that can't be inlined.
|
||||||
|
|
||||||
|
@cindex automatic @code{inline} for C++ member fns
|
||||||
|
@cindex @code{inline} automatic for C++ member fns
|
||||||
|
@cindex member fns, automatically @code{inline}
|
||||||
|
@cindex C++ member fns, automatically @code{inline}
|
||||||
|
@opindex fno-default-inline
|
||||||
|
As required by ISO C++, GCC considers member functions defined within
|
||||||
|
the body of a class to be marked inline even if they are
|
||||||
|
not explicitly declared with the @code{inline} keyword. You can
|
||||||
|
override this with @option{-fno-default-inline}; @pxref{C++ Dialect
|
||||||
|
Options,,Options Controlling C++ Dialect}.
|
||||||
|
|
||||||
|
GCC does not inline any functions when not optimizing unless you specify
|
||||||
|
the @samp{always_inline} attribute for the function, like this:
|
||||||
|
|
||||||
|
@smallexample
|
||||||
|
/* @r{Prototype.} */
|
||||||
|
inline void foo (const char) __attribute__((always_inline));
|
||||||
|
@end smallexample
|
||||||
|
|
||||||
|
The remainder of this section is specific to GNU C89 inlining.
|
||||||
|
|
||||||
@cindex non-static inline function
|
@cindex non-static inline function
|
||||||
When an inline function is not @code{static}, then the compiler must assume
|
When an inline function is not @code{static}, then the compiler must assume
|
||||||
that there may be calls from other source files; since a global symbol can
|
that there may be calls from other source files; since a global symbol can
|
||||||
@ -3926,24 +3935,6 @@ The definition in the header file will cause most calls to the function
|
|||||||
to be inlined. If any uses of the function remain, they will refer to
|
to be inlined. If any uses of the function remain, they will refer to
|
||||||
the single copy in the library.
|
the single copy in the library.
|
||||||
|
|
||||||
Since GCC 4.3 will implement ISO C99 semantics for
|
|
||||||
inline functions, it is simplest to use @code{static inline} only
|
|
||||||
to guarantee compatibility. (The
|
|
||||||
existing semantics will remain available when @option{-std=gnu89} is
|
|
||||||
specified, but eventually the default will be @option{-std=gnu99};
|
|
||||||
that will implement the C99 semantics, though it does not do so in
|
|
||||||
versions of GCC before 4.3. After the default changes, the existing
|
|
||||||
semantics will still be available via the @option{-fgnu89-inline}
|
|
||||||
option or the @code{gnu_inline} function attribute.)
|
|
||||||
|
|
||||||
GCC does not inline any functions when not optimizing unless you specify
|
|
||||||
the @samp{always_inline} attribute for the function, like this:
|
|
||||||
|
|
||||||
@smallexample
|
|
||||||
/* @r{Prototype.} */
|
|
||||||
inline void foo (const char) __attribute__((always_inline));
|
|
||||||
@end smallexample
|
|
||||||
|
|
||||||
@node Extended Asm
|
@node Extended Asm
|
||||||
@section Assembler Instructions with C Expression Operands
|
@section Assembler Instructions with C Expression Operands
|
||||||
@cindex extended @code{asm}
|
@cindex extended @code{asm}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user