This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] handle fallout from attributes patch (PR 84617)
- From: Martin Sebor <msebor at gmail dot com>
- To: Jason Merrill <jason at redhat dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 28 Feb 2018 10:09:31 -0700
- Subject: [PATCH] handle fallout from attributes patch (PR 84617)
- Authentication-results: sourceware.org; auth=none
The attached patch fixes the regressions in merging attributes
on ordinary functions introduced by yesterday's commit to fix
bug 83871. I've also added a new test to exercise the malloc
bit even better (this is test #3 for a single bit).
I have xfailed for now the remaining failures that expose
the bug where attributes on multiple declarations of the same
template function are not merged. I'm assuming this being
tracked in bug 84294. I'll look into it next but I want to
get the regressions resolved quickly.
A full bootstrap/regression test run is in progress.
Martin
PR testsuite/84617 - new test cases g++.dg/ext/attr-const.C and g++.dg/ext/attr-pure.C fail
gcc/cp/ChangeLog:
PR testsuite/84617
* decl.c (duplicate_decls): Fully merge attributes const, pure,
and malloc.
gcc/testsuite/ChangeLog:
PR testsuite/84617
* g++.dg/ext/attr-malloc-3.C: New test.
* g++.dg/ext/attr-const.C: Adjust. Xfail assertions failing due
to pre-existing problems.
* g++.dg/ext/attr-pure.C: Same.
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c (revision 258068)
+++ gcc/cp/decl.c (working copy)
@@ -2234,8 +2234,11 @@ next_arg:;
TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
+ TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
+ DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
+ DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
}
else
{
Index: gcc/testsuite/g++.dg/ext/attr-const.C
===================================================================
--- gcc/testsuite/g++.dg/ext/attr-const.C (revision 258068)
+++ gcc/testsuite/g++.dg/ext/attr-const.C (working copy)
@@ -1,12 +1,12 @@
/* PR c++/83871 - wrong code for attribute const and pure on distinct
template specializations
{ dg-do compile }
- { dg-options "-O -Wall" } */
+ { dg-options "-O1 -Wall -fdump-tree-optimized" } */
int __attribute__ ((const)) fconst_none ();
int fconst_none ();
-void test_const_none_failed ();
+void func_const_none_failed ();
void func_const_none ()
{
@@ -13,9 +13,9 @@ void func_const_none ()
int i0 = fconst_none ();
int i1 = fconst_none ();
if (i0 != i1)
- test_const_none_failed ();
+ func_const_none_failed ();
- // { dg-final { scan-tree-dump-not "test_const_none_failed" "optimized" } }
+ // { dg-final { scan-tree-dump-not "func_const_none_failed" "optimized" } }
}
@@ -22,7 +22,7 @@ void func_const_none ()
int fnone_const ();
int __attribute__ ((const)) fnone_const ();
-void test_none_const_failed ();
+void func_none_const_failed ();
void func_none_const ()
{
@@ -29,12 +29,11 @@ void func_none_const ()
int i0 = fnone_const ();
int i1 = fnone_const ();
if (i0 != i1)
- test_none_const_failed ();
+ func_none_const_failed ();
- // { dg-final { scan-tree-dump-not "test_none_const_failed" "optimized" } }
+ // { dg-final { scan-tree-dump-not "func_none_const_failed" "optimized" } }
}
-
template <class T>
int __attribute__ ((const)) fconst_none (T);
@@ -41,14 +40,16 @@ int __attribute__ ((const)) fconst_none (T);
template <class T>
int fconst_none (T);
+void templ_const_none_failed ();
+
void template_const_none ()
{
int i0 = fconst_none<int> (0);
int i1 = fconst_none<int> (0);
if (i0 != i1)
- test_const_none_failed ();
+ templ_const_none_failed ();
- // { dg-final { scan-tree-dump-not "test_const_none_failed" "optimized" } }
+ // { dg-final { scan-tree-dump-not "templ_const_none_failed" "optimized" } }
}
@@ -58,12 +59,15 @@ int fnone_const (T);
template <class T>
int __attribute__ ((const)) fnone_const (T);
+void templ_none_const_failed ();
+
void test_fnone_const ()
{
int i0 = fnone_const<int> (0);
int i1 = fnone_const<int> (0);
if (i0 != i1)
- test_none_const_failed ();
+ templ_none_const_failed ();
- // { dg-final { scan-tree-dump-not "test_none_const_failed" "optimized" } }
+ // The following fails (most likely) due to bug 84294.
+ // { dg-final { scan-tree-dump-not "templ_none_const_failed" "optimized" { xfail *-*-* } } }
}
Index: gcc/testsuite/g++.dg/ext/attr-malloc-3.C
===================================================================
--- gcc/testsuite/g++.dg/ext/attr-malloc-3.C (nonexistent)
+++ gcc/testsuite/g++.dg/ext/attr-malloc-3.C (working copy)
@@ -0,0 +1,97 @@
+// Bug c++/84617 - new test cases g++.dg/ext/attr-const.C and
+// g++.dg/ext/attr-pure.C fail
+// { dg-do compile }
+// { dg-options "-O -Wall -fdump-tree-optimized" }
+
+static char a[8];
+
+void* __attribute__ ((malloc))
+func_malloc_none (unsigned);
+
+void*
+func_alloc_none (unsigned); // redeclare with no attribute
+
+void func_malloc_none_failed ();
+
+void test_func_malloc_none (void)
+{
+ void *p = func_malloc_none (1);
+ if (!p)
+ return;
+
+ if (p == a) // must be false
+ func_malloc_none_failed (); // should be eliminated
+
+ // Verify that the call to func_malloc_none_failed() is eliminated.
+ // { dg-final { scan-tree-dump-not "func_malloc_none_failed" "optimized" } }
+}
+
+
+void*
+func_none_malloc (unsigned);
+
+void* __attribute__ ((malloc))
+func_none_malloc (unsigned); // redeclare with an attribute
+
+void func_none_malloc_failed ();
+
+void test_func_none_malloc (void)
+{
+ void *p = func_none_malloc (1);
+ if (!p)
+ return;
+
+ if (p == a) // must be false
+ func_none_malloc_failed (); // should be eliminated
+
+ // Verify that the call to func_none_malloc_failed() is eliminated.
+ // { dg-final { scan-tree-dump-not "func_none_malloc_failed" "optimized" } }
+}
+
+
+template <class>
+void* __attribute__ ((malloc))
+templ_malloc_none (unsigned);
+
+template <class>
+void*
+templ_malloc_none (unsigned); // redeclare with no attribute
+
+void templ_malloc_none_failed ();
+
+void test_templ_malloc_none (void)
+{
+ void *p = templ_malloc_none<void>(1);
+ if (!p)
+ return;
+
+ if (p == a) // must be false
+ templ_malloc_none_failed (); // should be eliminated
+
+ // Verify that the call to templ_malloc_none_failed() is eliminated.
+ // { dg-final { scan-tree-dump-not "templ_malloc_none_failed" "optimized" } }
+}
+
+template <class>
+void*
+templ_none_malloc (unsigned);
+
+template <class>
+void* __attribute__ ((malloc))
+templ_none_malloc (unsigned); // redeclared with an attribute
+
+void templ_none_malloc_failed ();
+
+void test_templ_none_malloc (void)
+{
+ void *p = templ_none_malloc<void>(1);
+ if (!p)
+ return;
+
+ if (p == a) // must be false
+ templ_none_malloc_failed (); // should be eliminated
+
+ // The following fails (most likely) due to bug 84294.
+ // Verify that the call to templ_none_malloc_failed() is eliminated.
+ // { dg-final { scan-tree-dump-not "templ_none_malloc_failed" "optimized" { xfail *-*-* } } }
+}
Index: gcc/testsuite/g++.dg/ext/attr-pure.C
===================================================================
--- gcc/testsuite/g++.dg/ext/attr-pure.C (revision 258068)
+++ gcc/testsuite/g++.dg/ext/attr-pure.C (working copy)
@@ -1,12 +1,12 @@
/* PR c++/83871 - wrong code for attribute const and pure on distinct
template specializations
{ dg-do compile }
- { dg-options "-O -Wall" } */
+ { dg-options "-O -Wall -fdump-tree-optimized" } */
int __attribute__ ((pure)) fpure_none ();
int fpure_none ();
-void test_pure_none_failed ();
+void func_pure_none_failed ();
void func_pure_none ()
{
@@ -13,9 +13,9 @@ void func_pure_none ()
int i0 = fpure_none ();
int i1 = fpure_none ();
if (i0 != i1)
- test_pure_none_failed ();
+ func_pure_none_failed ();
- // { dg-final { scan-tree-dump-not "test_pure_none_failed" "optimized" } }
+ // { dg-final { scan-tree-dump-not "func_pure_none_failed" "optimized" } }
}
@@ -22,7 +22,7 @@ void func_pure_none ()
int fnone_pure ();
int __attribute__ ((pure)) fnone_pure ();
-void test_none_pure_failed ();
+void func_none_pure_failed ();
void func_none_pure ()
{
@@ -29,9 +29,9 @@ void func_none_pure ()
int i0 = fnone_pure ();
int i1 = fnone_pure ();
if (i0 != i1)
- test_none_pure_failed ();
+ func_none_pure_failed ();
- // { dg-final { scan-tree-dump-not "test_none_pure_failed" "optimized" } }
+ // { dg-final { scan-tree-dump-not "func_none_pure_failed" "optimized" } }
}
@@ -41,29 +41,34 @@ int __attribute__ ((pure)) fpure_none (T);
template <class T>
int fpure_none (T);
+void templ_pure_none_failed ();
+
void template_pure_none ()
{
int i0 = fpure_none<int> (0);
int i1 = fpure_none<int> (0);
if (i0 != i1)
- test_pure_none_failed ();
+ templ_pure_none_failed ();
- // { dg-final { scan-tree-dump-not "test_pure_none_failed" "optimized" } }
+ // { dg-final { scan-tree-dump-not "templ_pure_none_failed" "optimized" } }
}
template <class T>
-int fnone_pure (T);
+int fnone_const (T);
template <class T>
-int __attribute__ ((pure)) fnone_pure (T);
+int __attribute__ ((const)) fnone_const (T);
-void test_fnone_pure ()
+void templ_none_const_failed ();
+
+void test_fnone_const ()
{
- int i0 = fnone_pure<int> (0);
- int i1 = fnone_pure<int> (0);
+ int i0 = fnone_const<int> (0);
+ int i1 = fnone_const<int> (0);
if (i0 != i1)
- test_none_pure_failed ();
+ templ_none_const_failed ();
- // { dg-final { scan-tree-dump-not "test_none_pure_failed" "optimized" } }
+ // The following fails (most likely) due to bug 84294.
+ // { dg-final { scan-tree-dump-not "templ_none_const_failed" "optimized" { xfail *-*-* } } }
}