From patchwork Tue Jun 27 15:29:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 113487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8297756vqr; Tue, 27 Jun 2023 08:50:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4URLHBQWVzXNIkc2BZnmaidEWddHixscrcaRXaMf7D17gksYZhIxK26PZblcxpMcR5YYAk X-Received: by 2002:a05:6a21:3392:b0:123:7989:ba55 with SMTP id yy18-20020a056a21339200b001237989ba55mr15456128pzb.41.1687881038639; Tue, 27 Jun 2023 08:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687881038; cv=none; d=google.com; s=arc-20160816; b=pJqwqKKndMtKlefTviKx43IVQ8Fz0dqMikyNlqgs+AGRQMgB4tgwDT3Ef9tyGDZYO7 vEkcMOqcrKYUc6+ElR7G3XmA9zroywvbiPWKC4hj0jjSI8RBkTZzcJjFjZEl0oz52N+F +u/fp86/4DckTMFlCDfjar1R7i6nsYm1w29W9fhhlreyeVDh2jJksM8OZfUugPDpJjAR NjLtUW9qdOGD0MoNAHQqL9zadze/1e2tZQdUq23EprpjgZbK20VBgluRiBsytf5cOxp2 t0ruPuT6Pj0BbGyszbtlvkBoaRlZux1Nnhb8G8T9qe9xdHV1AkHJBs6nMU7LL+oMqJWZ 3JqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QZDyc+LphveGbkV8flCr5/AlZBA+s2syS9K6n52w050=; fh=HjVUg7QR3dsJtud2zMTn2hjb/BaTIryYfe/7zrQJEa8=; b=ogROovw5w/8fMX2YYxyVEHCNApc4S5bxafBhprVksqTu/oeDPqNVgSP8ZOkqlJubsY r8Ct/IgMLT/ITrTsuRJm1+2Y08NQ2P8NMizYzxU4JppjhgKs/2tLq12zkjbXBM6Uc/tC +rtXx5hvfrdN1n29LtIF8cpHuplPy60OrwWHZ6EkemxU4QO6rrrR3gCDqy5GWQMwtz7f xRpxHrFMQUzeyx4rEONz2YDXAPpVsDowmmWbJSyuTIQXE0U1TeN0Oe8dtnuoq4EKoeuc xVO9fsK5ei6Jm6pYJODw6DZ5GsjS2IAZUbP8fFHWUYoTBaVkBpCHC5o8a91SAXEcpsKD HDEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=hXNcy6nC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020a056a00085100b0064d2d8d7c33si7838119pfk.45.2023.06.27.08.50.25; Tue, 27 Jun 2023 08:50:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=hXNcy6nC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232420AbjF0P3x (ORCPT + 99 others); Tue, 27 Jun 2023 11:29:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231924AbjF0P3n (ORCPT ); Tue, 27 Jun 2023 11:29:43 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1309E2942; Tue, 27 Jun 2023 08:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1687879779; bh=oKkXMwl9CppgPR3HEtDQfgVFXUAQ6EoIiQSv7ieSscM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hXNcy6nCTJIqA16UhPSgfyd6AmV61FoDTnapkgcJ42vPjzC5RL+3HyDJCfADcjXKz qhH8QxzBY3MBiUTblRqiY2gzlwUztpGUHOnefGoLogsru3uDCxZx9GV6NMw2u3U87k uZFgwcGLpCBzuzh+iIJ3Egtrv3EU+t6PGpl8e7vJhLQpUvr2/Oxi9tNLFbqLDWx6dB QEq7SIdMs/UB2+4uZtMup+3ZAMWza3WUDlYXJPN1IkRZBpxhVPGaeG7kgtRjkAc+qv bZsKJrTeuD11edopYYKU10/3SBu7m7Uwb+yVAQen3jLIoFlRHNfUtFir9yzWxURvyg jSAzD8CS+++YA== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4Qr7tW19F9z19RQ; Tue, 27 Jun 2023 11:29:39 -0400 (EDT) From: Mathieu Desnoyers To: Shuah Khan Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Peter Zijlstra , "Paul E . McKenney" , Boqun Feng , "H . Peter Anvin" , Paul Turner , linux-api@vger.kernel.org, linux-kselftest@vger.kernel.org, Mathieu Desnoyers Subject: [PATCH 2/4] selftests/rseq: Implement rseq_unqual_scalar_typeof Date: Tue, 27 Jun 2023 11:29:21 -0400 Message-Id: <20230627152923.133238-3-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230627152923.133238-1-mathieu.desnoyers@efficios.com> References: <20230627152923.133238-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769871547829987042?= X-GMAIL-MSGID: =?utf-8?q?1769871547829987042?= Allow defining variables and perform cast with a typeof which removes the volatile and const qualifiers. This prevents declaring a stack variable with a volatile qualifier within a macro, which would generate sub-optimal assembler. This is imported from the "librseq" project. Signed-off-by: Mathieu Desnoyers --- tools/testing/selftests/rseq/compiler.h | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/testing/selftests/rseq/compiler.h b/tools/testing/selftests/rseq/compiler.h index f47092bddeba..49d62fbd6dda 100644 --- a/tools/testing/selftests/rseq/compiler.h +++ b/tools/testing/selftests/rseq/compiler.h @@ -33,4 +33,30 @@ #define RSEQ_COMBINE_TOKENS(_tokena, _tokenb) \ RSEQ__COMBINE_TOKENS(_tokena, _tokenb) +#ifdef __cplusplus +#define rseq_unqual_scalar_typeof(x) \ + std::remove_cv::type>::type +#else +#define rseq_scalar_type_to_expr(type) \ + unsigned type: (unsigned type)0, \ + signed type: (signed type)0 + +/* + * Use C11 _Generic to express unqualified type from expression. This removes + * volatile qualifier from expression type. + */ +#define rseq_unqual_scalar_typeof(x) \ + __typeof__( \ + _Generic((x), \ + char: (char)0, \ + rseq_scalar_type_to_expr(char), \ + rseq_scalar_type_to_expr(short), \ + rseq_scalar_type_to_expr(int), \ + rseq_scalar_type_to_expr(long), \ + rseq_scalar_type_to_expr(long long), \ + default: (x) \ + ) \ + ) +#endif + #endif /* RSEQ_COMPILER_H_ */