From patchwork Mon May 15 13:57:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 94161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6954270vqo; Mon, 15 May 2023 07:14:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4i3SgqkszW1cOki6I3iOGWgVr2qrEu0N7fJbEGeh7IwN8k64qjCtZexnmFKi6YpY7CQfiP X-Received: by 2002:a05:6a20:394a:b0:101:9344:bf89 with SMTP id r10-20020a056a20394a00b001019344bf89mr27057211pzg.49.1684160075359; Mon, 15 May 2023 07:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684160075; cv=none; d=google.com; s=arc-20160816; b=P0nRb2Hqp45XiLoGs/wpZmdJsBuhYo//d5Ii0PxoVygej7+H1RpZ9GREmCskT+yFj3 EnlUqvmIj2ctxJNAInBYwAx5kPUtqCF73frwrVJDByhOpacb/yBWMPlxCEJ4KsfK+IFa kSDPJhVOoBDQszgeISspLvE5HXm15jPYTxLnrtffNXhd3XQHiQw2OPLHRNk1iGQEAoD4 beDolBcnjxg4zDXaZe/rHgpmY8aou7uSiTYYg8IWl2+YALTP7Yah3z+yZPr0eBL+DubH wrdvJjJ1a+atamJkndtXkDmS57crZjKfWaliVUXf6CUa7u3STgjL76BNvVFouY6RBlLE C8QA== 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=; b=W4CYB8f7k9gd0fRhTBfpy2df5MSgCOcCg08TpNcZKxNVnHVW/0NI9HiuZJJg5WEHkh PBOgNm4FUMRxs2q1j5mkv5xoEDhqgvuZMFdXx7gPEFo/FZ6Y95RierfXphH0Z1kZKudj IrOGcEfdj3zNTzJ3oQKdcgK3FlgbWw6TMj7nAT7d0fPc4i2n/rmrWLfY2PyE9boXipyQ I3yBAlsGixjhjBwWMT21lHCC1NZgcl9d49VcJGChKUwIeX4zSevHTO6E0Xzp57OpXlbN CYDiZQWa9nk0EHbqZ6RMjlgXKdcAM5j7xJX73x9h/AsGHBaK/0PSKcmMEt7Bx+yom6f0 e/Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=f0KlErVn; 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 g67-20020a636b46000000b005030006a2desi15232945pgc.182.2023.05.15.07.14.15; Mon, 15 May 2023 07:14:35 -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=f0KlErVn; 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 S238294AbjEON6U (ORCPT + 99 others); Mon, 15 May 2023 09:58:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235698AbjEON6N (ORCPT ); Mon, 15 May 2023 09:58:13 -0400 Received: from smtpout.efficios.com (unknown [IPv6:2607:5300:203:b2ee::31e5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5646B1996; Mon, 15 May 2023 06:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1684159089; bh=oKkXMwl9CppgPR3HEtDQfgVFXUAQ6EoIiQSv7ieSscM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f0KlErVnELFnQBYCIU7/4DVtm8ChMs3Um1YTqbh3V+4stsWeoXaGXJ+f5gdeuTz9P UxQgDzjIr4w/SFIXS6tOvjnoNwxU09OZGkqioRJgyyUlnZXhXpxvjKcz3ob3o4wFJW 3Z3KLAPFbC8gLxGArXONszk1T9F/Jpw5rxvs46xSVt/7OYJJxZgiEamGgSSB3QcliJ vHl6gRlaI18Os/wxxEez521Asbd333ADvJFOVT3j/6FaL6ThuuSc8uOmf+Pcs055i/ 2FvNZb1aWRX4zfjisnosOT6pPgwgP+YJ1gBOG2UY33Br0VfmSB7HfNwwvNDTzhrr3w NlIVY6N+LKLFw== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4QKgtn2TMyz12dS; Mon, 15 May 2023 09:58:09 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , "Paul E . McKenney" , Boqun Feng , "H . Peter Anvin" , Paul Turner , linux-api@vger.kernel.org, Shuah Khan , linux-kselftest@vger.kernel.org, Mathieu Desnoyers Subject: [PATCH 2/4] selftests/rseq: Implement rseq_unqual_scalar_typeof Date: Mon, 15 May 2023 09:57:59 -0400 Message-Id: <20230515135801.15220-3-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230515135801.15220-1-mathieu.desnoyers@efficios.com> References: <20230515135801.15220-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RDNS_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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?1765969835342305642?= X-GMAIL-MSGID: =?utf-8?q?1765969835342305642?= 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_ */