This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [testcase] Simplified testcases why current gcc trunk cannot compile glibc
On Oct 15, 2001, Jakub Jelinek <jakub@redhat.com> wrote:
> I prefer something like __attribute__((used)) and __attribute__((noinline)),
How about this? Ok to install? Tested on athlon-pc-linux-gnu.
Index: gcc/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* attribs.c (handle_noinline_attribute): New function.
(handle_used_attribute): Likewise.
(c_common_attribute_table): Added noinline and used.
* doc/extend.texi (Function Attributes): Document them.
* c-decl.c (duplicate_decls): Propagate DECL_UNINLINABLE.
Index: gcc/cp/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* decl.c (duplicate_decls): Propagate DECL_UNINLINABLE.
Index: gcc/testsuite/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
* gcc.dg/attr-noinline.c, gcc.dg/attr-used.c: New tests.
Index: gcc/attribs.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/attribs.c,v
retrieving revision 1.2
diff -u -p -r1.2 attribs.c
--- gcc/attribs.c 2001/10/02 07:12:20 1.2
+++ gcc/attribs.c 2001/10/17 18:56:10
@@ -49,6 +49,10 @@ static tree handle_common_attribute PARA
bool *));
static tree handle_noreturn_attribute PARAMS ((tree *, tree, tree, int,
bool *));
+static tree handle_noinline_attribute PARAMS ((tree *, tree, tree, int,
+ bool *));
+static tree handle_used_attribute PARAMS ((tree *, tree, tree, int,
+ bool *));
static tree handle_unused_attribute PARAMS ((tree *, tree, tree, int,
bool *));
static tree handle_const_attribute PARAMS ((tree *, tree, tree, int,
@@ -100,6 +104,10 @@ static const struct attribute_spec c_com
handle_noreturn_attribute },
{ "volatile", 0, 0, true, false, false,
handle_noreturn_attribute },
+ { "noinline", 0, 0, true, false, false,
+ handle_noinline_attribute },
+ { "used", 0, 0, true, false, false,
+ handle_used_attribute },
{ "unused", 0, 0, false, false, false,
handle_unused_attribute },
/* The same comments as for noreturn attributes apply to const ones. */
@@ -500,6 +508,53 @@ handle_noreturn_attribute (node, name, a
= build_pointer_type
(build_type_variant (TREE_TYPE (type),
TREE_READONLY (TREE_TYPE (type)), 1));
+ else
+ {
+ warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
+
+/* Handle a "noinline" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+static tree
+handle_noinline_attribute (node, name, args, flags, no_add_attrs)
+ tree *node;
+ tree name;
+ tree args ATTRIBUTE_UNUSED;
+ int flags ATTRIBUTE_UNUSED;
+ bool *no_add_attrs;
+{
+ tree type = TREE_TYPE (*node);
+
+ if (TREE_CODE (*node) == FUNCTION_DECL)
+ DECL_UNINLINABLE (*node) = 1;
+ else
+ {
+ warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
+
+/* Handle a "used" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+static tree
+handle_used_attribute (node, name, args, flags, no_add_attrs)
+ tree *node;
+ tree name;
+ tree args ATTRIBUTE_UNUSED;
+ int flags ATTRIBUTE_UNUSED;
+ bool *no_add_attrs;
+{
+ if (TREE_CODE (*node) == FUNCTION_DECL)
+ TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (*node))
+ = TREE_USED (*node) = 1;
else
{
warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-decl.c,v
retrieving revision 1.254
diff -u -p -r1.254 c-decl.c
--- gcc/c-decl.c 2001/10/11 03:15:18 1.254
+++ gcc/c-decl.c 2001/10/17 18:56:11
@@ -1983,6 +1983,11 @@ duplicate_decls (newdecl, olddecl, diffe
DECL_DECLARED_INLINE_P (olddecl) = 1;
DECL_DECLARED_INLINE_P (newdecl) = DECL_DECLARED_INLINE_P (olddecl);
+
+ /* If either decl has attribute `noinline', make both
+ uninlinable. */
+ DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
+ = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
}
if (DECL_BUILT_IN (olddecl))
Index: gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.820
diff -u -p -r1.820 decl.c
--- gcc/cp/decl.c 2001/10/16 13:01:44 1.820
+++ gcc/cp/decl.c 2001/10/17 18:56:12
@@ -3640,6 +3640,11 @@ duplicate_decls (newdecl, olddecl)
DECL_INLINE (olddecl) = 1;
DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
+ /* If either decl has attribute `noinline', make both
+ uninlinable. */
+ DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
+ = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
+
/* Preserve abstractness on cloned [cd]tors. */
DECL_ABSTRACT (newdecl) = DECL_ABSTRACT (olddecl);
Index: gcc/doc/extend.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/doc/extend.texi,v
retrieving revision 1.31
diff -u -p -r1.31 extend.texi
--- gcc/doc/extend.texi 2001/10/11 07:07:30 1.31
+++ gcc/doc/extend.texi 2001/10/17 18:56:13
@@ -1925,13 +1925,14 @@ carefully.
The keyword @code{__attribute__} allows you to specify special
attributes when making a declaration. This keyword is followed by an
-attribute specification inside double parentheses. Fourteen attributes,
-@code{noreturn}, @code{pure}, @code{const}, @code{format},
-@code{format_arg}, @code{no_instrument_function}, @code{section},
-@code{constructor}, @code{destructor}, @code{unused}, @code{weak},
-@code{malloc}, @code{alias} and @code{no_check_memory_usage} are
-currently defined for functions. Several other attributes are defined
-for functions on particular target systems. Other attributes, including
+attribute specification inside double parentheses. The following
+attributs are currently defined for functions on all targets:
+@code{noreturn}, @code{noinline}, @code{pure}, @code{const},
+@code{format}, @code{format_arg}, @code{no_instrument_function},
+@code{section}, @code{constructor}, @code{destructor}, @code{used},
+@code{unused}, @code{weak}, @code{malloc}, @code{alias} and
+@code{no_check_memory_usage}. Several other attributes are defined for
+functions on particular target systems. Other attributes, including
@code{section} are supported for variables declarations (@pxref{Variable
Attributes}) and for types (@pxref{Type Attributes}).
@@ -1987,6 +1988,11 @@ typedef void voidfn ();
volatile voidfn fatal;
@end smallexample
+@cindex @code{noinline} function attribute
+@item noinline
+This function attribute prevents a function from being considered for
+inlining.
+
@cindex @code{pure} function attribute
@item pure
Many functions have no effects except the return value and their
@@ -2174,11 +2180,19 @@ the program.
These attributes are not currently implemented for Objective-C@.
+@cindex @code{unused} attribute.
@item unused
This attribute, attached to a function, means that the function is meant
to be possibly unused. GCC will not produce a warning for this
function. GNU C++ does not currently support this attribute as
definitions without parameters are valid in C++.
+
+@cindex @code{used} attribute.
+@item used
+This attribute, attached to a function, means that code must be emitted
+for the function even if it appears that the function is not referenced.
+This is useful, for example, when the function is referenced only in
+inline assembly.
@item weak
@cindex @code{weak} attribute
Index: gcc/testsuite/gcc.dg/attr-noinline.c
===================================================================
RCS file: attr-noinline.c
diff -N attr-noinline.c
--- /dev/null Tue May 5 13:32:27 1998
+++ gcc/testsuite/gcc.dg/attr-noinline.c Wed Oct 17 12:03:08 2001
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern inline void function_declaration_before(void) __attribute__((__noinline__));
+
+extern inline void function_declaration_before(void) {}
+
+extern inline void function_declaration_after(void) {}
+
+extern inline void function_declaration_after(void) __attribute__((__noinline__));
+
+int f () {
+ function_declaration_before ();
+ function_declaration_after ();
+}
+
+/* { dg-final { scan-assembler "function_declaration_before" } } */
+/* { dg-final { scan-assembler "function_declaration_after" } } */
Index: gcc/testsuite/gcc.dg/attr-used.c
===================================================================
RCS file: attr-used.c
diff -N attr-used.c
--- /dev/null Tue May 5 13:32:27 1998
+++ gcc/testsuite/gcc.dg/attr-used.c Wed Oct 17 12:03:08 2001
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+static void function_declaration_before(void) __attribute__((__used__));
+
+static void function_declaration_before(void) {}
+
+static void function_declaration_after(void) {}
+
+static void function_declaration_after(void) __attribute__((__used__));
+
+/* { dg-final { scan-assembler "function_declaration_before" } } */
+/* { dg-final { scan-assembler "function_declaration_after" } } */
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me