From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 64532 invoked by alias); 2 Jun 2017 17:19:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 64516 invoked by uid 89); 2 Jun 2017 17:19:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Jun 2017 17:19:14 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBD056A6C5; Fri, 2 Jun 2017 17:19:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BBD056A6C5 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=polacek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BBD056A6C5 Received: from redhat.com ([10.40.205.13]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v52HJDja003564 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 2 Jun 2017 13:19:15 -0400 Date: Fri, 02 Jun 2017 17:19:00 -0000 From: Marek Polacek To: GCC Patches , Joseph Myers , David Malcolm Subject: C PATCH to fix ICE with -Wformat and zero-length array (PR c/80919) Message-ID: <20170602171912.GH3413@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.8.0 (2017-02-23) X-SW-Source: 2017-06/txt/msg00153.txt.bz2 In the C FE, zero-length arrays require structural equality, so we can't compare their canonical types, 'cause they're NULL. But matching_type_p didn't know that so we were crashing. With this patch the ICE is gone and the warning messages are the same as with e.g. "int a[1]". Bootstrapped/regtested on x86_64-linux, ok for trunk/7? 2017-06-02 Marek Polacek 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. diff --git gcc/c-family/c-format.c gcc/c-family/c-format.c index faef267..732339b 100644 --- gcc/c-family/c-format.c +++ 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 gcc/testsuite/gcc.dg/format/pr80919.c gcc/testsuite/gcc.dg/format/pr80919.c index e69de29..510c2e4 100644 --- gcc/testsuite/gcc.dg/format/pr80919.c +++ 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" } */ +} Marek