From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x432.google.com with SMTP id b4so2536285wrs.1 for ; Thu, 13 Oct 2022 05:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=yCuQ34bxetac/5jYW2C6QD0CMa7eqn23MyWEkubOUf8=; b=Jc9EvP96e+J/IS1G7Mjl7fvCctVjccLNViwporSo+bsPYKH/4ybH3w1D7WlO4THktO pNFAfT8i5OwAGb0NwHgP3/K4VGFcO192ucbtHITVa+0rEr+y3kWwqVbPPc1QuUZZsIXn /3xx5AQPRGRCq0px6Y82on+th+HVZOQbDeOefx2pv0KuKjgJPfaCbQQMeJLpcqJriyxw becQclijfhhxMCwzLdfmQvdb9QTrORh8mFsnyhHMebRY7aIu/E2c/h4O5PN/WbypMNpN +NIl0ag1Co72VLPV9jTTMMFkOld57vdRMfVSArf3VvL7vlK9vpNgIKRuRrU8DutMBwwp LWDA== 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-Google-Smtp-Source: AMsMyM5QjFk8emTfy7Oeme1/lk++RxB+Eq71NWQuI7UFT02Y1OlEvXUhCrpYBhOYRfDwuUL1yw4Fww== 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) From: Eric Botcazou 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 Content-Type: multipart/mixed; boundary="nextPart3200180.44csPzL39Z" Content-Transfer-Encoding: 7Bit 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 List-Id: This is a multi-part message in MIME format. --nextPart3200180.44csPzL39Z Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" 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. -- Eric Botcazou --nextPart3200180.44csPzL39Z Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="p.diff" 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)) { --nextPart3200180.44csPzL39Z Content-Disposition: attachment; filename="Wstringop-overflow-89.c" Content-Transfer-Encoding: 7Bit Content-Type: text/x-csrc; charset="utf-8"; name="Wstringop-overflow-89.c" /* { dg-do compile } */ /* { dg-options "-O2 -fno-inline -Wall" } */ extern void process (char); void process_array4 (char a[4], int n) { for (int i = 0; i < n; i++) process (a[i]); } void process_array3 (char a[3], int n) { for (int i = 0; i < n; i++) process (a[i]); } --nextPart3200180.44csPzL39Z--