c-common.c: Add support for __attribute__((nothrow)) to specify that a function cannot...
* c-common.c: Add support for __attribute__((nothrow)) to specify that a function cannot throw an exception (using TREE_NOTHROW). (handle_nothrow_attribute): New function to process this attribute. * doc/extend.texi: Document the new nothrow function attribute. 2002-05-27 Richard Henderson <rth@redhat.com> * g++.dg/ext/attrib6.C: New test case. From-SVN: r53940
This commit is contained in:
parent
d51b0053f5
commit
39f2f3c85a
5 changed files with 69 additions and 1 deletions
|
@ -1,3 +1,11 @@
|
|||
2002-05-27 Roger Sayle <roger@eyesopen.com>
|
||||
|
||||
* c-common.c: Add support for __attribute__((nothrow)) to specify
|
||||
that a function cannot throw an exception (using TREE_NOTHROW).
|
||||
(handle_nothrow_attribute): New function to process this attribute.
|
||||
|
||||
* doc/extend.texi: Document the new nothrow function attribute.
|
||||
|
||||
2002-05-27 H.J. Lu (hjl@gnu.org)
|
||||
|
||||
* cppexp.c (num_trim): Use 1UL instead of 1 for long int.
|
||||
|
|
|
@ -351,6 +351,8 @@ static tree handle_vector_size_attribute PARAMS ((tree *, tree, tree, int,
|
|||
bool *));
|
||||
static tree handle_nonnull_attribute PARAMS ((tree *, tree, tree, int,
|
||||
bool *));
|
||||
static tree handle_nothrow_attribute PARAMS ((tree *, tree, tree, int,
|
||||
bool *));
|
||||
static tree vector_size_helper PARAMS ((tree, tree));
|
||||
|
||||
static void check_function_nonnull PARAMS ((tree, tree));
|
||||
|
@ -425,6 +427,8 @@ const struct attribute_spec c_common_attribute_table[] =
|
|||
handle_visibility_attribute },
|
||||
{ "nonnull", 0, -1, false, true, true,
|
||||
handle_nonnull_attribute },
|
||||
{ "nothrow", 0, 0, true, false, false,
|
||||
handle_nothrow_attribute },
|
||||
{ NULL, 0, 0, false, false, false, NULL }
|
||||
};
|
||||
|
||||
|
@ -5795,6 +5799,29 @@ get_nonnull_operand (arg_num_expr, valp)
|
|||
*valp = TREE_INT_CST_LOW (arg_num_expr);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Handle a "nothrow" attribute; arguments as in
|
||||
struct attribute_spec.handler. */
|
||||
|
||||
static tree
|
||||
handle_nothrow_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_NOTHROW (*node) = 1;
|
||||
/* ??? TODO: Support types. */
|
||||
else
|
||||
{
|
||||
warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
|
||||
*no_add_attrs = true;
|
||||
}
|
||||
|
||||
return NULL_TREE;
|
||||
}
|
||||
|
||||
/* Check for valid arguments being passed to a function. */
|
||||
void
|
||||
|
|
|
@ -1883,7 +1883,7 @@ 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{pure}, @code{const},
|
||||
@code{pure}, @code{const}, @code{nothrow},
|
||||
@code{format}, @code{format_arg}, @code{no_instrument_function},
|
||||
@code{section}, @code{constructor}, @code{destructor}, @code{used},
|
||||
@code{unused}, @code{deprecated}, @code{weak}, @code{malloc},
|
||||
|
@ -2007,6 +2007,14 @@ extern const intfn square;
|
|||
This approach does not work in GNU C++ from 2.6.0 on, since the language
|
||||
specifies that the @samp{const} must be attached to the return value.
|
||||
|
||||
@cindex @code{nothrow} function attribute
|
||||
@item nothrow
|
||||
The @code{nothrow} attribute is used to inform the compiler that a
|
||||
function cannot throw an exception. For example, most functions in
|
||||
the standard C library can be guaranteed not to throw an exception
|
||||
with the notable exceptions of @code{qsort} and @code{bsearch} that
|
||||
take function pointer arguments. The @code{nothrow} attribute is not
|
||||
implemented in GCC versions earlier than 3.2.
|
||||
|
||||
@item format (@var{archetype}, @var{string-index}, @var{first-to-check})
|
||||
@cindex @code{format} function attribute
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2002-05-27 Richard Henderson <rth@redhat.com>
|
||||
|
||||
* g++.dg/ext/attrib6.C: New test case.
|
||||
|
||||
2002-05-27 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
|
||||
|
||||
* gcc.c-torture/execute/pure-1.c: New test.
|
||||
|
|
21
gcc/testsuite/g++.dg/ext/attrib6.C
Normal file
21
gcc/testsuite/g++.dg/ext/attrib6.C
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2002 Free Software Foundation.
|
||||
//
|
||||
// Test that the nothrow attribute is working correctly.
|
||||
//
|
||||
// Written by Richard Henderson, 26 May 2002.
|
||||
|
||||
// { dg-do link }
|
||||
extern void foo() __attribute__((nothrow));
|
||||
extern void link_error();
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
foo();
|
||||
} catch (...) {
|
||||
link_error();
|
||||
}
|
||||
}
|
||||
|
||||
void foo() { }
|
||||
|
Loading…
Add table
Reference in a new issue