re PR c++/84724 (internal compiler error: in single_succ_edge, at basic-block.h:339...
authorJakub Jelinek <jakub@redhat.com>
Fri, 9 Mar 2018 18:01:22 +0000 (19:01 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 9 Mar 2018 18:01:22 +0000 (19:01 +0100)
PR c++/84724
* decl.c (duplicate_decls): Don't override __* prefixed builtins
except for __[^b]*_chk, instead issue permerror and for -fpermissive
also a note and return olddecl.

* g++.dg/ext/pr84724.C: New test.

From-SVN: r258391

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/pr84724-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/pr84724-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/pr84724-3.C [new file with mode: 0644]

index eeaf71d445e5a677f0ea6259d529a72504461efd..ae980fd6c3e17175c1767c42d7e7748c078cb0a9 100644 (file)
@@ -1,3 +1,10 @@
+2018-03-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84724
+       * decl.c (duplicate_decls): Don't override __* prefixed builtins
+       except for __[^b]*_chk, instead issue permerror and for -fpermissive
+       also a note and return olddecl.
+
 2018-03-09  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/84733
index b2e19a6549d10e967cea3d775be121d09e2ba4af..afd04cea630edcbc80b7900414a55f0b160268ef 100644 (file)
@@ -1566,6 +1566,33 @@ next_arg:;
                   || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
                                 TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
            {
+             /* Don't really override olddecl for __* prefixed builtins
+                except for __[^b]*_chk, the compiler might be using those
+                explicitly.  */
+             if (DECL_BUILT_IN (olddecl))
+               {
+                 tree id = DECL_NAME (olddecl);
+                 const char *name = IDENTIFIER_POINTER (id);
+                 size_t len;
+
+                 if (name[0] == '_'
+                     && name[1] == '_'
+                     && (strncmp (name + 2, "builtin_",
+                                  strlen ("builtin_")) == 0
+                         || (len = strlen (name)) <= strlen ("___chk")
+                         || memcmp (name + len - strlen ("_chk"),
+                                    "_chk", strlen ("_chk") + 1) != 0))
+                   {
+                     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;
+                   }
+               }
+
              /* A near match; override the builtin.  */
 
              if (TREE_PUBLIC (newdecl))
index f9c6b6d6020be4fed14062aaa7cf8f57a89919a0..b03f7e617b83093e0fe188ff09c98859c698be03 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84724
+       * g++.dg/ext/pr84724.C: New test.
+
 2018-03-09  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR target/83712
diff --git a/gcc/testsuite/g++.dg/ext/pr84724-1.C b/gcc/testsuite/g++.dg/ext/pr84724-1.C
new file mode 100644 (file)
index 0000000..9f03a29
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/84724
+// { dg-do compile }
+// { dg-options "-O3 -fpermissive" }
+
+int __builtin_trap ();         // { dg-warning "ambiguates built-in declaration" }
+                               // { dg-message "ignoring the 'int __builtin_trap\\(\\)' declaration" "" { target *-*-* } .-1 }
+
+int
+foo ()
+{
+  int b;
+  int c (&b);                  // { dg-warning "invalid conversion from" }
+  return b %= b ? c : 0;
+}
diff --git a/gcc/testsuite/g++.dg/ext/pr84724-2.C b/gcc/testsuite/g++.dg/ext/pr84724-2.C
new file mode 100644 (file)
index 0000000..de69425
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/84724
+// { dg-do compile }
+// { dg-options "-O3 -fpermissive -w" }
+
+int __builtin_trap ();         // { dg-bogus "ambiguates built-in declaration" }
+                               // { dg-bogus "ignoring the 'int __builtin_trap\\(\\)' declaration" "" { target *-*-* } .-1 }
+
+int
+foo ()
+{
+  int b;
+  int c (&b);                  // { dg-bogus "invalid conversion from" }
+  return b %= b ? c : 0;
+}
diff --git a/gcc/testsuite/g++.dg/ext/pr84724-3.C b/gcc/testsuite/g++.dg/ext/pr84724-3.C
new file mode 100644 (file)
index 0000000..0cd8cce
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/84724
+// { dg-do compile }
+// { dg-options "" }
+
+int __builtin_trap ();         // { dg-error "ambiguates built-in declaration" }