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 D8D993858403 for ; Fri, 2 Feb 2024 11:02:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8D993858403 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D8D993858403 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=1706871748; cv=none; b=LMAC5VY9LecgoNop3jdThAfsYUfBnUWPZps3tEXrVyEwusVBJ/uX5SDIH8UYeCRPH+OFTy2bsvKsobu9vMPHa82KhTeDP+n/TV4CaQZwPCAnEHHqj2krn92MmnTrUhThmkjJnrl3UYpJFtyrEgUFzZqaUTIaoeDOfeUpQWVueBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706871748; c=relaxed/simple; bh=mGgC/1QfMfj3GbahIvOvkbwa7i0fn/J8JdvmHtN+ZZA=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=wx5Cxwz3/aKwBKX0FVP54Nzn6Fv5ZjMEVi6mwuwsap4WzBR2k0twcjmJHsJIQEQHge6djQyWddTe59zq+TNfqvjkXmETsPEC8ZPpYr6tA/Hs6xeZyotozy6XwkShtTKFNVxOPK1P0mPk6dCzMUPk3ZEyJ2arTk/3SJhKAsm6HvQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rVrJP-0004jf-0P for gcc-patches@gnu.org; Fri, 02 Feb 2024 06:02:24 -0500 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40ef6bbb61fso16422365e9.1 for ; Fri, 02 Feb 2024 03:02:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706871741; x=1707476541; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=p26+3RCQSYjxDP1hcfvy7xByGTJ8HqVPndQdypa7pbE=; b=lEZ0x3Sbky+8KUQjpl3b1Bl/493pCac8eBfuw52Em7WUvqcOGq5dkFvYM/ZRj2s24T z1XxdPk14DPpWbowEuuxMVvFc/bxodzumty3DazyM/t+WwyuIkHrRfStAE/Z05mimQwK Mqu++5dTmI4N+3nVAClhZrtAJCW66qGjzV5omeNEe54S7qAjnPYvYdR46ge4LKGx8tq1 aV4PVhA+3VhPbfuMnUnXbNSr/DuyKU2fa1thB4CK6PAc1MtWxeoNglktpfvZz3F1SUJ2 Fq0zfu/EDQ4UqMND+TS6BgXQKcRUlKXPEQ1LicZzA3bDrMXedrqZNRS8N95HZmZhqpBw fbBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706871741; x=1707476541; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p26+3RCQSYjxDP1hcfvy7xByGTJ8HqVPndQdypa7pbE=; b=wMkfzahqwu90K0AoVDGiGAs+A2PE9Z51XFuEZ9Tu+N9OhM0qR2WxvMGXmvvTRmnJF9 yiBvgM+i4oTSJxUBbMUHCMN5WLzCRpbGrrTPAyGN2ZI1tGnUL5ezSFNATDJRaDDEF+qF kX3A4p3IzghFBH02WJXBdNUwM9xKWxr39NgTuwmZWuhINMHZld0y+lv51W2Ntn1fMMBw G4QfqbtKZ1riQyF370PiJ1zF8grEpZC1gltHWH8eLOy9S7HZ0YGMWwiZU5qh//uWv+P4 l0xSfEgy0My0U8ocS53G42doWFd/igSQY3LiHDaNDpQNO/AMXlabYCuqJl1FEcFCJk9A GM7w== X-Gm-Message-State: AOJu0YzJ0jBVeOZrgrPGQD8kPz4lMbh6Wy+joM5WaoJ0i8ac7hZ+1Gjq j/Gn+B8SmArLuCv4x3K7b16TGragOOhGyFVXHpxSzUyLx9F2Ex/0Sbinj/zKN2ZpXGs4d/Y1KoQ BK3Yo0RJtv+PsWhTTNiLKfVpzU0Xf9Rux2SAsQ/IudIBDCVQk X-Google-Smtp-Source: AGHT+IH+ZqNMoMyFxcBoL7L6Fxn9JSSpWPSYzHHi1te+ETBoJjrA2YpnPy8sfwAaaSrVe98PZBv62Vbfl295a5IUAP0= X-Received: by 2002:a05:600c:1c06:b0:40e:779f:416 with SMTP id j6-20020a05600c1c0600b0040e779f0416mr1500187wms.2.1706871740964; Fri, 02 Feb 2024 03:02:20 -0800 (PST) MIME-Version: 1.0 References: <20240202091322.1898280-1-ak@linux.intel.com> <20240202091322.1898280-5-ak@linux.intel.com> In-Reply-To: <20240202091322.1898280-5-ak@linux.intel.com> From: Prathamesh Kulkarni Date: Fri, 2 Feb 2024 16:31:45 +0530 Message-ID: Subject: Re: [PATCH v4 4/5] Add tests for C/C++ musttail attributes To: Andi Kleen Cc: gcc-patches@gnu.org Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=prathamesh.kulkarni@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DKIM_VALID_EF=-0.1,RCVD_IN_DNSWL_NONE=-0.0001,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_SOFTFAIL,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: On Fri, 2 Feb 2024 at 14:44, Andi Kleen wrote: > > 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) Hi Andy, Sorry, I wasn't clear about this in previous patch -- noipa will subsume other ipa attributes, so there's no need to have noinline, noclone along with noipa. int __attribute__((noipa)) callee(int i) should be sufficient for disabling IPA optimizations involving callee. Thanks, Prathamesh > +{ > + 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 >