From patchwork Wed Jan 31 02:17:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1893188 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=fV2INRfY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4TPm1x0Pv4z1yQ0 for ; Wed, 31 Jan 2024 13:19:16 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 061A2385801D for ; Wed, 31 Jan 2024 02:19:15 +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 06D0A3858420 for ; Wed, 31 Jan 2024 02:18:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 06D0A3858420 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 06D0A3858420 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=1706667521; cv=none; b=FmYIi6WNSpIAXFK2TIPz0piQ3HKgc+PXHUrbFoTqd1oVIhjAHt0tmBQVDekd6EYDEedyYaJHEffpHnOw2mFeDFFH42DdKDdV4oUgdymvF70BBkOTWUx1tBau8yCDfS6uky55gLHpncSjHjj55X9dTy4zQM3/1+7tbHIuUKuWsoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706667521; c=relaxed/simple; bh=ajSFeBfgrFpsF9xpcSMST2fjc9q41Aiu+UrBs6/6PCM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tkZ/eIP9uZDj+u8Qd5bW2XNNC8XOUkjQ90+sJflAPXecTn4IYVAUH3kEsi3IcS2Vb5INES1Sq80KYACscre5lCYtD4hwYOm5ctqscqMiNirDsbB30UiK572ItZlmTJYGP7sSlvrHzRNHng1SaaQVOy4gI26/X7bMufBZ2JnuKVg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mgamail.intel.com ([198.175.65.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rV0BQ-0002VP-R8 for gcc-patches@gnu.org; Tue, 30 Jan 2024 21:18:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706667517; x=1738203517; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ajSFeBfgrFpsF9xpcSMST2fjc9q41Aiu+UrBs6/6PCM=; b=fV2INRfYo6tPS8LfunG3bc4reCAdBNnT7dVRupZKJIF5Fl2TDMpuLU7c Pn9en58duiihEvVaQ713v6pn91MAV76IbUkC2z0PkKxvvabZ/P2kwUws5 UZ0rv6dPxxBu2RRWhj9Vy5o/SgHY0/sw3OlIn+7wyMeoX1MdBNihYr+x3 CglQD5MXo3vNwjwLHhRdhyHPgbNlNS9ymEiYF0HsEibv2w/zFprGOwb6D TBzqNcxxc3e8Z5AoExMmSVzqRbRHFDaN4fYWbKsH9aE8MJnR+lOMW54E+ srD83+SgLZ4DuSBeivzrmqXn8Mum9iGjM9dVWSXaY6XKFh/sJnwrURNDH w==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="10561935" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="10561935" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 18:18:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="737946820" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="737946820" Received: from tassilo.jf.intel.com ([10.54.38.190]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 18:18:15 -0800 From: Andi Kleen To: gcc-patches@gnu.org Cc: Andi Kleen Subject: [PATCH v3 4/5] Add tests for C/C++ musttail attributes Date: Tue, 30 Jan 2024 18:17:17 -0800 Message-ID: <20240131021808.151575-5-ak@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131021808.151575-1-ak@linux.intel.com> References: <20240131021808.151575-1-ak@linux.intel.com> MIME-Version: 1.0 Received-SPF: none client-ip=198.175.65.13; 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.3 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 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/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 +++++++++++++ gcc/testsuite/gcc.dg/musttail-invalid.c | 17 ++++++++++++ 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/gcc.dg/musttail-invalid.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: " } */ +} diff --git a/gcc/testsuite/gcc.dg/musttail-invalid.c b/gcc/testsuite/gcc.dg/musttail-invalid.c new file mode 100644 index 000000000000..c4725b4b8226 --- /dev/null +++ b/gcc/testsuite/gcc.dg/musttail-invalid.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c23" } */ + +[[musttail]] int j; /* { dg-warning "attribute ignored" } */ +__attribute__((musttail)) int k; /* { dg-warning "attribute directive ignored" } */ + +void foo(void) +{ + [[musttail]] j++; /* { dg-warning "attribute ignored" } */ + [[musttail]] if (k > 0) /* { dg-warning "attribute ignored" } */ + [[musttail]] k++; /* { dg-warning "attribute ignored" } */ +} + +int foo2(int p) +{ + [[gnu::musttail(1)]] return foo2(p + 1); /* { dg-error "has arguments" } */ +}