From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2088.outbound.protection.outlook.com [40.107.8.88]) by sourceware.org (Postfix) with ESMTPS id DE7E13858D37 for ; Wed, 2 Aug 2023 10:47:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE7E13858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kOTKUROpOZF6GQXLz3KNSJNuP2ACdHtL9ASMpanfusM=; b=VspwgT8gdMDApwvKeENt6eEDEvphIKrYdg1k92CVDbf8E4XRI5N4IwDXZBUcW67zpm68QBQESCEPSQvU4bzRz3rexW4y88qlkcoQWeOMZ16BfMyDau9q/ny/gKZEvxbQPyQNCmz+kMjn2h6zK2fmtITrOXJ35FLHRe9hq3yIHe4= Received: from AS9PR06CA0213.eurprd06.prod.outlook.com (2603:10a6:20b:45e::12) by DBAPR08MB5864.eurprd08.prod.outlook.com (2603:10a6:10:1a0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.45; Wed, 2 Aug 2023 10:47:22 +0000 Received: from AM7EUR03FT017.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45e:cafe::50) by AS9PR06CA0213.outlook.office365.com (2603:10a6:20b:45e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.44 via Frontend Transport; Wed, 2 Aug 2023 10:47:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT017.mail.protection.outlook.com (100.127.140.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.45 via Frontend Transport; Wed, 2 Aug 2023 10:47:21 +0000 Received: ("Tessian outbound e1fdbe8a48d3:v145"); Wed, 02 Aug 2023 10:47:21 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 944798376daebfdb X-CR-MTA-TID: 64aa7808 Received: from 9183277d06c7.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 363CAD81-4AB0-4D56-BB36-4EDD307DFB04.1; Wed, 02 Aug 2023 10:47:15 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9183277d06c7.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 02 Aug 2023 10:47:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DCXqDMPrm0s/Xcv5/vqYL1QEUsVkZZJZwEfpid7lYJgT0MdCR08w7RU2qFv+4kK1GPUnYVxrRyekhTUkAyKAMMOseSElTucqX9RrRZYYBD/bnADKwNTdMcs8rtizWUly6nP5FKOlDYRqrSuvCkPsIVAlwOUWmL5/iuoEnPKKnDafANI0AtTktyjlvl0K/dRAx/Knx2Dk9u12SlGK5sYLxbKTNR4jrKERq93V30hhGS/xLc3f6DBYcbISNtz+eb8UCNUWVzrbCbYfCJBP0z3xERWQyYX3Wnx0Nj5nXb06LM+5N9lllM+zIzdmAFcI9TCDjXoTEPX8E3Zot5e9st2Mhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kOTKUROpOZF6GQXLz3KNSJNuP2ACdHtL9ASMpanfusM=; b=OgPqRi1ZM4Da7CKpEAKpyBZALX/EOkxZoNfBkIjg9CcAmbulwDFF025utMOZNpQXMcJn2ORzRJNZn8xrZhXfwsGMevTb8eDWuuAfZTZFQNISC+dto3/1Tj4fWizVv6UoMYxAYbHHRTvDgPOd1AjNAc+mPqdR+6fVtm7Jd5fTX8dGvnFf5upnCCVjNEis8IRh/3QpGjCTKpjQeJMfzthiIyubZV+gEVDBHrB+gednYCaO+X4fQbY8Bg8Vc614zOFLSpLOXGdEJoRUX6N2RDh+FvlltmvXNxzal07pgAmuxctA6A4NCZGLGLwWTEqiD2eCxoWa3EjC6/XuIYWU3juNMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kOTKUROpOZF6GQXLz3KNSJNuP2ACdHtL9ASMpanfusM=; b=VspwgT8gdMDApwvKeENt6eEDEvphIKrYdg1k92CVDbf8E4XRI5N4IwDXZBUcW67zpm68QBQESCEPSQvU4bzRz3rexW4y88qlkcoQWeOMZ16BfMyDau9q/ny/gKZEvxbQPyQNCmz+kMjn2h6zK2fmtITrOXJ35FLHRe9hq3yIHe4= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from PAWPR08MB8958.eurprd08.prod.outlook.com (2603:10a6:102:33e::15) by AS8PR08MB8109.eurprd08.prod.outlook.com (2603:10a6:20b:54b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.45; Wed, 2 Aug 2023 10:47:13 +0000 Received: from PAWPR08MB8958.eurprd08.prod.outlook.com ([fe80::f352:a0c5:bddf:2510]) by PAWPR08MB8958.eurprd08.prod.outlook.com ([fe80::f352:a0c5:bddf:2510%7]) with mapi id 15.20.6631.045; Wed, 2 Aug 2023 10:47:13 +0000 Date: Wed, 2 Aug 2023 11:47:07 +0100 From: Alex Coplan To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, Nathan Sidwell , Joseph Myers , Iain Sandoe Subject: Re: [PATCH v2][RFC] c-family: Implement __has_feature and __has_extension [PR60512] Message-ID: References: Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: LO4P265CA0138.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c4::9) To PAWPR08MB8958.eurprd08.prod.outlook.com (2603:10a6:102:33e::15) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: PAWPR08MB8958:EE_|AS8PR08MB8109:EE_|AM7EUR03FT017:EE_|DBAPR08MB5864:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a3fd467-7c9c-4d4c-7b7c-08db9345d9e3 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Lvmnrr+c2lgPAr7Wc30PheFWW7MNLOXRi/NPLmd/NDNWBBEHqgYW6MHZly5adkuhpAKVauq69G62r19LnnccXZ8tPQ4US3z4u2QVeGfjYqbTKTfMzLv2tpPSJDU1MzL2SJGOC4YCZWZHxKxmk5lcpCCucN4OEGfvTKmilHkxh2IquiDBYzef3T2EiSf52h/LO5gCavHoB0YO5FkOdy3ZYVwY8muMC68vOnrjUQNZII3LFrElaue9Uw+u7AUfSbI/pTavcvobZAx7W6ttQhKNC7sccPV4xISrpC4JxTcvRUHQCZufHdRi9m2DSo2471YAvfCxXON/YPT2wDknpTn2OHKIQxQGAVpJw5ky3fbFCurl3AH8Zflrj+6Dyt9o+UEUoMWBzZgpyN76a5pE9rBo4kCFYojUbr8zep60SPPAIns7R23K44jEhbcYRY4BL3SCgrFGMMaURExzuYN44Ghff2UF3TOPyp/Ak3lgst0y/DoJYYpPc8HmG3JJLmLhUo+oWg2zQ9kAeCrbHMayH5++OXFOqWSkjt+f+U4U5s9C7PY= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAWPR08MB8958.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(396003)(136003)(366004)(376002)(39860400002)(451199021)(186003)(8936002)(83380400001)(8676002)(26005)(41300700001)(2906002)(5660300002)(44832011)(2616005)(86362001)(478600001)(54906003)(316002)(38100700002)(53546011)(6506007)(6486002)(66946007)(66476007)(6666004)(66556008)(6916009)(4326008)(6512007)(966005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8109 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 5724a2a2-b224-4aa4-6181-08db9345d3b9 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rbgk6P6rTMiaROGTu+QBHvMJkJVWFlBvPovNmbYDyKkE3tdqd+/uikMnfF9JfvJVtjOPHsHiK62HVU2hhJDyOW0mVEBF1GvbfeGl7eMivQD22ANn+OOVxT2sKtveDrCyiUTVVET77Ma1ikts0WYKXBBiEOIs37TXuJuS4qQ8Oj0DifE7tuq6qhhJbdUz34KCkNCejED+4cuYIsxJuzTK4NHSWxTlIzWvVH308YWMwXbQy5/N4NgxPhEdyLhKD9+1/XzjRw9uu8b+Avf0tnZHyC73Ke5LAyYjItPTzpxCksh1OSTM44SeTXIlLFKAqNIGlUrWxVYxcaGK8j8d5UoEhRzFNvv7jqW2CP3rQi+m7m2wnHCaKjpZX4+K8Pd06zjNw85yHqZyA45tYcTi20UJyXzYWY2DTGdmHjol7OJpQv2j0zsn0R94j1QUy13g8VZx71CFRU3zDLN2vBpBUQUGda+D29QanIVMzrM5iTDlIITsPkHhQIU943QMwwK9UOpiJM3PzADmwY0wtoPs4JXrPOK9YD+A9ioyPVzmquaF7XGVWomZPoyyJ0wPehBdrE5QG9FlWzBE+HYtExF623dRsk1uHsqiSjzqjaqETokOgeDERZwGz7wdag9S29jKc0PhAjxSijEoWqV5H37pO4oYmChUeD7ruAVWyvXObM2EiiYgFhpCYesAjMA/IswYmPhF0Vq96RUfsXfdNr1BG0zmNsitkczBG0JEKtz9TdZa+aiPNMfmp4HG/eQ/r3Keg5fny8p6MZdSZwl2aT8C/80+xg== X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230028)(4636009)(39850400004)(346002)(396003)(136003)(376002)(82310400008)(451199021)(36840700001)(40470700004)(46966006)(8936002)(8676002)(5660300002)(26005)(41300700001)(107886003)(36860700001)(2906002)(83380400001)(44832011)(6862004)(47076005)(36756003)(40460700003)(336012)(2616005)(40480700001)(478600001)(54906003)(81166007)(316002)(86362001)(6506007)(53546011)(82740400003)(6486002)(356005)(70586007)(70206006)(6666004)(4326008)(186003)(6512007)(966005);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2023 10:47:21.9710 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a3fd467-7c9c-4d4c-7b7c-08db9345d9e3 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5864 X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,KAM_DMARC_NONE,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no 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 26/07/2023 16:26, Jason Merrill wrote: > On 6/28/23 06:35, Alex Coplan wrote: > > Hi, > > > > This patch implements clang's __has_feature and __has_extension in GCC. > > This is a v2 of the original RFC posted here: > > > > https://gcc.gnu.org/pipermail/gcc-patches/2023-May/617878.html > > > > Changes since v1: > > - Follow the clang behaviour where -pedantic-errors means that > > __has_extension behaves exactly like __has_feature. > > - We're now more conservative with reporting C++ features as extensions > > available in C++98. For features where we issue a pedwarn in C++98 > > mode, we no longer report these as available extensions for C++98. > > - Switch to using a hash_map to store the features. As well as ensuring > > lookup is constant time, this allows us to dynamically register > > features (right now based on frontend, but later we could allow the > > target to register additional features). > > - Also implement some Objective-C features, add a langhook to dispatch > > to each frontend to allow it to register language-specific features. > > Hmm, it seems questionable to use a generic langhook for something that the > generic code doesn't care about, only the c-family front ends. A common > pattern in c-family is to declare a signature in c-common.h and define it > differently for the various front-ends, i.e. in the *-lang.cc files. Thanks. I wasn't sure if, for each frontend, there was a source file that gets linked into exactly one frontend, but it looks like the *-lang.cc files will do the job. I'll rework the patch to drop the langhook and use this approach instead. > > > There is an outstanding question around what to do with > > cxx_binary_literals in the C frontend for C2x. Should we introduce a new > > c_binary_literals feature that is a feature in C2x and an extension > > below that, or should we just continue using the cxx_binary_literals > > feature and mark that as a standard feature in C2x? See the comment in > > c_feature_table in the patch. > > What does clang do here? The status quo in clang is that there is no identifier that gets reported as a feature for this in C (even with -std=c2x). cxx_binary_literals is reported just as an extension (even with -std=c2x). It does seem that there should be at least one identifier which reports this as a feature with -std=c2x, though. WDYT? > > > There is also some doubt over what to do with the undocumented "tls" > > feature. In clang this is gated on whether the target supports TLS, but > > in clang (unlike GCC) it is a hard error to use TLS when the target > > doesn't support it. In GCC I believe you can always use TLS, you just > > get emulated TLS in the case that the target doesn't support it > > natively. So in this patch GCC always reports having the "tls" feature. > > Would appreciate if anyone has feedback on this aspect. > > Hmm, I don't think GCC always supports TLS, given that the testsuite has a > predicate to check for that support (and others to check for emulated or > native support). Hmm, I see there is a check_effective_target_tls predicate for this, indeed. I wonder if this might be a holdover, though. I can't seem to configure a GCC without TLS. Even if I configure with --target=aarch64-none-elf --disable-tls, for example, I get emutls if I compile code using thread-local variables. Do we know of a GCC configuration where thread-local variables actually get rejected (and hence check_effective_target_tls returns false)? > > But I think it's right to report having "tls" for emulated support. > > > I know Iain was concerned that it should be possible to have > > target-specific features. Hopefully it is clear that the design in this > > patch is more amenable in this. I think for Darwin it should be possible > > to add a targetcm hook to register additional features (either passing > > through a callback to allow the target code to add to the hash_map, or > > exposing a separate langhook that the target can call to register > > features). > > The design seems a bit complicated still, with putting a callback into the > map. Do we need the callbacks? Do we expect the value of __has_feature to > change at different points in compilation? Does that happen in clang? This is a good point. Certainly if we were to add features that depend on the target architecture features, then this can change mid-way through a TU, so having this flexibility in the design does provide some potential future-proofing. I had a look through the existing features, and I did wonder about cases like this: __attribute__((no_sanitize("undefined"))) int f() { return __has_feature (undefined_behavior_sanitizer); } but of course since __has_feature is evaluated during preprocessing, there's no way that the attribute could be taken into account here (and indeed clang does not). I'll drop the callbacks from the patch for now, unless you think we should keep them for future-proofing. > > > Bootstrapped/regtested on aarch64-linux-gnu and x86_64-apple-darwin. Any > > thoughts? > > Most of the patch needs more comments, particularly before various top-level > definitions. Ack. I'll add more comments in the next revision. Thanks a lot for the review. Alex > > Jason >