From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 1AB5C3858C62 for ; Wed, 12 Oct 2022 17:09:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1AB5C3858C62 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-pj1-x1031.google.com with SMTP id o9-20020a17090a0a0900b0020ad4e758b3so2651235pjo.4 for ; Wed, 12 Oct 2022 10:09:30 -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:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=WOUOpiSRkz8xfkUkiPdHoBmq22zts/uzmahopfQuR3I=; b=YnUlVp19kyK6lMU3ftapgvZ+sc5pfT5g9D85ax8YJZBZssFqOZgbsjePmmOkMxqdoz 7RmwyO24vMTVGAgA5QVtAj35qZGM9CBKgGBUOXqJeImVrbW4qYtB0ASRlljcwsiHHQ4u rTTh0+9DeGRkKSfd3J0l1hlA/GBNyA7KAjbke0etNpeLtHCsIRoLXorfuUwY4G+Ex96w ypEDoy3nCXxMXfdCPo8CMMNNSJwayOpOCwss7CyOl3qup5RFw1NuaFyR//fdy+v/4UYx kKmc5PB5mRoVErq/q/VPYtT2z6QSg6nut3qpVUeiSsgmXn3XwPR8QzHqSMFpH2Uiub/p FSLQ== 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: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=WOUOpiSRkz8xfkUkiPdHoBmq22zts/uzmahopfQuR3I=; b=oUXXPogPVbIkGZrYrFfg2P1LZEKo4Ffbxxf/nqzk/f3TqNfFQs53LIIU0bp/0N+Zgc mebNgXbweeyRlH+bEh9yfZoiMMQ82Fr7XO6r6sd+wXMrYsX4FFkEXxDDwM9ahnX6wt6G Kj5ciUXz5GFxb/+mlo5SQaISZtYOGJ6z7Ajo7Jz2KDEJLrJIVHrpIp9mOPAB+IuMQVYH Pg/MMJWgJmTrsutSymoHKNCq9yWbkClLBaCC6xrGifRfUe2l5MtEDNeQhiPCaScUK8yU zydJIN9zMpOSlC1/0VBRb4mHcvMcFV+RTidpo1BF6iAvfF0irsoxlySJ67nbMRqMkYLh 7ipA== X-Gm-Message-State: ACrzQf0MwARBkshGds+eGGmVmKxgoivA0BervRBXeD5CunwUPpMjiTbN H3kKeZfrfMAuVtzK9xDrgHTsmo9mzU1/HA== X-Google-Smtp-Source: AMsMyM5AX6hw8EDE6GhCTRbEqqoL4/ThqnDRVlquwRyWbBnSbxu/3BDUTJKzglNB3y2guuzmTBL3xQ== X-Received: by 2002:a17:90b:2643:b0:205:bd0d:bdff with SMTP id pa3-20020a17090b264300b00205bd0dbdffmr6061774pjb.99.1665594568524; Wed, 12 Oct 2022 10:09:28 -0700 (PDT) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id h9-20020a17090a054900b0020adf65cebbsm1708147pjf.8.2022.10.12.10.09.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Oct 2022 10:09:28 -0700 (PDT) Message-ID: Date: Wed, 12 Oct 2022 11:09:27 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH] preprocessor: Fix tracking of system header state [PR60014, PR60723] Content-Language: en-US To: gcc-patches@gcc.gnu.org References: <5dce970b21e788deaa3d08f21995d8cb3cdb3752.1665263871.git.lhyatt@gmail.com> From: Jeff Law In-Reply-To: <5dce970b21e788deaa3d08f21995d8cb3cdb3752.1665263871.git.lhyatt@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.0 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/8/22 15:18, Lewis Hyatt via Gcc-patches wrote: > The token_streamer class (which implements gcc mode -E and > -save-temps/-no-integrated-cpp) needs to keep track whether the last tokens > output were in a system header, so that it can generate line marker > annotations as necessary for a downstream consumer to reconstruct the > state. The logic for tracking it, which was added by r5-1863 to resolve > PR60723, has some edge case issues as revealed by the three new test > cases. The first, coming from the original PR60014, was incidentally fixed by > r9-1926 for unrelated reasons. The other two were still failing on master > prior to this commit. Such code paths were not realizable prior to r13-1544, > which made it possible for the token streamer to see CPP_PRAGMA tokens in more > contexts. > > The two main issues being corrected here are: > > 1) print.prev_was_system_token needs to indicate whether the previous token > output was in a system location. However, it was not being set on every token, > only on those that triggered the main code path; specifically it was not > triggered on a CPP_PRAGMA token. Testcase 2 covers this case. > > 2) The token_streamer uses a variable "line_marker_emitted" to remember > whether a line marker has been emitted while processing a given token, so that > it wouldn't be done more than once in case multiple conditions requiring a > line marker are true. There was no reason for this to be a member variable > that retains its value from token to token, since it is just needed for > tracking the state locally while processing a single given token. The fact > that it could retain its value for a subsequent token is rather difficult to > observe, but testcase 3 demonstrates incorrect behavior resulting from > that. Moving this to a local variable also simplifies understanding the > control flow going forward. > > gcc/c-family/ChangeLog: > > PR preprocessor/60014 > PR preprocessor/60723 > * c-ppoutput.cc (class token_streamer): Remove member > line_marker_emitted to... > (token_streamer::stream): ...a local variable here. Set > print.prev_was_system_token on all code paths. > > gcc/testsuite/ChangeLog: > > PR preprocessor/60014 > PR preprocessor/60723 > * gcc.dg/cpp/pr60014-1.c: New test. > * gcc.dg/cpp/pr60014-1.h: New test. > * gcc.dg/cpp/pr60014-2.c: New test. > * gcc.dg/cpp/pr60014-2.h: New test. > * gcc.dg/cpp/pr60014-3.c: New test. > * gcc.dg/cpp/pr60014-3.h: New test. OK jeff