From patchwork Fri Jul 16 01:59:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1505968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+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.a=rsa-sha256 header.s=default header.b=kKxaWrqL; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GQvZk4wjlz9sWc for ; Fri, 16 Jul 2021 12:00:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26AF83855000 for ; Fri, 16 Jul 2021 02:00:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26AF83855000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1626400810; bh=sWDnAfFmCOrG6T454lLojydzho88tNpnLzDTyoQzweQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=kKxaWrqL+ys1mhD9tOR3wrI1sndMtW1Jtu3RxNzUHsWsG/5pOTraQwZhlzWeNU4fk B7K1ipAYTMQY4CMcw8u/ZpiiMWCC6GsahS6Tj48bXOOIfawdvIdrttaw9z7kfThsec gwR0wjtn3q5LbFcTthF6XOgayORv1WFCMmJ5frss= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 3294C3857C4B for ; Fri, 16 Jul 2021 01:59:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3294C3857C4B Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16G1tsKt022729 for ; Thu, 15 Jul 2021 18:59:25 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com with ESMTP id 39tw340q49-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 15 Jul 2021 18:59:25 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 15 Jul 2021 18:59:23 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Thu, 15 Jul 2021 18:59:23 -0700 Received: from linux.wrightpinski.org.com (unknown [10.76.242.44]) by maili.marvell.com (Postfix) with ESMTP id F09A23F7085; Thu, 15 Jul 2021 18:59:22 -0700 (PDT) To: Subject: [PATCH] Fix PR 101453: ICE with optimize and large integer constant Date: Thu, 15 Jul 2021 18:59:17 -0700 Message-ID: <1626400757-22417-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: UpiDJ1RG_mNyXVf3AaSWCYAwCxWIl6JA X-Proofpoint-ORIG-GUID: UpiDJ1RG_mNyXVf3AaSWCYAwCxWIl6JA X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-15_16:2021-07-14, 2021-07-15 signatures=0 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski Every base 10 digit will take use ~3.32 bits to represent. So for a 64bit signed integer, it is 20 characters. The buffer was only 20 so it did not fit; add in the null character and "-O" part, the buffer would be 3 bytes too small. Instead of just increasing the size of the buffer, I decided to calculate the size at compile time and use constexpr to get a constant for the size. Since GCC is written in C++11, using constexpr is the best way to force the size calculated at compile time. OK? Bootstrapped and tested on x86_64-linux with no regressions. gcc/c-family/ChangeLog: PR c/101453 * c-common.c (parse_optimize_options): Use the correct size for buffer. --- gcc/c-family/c-common.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 20ec26317c5..4c5b75a9548 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -5799,7 +5799,9 @@ parse_optimize_options (tree args, bool attr_p) if (TREE_CODE (value) == INTEGER_CST) { - char buffer[20]; + constexpr double log10 = 3.32; + constexpr int longdigits = ((int)((sizeof(long)*CHAR_BIT)/log10))+1; + char buffer[longdigits + 3]; sprintf (buffer, "-O%ld", (long) TREE_INT_CST_LOW (value)); vec_safe_push (optimize_args, ggc_strdup (buffer)); }