From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E116F38A9091 for ; Tue, 15 Nov 2022 18:39:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E116F38A9091 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668537581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=w1v8TRnQ3+HhjZWglJgI3scV5UHW3IjbW1oA1vBY6Ug=; b=LMdrkdlWDSsVw7e3WAU5r/8374y+aTVCoWrKKGkf2kcSLJwCxnZrEZdABdr/CACv6KdCPS dRByZP9HkuE9X3rZWxvdS5Ac9JI92hW7L8hrkfkwhTv8/hSPjJSTNhM3fwqngCpN4jRwX1 667JcY2nkMm+JO1UBJdTXKWG3UsDUXI= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-118-3q5SYBG2O9u1dbxwhUbHmQ-1; Tue, 15 Nov 2022 13:39:40 -0500 X-MC-Unique: 3q5SYBG2O9u1dbxwhUbHmQ-1 Received: by mail-qk1-f199.google.com with SMTP id bj1-20020a05620a190100b006fa12a05188so14444439qkb.4 for ; Tue, 15 Nov 2022 10:39:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w1v8TRnQ3+HhjZWglJgI3scV5UHW3IjbW1oA1vBY6Ug=; b=Tq1raZ2lBMkD/1DHetWmrDjsSHFr/8kEBOJj0ntp8zVGcfnzytK+naRdGWZmSw+dpq kdWVYVAPR6XHbaU+VUPQTQ9MWcL+Nzo/U89K6/k+jFguh2YHC0qYBUr751i96RGpNdHD OXZ9Dbqs9LamCkxa6qWveFa5S3irD+mA024ho6dSuViQPOBpbwif59ew+6XSvAGPGuty UktC0MhGNWQDPxkrZLWKsN2sdkF4IEoJ3i6W0U/+87dKw5IBesiW+toTydYkOIei7Ieq tr/iX1cYA2nFc7ca6iU75foy4vzq1siw1Hbahszy1dH/ZJLhOVhhzGiKUVBApnSkJTSz UFWw== X-Gm-Message-State: ANoB5pnnrZUU9vyI8uOSsXxfFoXwKKjLkaikmXeOtWup5lMy0gCyKeg+ lzG11b/PPICAQlmxfSXfOvSp0/5zpv6OprP1lpMp7YHvDT7mtCjf03EqTXkjBh3UC6xFLhjxkmW 40noa8/JCOnR/lYBFDg== X-Received: by 2002:a37:b405:0:b0:6fa:2060:13f8 with SMTP id d5-20020a37b405000000b006fa206013f8mr16456332qkf.772.1668537579871; Tue, 15 Nov 2022 10:39:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf7XsUB+EBLenettsZbs67DHDZBd+cKX6G+STl9PX6l3TxoX2rEEbL19qHgd6cc+ECWWGoc33A== X-Received: by 2002:a37:b405:0:b0:6fa:2060:13f8 with SMTP id d5-20020a37b405000000b006fa206013f8mr16456307qkf.772.1668537579641; Tue, 15 Nov 2022 10:39:39 -0800 (PST) Received: from redhat.com (2603-7000-9500-2e39-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:2e39::1db4]) by smtp.gmail.com with ESMTPSA id v7-20020a05620a0f0700b006bba46e5eeasm8768938qkl.37.2022.11.15.10.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 10:39:39 -0800 (PST) Date: Tue, 15 Nov 2022 13:39:37 -0500 From: Marek Polacek To: David Malcolm Cc: gcc-patches@gcc.gnu.org, Joseph Myers Subject: Re: [PATCH v3] c, analyzer: support named constants in analyzer [PR106302] Message-ID: References: <20221112032310.2723361-1-dmalcolm@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.7 (2022-08-07) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 Tue, Nov 15, 2022 at 01:35:05PM -0500, David Malcolm wrote: > On Mon, 2022-11-14 at 15:42 -0500, Marek Polacek wrote: > > On Fri, Nov 11, 2022 at 10:23:10PM -0500, David Malcolm wrote: > > > Changes since v1: ported the doc changes from texinfo to sphinx > > > > > > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. > > > > > > Are the C frontend parts OK for trunk? (I can self-approve the > > > analyzer parts) > > > > Sorry for the delay. > > > > > The patch adds an interface for frontends to call into the analyzer > > > as > > > the translation unit finishes. The analyzer can then call back > > > into the > > > frontend to ask about the values of the named constants it cares > > > about > > > whilst the frontend's data structures are still around. > > > > > > The patch implements this for the C frontend, which looks up the > > > names > > > by looking for named CONST_DECLs (which handles enum values). > > > Failing > > > that, it attempts to look up the values of macros but only the > > > simplest > > > cases are supported (a non-traditional macro with a single > > > CPP_NUMBER > > > token). It does this by building a buffer containing the macro > > > definition and rerunning a lexer on it. > > > > > > The analyzer gracefully handles the cases where named values aren't > > > found (such as anything more complicated than described above). > > > > > > The patch ports the analyzer to use this mechanism for "O_RDONLY", > > > "O_WRONLY", and "O_ACCMODE". I have successfully tested my socket > > > patch > > > to also use this for "SOCK_STREAM" and "SOCK_DGRAM", so the > > > technique > > > seems to work. > > > > So this works well for code like > > > > enum __socket_type { > > SOCK_STREAM = 1, > > > > #define SOCK_STREAM SOCK_STREAM > > }; > > > > ? > > Yes: c_translation_unit::lookup_constant_by_id does the "lookup_name" > first, and this finds the CONST_DECL, so it doesn't need to look at > macros for this case. Ah, nice. > I've added a testcase for this in the v3 patch (gcc.dg/analyzer/named- > constants-via-enum-and-macro.c) Thanks. > Thanks for the review. Here's a v3 version of the patch. > > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. > > Are the C FE parts OK for trunk? Ok, thanks. Marek