From patchwork Wed Sep 13 11:00:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 813348 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-462023-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="kOE78Hxy"; dkim-atps=neutral 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 3xsdy04rPRz9sBW for ; Wed, 13 Sep 2017 21:01:12 +1000 (AEST) 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=NG1ey51KyFJkqRWUGIbwyQ9XiMMF2hHR9/+SwA5RyBhtIPXfde3r2 CLMYyFtwNdEDG1xRxAmpz3RuyGLWaRm8FfotxZ+kJVDUCVTB4t/bEiNFaIQSiyhN 4OUEJP8Q/3pK3HraFNihG6DdoxtM/1mLtvYR7UNM1aNdOvggLE9HXo= 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=awp8k1fdNL+2hPumojvINCX0azg=; b=kOE78HxyeCA5COxnY8M/ 0Wf2R1XKOwCg1uUjTXaah2myu++Vdj5D+JvvgliazqMp52EdH2/eHiRyOvNKNsHP ACSLQ185ePrXJ0H9XRHGwuSiXRrSvoBIbvGs0CebJ9fFvqDAgA18ddZobvtjGE7a pVfLV63i8/ywnC3UJFr2xVs= Received: (qmail 95478 invoked by alias); 13 Sep 2017 11:01:02 -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 94043 invoked by uid 89); 13 Sep 2017 11:01:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=crashed 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; Wed, 13 Sep 2017 11:01:00 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74ADEC04B952; Wed, 13 Sep 2017 11:00:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 74ADEC04B952 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=polacek@redhat.com Received: from redhat.com (ovpn-204-68.brq.redhat.com [10.40.204.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7719066FFB; Wed, 13 Sep 2017 11:00:58 +0000 (UTC) Date: Wed, 13 Sep 2017 13:00:33 +0200 From: Marek Polacek To: GCC Patches , Joseph Myers Subject: C PATCH to fix ICE with -Wsizeof-array-argument (PR c/82167) Message-ID: <20170913110032.GL20631@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) This fixes a segv, where -Wsizeof-array-argument crashed because expr.original_type was null. It was null because for sizeof (*&a) we go to c_parser_unary_expression's case CPP_AND: and case CPP_MULT:, and that removes the original_type. But we don't need the original type, we can just use TREE_TYPE of expr.value. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2017-09-13 Marek Polacek PR c/82167 * c-typeck.c (c_expr_sizeof_expr): Use the type of expr.value rather than expr.original_type. * gcc.dg/pr82167.c: New test. Marek diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index 91996c95ed0..f45fd3cfbbf 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -2909,7 +2909,7 @@ c_expr_sizeof_expr (location_t loc, struct c_expr expr) if (warning_at (loc, OPT_Wsizeof_array_argument, "% on array function parameter %qE will " "return size of %qT", expr.value, - expr.original_type)) + TREE_TYPE (expr.value))) inform (DECL_SOURCE_LOCATION (expr.value), "declared here"); } tree folded_expr = c_fully_fold (expr.value, require_constant_value, diff --git gcc/testsuite/gcc.dg/pr82167.c gcc/testsuite/gcc.dg/pr82167.c index e69de29bb2d..af3b3a5a1c9 100644 --- gcc/testsuite/gcc.dg/pr82167.c +++ gcc/testsuite/gcc.dg/pr82167.c @@ -0,0 +1,14 @@ +/* PR c/82167 */ +/* { dg-do compile } */ + +void +fn1 (int a[]) +{ + __builtin_printf ("%zu\n", sizeof (*&a)); /* { dg-warning ".sizeof. on array function parameter .a. will return size of .int \\*." } */ +} + +void +fn2 (int *a[]) +{ + __builtin_printf ("%zu\n", sizeof (*&a)); /* { dg-warning ".sizeof. on array function parameter .a. will return size of .int \\*\\*." } */ +}