From patchwork Thu Oct 13 12:06:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 2033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp235763wrs; Thu, 13 Oct 2022 05:08:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5jKOzM9JSW2lTK5zSk5MSi4yj6MIzzsunc383Tot2gzIGbQYYrk61Iiz7DSls06Vwc3Aku X-Received: by 2002:a05:6402:4505:b0:451:1551:7b14 with SMTP id ez5-20020a056402450500b0045115517b14mr32225282edb.300.1665662896191; Thu, 13 Oct 2022 05:08:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665662896; cv=none; d=google.com; s=arc-20160816; b=M9L7F6Ng0rlQTpnpMgq+4h7kfAxGsV2J/X5+GFyHLtiFiRYUp6CbBMlsXH724A73Op GKOoMV/rwxpMdzl7dK+HH7fXxPU2AliilWc7mLexOq7sra0IDZ6Txfo7oAhLkqGERVEh hbEybqCic6EqLV2FpSiyeizICk2YTV5EkFz6OGaJcIM0JYEXi1/fRYvgoSPXJ3/kY8ZG Fk/OGDdUTv80uU4b3qI5bYPwpuyYqePAgMs1kA60Jcnu8jOpgjwZX+LrRf7YOT3xvfkw VXFbSBs18ft2GrVtZW31oladJS6gtkz3BFQ2s1wNyYvdmqnyNjruPjg+amRReYi79RTv eKnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=yCuQ34bxetac/5jYW2C6QD0CMa7eqn23MyWEkubOUf8=; b=POMR2a5bpMKD3AWeQ+lt3B0dfVtkoJYV8Z2SrBOtp8pHBv1h1eNgNSAvRDNR6RET4t sPwHEMza+7tkRdlJ/vgNiXXffascgE+vaUr7rgAuRoLg5tO0jMQs5oGujyEmn34GLHLc sCuNA1RWPaMKT5wyj9VBdcnSXoeMu7trgDIHXRBSq/eK+EqavT6UNXPnREa2xxSy8VGk qFyT4srRG93EKCbSvkdMQa3i3DSIJkbR0W9On8/qBmcz+8meo2r4GSMzdWMbM9Eid6ZO bZyQt6ApB7LVdcRu4hd8QAiWTEHp5bWJBhBV18axAh/JYuk69HFlUVRTg38VYx4YmYVF d6fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wYC+rtUE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m16-20020a056402431000b0045cc691da27si3663210edc.518.2022.10.13.05.08.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 05:08:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wYC+rtUE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 16AC5385383C for ; Thu, 13 Oct 2022 12:08:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16AC5385383C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665662883; bh=yCuQ34bxetac/5jYW2C6QD0CMa7eqn23MyWEkubOUf8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wYC+rtUE2G2PRXQEutBBrNKO4vYGqoTElzVMDwU0pY6UaCPVDgixOLfTxkxdRcrWL puOMtcHpUN1ID1gtSFakEwpzyQ/hDM2AFtG1ZPvtRx8kG8sj1qwsASPFynGff1eCg1 tmKmyWgfZiiiIbKy3SdDvTlLKBX6aRUBVRxltNgs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 44AF03856DD6 for ; Thu, 13 Oct 2022 12:07:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 44AF03856DD6 Received: by mail-wr1-x432.google.com with SMTP id b4so2536285wrs.1 for ; Thu, 13 Oct 2022 05:07:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yCuQ34bxetac/5jYW2C6QD0CMa7eqn23MyWEkubOUf8=; b=JtZ7j9pEkShTPBUISssFJY55X75oNliRIr+++OM7FhZuSxHgJn59pO6mddJb6dTXdP lIDmLOYexkKHBSaNPCqpDjaH043p6YZ/AzOa1ATZQ9ljw7tWxV7ZbIsTF6YCsA9Tsnu1 yDNUyEn7FeZCzN9yXc5bFzpbmtLuNZiTTSQ5r1EXJm15ZSTh58lOlRKrXHpdVcK+78QR agZjk7Lmy5K0Y2MFESJnzp8tQ9L2mDcL5IJCfkw/jbm9AuDSy4C5bRjWA+U3WV4Gr6aK 7QdNpQVfvrxuHmZ9qLdLBTCpAfan//3BOmb+QQzqAYqtlnYnlXOALzMCVfPQI+tcaQOc WVSg== X-Gm-Message-State: ACrzQf2uRkojLbpYU9/EJ2zyum8U9T7WWyLU6qKpLnDlDsSp/UymNRAD 0jVe/zZjMsUJiLcgQwiVPeOj0ijoeeOIBA== X-Received: by 2002:a05:6000:8c:b0:22e:45c6:bc4c with SMTP id m12-20020a056000008c00b0022e45c6bc4cmr20505604wrx.555.1665662838753; Thu, 13 Oct 2022 05:07:18 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id d15-20020a056000114f00b0022e309d35f8sm1929193wrx.12.2022.10.13.05.07.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 05:07:18 -0700 (PDT) X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix bogus -Wstringop-overflow warning Date: Thu, 13 Oct 2022 14:06:15 +0200 Message-ID: <3194055.aeNJFYEL58@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eric Botcazou via Gcc-patches From: Eric Botcazou Reply-To: Eric Botcazou Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746574137170976967?= X-GMAIL-MSGID: =?utf-8?q?1746574137170976967?= Hi, if you compile the attached testcase with -O2 -fno-inline -Wall, you get: In function 'process_array3': cc1: warning: 'process_array4' accessing 4 bytes in a region of size 3 [- Wstringop-overflow=] cc1: note: referencing argument 1 of type 'char[4]' t.c:6:6: note: in a call to function 'process_array4' 6 | void process_array4 (char a[4], int n) | ^~~~~~~~~~~~~~ cc1: warning: 'process_array4' accessing 4 bytes in a region of size 3 [- Wstringop-overflow=] cc1: note: referencing argument 1 of type 'char[4]' t.c:6:6: note: in a call to function 'process_array4' That's because the ICF IPA pass has identified the two functions and turned process_array3 into a wrapper of process_array4. This looks sensible to me given that the only difference between them is an "access" attribute on their type describing the access size of the parameter and the "access" attribute does not affect type identity (struct attribute_spec.affects_type_identity). Hence the proposed fix, tested on x86-64/Linux, OK for the mainline? 2022-10-13 Eric Botcazou * gimple-ssa-warn-access.cc (pass_waccess::check_call): Return early for calls made from thunks. 2022-10-13 Eric Botcazou * gcc.dg/Wstringop-overflow-89.c: New test. diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc index 04aa849a4b1..59a70530600 100644 --- a/gcc/gimple-ssa-warn-access.cc +++ b/gcc/gimple-ssa-warn-access.cc @@ -4291,14 +4291,18 @@ pass_waccess::check_pointer_uses (gimple *stmt, tree ptr, void pass_waccess::check_call (gcall *stmt) { - if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) - check_builtin (stmt); + /* Skip special calls generated by the compiler. */ + if (gimple_call_from_thunk_p (stmt)) + return; /* .ASAN_MARK doesn't access any vars, only modifies shadow memory. */ if (gimple_call_internal_p (stmt) && gimple_call_internal_fn (stmt) == IFN_ASAN_MARK) return; + if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) + check_builtin (stmt); + if (!m_early_checks_p) if (tree callee = gimple_call_fndecl (stmt)) {