From patchwork Sun May 5 18:14:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 1931593 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=HwoNW8eh; 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 4VXXmJ2FRwz1xnS for ; Mon, 6 May 2024 04:16:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 818B23846405 for ; Sun, 5 May 2024 18:16:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by sourceware.org (Postfix) with ESMTPS id 867483858429 for ; Sun, 5 May 2024 18:15:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 867483858429 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 867483858429 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.9 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714932936; cv=none; b=MxMcyEK+TAbwthDEGs9jXeDG7dXCPF2raxf2wH8R5oCYYryAxvv7ZHKOlj4BsSO52QSzVp7KhoSCwHRBQOC+334I0hInTIk0HOUcYr9gmNIs1L6IAnej6T2Z618cV8rCXxLZRQznpZIGCw+BzgaYqms+f2E+bW5u6ajkjh3SXek= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714932936; c=relaxed/simple; bh=6QUFda8jNA/1tmpfSZ0dv+GQya5S//uHkmiNa6P2qSE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HKy0zeEJpVpDeFD3yf1HP+zANNwg3K5+nrQ/pIuXmjuiKrz0SnOTcTg6z3uhwSjNZS+VGWmo28anAoEUa3EvpTgB2HEDs9yXOzCrLysw/0HnO9SjeSVfrYRQwqPUITFKdDC7Z9HlDVO08UH6pPTlvFg6mLCBdbA5teASaK5eJi8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714932934; x=1746468934; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6QUFda8jNA/1tmpfSZ0dv+GQya5S//uHkmiNa6P2qSE=; b=HwoNW8ehLkN3wxhdp+ZYQCcEqKAovQsXrtdhcxiOqOWJ2uMlYnUHT7hq 6Ir/HONT9MT1HCgEh9ncjqehaBKut5tQIz+LEXu0GSeQ3c2MT/uZR8Se6 fzvAmr/jpXJgQ7ka14Jd7dNMdzfcrvlE/3p6y48NpZ3IbB/Od9gbSsLuZ sjxHtd3nZvYEm9Qv9NxqQk8WMeVb5+OYeRmABtZa6ZoLlvXNT/acrqmGP T4DVy09JA5MNJJ90aghgekksuKDb5ewcRXRUnJBTzqhTrp3C1D+pgAO2J PJ6KbnFZSSGe90Lf01dl+1vxQUP3zC9Ea+n1OgyW8n/aVOhINB41c0qa9 Q==; X-CSE-ConnectionGUID: jfnW3uqaQyq1z+1sSWLeVw== X-CSE-MsgGUID: QWPjOgz6Soe/y0zrAuqOGg== X-IronPort-AV: E=McAfee;i="6600,9927,11064"; a="21356327" X-IronPort-AV: E=Sophos;i="6.07,256,1708416000"; d="scan'208";a="21356327" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2024 11:15:26 -0700 X-CSE-ConnectionGUID: Y2R1ioT8TnWarfhm5zIEiQ== X-CSE-MsgGUID: xqCq3h6vRZ+Uodf3HBqRVw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,256,1708416000"; d="scan'208";a="28457582" Received: from tassilo.jf.intel.com ([10.54.38.190]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2024 11:15:25 -0700 From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: nathan@acm.org, josmyers@redhat.com, richard.sandiford@arm.com, jason@redhat.com, Andi Kleen Subject: [PATCH v5 4/5] Add tests for C/C++ musttail attributes Date: Sun, 5 May 2024 11:14:57 -0700 Message-ID: <20240505181458.2903045-4-ak@linux.intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240505181458.2903045-1-ak@linux.intel.com> References: <20240505181458.2903045-1-ak@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP 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/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 | 28 +++++++++++++++++++++ 5 files changed, 123 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..7938e7ff80e4 --- /dev/null +++ b/gcc/testsuite/c-c++-common/musttail5.c @@ -0,0 +1,28 @@ +/* { 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; + +int foo3(void) +{ + [[musttail]] i++; /* { dg-warning "attribute" } */ + [[musttail]] if (i > 10) /* { dg-warning "attribute" } */ + [[musttail]] return foo2(i); /* { dg-warning "attribute" } */ + return 0; +}