From patchwork Wed May 12 21:56:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1477851 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@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=DXurBmXx; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4FgTC95RpTz9sWM for ; Thu, 13 May 2021 07:56:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CEAB13894C24; Wed, 12 May 2021 21:56:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEAB13894C24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1620856595; bh=AgRn4U0+1reYefNHdb6PvUtDOsDHgSk3BjsmQ2qrHdk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DXurBmXx4G5VWQGDR7Chx88JK+tOVR8XU/Bq6+Pq0CwhUV+2i/hpr/1RUDNXTLa8i YCuorXk+UHK/s3W6S6J33alNtVLRH4AkqqByi8y4D5FdbXBz/TNrN1cFkvhv8De2Et N/+Ivmkjds8B0ntimP+QHQrFGkf165NiyUbrWUvk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 98AEC3894C05 for ; Wed, 12 May 2021 21:56:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 98AEC3894C05 Received: by mail-qk1-x729.google.com with SMTP id f18so1940524qko.7 for ; Wed, 12 May 2021 14:56:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=AgRn4U0+1reYefNHdb6PvUtDOsDHgSk3BjsmQ2qrHdk=; b=dcrNhxI2NodlTFTFpK5uxB6CaW5CMYy6qRxBh8n2+m4TJhC8vT+TwjiBBs+R4pFH4H hzj9cCZSlevrw1UCbWJde4kxfQVkG+Saiq2fwCKCVBPcvzMcgyAHlzGo0eUckbszc6nY bLJqdFQGu3HVfq9/zqKOGbsqhS/MOXJMsEEL5OULAzo+hlHKcjyOKUVmxDB3B8h7z+zh q3ttYcH7oY52ZAUtIR4tmiM6gk0dnBMwnkQ841rwAa7P9flK1qBn61khaIiFUJ6iPjdq lNVofJcwrcHlKmDMYsrkgMQujto+tlI2W8EC3W70vfzbPJRSuLGoW9u626ZXb8YFRzWK QRfA== X-Gm-Message-State: AOAM530tdFXNxqXkERq/kh/H9hseCXAtv3Q9owOxSeDBO0JEQd4fmIvc F3kGtsKyh1CglCiQim+ckCmX07NH8TI= X-Google-Smtp-Source: ABdhPJxdqtlk6ks39KmPtQoQ9n+mE/qtxEbJ19XzTa53fDqmVMbV00C1N9rjx8FxsNAqlZD2Svsljw== X-Received: by 2002:a05:620a:141b:: with SMTP id d27mr4057564qkj.357.1620856592944; Wed, 12 May 2021 14:56:32 -0700 (PDT) Received: from [192.168.0.41] (71-218-14-121.hlrn.qwest.net. [71.218.14.121]) by smtp.gmail.com with ESMTPSA id j13sm1010407qth.57.2021.05.12.14.56.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 May 2021 14:56:32 -0700 (PDT) To: gcc-patches Subject: [committed] avoid bogus -Wstringop-overflow with VLA (PR 100571) Message-ID: Date: Wed, 12 May 2021 15:56:31 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" A recent Glibc enhancement to add attribute access to a bunch of APIs has triggered a couple of false positives in the test suite when using GCC 10. The problem has been fixed on trunk as part of a bigger commit that's not suitable for backporting (it adds new warnings). The attached change fixes just the narrow problem that impacts Glibc. I have committed it to 10-branch in r10-9819. Martin commit 7b6740756c9ca64dd01097b629c19e26d3d6a504 Author: Martin Sebor Date: Wed May 12 15:45:44 2021 -0600 PR middle-end/100571 - bogus -Wstringop-overflow with VLA of elements larger than byte gcc/ChangeLog: PR middle-end/100571 * gcc/calls.c (maybe_warn_rdwr_sizes): Clear object size if it can't be determined. gcc/testsuite/ChangeLog: PR middle-end/100571 * gcc.dg/Wstringop-overflow-67.c: New test. diff --git a/gcc/calls.c b/gcc/calls.c index 26894342c21..45c137cee1e 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -2112,6 +2112,11 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp) } else { + /* If the size cannot be determined clear it to keep it from + being taken as real (and excessive). */ + if (objsize && integer_all_onesp (objsize)) + objsize = NULL_TREE; + /* For read-only and read-write attributes also set the source size. */ srcsize = objsize; diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c new file mode 100644 index 00000000000..7b8f3f014c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-67.c @@ -0,0 +1,92 @@ +/* PR middle-end/100571 - bogus -Wstringop-overflow with VLA of elements + larger than byte + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +__attribute__ ((access (read_only, 1, 2))) void fro (int *, int); +__attribute__ ((access (write_only, 1, 2))) void fwo (int *, int); +__attribute__ ((access (read_write, 1, 2))) void frw (int *, int); + +extern __SIZE_TYPE__ n; + +void alloca_ro (void) +{ + int *a = __builtin_alloca (n * sizeof *a); + a[0] = 0; + fro (a, n); +} + +void alloca_wo (void) +{ + int *a = __builtin_alloca (n * sizeof *a); + fwo (a, n); +} + +void alloca_rw (void) +{ + int *a = __builtin_alloca (n * sizeof *a); + a[0] = 0; + frw (a, n); +} + + +void calloc_ro (void) +{ + int *a = __builtin_calloc (n, sizeof *a); + fro (a, n); +} + +void calloc_wo (void) +{ + int *a = __builtin_calloc (n, sizeof *a); + fwo (a, n); +} + +void calloc_rw (void) +{ + int *a = __builtin_calloc (n, sizeof *a); + a[0] = 0; + frw (a, n); +} + + +void malloc_ro (void) +{ + int *a = __builtin_malloc (n * sizeof *a); + a[0] = 0; + fro (a, n); +} + +void malloc_wo (void) +{ + int *a = __builtin_malloc (n * sizeof *a); + fwo (a, n); +} + +void malloc_rw (void) +{ + int *a = __builtin_malloc (n * sizeof *a); + a[0] = 0; + frw (a, n); +} + + +void vla_ro (void) +{ + int a[n]; + a[0] = 0; + fro (a, n); +} + +void vla_wo (void) +{ + int a[n]; + fwo (a, n); +} + +void vla_rw (void) +{ + int a[n]; + a[0] = 0; + frw (a, n); +}