From patchwork Fri Nov 4 13:44:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 15525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp411694wru; Fri, 4 Nov 2022 06:46:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vXRdc+WgJqZsbbt8u4nCqC/DWhNQQbB7aAv00f9/u09zHZA5wxliW8ugiUodnqR4WQR/P X-Received: by 2002:a17:907:7244:b0:78d:cedc:7a9e with SMTP id ds4-20020a170907724400b0078dcedc7a9emr34540142ejc.600.1667569570602; Fri, 04 Nov 2022 06:46:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667569570; cv=none; d=google.com; s=arc-20160816; b=mJo62g55bhJE8gLbt3bMtenkjXz3AwI2xv02uuVOreJ1Z+20Gpx/jtmDSUby7pgq+k LDmTR64gMBAenaiGqsBYr5ZI4khQby+97fC95Lr+gkrC03wmdFM7DQj3l3w835nRzG9e Pff+eb8VFqzaJLnf5gw8lTWInn2mRbz4YTxDkqlRCy/aElrKIIp5Pvml8uX4N85r5i48 gt0NMS7pXPdvl5e6r+HinYf1C6NFsbpWbg17jaBIS2UBFM1icCQDhDuo6iQw+/27ei45 PAoxgxJ74wSiosqvdy9Pb0rgTNMCxDg0w8Fvx4vlQMDpMzv3mGfV9LCofQQKTGtwF03t +1dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=PqljkW5Gt+9XoJUg1yU15qhIpCcIQ9l9wZi0IX7wwp4=; b=yns+Qw6DmMgqNN3T3no2fek2k618TBJnsFNmC2OP6twny8SPA2U/5HF6/8VpLf9FmU DQaLqwwc0y7PPmNTYNFbn0Jh06KwhHd8z9lNK/N9WYQ1FzU0zgLtwvF2jRtEltoFg1Sz 5VxHgqbDiUCTw7aqFMxnXJbhNlJAD4kDCP/RK5Z6uMdUp/AuU0GX/cL4By9bRyQJxNez 0Q1dtIv7WCKH3FH3JYHnE1avo+vvZLPtyPEfh91RRi7SQcqMZNEORQDNLd/M39vm/+G/ PLrz5iKZeh/Iam4857svyQ3uhKc+6bxD9h9v3jidv8bcx0Pvwr/FSNivcnrDJ4sheJec cmRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HeI8HIkb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ht20-20020a170907609400b00782627f37d6si5954189ejc.778.2022.11.04.06.46.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:46:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HeI8HIkb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BEEE73857B93 for ; Fri, 4 Nov 2022 13:45:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEEE73857B93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667569533; bh=PqljkW5Gt+9XoJUg1yU15qhIpCcIQ9l9wZi0IX7wwp4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HeI8HIkbCGcqTv+P1KdcIFDUPpManSUtIyb3VVBFebCMO0y2xULWPTrYm5wOfpR8i 7mwve7QUyp5GRIphuO6R/Y77VDgPRVzf6IElXWrjp/3uc/vvjAQzjuztT/oh2QgVbo 8sjtfm1EUiMH/WBbV0xeI4eCSqMa4mqDlhvvERwc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 2099E3858286 for ; Fri, 4 Nov 2022 13:44:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2099E3858286 Received: by mail-qk1-x730.google.com with SMTP id k26so3056161qkg.2 for ; Fri, 04 Nov 2022 06:44:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PqljkW5Gt+9XoJUg1yU15qhIpCcIQ9l9wZi0IX7wwp4=; b=xtB8/TPQ19PFGdEL16OSbVy6nV2tY1NhUBZHjm3O62bxs4sa1k8O+nNp/P74DkMnco aHQApLAdTD8C8jh4VhcOs+mATRPO0SmUeU+u4rZuD8DRp4PxabmWV0mtw8PyGQqB8iA2 6JrL+sBAWvUjSLo9MLutNULP7JxHrRWd9iTKGQlBraBwKbDkrU/ZegZ7x7QRndbG0Rnk Mq4cF3tz66OpYxDpNP1fgofAcCcCr7nKSnJeuFhpFOIWyheIsogc3OSabQfp09fGbsL6 5ZrpBGuUZsK8543gLRd8IHwpoGEYWJv9wdbuJt09BlJKCzIJH9x5pI1b9YED28vzBlAU 3LMg== X-Gm-Message-State: ACrzQf2Ub+K9mi6gSrUhy37XYB0uZshS7Rn+Lz53Pj7up024M63RnYs8 +9hlMWjYZ0fRAD/EESfYjjar7WMs8fc= X-Received: by 2002:a37:6588:0:b0:6fa:3046:7f8b with SMTP id z130-20020a376588000000b006fa30467f8bmr19084106qkb.752.1667569483402; Fri, 04 Nov 2022 06:44:43 -0700 (PDT) Received: from localhost.localdomain (96-67-140-173-static.hfc.comcastbusiness.net. [96.67.140.173]) by smtp.gmail.com with ESMTPSA id ey21-20020a05622a4c1500b003988b3d5280sm2470577qtb.70.2022.11.04.06.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:44:42 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/6] libcpp: Fix paste error with unknown pragma after macro expansion Date: Fri, 4 Nov 2022 09:44:11 -0400 Message-Id: <2222c8ff04699ae5671e1b654aafe5502259feaa.1667514153.git.lhyatt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-3038.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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-Patchwork-Original-From: Lewis Hyatt via Gcc-patches From: Lewis Hyatt Reply-To: Lewis Hyatt Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748573429870457019?= X-GMAIL-MSGID: =?utf-8?q?1748573429870457019?= In directives.cc, do_pragma() contains logic to handle a case such as the new testcase pragma-omp-unknown.c, where an unknown pragma was the result of macro expansion (for pragma namespaces that permit expansion). This no longer works correctly as shown by the testcase, fixed by adding PREV_WHITE to the flags on the second token to prevent an unwanted paste. Also fixed the memory leak, since the temporary tokens are pushed on their own context, nothing prevents freeing of the buffer that holds them when the context is eventually popped. libcpp/ChangeLog: * directives.cc (do_pragma): Fix memory leak in token buffer. Fix unwanted paste between two tokens. gcc/testsuite/ChangeLog: * c-c++-common/gomp/pragma-omp-unknown.c: New test. --- gcc/testsuite/c-c++-common/gomp/pragma-omp-unknown.c | 10 ++++++++++ libcpp/directives.cc | 10 +++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/pragma-omp-unknown.c diff --git a/gcc/testsuite/c-c++-common/gomp/pragma-omp-unknown.c b/gcc/testsuite/c-c++-common/gomp/pragma-omp-unknown.c new file mode 100644 index 00000000000..04881f786ab --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pragma-omp-unknown.c @@ -0,0 +1,10 @@ +/* { dg-do preprocess } */ +/* { dg-options "-fopenmp" } */ + +#define X UNKNOWN1 +#pragma omp X +/* { dg-final { scan-file pragma-omp-unknown.i "#pragma omp UNKNOWN1" } } */ + +#define Y UNKNOWN2 +_Pragma("omp Y") +/* { dg-final { scan-file pragma-omp-unknown.i "#pragma omp UNKNOWN2" } } */ diff --git a/libcpp/directives.cc b/libcpp/directives.cc index 918752f6b1f..9dc4363c65a 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -1565,15 +1565,15 @@ do_pragma (cpp_reader *pfile) { /* Invalid name comes from macro expansion, _cpp_backup_tokens won't allow backing 2 tokens. */ - /* ??? The token buffer is leaked. Perhaps if def_pragma hook - reads both tokens, we could perhaps free it, but if it doesn't, - we don't know the exact lifespan. */ - cpp_token *toks = XNEWVEC (cpp_token, 2); + const auto tok_buff = _cpp_get_buff (pfile, 2 * sizeof (cpp_token)); + const auto toks = (cpp_token *)tok_buff->base; toks[0] = ns_token; toks[0].flags |= NO_EXPAND; toks[1] = *token; - toks[1].flags |= NO_EXPAND; + toks[1].flags |= NO_EXPAND | PREV_WHITE; _cpp_push_token_context (pfile, NULL, toks, 2); + /* Arrange to free this buffer when no longer needed. */ + pfile->context->buff = tok_buff; } pfile->cb.def_pragma (pfile, pfile->directive_line); }