Commit 0a052b16 by Geoffrey Keating

re PR c/16622 ([C99] extern inline is handled wrong in C99 mode)

	* c-decl.c (grokdeclarator): Don't set DECL_EXTERNAL on
	inline static functions in c99 mode.

	PR 16622
	* doc/extend.texi (Inline): Update.
	* c-tree.h (struct language_function): Remove field 'extern_inline'.
	* c-decl.c (current_extern_inline): Delete.
	(pop_scope): Adjust test for an undefined nested function.
	Add warning about undeclared inline function.
	(diagnose_mismatched_decls): Update comments.  Disallow overriding
	of inline functions in a translation unit in C99.  Allow inline
	declarations in C99 at any time.
	(merge_decls): Boolize variables.  Handle C99 'extern inline'
	semantics.
	(grokdeclarator): Set DECL_EXTERNAL here for functions.  Handle
	C99 inline semantics.
	(start_function): Don't clear current_extern_inline.  Don't set
	DECL_EXTERNAL.
	(c_push_function_context): Don't push current_extern_inline.
	(c_pop_function_context): Don't restore current_extern_inline.

	PR 11377
	* c-typeck.c (build_external_ref): Warn about static variables
	used in extern inline functions.
	* c-decl.c (start_decl): Warn about static variables declared
	in extern inline functions.

From-SVN: r118357
parent 71113fcd
...@@ -3789,58 +3789,54 @@ These attributes mainly are intended to support the @code{__vector}, ...@@ -3789,58 +3789,54 @@ 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. @option{-std=c99} or @option{-std=gnu99}, and the third is used when
compiling C++.
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
inline int static inline int
inc (int *a) inc (int *a)
@{ @{
(*a)++; (*a)++;
@} @}
@end smallexample @end smallexample
(If you are writing a header file to be included in ISO C programs, write If you are writing a header file to be included in ISO C89 programs, write
@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.) @code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.
You can also make all ``simple enough'' functions inline with the option
@option{-finline-functions}.
@opindex Winline The three types of inlining behave similarly in two important cases:
Note that certain usages in a function definition can make it unsuitable when the @code{inline} keyword is used on a @code{static} function,
for inline substitution. Among these usages are: use of varargs, use of like the example above, and when a function is first declared without
alloca, use of variable sized data types (@pxref{Variable Length}), using the @code{inline} keyword and then is defined with
use of computed goto (@pxref{Labels as Values}), use of nonlocal goto, @code{inline}, like this:
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 @smallexample
does not affect the linkage of the function. extern int inc (int *a);
inline int
inc (int *a)
@{
(*a)++;
@}
@end smallexample
@cindex automatic @code{inline} for C++ member fns In both of these common cases, the program behaves the same as if you
@cindex @code{inline} automatic for C++ member fns had not used the @code{inline} keyword, except for its speed.
@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
...@@ -3856,6 +3852,36 @@ nonintegrated call, then the function is compiled to assembler code as ...@@ -3856,6 +3852,36 @@ 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.
@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.
@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
...@@ -3878,21 +3904,6 @@ The definition in the header file will cause most calls to the function ...@@ -3878,21 +3904,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 eventually will implement ISO C99 semantics for
inline functions, it is best 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} and
that will implement the C99 semantics, though it does not do so yet.)
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}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment