From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 512EB385B508 for ; Mon, 3 Jun 2024 14:46:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 512EB385B508 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 512EB385B508 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717425974; cv=none; b=eYENUwaNZW5kTe9aOYWio0j3PD2VbAjtNyuuCle43jFzaXLGB1sz8BlkqK8eyoUDaGxzhwc/U7rTxLzlVJv1seiIHOGnTJr46ZTPoFhOWvp5sA9YhEHXFL4jMFOPs3tI+PW+cVYeMfQsszaqm6n7c+zJd0bPyEHJRbb+cIrAELk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717425974; c=relaxed/simple; bh=xnCBL3BpsUtcvq8rvDDOlZEXNtCVYJ8AmGHRElwCHlo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=m4vKYXRl+2eoukrTaZcJlNgSSgiP6xIDV4If2Gny7/h6K9p2FdfGfC3cqBWMlTrMMMdBavtBWLy3xJIVnfyRNwzfbUatpqsJtCM9XuL8bhCsp1p+NjgZwDk7GX77Z/ozB8JUYUsbfpV0MeLoyTJxcNQTtHwDgnvb6AdpoLPm7Ak= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717425969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uVjHLPgO3tjJyXj2liHZDNL+tme7SSyJDQ1Sdj3hMOA=; b=ejmXQbYlhkfJ3e0V1lHk+UVF07pKV7O1KoXfHOBqb6BHuDAIiOrp/EbPw9nDZfGmmnh1q+ dmYc2ZY2MfhAg5NS36je40iVLjTlkdKqCjraelayQ3wqMJBNseBY6vb+BuDq2K2F1tjF53 P8Lw/t9xetwECobuzS333kYj8fGIOvU= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-_Xwj135wMfKjTAbnvnIhFA-1; Mon, 03 Jun 2024 10:46:07 -0400 X-MC-Unique: _Xwj135wMfKjTAbnvnIhFA-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-43ff221bd97so39979511cf.1 for ; Mon, 03 Jun 2024 07:46:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717425966; x=1718030766; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uVjHLPgO3tjJyXj2liHZDNL+tme7SSyJDQ1Sdj3hMOA=; b=gN5q0CjNGOTVV/ux012c9YqlbOlVJJ7+JnNl75rtdGDOPmrN5BAUgB46RSCaQwjcr+ tajJTfHrAk1f5dwnqV3w12nnQF8CJML+esNrtIL2pj9xO+BTZAeOjGwH104Hgrx5WYaU oxVfpZvkFU8thna7DacMU6MJNi5D/LaWVvXR6QQVHhn4j6JuyzpUbh4BzoqJn/n403Im 3GnIVBfS88MsWEXrcxNdcZJ+cFFJpeiswsRhNUgEMigZSH8fc6D60L7kCrFA84N54ybj k/U7btL9FxD6Ee8ouakQlV0YuOqFJ8JJC8Dz3tlireyTwJs1+GdpCb/Rb1QLDiHQdHgM sY7Q== X-Forwarded-Encrypted: i=1; AJvYcCX7etfWOkvjUuVGuZmsP/2BBnq/rO4EeGY6o/MBm4ESRcAOuT+1s/XsFY/f7KYdN+Xjc5zvnTZt2Ek+IIGHc+yL7MKxaFyG3g== X-Gm-Message-State: AOJu0YxhRFRgI04hgaqfALrbZxCW4HU+AdR/f7kerIAFPBRQ5Vegd0Wm X7gZgUSCggtJXOAEG+sjTbuX/Oo0Vx/UUvV+dwYxriByDNd4hmoOi8CD3FcRqA+jToNh22YVZ3e JbZNkF6SCJp7/GuLVlz8YQylRUjoc7ujt62dZjXA3mdroMR2iXoGAfwurbK8vtBw= X-Received: by 2002:a05:622a:a293:b0:43a:f7fb:9698 with SMTP id d75a77b69052e-43ff52b693bmr50453501cf.41.1717425966102; Mon, 03 Jun 2024 07:46:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4KyznyCqOvUeZoAyeuD5336vKtImfPDJtxb5X1UiDsLhs82Vwl9iQscRmKOcdXKDpnSqQNA== X-Received: by 2002:a05:622a:a293:b0:43a:f7fb:9698 with SMTP id d75a77b69052e-43ff52b693bmr50453311cf.41.1717425965654; Mon, 03 Jun 2024 07:46:05 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43ff23e269bsm40451171cf.46.2024.06.03.07.46.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 Jun 2024 07:46:05 -0700 (PDT) Message-ID: <0990b0f7-3c60-499e-88fa-58bcf85ae9df@redhat.com> Date: Mon, 3 Jun 2024 10:46:04 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 6/9] Add tests for C/C++ musttail attributes To: Andi Kleen , gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, nathan@acm.org, josmyers@redhat.com, richard.sandiford@arm.com References: <20240602172205.2151579-1-ak@linux.intel.com> <20240602172205.2151579-7-ak@linux.intel.com> From: Jason Merrill In-Reply-To: <20240602172205.2151579-7-ak@linux.intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,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 List-Id: On 6/2/24 13:16, 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/musttail7.c: New test. > * c-c++-common/musttail8.c: New test. > * g++.dg/musttail6.C: New test. > * g++.dg/musttail9.C: New test. > * g++.dg/musttail10.C: New test. > --- > gcc/testsuite/c-c++-common/musttail1.c | 14 +++++++ > gcc/testsuite/c-c++-common/musttail2.c | 33 +++++++++++++++ > gcc/testsuite/c-c++-common/musttail3.c | 29 +++++++++++++ > gcc/testsuite/c-c++-common/musttail4.c | 17 ++++++++ > gcc/testsuite/c-c++-common/musttail5.c | 28 +++++++++++++ > gcc/testsuite/c-c++-common/musttail7.c | 14 +++++++ > gcc/testsuite/c-c++-common/musttail8.c | 17 ++++++++ > gcc/testsuite/g++.dg/musttail10.C | 20 +++++++++ > gcc/testsuite/g++.dg/musttail6.C | 58 ++++++++++++++++++++++++++ > gcc/testsuite/g++.dg/musttail9.C | 10 +++++ > 10 files changed, 240 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 > create mode 100644 gcc/testsuite/c-c++-common/musttail7.c > create mode 100644 gcc/testsuite/c-c++-common/musttail8.c > create mode 100644 gcc/testsuite/g++.dg/musttail10.C > create mode 100644 gcc/testsuite/g++.dg/musttail6.C > create mode 100644 gcc/testsuite/g++.dg/musttail9.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..74efcc2a0bc6 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/musttail1.c > @@ -0,0 +1,14 @@ > +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ > +/* { 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..86f2c3d77404 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/musttail2.c > @@ -0,0 +1,33 @@ > +/* { 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: " } */ > +} > + > +extern float f7(void); > + > +int > +test_6 (void) > +{ > + [[gnu::musttail]] return f7(); /* { 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..234da0d3f2a9 > --- /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 "\(before numeric constant|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; > +} > diff --git a/gcc/testsuite/c-c++-common/musttail7.c b/gcc/testsuite/c-c++-common/musttail7.c > new file mode 100644 > index 000000000000..5e4eb1bfbacc > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/musttail7.c > @@ -0,0 +1,14 @@ > +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ > +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ > + > +extern void f(); > + > +void f2() > +{ > + [[gnu::musttail]] return f2(); > +} > + > +void f3() > +{ > + [[gnu::musttail]] return f(); > +} > diff --git a/gcc/testsuite/c-c++-common/musttail8.c b/gcc/testsuite/c-c++-common/musttail8.c > new file mode 100644 > index 000000000000..9fa10e0b54c4 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/musttail8.c > @@ -0,0 +1,17 @@ > +/* { dg-do compile { target { tail_call && { c || c++11 } } } } */ > + > +float f1(void); > + > +int f2(void) > +{ > + [[gnu::musttail]] return f1 (); /* { dg-error "changed after call" } */ > +} > + > + > +int f3(int *); > + > +int f4(void) > +{ > + int x; > + [[gnu::musttail]] return f3(&x); /* { dg-error "\(refers to locals|other reasons\)" } */ > +} > diff --git a/gcc/testsuite/g++.dg/musttail10.C b/gcc/testsuite/g++.dg/musttail10.C > new file mode 100644 > index 000000000000..6da7e021f826 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/musttail10.C > @@ -0,0 +1,20 @@ > +/* { dg-do compile { target { tail_call } } } */ > +/* { dg-options "-std=gnu++11" } */ > +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ > + > +int f(); > + > +double h() { [[gnu::musttail]] return f(); } /* { dg-error "cannot tail-call" } */ > + > +/* The error check cannot distinguish between the (valid) int and the invalid > + double conversion case because the template context is lost when tree-tailcall > + finally runs. */ Maybe use identical g1 and g2 to distinguish? > + > +template > +T g() { [[gnu::musttail]] return f(); } /* { dg-error "cannot tail-call" } */ > + > +int main() > +{ > + g(); > + g(); > +} > diff --git a/gcc/testsuite/g++.dg/musttail6.C b/gcc/testsuite/g++.dg/musttail6.C > new file mode 100644 > index 000000000000..e0e478e08d58 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/musttail6.C > @@ -0,0 +1,58 @@ > +/* { dg-do compile { target { tail_call } } } */ > +/* { dg-options "-std=gnu++11" } */ > +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ > + > +class Foo { > +public: > + int a, b; > + Foo(int a, int b) : a(a), b(b) {} > +}; > + > +Foo __attribute__((noinline,noclone,noipa)) > +callee (int i) > +{ > + return Foo(i, i+1); > +} > + > +Foo __attribute__((noinline,noclone,noipa)) > +caller (int i) > +{ > + [[gnu::musttail]] return callee (i + 1); > +} > + > +template > +T __attribute__((noinline,noclone,noipa)) foo (T i) > +{ > + return i + 1; > +} > + > +int > +caller2 (int k) > +{ > + [[gnu::musttail]] return foo(1); > +} > + > +template > +T caller3 (T v) > +{ > + [[gnu::musttail]] return foo(v); > +} > + > +int call3(int i) > +{ > + [[gnu::musttail]] return caller3(i + 1); > +} > + > +struct Bar { > + int a; > + Bar(int a) : a(a) {} > + Bar operator+(Bar o) { return Bar(a + o.a); } > +}; > + > +#if __OPTIMIZE__ >= 1 > +Bar > +caller4 (Bar k) > +{ > + [[gnu::musttail]] return caller3(Bar(99)); > +} > +#endif > diff --git a/gcc/testsuite/g++.dg/musttail9.C b/gcc/testsuite/g++.dg/musttail9.C > new file mode 100644 > index 000000000000..8095bdf6fe62 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/musttail9.C > @@ -0,0 +1,10 @@ > +/* { dg-do compile { target { tail_call } } } */ > +/* { dg-options "-std=gnu++11 -Wno-deprecated" } */ > +/* { dg-additional-options "-fdelayed-branch" { target sparc*-*-* } } */ > + > +extern void foo() throw(const char *); > + > +void f() throw() > +{ > + [[gnu::musttail]] return foo(); /* { dg-error "call may throw exception that does not propagate" } */ > +} Instead of -Wno-deprecated let's use C++11 exception-specifications; you can leave out the exception specification on foo and change f's to "noexcept". Jason