From patchwork Thu Aug 3 08:43:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 797081 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-459703-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="YxDadhoU"; 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 3xNNqn6QLMz9s7g for ; Thu, 3 Aug 2017 18:43:16 +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:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=ONlkilzUI6PRNI2BD84UXWXoEC0/i tboj7Nl6s02Ag+NTEAR6qCdB4UvALBTHZj36ookUNM+6Cs6RIyGVRlia/KMned4Z kIpcGv/Pw6UIUFNNy2X/utiyuZtcWmiyebCWSdB9V5tjD5oXA8PY2fEOCdJKTLJz OJ0Pj6v9CbECas= 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:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=jUQKf5a8W2o50CJ83NVF/XaYj88=; b=YxD adhoUbm5rJPrDiWtP1QbwIL/ci1ng7SiTS1+ihvqASr8TZCfYn5H3m4zOR3ZfVxR WuoKeYXPH2iS3zcGYdyLPxBnasIS9CTux4tcAA1MB0gDVz6lu3793eXvMEvijV12 w41cQGrXou8W6fMVT+D9XO44eFg7wQJT9sU9yEdA= Received: (qmail 34126 invoked by alias); 3 Aug 2017 08:43:08 -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 34104 invoked by uid 89); 3 Aug 2017 08:43:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:3354, kib, talks, diagnosing 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; Thu, 03 Aug 2017 08:43:06 +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 0E4FE883B4; Thu, 3 Aug 2017 08:43:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0E4FE883B4 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jakub@redhat.com Received: from tucnak.zalov.cz (ovpn-116-40.ams2.redhat.com [10.36.116.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8FCC16C41A; Thu, 3 Aug 2017 08:43:04 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v738h2gD020957; Thu, 3 Aug 2017 10:43:02 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v738h0bm020956; Thu, 3 Aug 2017 10:43:00 +0200 Date: Thu, 3 Aug 2017 10:43:00 +0200 From: Jakub Jelinek To: Richard Biener , Martin Sebor Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Some -Walloc-size-larger-than= warning fixes (PR driver/81650) Message-ID: <20170803084300.GS2123@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! This patch attempts to fix some overflows during computation of the size and then effectively uses MIN (SSIZE_MAX, user_specified_value) as the bound. Not really sure what exact behavior we want, whether that, or default to SSIZE_MAX (note the documentation mistakenly talks about SIZE_MAX / 2 instead) and use MIN (SIZE_MAX, user_specified_value) for user specified value, or error out if user_specified_value is larger than SSIZE_MAX or larger than SIZE_MAX. Also the else unit = 0; case probably should get diagnostics. Another issue is if we want to diagnose, that right now it will be diagnosed only if some allocation routine is seen, diagnosing stuff during option processing is unfortunately too early because we don't have sizetype/ssizetype built yet. Anyway, the following has been bootstrapped/regtested on x86_64-linux and i686-linux. 2017-08-03 Jakub Jelinek PR driver/81650 * calls.c (alloc_max_size): Use HOST_WIDE_INT_UC (10??) instead of 10??LU, perform unit multiplication in wide_int, don't change alloc_object_size_limit if the limit is larger than SSIZE_MAX. * gcc.dg/pr81650.c: New test. Jakub --- gcc/calls.c.jj 2017-06-12 12:42:01.000000000 +0200 +++ gcc/calls.c 2017-08-02 13:41:00.887324420 +0200 @@ -1222,32 +1222,38 @@ alloc_max_size (void) else if (!strcasecmp (end, "KiB") || strcmp (end, "KB")) unit = 1024; else if (!strcmp (end, "MB")) - unit = 1000LU * 1000; + unit = HOST_WIDE_INT_UC (1000) * 1000; else if (!strcasecmp (end, "MiB")) - unit = 1024LU * 1024; + unit = HOST_WIDE_INT_UC (1024) * 1024; else if (!strcasecmp (end, "GB")) - unit = 1000LU * 1000 * 1000; + unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000; else if (!strcasecmp (end, "GiB")) - unit = 1024LU * 1024 * 1024; + unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024; else if (!strcasecmp (end, "TB")) - unit = 1000LU * 1000 * 1000 * 1000; + unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000; else if (!strcasecmp (end, "TiB")) - unit = 1024LU * 1024 * 1024 * 1024; + unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024; else if (!strcasecmp (end, "PB")) - unit = 1000LU * 1000 * 1000 * 1000 * 1000; + unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000 * 1000; else if (!strcasecmp (end, "PiB")) - unit = 1024LU * 1024 * 1024 * 1024 * 1024; + unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024 * 1024; else if (!strcasecmp (end, "EB")) - unit = 1000LU * 1000 * 1000 * 1000 * 1000 * 1000; + unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000 * 1000 + * 1000; else if (!strcasecmp (end, "EiB")) - unit = 1024LU * 1024 * 1024 * 1024 * 1024 * 1024; + unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024 * 1024 + * 1024; else unit = 0; } if (unit) - alloc_object_size_limit - = build_int_cst (ssizetype, limit * unit); + { + wide_int w = wi::uhwi (limit, HOST_BITS_PER_WIDE_INT + 64); + w *= unit; + if (wi::ltu_p (w, alloc_object_size_limit)) + alloc_object_size_limit = wide_int_to_tree (ssizetype, w); + } } } } --- gcc/testsuite/gcc.dg/pr81650.c.jj 2017-08-02 14:52:22.864787221 +0200 +++ gcc/testsuite/gcc.dg/pr81650.c 2017-08-02 14:21:11.000000000 +0200 @@ -0,0 +1,9 @@ +/* PR driver/81650 */ +/* { dg-do compile } */ +/* { dg-options "-Walloc-size-larger-than=9223372036854775807" } */ + +void * +foo (void) +{ + return __builtin_malloc (5); +}