From patchwork Fri Jun 2 17:19:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 770530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wfWD22rX1z9s65 for ; Sat, 3 Jun 2017 03:19:28 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="DCw+5RS4"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=tSA4L79GaR6KbhvYGy2QBWXVWfxkIZ+l736Q80A91/F1SKWe+BC8u z+WY0cLKO6AKXpfuINp2EecW5c0K4BEB39vW12AvKOoVeDIHseMayTyTnDO0PW7Q Qal6Ixpiu/ltvL2AJyJuYUb26TVHDYfKUhL6XSDXTY7iv2daZHDajU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=0Nv3LUS4VB/iVP/KKUO2OpjkblA=; b=DCw+5RS40Kp/9JL5Gh78 PfMxaDp3G604eiByAbQagXNldKixEVT4aychHe5Fjjs1IhakpBYQWQSGrYLVmzfO uPHlRcOAg+7VineK9UoFCZvBeztNrVg1b9clrxEXplbGAHp84Mlx87/6dXAYKl6m PE0C9A/uEFlzvSnzJJHkRN4= 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-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@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, 2 Jun 2017 19:19:12 +0200 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-Disposition: inline User-Agent: Mutt/1.8.0 (2017-02-23) 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. Marek 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" } */ +}