From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zimbra.cs.ucla.edu (zimbra.cs.ucla.edu [131.179.128.68]) by sourceware.org (Postfix) with ESMTPS id F098C3858407 for ; Fri, 13 Aug 2021 22:34:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F098C3858407 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.ucla.edu Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 6F71F1600C3; Fri, 13 Aug 2021 15:34:15 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 4ODqkZsSy6hW; Fri, 13 Aug 2021 15:34:14 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id A474E1600EA; Fri, 13 Aug 2021 15:34:14 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id gQ_crebf10JW; Fri, 13 Aug 2021 15:34:14 -0700 (PDT) Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 830CA1600C3; Fri, 13 Aug 2021 15:34:14 -0700 (PDT) To: Martin Sebor Cc: GNU C Library References: <15a32181-8060-4135-cb72-9e79831697d5@gmail.com> From: Paul Eggert Organization: UCLA Computer Science Department Subject: Re: [PATCH] remove attribute access from regexec Message-ID: <4251e9f2-d4d1-b649-8e86-a4336164a5b1@cs.ucla.edu> Date: Fri, 13 Aug 2021 15:34:14 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Aug 2021 22:34:18 -0000 On 8/13/21 2:30 PM, Martin Sebor wrote: > Attached is a revised patch with this approach. The revised patch is to include/regex.h but the original patch was to=20 posix/regex.h. Is that intentional? We need to check whether __STDC_VERSION__ is defined. Also, no need for=20 parens around arg of 'defined'. Something like this perhaps: #if (defined __STDC_VERSION__ && 199901L <=3D __STDC_VERSION__ \ && !defined __STDC_NO_VLA__) Also, the duplication of the declarations make the headers harder to=20 read and encourage typos (I noticed one typo: "_Restrict_arr" without=20 the trailing "_"). Instead, I suggest something like this: #if (defined __STDC_VERSION__ && 199901L <=3D __STDC_VERSION__ \ && !defined __STDC_NO_VLA__) # define _REGEX_VLA(arg) arg #else # define _REGEX_VLA(arg) #endif That way, we can simply change "regmatch_t __pmatch[_Restrict_arr_]" to=20 "regmatch_t __pmatch[_Restrict_arr_ _REGEX_VLA (__nmatch)]" without=20 having to duplicate the entire function declaration. > PS POSIX says regexec() ignores pnmatch when REG_NOSUB is set, so > strictly speaking, warning for such calls to it in that case is > also a false positive. Ouch, this casts doubt on the entire exercise. It's not simply about=20 warnings: it's about the code being generated for the matcher. For=20 example, for: int f (_Bool flag, unsigned long n, int a[n]) { return n =3D=3D 0 ? 0 : flag ? a[n - 1] : a[0]; } a compiler is allowed to generate code that loads a[n - 1] even when=20 FLAG is false. Similarly, if we add this VLA business to regexec, the=20 generated machine code could dereference pmatch unconditionally even if=20 our source code makes the dereferencing conditional on REG_NOSUB, and=20 the resulting behavior would fail to conform to POSIX.