public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [C++ PATCH] Fix ICE with builtin redefinition (PR c++/84843)
  2018-03-13 20:35 [C++ PATCH] Fix ICE with builtin redefinition (PR c++/84843) Jakub Jelinek
@ 2018-03-13 20:35 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2018-03-13 20:35 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches List

OK.

On Tue, Mar 13, 2018 at 4:17 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> If we return olddecl on an (invalid) builtin function redefinition rather
> than redeclaration, we ICE shortly afterwards, because we assume we have
> non-NULL DECL_INITIAL on whatever is returned (except for error_mark_node).
>
> The following patch errors unconditionally for definitions of builtin
> functions, and also makes sure to return error_mark_node if we've emitted
> an error from the permerror.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2018-03-13  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/84843
>         * decl.c (duplicate_decls): For redefinition of built-in, use error
>         and return error_mark_node.  For redeclaration, return error_mark_node
>         rather than olddecl if !flag_permissive.
>
>         * g++.dg/ext/pr84843-1.C: New test.
>         * g++.dg/ext/pr84843-2.C: New test.
>
> --- gcc/cp/decl.c.jj    2018-03-09 19:00:44.350969146 +0100
> +++ gcc/cp/decl.c       2018-03-13 14:56:45.244872506 +0100
> @@ -1583,13 +1583,20 @@ next_arg:;
>                           || memcmp (name + len - strlen ("_chk"),
>                                      "_chk", strlen ("_chk") + 1) != 0))
>                     {
> +                     if (DECL_INITIAL (newdecl))
> +                       {
> +                         error_at (DECL_SOURCE_LOCATION (newdecl),
> +                                   "definition of %q#D ambiguates built-in "
> +                                   "declaration %q#D", newdecl, olddecl);
> +                         return error_mark_node;
> +                       }
>                       if (permerror (DECL_SOURCE_LOCATION (newdecl),
>                                      "new declaration %q#D ambiguates built-in"
>                                      " declaration %q#D", newdecl, olddecl)
>                           && flag_permissive)
>                         inform (DECL_SOURCE_LOCATION (newdecl),
>                                 "ignoring the %q#D declaration", newdecl);
> -                     return olddecl;
> +                     return flag_permissive ? olddecl : error_mark_node;
>                     }
>                 }
>
> --- gcc/testsuite/g++.dg/ext/pr84843-1.C.jj     2018-03-13 14:55:15.927831678 +0100
> +++ gcc/testsuite/g++.dg/ext/pr84843-1.C        2018-03-13 14:57:51.652902862 +0100
> @@ -0,0 +1,9 @@
> +// PR c++/84843
> +// { dg-do compile }
> +// { dg-options "-fpermissive" }
> +
> +extern "C" int
> +__atomic_compare_exchange (int x, int y)       // { dg-error "ambiguates built-in declaration" }
> +{
> +  return x + y;
> +}
> --- gcc/testsuite/g++.dg/ext/pr84843-2.C.jj     2018-03-13 14:55:19.349833246 +0100
> +++ gcc/testsuite/g++.dg/ext/pr84843-2.C        2018-03-13 14:57:58.205905859 +0100
> @@ -0,0 +1,9 @@
> +// PR c++/84843
> +// { dg-do compile }
> +// { dg-options "" }
> +
> +extern "C" int
> +__atomic_compare_exchange (int x, int y)       // { dg-error "ambiguates built-in declaration" }
> +{
> +  return x + y;
> +}
>
>         Jakub

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

* [C++ PATCH] Fix ICE with builtin redefinition (PR c++/84843)
@ 2018-03-13 20:35 Jakub Jelinek
  2018-03-13 20:35 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2018-03-13 20:35 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

If we return olddecl on an (invalid) builtin function redefinition rather
than redeclaration, we ICE shortly afterwards, because we assume we have
non-NULL DECL_INITIAL on whatever is returned (except for error_mark_node).

The following patch errors unconditionally for definitions of builtin
functions, and also makes sure to return error_mark_node if we've emitted
an error from the permerror.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-03-13  Jakub Jelinek  <jakub@redhat.com>

	PR c++/84843
	* decl.c (duplicate_decls): For redefinition of built-in, use error
	and return error_mark_node.  For redeclaration, return error_mark_node
	rather than olddecl if !flag_permissive.

	* g++.dg/ext/pr84843-1.C: New test.
	* g++.dg/ext/pr84843-2.C: New test.

--- gcc/cp/decl.c.jj	2018-03-09 19:00:44.350969146 +0100
+++ gcc/cp/decl.c	2018-03-13 14:56:45.244872506 +0100
@@ -1583,13 +1583,20 @@ next_arg:;
 			  || memcmp (name + len - strlen ("_chk"),
 				     "_chk", strlen ("_chk") + 1) != 0))
 		    {
+		      if (DECL_INITIAL (newdecl))
+			{
+			  error_at (DECL_SOURCE_LOCATION (newdecl),
+				    "definition of %q#D ambiguates built-in "
+				    "declaration %q#D", newdecl, olddecl);
+			  return error_mark_node;
+			}
 		      if (permerror (DECL_SOURCE_LOCATION (newdecl),
 				     "new declaration %q#D ambiguates built-in"
 				     " declaration %q#D", newdecl, olddecl)
 			  && flag_permissive)
 			inform (DECL_SOURCE_LOCATION (newdecl),
 				"ignoring the %q#D declaration", newdecl);
-		      return olddecl;
+		      return flag_permissive ? olddecl : error_mark_node;
 		    }
 		}
 
--- gcc/testsuite/g++.dg/ext/pr84843-1.C.jj	2018-03-13 14:55:15.927831678 +0100
+++ gcc/testsuite/g++.dg/ext/pr84843-1.C	2018-03-13 14:57:51.652902862 +0100
@@ -0,0 +1,9 @@
+// PR c++/84843
+// { dg-do compile }
+// { dg-options "-fpermissive" }
+
+extern "C" int
+__atomic_compare_exchange (int x, int y)	// { dg-error "ambiguates built-in declaration" }
+{
+  return x + y;
+}
--- gcc/testsuite/g++.dg/ext/pr84843-2.C.jj	2018-03-13 14:55:19.349833246 +0100
+++ gcc/testsuite/g++.dg/ext/pr84843-2.C	2018-03-13 14:57:58.205905859 +0100
@@ -0,0 +1,9 @@
+// PR c++/84843
+// { dg-do compile }
+// { dg-options "" }
+
+extern "C" int
+__atomic_compare_exchange (int x, int y)	// { dg-error "ambiguates built-in declaration" }
+{
+  return x + y;
+}

	Jakub

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

end of thread, other threads:[~2018-03-13 20:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-13 20:35 [C++ PATCH] Fix ICE with builtin redefinition (PR c++/84843) Jakub Jelinek
2018-03-13 20: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).