aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-01-03 20:43:47 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-01-03 13:43:47 -0700
commita594cff3b56f22153e50759c9eb4e0dbe54f3388 (patch)
tree4f749714f4626da6f165eb6211413bf86d5ab660 /gcc
parenta6fd2cd769c3bb446085e45794fcb22481eed400 (diff)
downloadgcc-a594cff3b56f22153e50759c9eb4e0dbe54f3388.zip
gcc-a594cff3b56f22153e50759c9eb4e0dbe54f3388.tar.gz
gcc-a594cff3b56f22153e50759c9eb4e0dbe54f3388.tar.bz2
PR c/83559 - -Wsuggest-attribute=const conflicts with -Wattributes warning about const attribute on function returning void
gcc/ChangeLog: PR c/83559 * doc/extend.texi (attribute const): Fix a typo. * ipa-pure-const.c ((warn_function_const, warn_function_pure): Avoid issuing -Wsuggest-attribute for void functions. gcc/testsuite/ChangeLog: PR c/83559 * gcc.dg/const-2.c: New test. * gcc.dg/pure-3.c: New test. From-SVN: r256188
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/doc/extend.texi2
-rw-r--r--gcc/ipa-pure-const.c15
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/const-2.c22
-rw-r--r--gcc/testsuite/gcc.dg/pure-3.c24
6 files changed, 72 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 10e8d9e..8786a91 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2018-01-03 Martin Sebor <msebor@redhat.com>
+ PR c/83559
+ * doc/extend.texi (attribute const): Fix a typo.
+ * ipa-pure-const.c ((warn_function_const, warn_function_pure): Avoid
+ issuing -Wsuggest-attribute for void functions.
+
+2018-01-03 Martin Sebor <msebor@redhat.com>
+
* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Use
offset_int::from instead of wide_int::to_shwi.
(maybe_diag_overlap): Remove assertion.
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 50967f5..5f0f4b8 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2500,7 +2500,7 @@ 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.
+both the @code{const} and the @code{pure} attribute is diagnosed.
@cindex pointer arguments
Note that a function that has pointer arguments and examines the data
diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index fee253e..a80b684 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -213,9 +213,13 @@ suggest_attribute (int option, tree decl, bool known_finite,
static void
warn_function_pure (tree decl, bool known_finite)
{
- static hash_set<tree> *warned_about;
+ /* Declaring a void function pure makes no sense and is diagnosed
+ by -Wattributes because calling it would have no effect. */
+ if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
+ return;
- warned_about
+ static hash_set<tree> *warned_about;
+ warned_about
= suggest_attribute (OPT_Wsuggest_attribute_pure, decl,
known_finite, warned_about, "pure");
}
@@ -226,8 +230,13 @@ warn_function_pure (tree decl, bool known_finite)
static void
warn_function_const (tree decl, bool known_finite)
{
+ /* Declaring a void function const makes no sense is diagnosed
+ by -Wattributes because calling it would have no effect. */
+ if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
+ return;
+
static hash_set<tree> *warned_about;
- warned_about
+ warned_about
= suggest_attribute (OPT_Wsuggest_attribute_const, decl,
known_finite, warned_about, "const");
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 55ed428..23c5d1c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2018-01-03 Martin Sebor <msebor@redhat.com>
+ PR c/83559
+ * gcc.dg/const-2.c: New test.
+ * gcc.dg/pure-3.c: New test.
+
+2018-01-03 Martin Sebor <msebor@redhat.com>
+
* gcc.dg/Wrestrict-3.c: New test.
2018-01-03 Jakub Jelinek <jakub@redhat.com>
diff --git a/gcc/testsuite/gcc.dg/const-2.c b/gcc/testsuite/gcc.dg/const-2.c
new file mode 100644
index 0000000..e48005d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/const-2.c
@@ -0,0 +1,22 @@
+/* PR tree-optimization/83559 - -Wsuggest-attribute=const conflicts with
+ -Wattributes warning about const attribute on function returning void
+ { dg-do compile { target nonpic } }
+ { dg-options "-O2 -Wsuggest-attribute=const" } */
+
+int f_i_v (void) /* { dg-warning "candidate for attribute .const." } */
+{
+ return 0;
+}
+
+int f_i () /* { dg-warning "candidate for attribute .const." } */
+{
+ return 0;
+}
+
+void f_v_v (void) /* { dg-bogus "candidate" } */
+{
+}
+
+void f_v () /* { dg-bogus "candidate" } */
+{
+}
diff --git a/gcc/testsuite/gcc.dg/pure-3.c b/gcc/testsuite/gcc.dg/pure-3.c
new file mode 100644
index 0000000..2eeb8a3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pure-3.c
@@ -0,0 +1,24 @@
+/* PR tree-optimization/83559 - -Wsuggest-attribute=const conflicts with
+ -Wattributes warning about const attribute on function returning void
+ { dg-do compile { target nonpic } }
+ { dg-options "-O2 -Wsuggest-attribute=pure" } */
+
+int global;
+
+int f_i_v (void) /* { dg-warning "candidate for attribute .pure." } */
+{
+ return global;
+}
+
+int f_i () /* { dg-warning "candidate for attribute .pure." } */
+{
+ return global;
+}
+
+void f_v_v (void) /* { dg-bogus "candidate" } */
+{
+}
+
+void f_v () /* { dg-bogus "candidate" } */
+{
+}