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 98C78385801D for ; Fri, 2 Feb 2024 09:13:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98C78385801D 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 98C78385801D 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=1706865223; cv=none; b=NNxqh6vQj/uZn9yuKuRJSUwqceZkEhiqX0kniePA7QiKVujg2Qc3fX6A5vJJR3wH20LkGiSgknMEcugzh7M1x6ZtYT7XheZwNX5i9uPFI9cpG9ywYRynV+8buLZfTgkuM23sXA8J9lj3R7McU0mP0X1ZOloHHNrODJ0e72M4R+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706865223; c=relaxed/simple; bh=99m77Taug1+JoH7WufnWD3/uSeNA0jgTNcvT//1pk7s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=POpKKIYTDK94LIFp1PiTgfxM5Mev1oT9nOMJFHUSPFWvdtxtQGtZU5P1XH7qSu0PPws0kb47lymJY4TmAa+y4Qn71+sWVlAgqbhL5OaWtH5VibbCYSh9u1EuG1la/+FFVGP2jeBa0Otqn9a/KHIGPviY3R0BTcO8EguK/yEhS6w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mgamail.intel.com ([192.198.163.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVpcB-0004EA-Pt for gcc-patches@gnu.org; Fri, 02 Feb 2024 04:13:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706865219; x=1738401219; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=99m77Taug1+JoH7WufnWD3/uSeNA0jgTNcvT//1pk7s=; b=g6M9nJsFQrd71ntWC4yDzUD44TYjWHqGiYHrsqp9J1gq6KU+IEwVofv2 7D8R9/n4pHgvm/UqiSPdCEqdz1ws+kL/7DRhl29EEToMaZ3Wxw7gLU6hA DAYiRFkDAW5Sd6Svc9yMtPSGlxhdz0w/z5Irgr4U9nyr6AmmWSiAqP1N7 rW1hM9s3meF6ZUDpAPIFokGz3MXJJOEkeLd1Cq1oqkBlMXUOUYG9WIvDi vnjgQ0fjIclKo1cxiVnJ7IDGIvLrtXDtkZsoTFohGaW0LIRlOghF8xOZA iuCIfooGnj0/WU5E7JZx1/JzozU7q8aiRYpWj25wR02EXLKAzyqOoLTJq A==; X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="3942951" X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="3942951" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:13:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,237,1701158400"; d="scan'208";a="23318067" Received: from tassilo.jf.intel.com ([10.54.38.190]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2024 01:13:30 -0800 From: Andi Kleen To: gcc-patches@gnu.org Cc: Andi Kleen Subject: [PATCH v4 4/5] Add tests for C/C++ musttail attributes Date: Fri, 2 Feb 2024 01:09:19 -0800 Message-ID: <20240202091322.1898280-5-ak@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202091322.1898280-1-ak@linux.intel.com> References: <20240202091322.1898280-1-ak@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: none client-ip=192.198.163.12; envelope-from=ak@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 5.0 requ) BAYES_00=-1.9,DKIMWL_WL_HIGH=-1.292,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_EF=-0.1,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.8 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/ChangeLog: * c-c++-common/musttail1.c: New test. * c-c++-common/musttail2.c: New test. * c-c++-common/musttail3.c: New test. * c-c++-common/musttail4.c: New test. * c-c++-common/musttail5.c: New test. --- gcc/testsuite/c-c++-common/musttail1.c | 15 ++++++++++++ gcc/testsuite/c-c++-common/musttail2.c | 34 ++++++++++++++++++++++++++ gcc/testsuite/c-c++-common/musttail3.c | 29 ++++++++++++++++++++++ gcc/testsuite/c-c++-common/musttail4.c | 17 +++++++++++++ gcc/testsuite/c-c++-common/musttail5.c | 25 +++++++++++++++++++ 5 files changed, 120 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 create mode 100644 gcc/testsuite/c-c++-common/musttail5.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..ac92f9f74616 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail1.c @@ -0,0 +1,15 @@ +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ +/* { dg-options "-O2" } */ +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ + +int __attribute__((noinline,noclone,noipa)) +callee (int i) +{ + return i * i; +} + +int __attribute__((noinline,noclone,noipa)) +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..058329b69cc2 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail2.c @@ -0,0 +1,34 @@ +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ + +struct box { char field[256]; int i; }; + +int __attribute__((noinline,noclone,noipa)) +test_2_callee (int i, struct box b) +{ + if (b.field[0]) + return 5; + return i * i; +} + +int __attribute__((noinline,noclone,noipa)) +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..ea9589c59ef2 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail3.c @@ -0,0 +1,29 @@ +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ + +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..23f4b5e1cd68 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail4.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ + +struct box { char field[64]; int i; }; + +struct box __attribute__((noinline,noclone,noipa)) +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: " } */ +} diff --git a/gcc/testsuite/c-c++-common/musttail5.c b/gcc/testsuite/c-c++-common/musttail5.c new file mode 100644 index 000000000000..71f4de40fc6d --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail5.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c23" { target c } } */ +/* { dg-options "-std=gnu++11" { target c++ } } */ + +[[musttail]] int j; /* { dg-warning "attribute" } */ +__attribute__((musttail)) int k; /* { dg-warning "attribute" } */ + +void foo(void) +{ + [[gnu::musttail]] j++; /* { dg-warning "attribute" } */ + [[gnu::musttail]] if (k > 0) /* { dg-warning "attribute" } */ + [[gnu::musttail]] k++; /* { dg-warning "attribute" } */ +} + +int foo2(int p) +{ + [[gnu::musttail(1)]] return foo2(p + 1); /* { dg-error "attribute" } */ +} + +int i; + +void foo3(void) +{ + [[musttail]] i++; /* { dg-warning "attribute" } */ +} -- 2.43.0