aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2017-12-07 16:32:03 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2017-12-07 09:32:03 -0700
commit5d9ae53d70c72991e26648d915e7fb8e00b8e811 (patch)
treea586e44e1f5c41fd8ae4cb8fd80446c763cc595d /gcc/doc
parent1d8b0222b15f2188b659de4a731d8fd5ea23bed0 (diff)
downloadgcc-5d9ae53d70c72991e26648d915e7fb8e00b8e811.zip
gcc-5d9ae53d70c72991e26648d915e7fb8e00b8e811.tar.gz
gcc-5d9ae53d70c72991e26648d915e7fb8e00b8e811.tar.bz2
PR c/81544 - attribute noreturn and warn_unused_result on the same function accepted
PR c/81544 - attribute noreturn and warn_unused_result on the same function accepted PR c/81566 - invalid attribute aligned accepted on functions gcc/ada/ChangeLog: PR c/81544 * gcc-interface/utils.c (gnat_internal_attribute_table): Initialize new member of struct attribute_spec. gcc/c/ChangeLog: PR c/81544 * c-decl.c (c_decl_attributes): Look up existing declaration and pass it to decl_attributes. gcc/c-family/ChangeLog: PR c/81544 PR c/81566 * c-attribs.c (attr_aligned_exclusions): New array. (attr_alloc_exclusions, attr_cold_hot_exclusions): Same. (attr_common_exclusions, attr_const_pure_exclusions): Same. (attr_gnu_inline_exclusions, attr_inline_exclusions): Same. (attr_noreturn_exclusions, attr_returns_twice_exclusions): Same. (attr_warn_unused_result_exclusions): Same. (handle_hot_attribute, handle_cold_attribute): Simplify. (handle_const_attribute): Warn on function returning void. (handle_pure_attribute): Same. (handle_aligned_attribute): Diagnose conflicting attribute specifications. * c-warn.c (diagnose_mismatched_attributes): Simplify. gcc/cp/ChangeLog: PR c/81544 * cp-tree.h (decls_match): Add default argument. * decl.c (decls_match): Avoid calling into the target back end and triggering an error. * decl2.c (cplus_decl_attributes): Look up existing declaration and pass it to decl_attributes. * tree.c (cxx_attribute_table): Initialize new member of struct attribute_spec. gcc/fortran/ChangeLog: PR c/81544 * f95-lang.c (gfc_attribute_table): Initialize new member of struct attribute_spec. gcc/lto/ChangeLog: PR c/81544 * lto-lang.c (lto_attribute_table): Initialize new member of struct attribute_spec. gcc/ChangeLog: PR c/81544 * attribs.c (empty_attribute_table): Initialize new member of struct attribute_spec. (decl_attributes): Add argument. Handle mutually exclusive combinations of attributes. (selftests::test_attribute_exclusions): New function. (selftests::attribute_c_tests): Ditto. * attribs.h (decl_attributes): Add default argument. * selftest.h (attribute_c_tests): Declare. * selftest-run-tests.c (selftest::run_tests): Call attribute_c_tests. * tree-core.h (attribute_spec::exclusions, exclude): New type and member. * doc/extend.texi (Common Function Attributes): Update const and pure. gcc/testsuite/ChangeLog: PR c/81544 * c-c++-common/Wattributes-2.c: New test. * c-c++-common/Wattributes.c: New test. * c-c++-common/attributes-3.c: Adjust. * gcc.dg/Wattributes-6.c: New test. * gcc.dg/Wattributes-7.c: New test. * gcc.dg/attr-noinline.c * gcc.dg/pr44964.c: Same. * gcc.dg/torture/pr42363.c: Same. * gcc.dg/tree-ssa/ssa-ccp-2.c: Same. From-SVN: r255469
Diffstat (limited to 'gcc/doc')
-rw-r--r--gcc/doc/extend.texi18
1 files changed, 14 insertions, 4 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 3d5e15c..ad4d9d3 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2493,9 +2493,14 @@ are automatically detected and this attribute is ignored.
@cindex @code{const} function attribute
@cindex functions that have no side effects
Many functions do not examine any values except their arguments, and
-have no effects except the return value. Basically this is just slightly
-more strict class than the @code{pure} attribute below, since function is not
-allowed to read global memory.
+have no effects except to return a value. Calls to such functions lend
+themselves to optimization such as common subexpression elimination.
+The @code{const} attribute imposes greater restrictions on a function's
+definition than the similar @code{pure} attribute below because it prohibits
+the function from reading global variables. Consequently, the presence of
+the attribute on a function declarations allows GCC to emit more efficient
+code for some calls to the function. Decorating the same function with
+both the @code{const} and the @code{pure} attribute is diagnnosed.
@cindex pointer arguments
Note that a function that has pointer arguments and examines the data
@@ -3190,7 +3195,7 @@ to prevent recursion.
@cindex functions that have no side effects
Many functions have no effects except the return value and their
return value depends only on the parameters and/or global variables.
-Such a function can be subject
+Calls to such functions can be subject
to common subexpression elimination and loop optimization just as an
arithmetic operator would be. These functions should be declared
with the attribute @code{pure}. For example,
@@ -3208,6 +3213,11 @@ Interesting non-pure functions are functions with infinite loops or those
depending on volatile memory or other system resource, that may change between
two consecutive calls (such as @code{feof} in a multithreading environment).
+The @code{pure} attribute imposes similar but looser restrictions on
+a function's defintion than the @code{const} attribute: it allows the
+function to read global variables. Decorating the same function with
+both the @code{pure} and the @code{const} attribute is diagnosed.
+
@item returns_nonnull
@cindex @code{returns_nonnull} function attribute
The @code{returns_nonnull} attribute specifies that the function