From patchwork Wed Mar 27 23:09:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1917058 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=golang-org.20230601.gappssmtp.com header.i=@golang-org.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=PbNPsBzJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V4j810WF1z1yYM for ; Thu, 28 Mar 2024 10:10:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38540385E446 for ; Wed, 27 Mar 2024 23:10:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by sourceware.org (Postfix) with ESMTPS id C2D14385E00B for ; Wed, 27 Mar 2024 23:10:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2D14385E00B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=golang.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=golang.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C2D14385E00B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711581002; cv=none; b=ieripQnEwoDcxpTJ/actKBuOo9idjWkm3vyTdN1wx23AL8FMtrQGrgvKSNA0NqIcDpwM+jMm5noY9fO54MmEBbtDa6TsOYy8IXcHv7XXZq7+nbaKFoAENW0nCAhDCRIkieRmL+KK8JAUvP86NE535k56Dd9x2iJ8eAH4G32EKKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711581002; c=relaxed/simple; bh=CMfnArQOGtk7zF4iDLqKQ0o77kb0slKw/bqIMuR/GgY=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=D1+Lt/2ntaZFzBsVklZ8LPKtGUeYz265nENQ3C5Kp3kvY40/YbsmEYLX8uSpU6OF4/bHb3CDj4ezds/QcZNSMjlMvy3B7UkS+GfZUBCe2ti5Y9Nzo4Urh9UtKt2aQPDeGD+ZF+8CPDnPkZx2J6DzsOrWb+u9eaRVra0rrjWI8I0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-611639a0e4eso9916127b3.0 for ; Wed, 27 Mar 2024 16:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20230601.gappssmtp.com; s=20230601; t=1711580998; x=1712185798; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=uK089ykuQwkmLvtwd8/uxQQZThr+Cdjv42n89Hb5Xbo=; b=PbNPsBzJ0Nij/yC8ZKWjx8oK90oZrDMBN81gkK01YJQtRtCuzwDSKCOTwgDIoUsdKk N4AH3sSL9un3qmXP5CFQr7ICDPq5Dm/ZARUixhukntSHDS9LNUya4Wy1RRzghM2UtobL i4XRN950mPVjoYxJuIpbxANmBFGeEakifT1tB4JcmYrmalPIa7g1Xc6kp+V3gT6CxYQp 6mvV9lyE1mxyxTFa5soMPlbt9MCXgKxhmH1Rul1UuBX2q+y9NvPVpa/Fvzcl1Q4c4k9o lQhraZ1j5xq49COgsIOn7iS05pDfyFYWXX+4r8ZLexWmveqg+6tl1qvMA2xqarvpem30 4w5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711580998; x=1712185798; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=uK089ykuQwkmLvtwd8/uxQQZThr+Cdjv42n89Hb5Xbo=; b=OaX8H+/CEoS5vYgEvFidvWYwnJBxfS9v74qQjBQx+idiDdxAVV33isXoPeT5jA/2MC pybm9YC73rT8unJlubKfbgmomMRw/P8grwdSB3tmpgGnQwxoyBh9ToGFV1xXxPYDDuVb 98faeFs3M15cwSOoRSy33bvYSnIjGBU3M7s+VnTdCDodCEQnPRd+BLmV/Oa0pZgctzMZ uJKz4SjqzSn7Cb/TUPNHQuuA5C16ewdTaGdj1YFWs5tqwYSE9gl9C62lZdj1RLScE0fg pr1b2VjAW91/kLc7nWAWlO/BrgFjmZwNzMf6o0ztDqBEPXvhXbLoIeK/cGY17BU5gBs9 KonA== X-Gm-Message-State: AOJu0YwbZVzDekWb+Fz775szh1pqWcm5vqmxs+VYp7GvgNoguDO1kuWe S+wabyScYDmYXyiYDX/GGggQhlPudBmVEZgt/+SoiRAMIElfGUSQcEOnZl1qScScawMtlUsPRJs Fz15lQsRhrJo7DvsEHrPHavVwjkf73NrzfsmJdYK7Afv2HjpPZeM= X-Google-Smtp-Source: AGHT+IFsbZvWntrwhbyXPweo3InG5qYublrlcdQEoQP/7OonZgw7tTBolQA7HhanuRinZZrHtRQBn1+La+dhm42BUlo= X-Received: by 2002:a25:cec6:0:b0:dcf:eb30:c580 with SMTP id x189-20020a25cec6000000b00dcfeb30c580mr554590ybe.3.1711580998578; Wed, 27 Mar 2024 16:09:58 -0700 (PDT) MIME-Version: 1.0 From: Ian Lance Taylor Date: Wed, 27 Mar 2024 16:09:46 -0700 Message-ID: Subject: Go patch committed: Use correct check for index value overflow To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch to the Go frontend uses the correct size and comparison when doing an index value overflow check. This has apparently been wrong since I introduced the code ten years ago. This fixes GCC PR 114500. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 1091113a0036c7315197e09af572dce2beaf1c4c diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index de6e21fb3b5..50d430d5034 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -3f597287b6b858794dabdfe1bf83b386aad18102 +98e92493db2ab7857a5934a950a830fc1f95a4e5 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 8429e553eac..238d5a56ca2 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -18790,7 +18790,7 @@ Composite_literal_expression::lower_array(Type* type) Named_type* ntype = Type::lookup_integer_type("int"); Integer_type* inttype = ntype->integer_type(); - if (sizeof(index) <= static_cast(inttype->bits() * 8) + if (sizeof(index) >= static_cast(inttype->bits() / 8) && index >> (inttype->bits() - 1) != 0) { go_error_at(index_expr->location(), "index value overflow");