From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id E69813857B8A for ; Sat, 30 Jul 2022 19:59:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E69813857B8A Received: by mail-pg1-x52d.google.com with SMTP id d7so3496316pgc.13 for ; Sat, 30 Jul 2022 12:59:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=ZGvzbm588TmrLlCTNaa0KbE5J/dQuJP9i+cdGWc/sLE=; b=IR6tAFobwjNtLvxlLScZ7BmCwqX8OM9uxCKjpSwSRBoUCkyHUVctsJAinkhAjARtQM yIXJhvP40x6nJMX/fa1yAWuXOfX4pg2Fc8+9my9YRQBAH8LSY7QDIlsTKgDArjWmFBaC zCwpny9XsMs4RKBMrYnBsGtCo5ILO0wmKHcsv/NAVyXhNjF3Z8WE3kUjPMDjchSsLM4r z/E0fNmT9hUTYWXcLlFK7owscb+YtmrvNOJ+IY9xjfMqshW0z4nkW03iN5DISFWJoziO qz7UyVK4gIjl+ziMIZv8+MYino6bGdKO24gHqTHXqtBoTesCmXgKo0cbx1H9CyF+MEAA ayXA== X-Gm-Message-State: ACgBeo1V7fmGqOKOunvdd7sFL47Y+isKZyhYTHzylJYbIRleioESbZ8z 0AMX9UHLnSvs8Do4hrLMd0EWeFuGTUM= X-Google-Smtp-Source: AA6agR6mQftoEbfnh2NjnUX0MtdIblV2m687rCSh8Ia+gjZeRZNERnl32AiCFnJYe94ENfZe5Uhk8Q== X-Received: by 2002:a63:84c1:0:b0:41b:ebff:f3bf with SMTP id k184-20020a6384c1000000b0041bebfff3bfmr903383pgd.435.1659211156527; Sat, 30 Jul 2022 12:59:16 -0700 (PDT) Received: from [172.31.0.204] (c-73-98-188-51.hsd1.ut.comcast.net. [73.98.188.51]) by smtp.gmail.com with ESMTPSA id x14-20020a63cc0e000000b0041aa01c8bb0sm4601481pgf.10.2022.07.30.12.59.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Jul 2022 12:59:16 -0700 (PDT) Message-ID: <2b81d8e7-7bc7-3a43-2680-925a31c254e6@gmail.com> Date: Sat, 30 Jul 2022 13:59:15 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] c++: Fix location for -Wunused-macros [PR66290] Content-Language: en-US To: gcc-patches@gcc.gnu.org References: <62328b0cdbdd374fdca89723306c34331d0531fa.1659015329.git.lhyatt@gmail.com> From: Jeff Law In-Reply-To: <62328b0cdbdd374fdca89723306c34331d0531fa.1659015329.git.lhyatt@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Jul 2022 19:59:19 -0000 On 7/28/2022 8:01 AM, Lewis Hyatt via Gcc-patches wrote: > In C++, since all tokens are lexed from libcpp up front, diagnostics generated > by libcpp after lexing has completed do not get a valid location from libcpp > (rather, libcpp thinks they all pertain to the end of the file.) This has long > been addressed using the global variable "done_lexing", which the C++ frontend > sets at the appropriate time; when done_lexing is true, then c_cpp_diagnostic(), > which outputs libcpp's diagnostics, uses input_location instead of the wrong > libcpp location. The C++ frontend arranges that input_location will point to the > token it is currently processing, so this generally works fine. However, there > is one exception currently, which is -Wunused-macros. This gets generated at the > end of processing in cpp_finish (), since we need to wait until then to > determine whether a macro was eventually used or not. But the locations it > passes to c_cpp_diagnostic () were remembered from the original lexing and hence > they should not be overridden with input_location, which is now the one > incorrectly pointing to the end of the file. > > Fixed by setting done_lexing=false again just prior to calling cpp_finish (). I > also renamed the variable from done_lexing to "override_libcpp_locations", since > it's now not strictly about lexing anymore. > > There is no new testcase with this patch, since we already had an xfailed > testcase which is now fixed. > > gcc/c-family/ChangeLog: > > PR c++/66290 > * c-common.h: Rename global done_lexing to > override_libcpp_locations. > * c-common.cc (c_cpp_diagnostic): Likewise. > * c-opts.cc (c_common_finish): Set override_libcpp_locations > (formerly done_lexing) immediately prior to calling cpp_finish (). > > gcc/cp/ChangeLog: > > PR c++/66290 > * parser.cc (cp_lexer_new_main): Rename global done_lexing to > override_libcpp_locations. > > gcc/testsuite/ChangeLog: > > PR c++/66290 > * c-c++-common/pragma-diag-15.c: Remove xfail for C++. Ewww.  But OK. Jeff