From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 21FD13857C70 for ; Wed, 24 Jan 2024 19:31:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 21FD13857C70 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 21FD13857C70 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=1706124719; cv=none; b=LxsY/LqKNF5v06UcKnwRmhcDNvNkywubWr5viwTU7Zwy/scZk/atk0HQmNn4XAg0Gw9//oOyvArWW94BAuBALYf2Y4M81C0dL63HdGmVySOZcZzc3+sxoeXRa5a7KOhc6VMXahB8/SQDPF1//SKRKvVwlOVUOlNCIGFTdoQX2aM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706124719; c=relaxed/simple; bh=x91JGsJ3frdk0exrvu82e9+G8LPstbbkKI0iJOtZwyY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=blXxv+Fj4nqFGFOz/63b+cZPp9x/MjJN/htNo+ECIT5rnBjlxZ+drVThZWhR5zM/PguxsmKKtmGlu/I09oYyvwF0siShCUO1C6gn7ajoCtzhQ2T89RsCx1ffYgKP75j+y/KKF5C0AeZkrZ4tbdFPBQkL4j+smS4KPF/wcM9k6VY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mgamail.intel.com ([192.55.52.88]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSiyW-0007Zw-Cs for gcc-patches@gnu.org; Wed, 24 Jan 2024 14:31:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706124712; x=1737660712; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x91JGsJ3frdk0exrvu82e9+G8LPstbbkKI0iJOtZwyY=; b=Dgf43kjfhOCNYJ/VsbTsPAvrMDPDyx9hYkSMxdJvV/Ta2DmCrpzEnuit QQNZwUOvbGVobV67UkGrTmhSICffdEthmV5DSeSfqtRUDliVGaMiRm4xD UQNetjnBk8Vlv7EiuCkR1P0z4mtW1dDlOwJsav/6UnNISxgUlTUSqBWyM O1aTi4hFLpHlomOGcODaQUoQ/ZqyHvOPHwnrbGZ7zKKybDyEiXSNxykCZ iT4E0RYkrQfbrTdDJgGX85Ng99R9Ct5RKVnV4+D8+DphNrrBCKhW+y62B QVE44DRTxwT47pKzmKEj6KWujgGwjs0jvdHkjxKBBAQp+I/88OD2uEuKD w==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="433111209" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="433111209" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 11:31:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="856810883" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="856810883" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 11:31:43 -0800 From: Andi Kleen To: gcc-patches@gnu.org Cc: Andi Kleen Subject: [PATCH v2 4/5] Add tests for C/C++ musttail attributes Date: Wed, 24 Jan 2024 11:30:44 -0800 Message-ID: <20240124193134.622934-5-ak@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124193134.622934-1-ak@linux.intel.com> References: <20240124193134.622934-1-ak@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: none client-ip=192.55.52.88; envelope-from=ak@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -57 X-Spam_score: -5.8 X-Spam_bar: ----- X-Spam_report: (-5.8 / 5.0 requ) BAYES_00=-1.9,DKIMWL_WL_HIGH=-1.5,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_EF=-0.1,RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_MSPIKE_H3=0.001,RCVD_IN_MSPIKE_WL=0.001,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=-12.0 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 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: Mostly adopted from the existing C musttail plugin tests. --- gcc/testsuite/c-c++-common/musttail1.c | 17 ++++++++++++ gcc/testsuite/c-c++-common/musttail2.c | 36 ++++++++++++++++++++++++++ gcc/testsuite/c-c++-common/musttail3.c | 31 ++++++++++++++++++++++ gcc/testsuite/c-c++-common/musttail4.c | 19 ++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/musttail1.c create mode 100644 gcc/testsuite/c-c++-common/musttail2.c create mode 100644 gcc/testsuite/c-c++-common/musttail3.c create mode 100644 gcc/testsuite/c-c++-common/musttail4.c diff --git a/gcc/testsuite/c-c++-common/musttail1.c b/gcc/testsuite/c-c++-common/musttail1.c new file mode 100644 index 000000000000..476185e3ed4b --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail1.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target tail_call } } */ +/* { dg-options "-O2" } */ +/* { dg-additional-options "-std=c++11" { target c++ } } */ +/* { dg-additional-options "-std=c23" { target c } } */ +/* { dg-additional-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/c-c++-common/musttail2.c b/gcc/testsuite/c-c++-common/musttail2.c new file mode 100644 index 000000000000..28f2f68ef13d --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail2.c @@ -0,0 +1,36 @@ +/* { dg-do compile { target tail_call } } */ +/* { dg-additional-options "-std=c++11" { target c++ } } */ +/* { dg-additional-options "-std=c23" { target c } } */ + +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/c-c++-common/musttail3.c b/gcc/testsuite/c-c++-common/musttail3.c new file mode 100644 index 000000000000..fdbb292944ad --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail3.c @@ -0,0 +1,31 @@ +/* { dg-do compile { target tail_call } } */ +/* { dg-additional-options "-std=c++11" { target c++ } } */ +/* { dg-additional-options "-std=c23" { target c } } */ + +extern int foo2 (int x, ...); + +struct str +{ + int a, b; +}; + +struct str +cstruct (int x) +{ + if (x < 10) + [[clang::musttail]] return cstruct (x + 1); + return ((struct str){ x, 0 }); +} + +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/c-c++-common/musttail4.c b/gcc/testsuite/c-c++-common/musttail4.c new file mode 100644 index 000000000000..7bf44816f14a --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail4.c @@ -0,0 +1,19 @@ +/* { dg-do compile { target tail_call } } */ +/* { dg-additional-options "-std=c++11" { target c++ } } */ +/* { dg-additional-options "-std=c23" { target c } } */ + +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 "cannot tail-call: " } */ +} -- 2.43.0