re PR c/80919 (ICE: Segmentation fault with -Wall when printing address of size 0...
authorMarek Polacek <polacek@redhat.com>
Sun, 4 Jun 2017 17:27:22 +0000 (17:27 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Sun, 4 Jun 2017 17:27:22 +0000 (17:27 +0000)
PR c/80919
* c-format.c (matching_type_p): Return false if any of the types
requires structural equality.

* gcc.dg/format/pr80919.c: New test.

From-SVN: r248860

gcc/c-family/ChangeLog
gcc/c-family/c-format.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format/pr80919.c [new file with mode: 0644]

index 569b456a72497c0b5fbfcd16044e0db4248b3fd5..97335e89b35c8be7ddb8ad571bf682872c559c2a 100644 (file)
@@ -1,3 +1,9 @@
+2017-06-04  Marek Polacek  <polacek@redhat.com>
+
+       PR c/80919
+       * c-format.c (matching_type_p): Return false if any of the types
+       requires structural equality.
+
 2017-06-02  Martin Sebor  <msebor@redhat.com>
 
        PR c/80892
index faef267220d50ef38375459e7da3c7e6f886f41a..732339b9b5eb5ffd3f0ef9dd9e080618fc0a731d 100644 (file)
@@ -3278,6 +3278,12 @@ matching_type_p (tree spec_type, tree arg_type)
   gcc_assert (spec_type);
   gcc_assert (arg_type);
 
+  /* If any of the types requires structural equality, we can't compare
+     their canonical types.  */
+  if (TYPE_STRUCTURAL_EQUALITY_P (spec_type)
+      || TYPE_STRUCTURAL_EQUALITY_P (arg_type))
+    return false;
+
   spec_type = TYPE_CANONICAL (spec_type);
   arg_type = TYPE_CANONICAL (arg_type);
 
index 537e6422d225dbe17b773da3faccb71f00e89dc5..bfadad536014157c4503b34024ca02f326d10bdc 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-04  Marek Polacek  <polacek@redhat.com>
+
+       PR c/80919
+       * gcc.dg/format/pr80919.c: New test.
+
 2017-06-02  Martin Sebor  <msebor@redhat.com>
 
        PR c/80892
diff --git a/gcc/testsuite/gcc.dg/format/pr80919.c b/gcc/testsuite/gcc.dg/format/pr80919.c
new file mode 100644 (file)
index 0000000..510c2e4
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR c/80919 */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+void
+fn (void)
+{
+  int a[0];
+  __builtin_printf("%d\n", &a); /* { dg-warning "expects argument of type" } */
+  __builtin_printf("%i\n", &a); /* { dg-warning "expects argument of type" } */
+
+  __builtin_printf("%o\n", &a); /* { dg-warning "expects argument of type" } */
+  __builtin_printf("%u\n", &a); /* { dg-warning "expects argument of type" } */
+  __builtin_printf("%x\n", &a); /* { dg-warning "expects argument of type" } */
+  __builtin_printf("%X\n", &a); /* { dg-warning "expects argument of type" } */
+}