public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] handle fallout from attributes patch (PR 84617)
@ 2018-02-28 17:09 Martin Sebor
  2018-02-28 17:35 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Sebor @ 2018-02-28 17:09 UTC (permalink / raw)
  To: Jason Merrill, Gcc Patch List

[-- Attachment #1: Type: text/plain, Size: 579 bytes --]

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

[-- Attachment #2: gcc-84617.diff --]
[-- Type: text/x-patch, Size: 9282 bytes --]

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 *-*-* } } }
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] handle fallout from attributes patch (PR 84617)
  2018-02-28 17:09 [PATCH] handle fallout from attributes patch (PR 84617) Martin Sebor
@ 2018-02-28 17:35 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2018-02-28 17:35 UTC (permalink / raw)
  To: Martin Sebor; +Cc: Gcc Patch List

OK if testing passes.

On Wed, Feb 28, 2018 at 12:09 PM, Martin Sebor <msebor@gmail.com> wrote:
> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-28 17:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28 17:09 [PATCH] handle fallout from attributes patch (PR 84617) Martin Sebor
2018-02-28 17:35 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).