diff options
author | Roger Sayle <sayle@gcc.gnu.org> | 2002-05-27 21:09:38 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2002-05-27 21:09:38 +0000 |
commit | 39f2f3c85a1e9999e3f38bfb5b9bbd35b062df67 (patch) | |
tree | ef5638bc097170d139e365da78c3dceb1d3a2ffa | |
parent | d51b0053f5c1dd2509c69729d3c474b2cf7de66c (diff) | |
download | gcc-39f2f3c85a1e9999e3f38bfb5b9bbd35b062df67.zip gcc-39f2f3c85a1e9999e3f38bfb5b9bbd35b062df67.tar.gz gcc-39f2f3c85a1e9999e3f38bfb5b9bbd35b062df67.tar.bz2 |
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
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-common.c | 27 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/attrib6.C | 21 |
5 files changed, 69 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6cd3ce6..e820f94 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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. diff --git a/gcc/c-common.c b/gcc/c-common.c index 6086b02..aeb6a2e 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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 diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 9d1fc7e..87701ef 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 101b0f0..2a9cf8b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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. diff --git a/gcc/testsuite/g++.dg/ext/attrib6.C b/gcc/testsuite/g++.dg/ext/attrib6.C new file mode 100644 index 0000000..2bdb180 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attrib6.C @@ -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() { } + |