+2005-03-08 Alexey Neyman <alex.neyman@auriga.ru>
+
+ PR c/14411
+ * calls.c (flags_from_decl_or_type): Handle eturns_twice' attribute.
+ * c-common.c (handle_returns_twice): New function.
+ (c_common_attribute_table): Declare eturns_twice' attribute.
+ * doc/extend.texi: Document eturns_twice' attribute.
+ * tree.h (DECL_IS_RETURNS_TWICE): New macro.
+ (struct tree_decl): Add returns_twice_flag.
+
2005-03-08 Kazu Hirata <kazu@cs.umass.edu>
* tree-ssa-phiopt.c: Fix a comment typo.
static tree handle_no_instrument_function_attribute (tree *, tree,
tree, int, bool *);
static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
+static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
static tree handle_no_limit_stack_attribute (tree *, tree, tree, int,
bool *);
static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
handle_no_instrument_function_attribute },
{ "malloc", 0, 0, true, false, false,
handle_malloc_attribute },
+ { "returns_twice", 0, 0, true, false, false,
+ handle_returns_twice_attribute },
{ "no_stack_limit", 0, 0, true, false, false,
handle_no_limit_stack_attribute },
{ "pure", 0, 0, true, false, false,
return NULL_TREE;
}
+/* Handle a "returns_twice" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+static tree
+handle_returns_twice_attribute (tree *node, tree name, tree ARG_UNUSED (args),
+ int ARG_UNUSED (flags), bool *no_add_attrs)
+{
+ if (TREE_CODE (*node) == FUNCTION_DECL)
+ DECL_IS_RETURNS_TWICE (*node) = 1;
+ else
+ {
+ warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
+
/* Handle a "no_limit_stack" attribute; arguments as in
struct attribute_spec.handler. */
if (DECL_IS_MALLOC (exp))
flags |= ECF_MALLOC;
+ /* The function exp may have the `returns_twice' attribute. */
+ if (DECL_IS_RETURNS_TWICE (exp))
+ flags |= ECF_RETURNS_TWICE;
+
/* The function exp may have the `pure' attribute. */
if (DECL_IS_PURE (exp))
flags |= ECF_PURE | ECF_LIBCALL_BLOCK;
@cindex function attributes
@cindex declaring attributes of functions
@cindex functions that never return
+@cindex functions that return more than once
@cindex functions that have no side effects
@cindex functions in arbitrary sections
@cindex functions that behave like malloc
attributes when making a declaration. This keyword is followed by an
attribute specification inside double parentheses. The following
attributes are currently defined for functions on all targets:
-@code{noreturn}, @code{noinline}, @code{always_inline},
+@code{noreturn}, @code{returns_twice}, @code{noinline}, @code{always_inline},
@code{pure}, @code{const}, @code{nothrow}, @code{sentinel},
@code{format}, @code{format_arg}, @code{no_instrument_function},
@code{section}, @code{constructor}, @code{destructor}, @code{used},
disabled with the linker or the loader if desired, to avoid the
problem.)
+@item returns_twice
+@cindex @code{returns_twice} attribute
+The @code{returns_twice} attribute tells the compiler that a function may
+return more than one time. The compiler will ensure that all registers
+are dead before calling such a function and will emit a warning about
+the variables that may be clobbered after the second return from the
+function. Examples of such functions are @code{setjmp} and @code{vfork}.
+The @code{longjmp}-like counterpart of such function, if any, might need
+to be marked with the @code{noreturn} attribute.
+
@item saveall
@cindex save all registers on the H8/300, H8/300H, and H8S
Use this attribute on the H8/300, H8/300H, and H8S to indicate that
--- /dev/null
+/* { dg-do compile { target i?86-*-* } } */
+/* { dg-options "-W" } */
+
+int newsetjmp(void) __attribute__((returns_twice));
+void g(int);
+
+int
+main (void)
+{
+ register int reg asm ("esi") = 1; /* { dg-warning "might be clobbered" "" } */
+
+ if (!newsetjmp ())
+ {
+ reg = 2;
+ g (reg);
+ }
+ else
+ {
+ g (reg);
+ }
+
+ return 0;
+}
not an alias. */
#define DECL_IS_MALLOC(NODE) (FUNCTION_DECL_CHECK (NODE)->decl.malloc_flag)
+/* Nonzero in a FUNCTION_DECL means this function may return more
+ than once. */
+#define DECL_IS_RETURNS_TWICE(NODE) \
+ (FUNCTION_DECL_CHECK (NODE)->decl.returns_twice_flag)
+
/* Nonzero in a FUNCTION_DECL means this function should be treated
as "pure" function (like const function, but may read global memory). */
#define DECL_IS_PURE(NODE) (FUNCTION_DECL_CHECK (NODE)->decl.pure_flag)
unsigned preserve_flag: 1;
unsigned gimple_formal_temp : 1;
unsigned debug_expr_is_from : 1;
- /* 12 unused bits. */
+ unsigned returns_twice_flag : 1;
+ /* 11 unused bits. */
union tree_decl_u1 {
/* In a FUNCTION_DECL for which DECL_BUILT_IN holds, this is