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: 194438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1626078dyb; Tue, 30 Jan 2024 18:19:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbaQp67usPkdgprB6roQQVrryKhRcZQcVJ43uas2cnay4NJ3APvoPFvm2ZBpdmuGWSR7oK X-Received: by 2002:a05:620a:3859:b0:783:331e:550e with SMTP id po25-20020a05620a385900b00783331e550emr195663qkn.61.1706667583836; Tue, 30 Jan 2024 18:19:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706667583; cv=pass; d=google.com; s=arc-20160816; b=oP/xPZ6XiMH/Rn+cWsDvghTm1ARmvkQ2+O/wKbsRXINk6FIeSwMInqMHh7yOiRazbW K7zHKE7CVh8QrS8hLS629V4hBr4ugaaZYs/eqkH2k+ZCUeT7rF9UcR9jfET1CYEctc3y +RX0S4A3/3OJuClEm6vREL1yObSsN/hvgOiZP4YoPiO8yEH6G05qQg12uFwiWsyngpNj MgFHnzzhrFTz8nmmnaeJY/Eb464EBUmUJV6tkjVaABdWbScklwrxB4JnHX84Kmx7mNn6 DkGLTR2+/KwMEcg7dptgw7WUvF4n5TTGBT3N6zIkjEQ78Dc0hyVcaWCPrQjogo933Wgd 5wfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=J7GyPuAHCgAXrXQv2Em5TGN3OJ+KzP8OSu4MWOEVOAo=; fh=idIlQ80w4P5Df6FyYYB2Gip91fGVW4mu4eZbpwtJ1n4=; b=WgML6hcEH6GlMrPAoTYpXCyf5EBPJFp3aejd0d05YA95v2RPbO3eG+AHxmERz0y5Pi ywKhKdl4v+kfECLwVB6JzDW2qK9swtihjYUKB2HYjlnbSl7aHcgjJhThldro/c0MQXSo WD+hsqNQn6YONwNLKPsKzKEMokvOfNB/KWrhE88OHEewBbrSwtaA2t1iXX8iSElIAWyM L9AD6dRno1IJKXFXtqeExrLYknvqWMAO3FRpMRp6QmQ6hq2qgvfJvv3fBSIZfLcBTyg1 rYU9tWIAcoKEvueod8ZwSfvSAFaYLO/gjcQlD+XyRbIzjcH18RlL1EjCvJSmNYdkQSYl hrkA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fV2INRfY; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCWuntVYhK/YtD2WDB3N7Qt+wUNX7s9S3HJt1ut5GY0hy7pTt5/caHZOPFQERfH5Y0jIA6KutZbQvry9522uiujsnDDCAA== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f18-20020a05622a105200b00429c0179530si10739726qte.704.2024.01.30.18.19.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 18:19:43 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fV2INRfY; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82E453858003 for ; Wed, 31 Jan 2024 02:19:43 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789570668190845388 X-GMAIL-MSGID: 1789570668190845388 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" } */ +}