From patchwork Wed Jan 24 11:07:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1890190 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=CZUAxuyu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TKh6Q2XS3z23dq for ; Wed, 24 Jan 2024 22:09:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 520B63858401 for ; Wed, 24 Jan 2024 11:09:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 49A8F3857B92 for ; Wed, 24 Jan 2024 11:08:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49A8F3857B92 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 49A8F3857B92 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706094509; cv=none; b=dsJoaaTBPbD3icVyGh9+y7t/1breUU+wrTEqx/vvaiWt2/c+/tCX2fuA2cevxvc7EnaCI5Z03E5NdS4bj7USfB8zP5JyTcTaz7Y40vgxwVsofWpZG5tVLmg4f4Dj+wH39TVezErtRXQi6tPkyqiM5fnmyoZwgtx9Me8oFV0zIuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706094509; c=relaxed/simple; bh=IKoysltldrXLzV8qnDPU7mZX9uLCGg07vL+asiw6+Lo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ICeIlsfTkgKIBhjv09v6dryO8XV9C8FkHeKAfxsQ2udApcQL5QtLFf83gG0ra+8uMdP+nAeJj1xy4LZCBHaSGm1tTXVtJXPCb55vbR7YOtCaW+gsrkp1xwdsCfOfk9JNHFa2eGxc8/gJ2ykaA220AVOQgjkGduLVLwc7dRuYSnQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mgamail.intel.com ([192.55.52.93]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSb7J-0004qb-DT for gcc-patches@gnu.org; Wed, 24 Jan 2024 06:08:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706094505; x=1737630505; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IKoysltldrXLzV8qnDPU7mZX9uLCGg07vL+asiw6+Lo=; b=CZUAxuyuF2Zbo/HtASWJ5J1FuUehpdJeHjUxGWmgTCBokGYrQmpvd0YT T+x3J98AVzSZ/glPymHYNo0BaQfo/q+j/v3UnGDXFNchx0YPJq9Rk7TD7 vQz6z7FFCDTUhGz/xQ5tkPPtkl/D0xMDw+xSFgB6onimeEtaXao30+gNr Pbzuges2IxkvhryOsT9BdNyM7N8dGsAya8oe8CqjEoY/HnsSbgEoNCWSI HYoGmN+PDGpi5MSfAIt7FAS5a86TyVHLSfAIdhS/k42k3lRqAAptrEp9z POdrMysICh+PSQCT0ev65baSRwHf0G6sO7kGK2Hgvoks78t54vNydDpQ4 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="398969570" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="398969570" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 03:08:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="959472955" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="959472955" Received: from tassilo.jf.intel.com ([10.54.38.190]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 03:08:17 -0800 From: Andi Kleen To: gcc-patches@gnu.org Cc: Andi Kleen Subject: [PATCH v1 3/4] Add tests for C++ musttail attribute Date: Wed, 24 Jan 2024 03:07:59 -0800 Message-ID: <20240124110800.3154093-3-ak@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124110800.3154093-1-ak@linux.intel.com> References: <20240124110800.3154093-1-ak@linux.intel.com> MIME-Version: 1.0 Received-SPF: none client-ip=192.55.52.93; envelope-from=ak@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -55 X-Spam_score: -5.6 X-Spam_bar: ----- X-Spam_report: (-5.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.327, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNWANTED_LANGUAGE_BODY 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Mostly adopted from the existing C musttail plugin tests. --- gcc/testsuite/g++.dg/musttail1.C | 15 ++++++++++++ gcc/testsuite/g++.dg/musttail2.C | 35 ++++++++++++++++++++++++++ gcc/testsuite/g++.dg/musttail3.C | 42 ++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/musttail4.C | 19 +++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 gcc/testsuite/g++.dg/musttail1.C create mode 100644 gcc/testsuite/g++.dg/musttail2.C create mode 100644 gcc/testsuite/g++.dg/musttail3.C create mode 100644 gcc/testsuite/g++.dg/musttail4.C diff --git a/gcc/testsuite/g++.dg/musttail1.C b/gcc/testsuite/g++.dg/musttail1.C new file mode 100644 index 000000000000..c9276e0ae86a --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail1.C @@ -0,0 +1,15 @@ +/* { dg-do compile { target tail_call } } */ +/* { dg-options "-std=c++11 -O2" } */ +/* { dg-options "-fdelayed-branch" { target sparc*-*-* } } */ + +int __attribute__((noinline,noclone)) +callee (int i) +{ + return i * i; +} + +int __attribute__((noinline,noclone)) +caller (int i) +{ + [[gnu::musttail]] return callee (i + 1); +} diff --git a/gcc/testsuite/g++.dg/musttail2.C b/gcc/testsuite/g++.dg/musttail2.C new file mode 100644 index 000000000000..d9151d25f517 --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail2.C @@ -0,0 +1,35 @@ +/* { dg-do compile { target tail_call } } */ +/* { dg-options "-std=c++11" } */ + +struct box { char field[256]; int i; }; + +int __attribute__((noinline,noclone)) +test_2_callee (int i, struct box b) +{ + if (b.field[0]) + return 5; + return i * i; +} + +int __attribute__((noinline,noclone)) +test_2_caller (int i) +{ + struct box b; + [[gnu::musttail]] return test_2_callee (i + 1, b); /* { dg-error "cannot tail-call: " } */ +} + +extern void setjmp (void); +void +test_3 (void) +{ + [[gnu::musttail]] return setjmp (); /* { dg-error "cannot tail-call: " } */ +} + +typedef void (fn_ptr_t) (void); +volatile fn_ptr_t fn_ptr; + +void +test_5 (void) +{ + [[gnu::musttail]] return fn_ptr (); /* { dg-error "cannot tail-call: " } */ +} diff --git a/gcc/testsuite/g++.dg/musttail3.C b/gcc/testsuite/g++.dg/musttail3.C new file mode 100644 index 000000000000..7d55f44124ee --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail3.C @@ -0,0 +1,42 @@ +/* { dg-do compile { target tail_call } } */ +/* { dg-options "-std=c++11" } */ + +extern int foo2 (int x, ...); + +struct str +{ + int a, b; +}; + +str +cstruct (int x) +{ + if (x < 10) + [[clang::musttail]] return cstruct (x + 1); + return { x, 0 }; +} + +int +cstruct2 (int x, str & ref) +{ + if (x < 10) + { + str r = { }; + [[clang::musttail]] return cstruct2 (x + 1, r); + } + return x + 1; +} + + +int +foo (int x) +{ + if (x < 10) + [[clang::musttail]] return foo2 (x, 29); + if (x < 100) + { + int k = foo (x + 1); + [[clang::musttail]] return k; /* { dg-error "cannot tail-call: " } */ + } + return x; +} diff --git a/gcc/testsuite/g++.dg/musttail4.C b/gcc/testsuite/g++.dg/musttail4.C new file mode 100644 index 000000000000..3122acfb1719 --- /dev/null +++ b/gcc/testsuite/g++.dg/musttail4.C @@ -0,0 +1,19 @@ +/* { dg-do compile { target tail_call } } */ +/* Allow nested functions. */ +/* { dg-options "-Wno-pedantic -std=c++11" } */ + +struct box { char field[64]; int i; }; + +struct box __attribute__((noinline,noclone)) +returns_struct (int i) +{ + struct box b; + b.i = i * i; + return b; +} + +int __attribute__((noinline,noclone)) +test_1 (int i) +{ + [[gnu::musttail]] return returns_struct (i * 5).i; /* { dg-error "return value must be a call" } */ +}