From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id F34733858D28 for ; Sat, 22 Oct 2022 16:54:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F34733858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-io1-xd33.google.com with SMTP id i65so4745995ioa.0 for ; Sat, 22 Oct 2022 09:54:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=8Ju2EbHH682BbbEykgkVwUbB9DSUncscJccNxbbXXow=; b=RHDQV0AGKy6ahkxrmeMQ1zpTUNQprGS3VFCDyNJ71FiT5bEN/kL/NnJM9y820XdUvN w42Y53AOhOqEQyw9kIEWEuVIYpWrvYFW9XMZ29eE54hdXqi32MnPDVf57sAvSUnDNOB0 u8zvf9dTaCTUZsVaqVeggVhNeb0+tc4V8Di6M6aKlQp8KW/0561ZB0OB26lWZCjIHdNh KCCwIgFYDQ8cA9q9OJjfEVx8E2m/j3+sJ51diC3nA3w2DDqGMJd1aep4mUuPe0sM4Ko1 bDwCZbichVRQJ7hPjdP686c+VsenoJS6tINJMmAJyTu57baJGOOWH9+ARLe/suEEJRKK WvQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=8Ju2EbHH682BbbEykgkVwUbB9DSUncscJccNxbbXXow=; b=rJygh3QwWFStA9H7/zbnxkR73eQnLAM8FnmlyOITdIN31rZ+NoJLEAlKoMqxYSiy2k p7I2V9Cg8gET9SGnUekqhzu1uxMsqSX2bWMaS/6ximLaMse0eMTNeNSvctBA5yQ/oEE9 pjTdUsHy9WMjjFqbl/LcINAohdIpafXUQQCstOieFZLrI7edd352dVM+WkvCUNMeXbUv i2PCYZib/NqxYeDULYVv6f2DskT6OBrvL7tlnTHnuAw23P5px/kAV+KCyCrRZNQWPI8x oMk/xyXdf49qlTp8x2LOMzf2fu7Y+s0o6vOe15Nxt6qm7Zj+JXRnJ8nSZIwBR22qwYTj 8GqA== X-Gm-Message-State: ACrzQf0vg5v/yhl1JIoEDscBquhpjVsiaVkmvGvt7XibczOh7AEx604v JBEM57MvMg4kQWxrgV/4nUs= X-Google-Smtp-Source: AMsMyM5fSrlupFkFi4RVuEYcgZ3cjlN3znt7PvAnIz4n42L28Bp9XV7QDwy6G1Fg5V8mn2ocf6XDjQ== X-Received: by 2002:a05:6638:16d2:b0:363:c860:a58e with SMTP id g18-20020a05663816d200b00363c860a58emr17596818jat.60.1666457678186; Sat, 22 Oct 2022 09:54:38 -0700 (PDT) Received: from [192.168.0.41] (97-118-98-114.hlrn.qwest.net. [97.118.98.114]) by smtp.gmail.com with ESMTPSA id g35-20020a028526000000b003722e5b561csm112811jai.52.2022.10.22.09.54.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 22 Oct 2022 09:54:37 -0700 (PDT) Message-ID: <56fa59d1-75d3-6698-51fb-3806b9559397@gmail.com> Date: Sat, 22 Oct 2022 10:54:36 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [RFC] how to handle the combination of -fstrict-flex-arrays + -Warray-bounds Content-Language: en-US To: Qing Zhao , Richard Biener , Jakub Jelinek Cc: gcc Patches References: <695014B4-2A9E-49D6-BD40-4B24644FA1D6@oracle.com> From: Martin Sebor In-Reply-To: <695014B4-2A9E-49D6-BD40-4B24644FA1D6@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,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 10/21/22 09:29, Qing Zhao wrote: > Hi, > > (FAM below refers to Flexible Array Members): > > I need inputs on how to handle the combination of -fstrict-flex-arrays + -Warray-bounds. > > Our initial goal is to update -Warray-bounds with multiple levels of -fstrict-flex-arrays=N > to issue warnings according to the different levels of “N”. > However, after detailed study, I found that this goal was very hard to be achieved. > > 1. -fstrict-flex-arrays and its levels > > The new option -fstrict-flex-arrays has 4 levels: > > level trailing arrays > treated as FAM > > 0 [],[0],[1],[n] the default without option > 1 [],[0],[1] > 2 [],[0] > 3 [] the default when option specified without value > > 2. -Warray-bounds and its levels > > The option -Warray-bounds currently has 2 levels: > > level trailing arrays > treated as FAM > > 1 [],[0],[1] the default when option specified without value > 2 [] > > i.e, > When -Warray-bounds=1, it treats [],[0],[1] as FAM, the same level as -fstrict-flex-arrays=1; > When -Warray-bounds=2, it only treat [] as FAM, the same level as -fstrict-flex-arrays=3; > > 3. How to handle the combination of -fstrict-flex-arrays and -Warray-bounds? > > Question 1: when -fstrict-flex-arrays does not present, the default is -strict-flex-arrays=0, > which treats [],[0],[1],[n] as FAM, so should we update the default behavior > of -Warray-bounds to treat any trailing array [n] as FAMs? > > My immediate answer to Q1 is NO, we shouldn’t, that will be a big regression on -Warray-bounds, right? Yes, it would disable -Warray-bounds in the cases where it warns for past-the-end accesses to trailing arrays with two or more elements. Diagnosing those has historically (i.e., before recent changes) been a design goal. > > Question 2: when -fstrict-flex-arrays=N1 and -Warray-bounds=N2 present at the same time, > Which one has higher priority? N1 or N2? > > -fstrict-flex-arrays=N1 controls how the compiler code generation treats the trailing arrays as FAMs, it seems > reasonable to give higher priority to N1, I tend to agree. In other words, set N2' = min(N1, N2). > However, then should we completely disable the level of -Warray-bounds > N2 under such situation? > > I really don’t know what’s the best way to handle the conflict between N1 and N2. > > Can we completely cancel the 2 levels of -Warray-bounds, and always honor the level of -fstrict-flex-arrays? > > Any comments or suggestion will be helpful. The recent -fstrict-flex-array changes aside, IIRC, there's only a subtle distinction between the two -Warray-bounds levels (since level 1 started warning on a number of instances that only level 2 used to diagnose a few releases ago). I think that subset of level 2 could be merged into level 1 without increasing the rate of false positives. Then level 2 could be assigned a new set of potential problems to detect (such as past-the-end accesses to trailing one-element arrays). Martin