From patchwork Fri Feb 2 09:09:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 195720 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp303323dyc; Fri, 2 Feb 2024 01:14:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiLeCqzi/zY/sli4rKGCaUrQ9NDMke7zToixuVClH2dgGxbbqtVopoJlxFdcDHIhSTujRL X-Received: by 2002:a05:6214:3284:b0:68c:8919:1a5f with SMTP id mu4-20020a056214328400b0068c89191a5fmr546916qvb.26.1706865299637; Fri, 02 Feb 2024 01:14:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706865299; cv=pass; d=google.com; s=arc-20160816; b=NhXMzF+r1sR8TNC7R/Hc5oF3LNGlmTsw4vKcpIT/mpeG06chAT/emgfhQnNDuB4yoz HHDnsRZgizWKTrALuk9RyFKoWI3Ldjw51+NQ5QH8LKUxCyhKBA9Z+9E7iWHouUZ9FLYk JnqCTcL2iZbn1KvPzO+yPCdyoZxstFPWHU8ZcUi5erNhjcJkMJ7nlz+UpkCWrDngtIj9 rE/4GB/q5K4uFtJ2UQpk8ulb3ZjfNiksw98HZhW/kHP8I1bRVGxjfmM206RZR7grkl6s KvSolowN4v0jf1UTItph2jxOcYC1fYNI/xp0UoeGfXSjyoLFiB/ysLVKpF1s0IQm1Ab7 FbvQ== 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=+V1SJdUxJ1h2F589KkoWr41SAnhTWp0NSy8NnESAiaQ=; fh=26Zz1i/zptu57JDEKQh71TCXgMF8g9FaleoonCgNgZo=; b=ihDKUdKssAt1/hmFXiTZ6ORPY7LnUEUfB2QV+hrzXhl0QRw2fnrWzsJI+brgYLBwt2 /HAuJdci1YHy4eKCg1qHO2dsLFKRtKJq9Rhc4H6zYaLqyYmWJQpD9XjXagx/Zd9f50Gn CxA5QqEZ+RMOLpJJeO/GqjAaRbZDabgawiLLR/olwgoreWc5LRBVVZS+ksoMTzEHJoZJ fFxFQX9oPMjSFag0jJCfJSbf9M1lP2TAwz4i13I9h5DzkZji9JcbXrW4nzM1sZo4wWWq q1BRY9TtrH0O7DYlZE4Gigsu/jeFDuflPOEoFs2NcBkKk11036V/9pTghb9mEgDHLcnP U9cA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g6M9nJsF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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; AJvYcCW6xAg7WTHXLEVpEUwD2FaMFtPs0I6Nj8Wx4sWKhY2Gwa0LYKgenv2Tk0/vc1FewQmK3KHnRmyZpDoxDDgVC/YAql+7Sw== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f5-20020a0cc305000000b006818c27e60dsi1566451qvi.539.2024.02.02.01.14.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:14:59 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g6M9nJsF; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 13A533857C5B for ; Fri, 2 Feb 2024 09:14:59 +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 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 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 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: 1789777988649106073 X-GMAIL-MSGID: 1789777988649106073 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" } */ +}