From 3de4ac6d80c8ae24b58586003aded178d7ec8453 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Sun, 4 Jun 2017 17:27:22 +0000 Subject: [PATCH] re PR c/80919 (ICE: Segmentation fault with -Wall when printing address of size 0 array) 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 | 6 ++++++ gcc/c-family/c-format.c | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/format/pr80919.c | 16 ++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/format/pr80919.c diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 569b456a724..97335e89b35 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2017-06-04 Marek Polacek + + PR c/80919 + * c-format.c (matching_type_p): Return false if any of the types + requires structural equality. + 2017-06-02 Martin Sebor PR c/80892 diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index faef267220d..732339b9b5e 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 537e6422d22..bfadad53601 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-06-04 Marek Polacek + + PR c/80919 + * gcc.dg/format/pr80919.c: New test. + 2017-06-02 Martin Sebor 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 index 00000000000..510c2e4e6c9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/pr80919.c @@ -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" } */ +} -- 2.30.2