From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 190F13858432 for ; Mon, 13 May 2024 20:46:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 190F13858432 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 190F13858432 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1036 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715633197; cv=none; b=Dc7xpY0pgx1zWaZopcFwqn3KtF7iOyWqwtZQVinoluiP6hqXhkmsQ4jm7iG4NihNRQRu+s/YkvlW4eKimpPae2Jw6jcYYVjZkyOoBpKwTdtNglN35ZuH9Jz7A9sPQRmkvii4JovuvVYPuyrw1kVeOUIVn/u3xX79BRRROWM//NE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715633197; c=relaxed/simple; bh=K4dDu/nJ08bxn6mQ9kJSHVDch0I76ACV7iZUTn4BBwA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Z9XUwiN49JdQw/p2qnUP01Jg1iieFcKjuXmjzhlqLUI+2x2k3mWArUfiKYFXEsV1yhl/KzITxt8KH0S/gxM5S82jba344AWy8lxILyUBoNtN/Es2a+ZMOvJ4LkS2TMQGT/w3A+juzUAT5CtlnzFvlQVsqiwsAapiBOK3EejUZhc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2b4952a1b51so3812458a91.0 for ; Mon, 13 May 2024 13:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715633194; x=1716237994; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ujjbE78IxhmFvZZFPFaX9DTGhm5VjWIHCCTfgpMwhX0=; b=h2y1oN/gOyydhtu2+/uZtQewk3s9ulXyAS45zEreINlXX0ToO+KLD68Fsl1MZGq7nZ a70w55/+srC+0JLfikHSpwVFE20uie8uHuZXp39CU8fXAXzWZqoQ3ViGvIgssVx3ozEO Xlr0LF97SioEP3o1X45ztKRyDLjE0mXC8iacFySJtWoKz/smstu7RWQ1vnpL+HTvdF4Q k3RoigiWXkARKVV/bg31pkRW9yQvyaX0Il2XhiMUiHNRpUmMCsv965ZVZUEVx4H/rlGt 9B/LSnactV+krgqLQfDjTuw/4nalQIqBExB6C+zO3hNYkLs5RrihQXhQOzk1mn4eQV1A 2aQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715633194; x=1716237994; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ujjbE78IxhmFvZZFPFaX9DTGhm5VjWIHCCTfgpMwhX0=; b=wPhF2pt0buPWLoDZE09fpdv5hNgcXE3T/k6c4DqOvYrDMQ5eLBkTLlCufLZDHdQAPb 9IuVqNJtUB/Q3szYXOj0DLUOtMFcHceqmNg7M5QGg4qWpupLDZE7hCoCqXGFuauNRYzE b4yD3sBJernmnRO+hiTiywJplCJzI2BvQmc2is7sI9UCEo8MRvndrdnkI1/+r9tEuPms M7TN9gwLKzt6SCZEnZqA4Zm5YczC7EEkEKxPTuDryMMy+1Jkxle9K1v4Sf3rFFuGMI5w 2pM6TTzVWXqzc6aJEKBtZ8mkjeslt42R+djuGPso7AsBFDE1bBou8V3y0h8OTbvdangY 6ihw== X-Forwarded-Encrypted: i=1; AJvYcCWtONK9JtznQOwBZ1Wd03rmjmPqgobCTfFlt9BCmCAEgTWSzodb6ybgeiC5RFLJi/pZMPhrn9wRFso3Q6stYbYr3LWuWauxdg== X-Gm-Message-State: AOJu0Yz3UacJji7VuJdbIwOYgeklgzXHmdiZs9cGsAO15o9mXCFz44Yc wcNs8aFDzpXV98xOULM1bkk4QOp+W+zjCLhSg/wmeDUK0F7YYx2x X-Google-Smtp-Source: AGHT+IEi5Fo0mfzbkazBUkhBten9x2EpbZPawUOZkgA8HsBOqk7kgEiCqkmki0JrAWF0LEzbDZoL5g== X-Received: by 2002:a17:90a:df90:b0:2b4:36d7:b6ad with SMTP id 98e67ed59e1d1-2b6cc340504mr8182346a91.4.1715633193891; Mon, 13 May 2024 13:46:33 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b671056503sm8343273a91.3.2024.05.13.13.46.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 May 2024 13:46:33 -0700 (PDT) Message-ID: <3c479063-8e5d-49e4-bb9c-e5df942c85f6@gmail.com> Date: Mon, 13 May 2024 14:46:32 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [RFC][PATCH] PR tree-optimization/109071 - -Warray-bounds false positive warnings due to code duplication from jump threading Content-Language: en-US To: Qing Zhao , gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, pinskia@gmail.com, keescook@chromium.org References: <20240513194830.1676938-1-qing.zhao@oracle.com> From: Jeff Law In-Reply-To: <20240513194830.1676938-1-qing.zhao@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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: On 5/13/24 1:48 PM, Qing Zhao wrote: > -Warray-bounds is an important option to enable linux kernal to keep > the array out-of-bound errors out of the source tree. > > However, due to the false positive warnings reported in PR109071 > (-Warray-bounds false positive warnings due to code duplication from > jump threading), -Warray-bounds=1 cannot be added on by default. > > Although it's impossible to elinimate all the false positive warnings > from -Warray-bounds=1 (See PR104355 Misleading -Warray-bounds > documentation says "always out of bounds"), we should minimize the > false positive warnings in -Warray-bounds=1. > > The root reason for the false positive warnings reported in PR109071 is: > > When the thread jump optimization tries to reduce the # of branches > inside the routine, sometimes it needs to duplicate the code and > split into two conditional pathes. for example: > > The original code: > > void sparx5_set (int * ptr, struct nums * sg, int index) > { > if (index >= 4) > warn (); > *ptr = 0; > *val = sg->vals[index]; > if (index >= 4) > warn (); > *ptr = *val; > > return; > } > > With the thread jump, the above becomes: > > void sparx5_set (int * ptr, struct nums * sg, int index) > { > if (index >= 4) > { > warn (); > *ptr = 0; // Code duplications since "warn" does return; > *val = sg->vals[index]; // same this line. > // In this path, since it's under the condition > // "index >= 4", the compiler knows the value > // of "index" is larger then 4, therefore the > // out-of-bound warning. > warn (); > } > else > { > *ptr = 0; > *val = sg->vals[index]; > } > *ptr = *val; > return; > } > > We can see, after the thread jump optimization, the # of branches inside > the routine "sparx5_set" is reduced from 2 to 1, however, due to the > code duplication (which is needed for the correctness of the code), we > got a false positive out-of-bound warning. > > In order to eliminate such false positive out-of-bound warning, > > A. Add one more flag for GIMPLE: is_splitted. > B. During the thread jump optimization, when the basic blocks are > duplicated, mark all the STMTs inside the original and duplicated > basic blocks as "is_splitted"; > C. Inside the array bound checker, add the following new heuristic: > > If > 1. the stmt is duplicated and splitted into two conditional paths; > + 2. the warning level < 2; > + 3. the current block is not dominating the exit block > Then not report the warning. > > The false positive warnings are moved from -Warray-bounds=1 to > -Warray-bounds=2 now. > > Bootstrapped and regression tested on both x86 and aarch64. adjusted > -Warray-bounds-61.c due to the false positive warnings. > > Let me know if you have any comments and suggestions. This sounds horribly wrong. In the code above, the warning is correct. Jeff