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 697DC3858D28 for ; Thu, 10 Nov 2022 03:13:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 697DC3858D28 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=1668050028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gV15Yjyxu9zmPD8vvAUsworyg9kqAGalDPKkxRRdozQ=; b=JxB+U4XHQczJIaByQ1yiDoAti0T9iLQ0EozEgTpC/DTNgYdGsv/3z2wTWtWUsMiGkYSNlu cgoovxfzxUiBRygrKAGkZ8Lj1QoSkgIY4O3/v/MUbvEtK+9ZIg0oeTassaJgQAZdfIedeo R/K2ddihTZ8Hgqsf0tGCj/A1LCzyd38= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-84-eXK8F31lPQ-l9g7DQMsr6Q-1; Wed, 09 Nov 2022 22:13:46 -0500 X-MC-Unique: eXK8F31lPQ-l9g7DQMsr6Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 80ECC85A5A6 for ; Thu, 10 Nov 2022 03:13:46 +0000 (UTC) Received: from localhost (unknown [10.33.36.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BB4E112131B for ; Thu, 10 Nov 2022 03:13:46 +0000 (UTC) From: Jonathan Wakely To: gcc-patches@gcc.gnu.org Subject: [PATCH] c-family: Support #pragma region/endregion [PR85487] Date: Thu, 10 Nov 2022 03:13:45 +0000 Message-Id: <20221110031345.193991-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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: Something similar has been proposed before, but didn't get approval. Jeff wanted a more general framework for ignoring pragmas. It might make sense to do that, and reuse it for the Darwin-specific 'mark' pragmas. But as I said in the PR, I looked at the darwin ones and they are unique among all pragmas in GCC. I am not going there, sorry :-) In the PR it was suggested that we should check for syntax errors in these pragmas or make sure there are matching region/endregion pairs. I disagree. This is a simple, low-risk patch that removes unhelpful warnings for users who have these macros for their editor to process. It's not our business to check for correct use of these macros, their meaning is determined by other tools that we don't control. We should just not complain when we see them, and no more. Tested powerpc64le-linux. OK for trunk? -- >8 -- These pragmas are used by some editors to mark regions of code for grouping and folding. GCC should silently ignore them, rather than giving -Wunknown-pragmas warnings. PR c/85487 gcc/ChangeLog: * doc/cpp/pragmas.rst (Pragmas): Document region pragmas. gcc/c-family/ChangeLog: * c-pragma.cc (handle_pragma_ignore): New function. (init_pragma): Register region and endregion pragmas. gcc/testsuite/ChangeLog: * c-c++-common/pragma-region.c: New test. --- gcc/c-family/c-pragma.cc | 9 +++++++++ gcc/doc/cpp/pragmas.rst | 3 +++ gcc/testsuite/c-c++-common/pragma-region.c | 11 +++++++++++ 3 files changed, 23 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/pragma-region.c diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc index b5a4b3c970f..142a46441ac 100644 --- a/gcc/c-family/c-pragma.cc +++ b/gcc/c-family/c-pragma.cc @@ -1403,6 +1403,12 @@ handle_pragma_message (cpp_reader *) TREE_STRING_POINTER (message)); } +/* Ignore a no-op pragma that GCC recognizes, but which has no effect. */ +static void +handle_pragma_ignore (cpp_reader *) +{ +} + /* Mark whether the current location is valid for a STDC pragma. */ static bool valid_location_for_stdc_pragma; @@ -1870,6 +1876,9 @@ init_pragma (void) c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options); c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options); + c_register_pragma (0, "region", handle_pragma_ignore); + c_register_pragma (0, "endregion", handle_pragma_ignore); + c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64", handle_pragma_float_const_decimal64); diff --git a/gcc/doc/cpp/pragmas.rst b/gcc/doc/cpp/pragmas.rst index da07cebf4a1..78277d7b623 100644 --- a/gcc/doc/cpp/pragmas.rst +++ b/gcc/doc/cpp/pragmas.rst @@ -119,3 +119,6 @@ GCC plugins may provide their own pragmas. file will never be read again, no matter what. It is a less-portable alternative to using :samp:`#ifndef` to guard the contents of header files against multiple inclusions. + +``#pragma region {tokens}...``, ``#pragma endregion {tokens}...`` + These pragmas are accepted, but have no effect. diff --git a/gcc/testsuite/c-c++-common/pragma-region.c b/gcc/testsuite/c-c++-common/pragma-region.c new file mode 100644 index 00000000000..8e0cbe1f16f --- /dev/null +++ b/gcc/testsuite/c-c++-common/pragma-region.c @@ -0,0 +1,11 @@ +/* { dg-options "-Wunknown-pragmas" } */ +/* { dg-final { scan-assembler "code_within_region" } } */ +/* { dg-final { scan-assembler "code_within_named_region" } } */ + +#pragma region +void code_within_region() { } +#pragma endregion + +#pragma region ignored name +void code_within_named_region() { } +#pragma endregion // ignored comment -- 2.38.1