public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-6919] c++: Invisible refs are not restrict [PR97474]
Date: Tue, 26 Jan 2021 22:11:49 +0000 (GMT)	[thread overview]
Message-ID: <20210126221149.134593860C3E@sourceware.org> (raw)

https://gcc.gnu.org/g:96253f069ead0736536de803b06a8053a85039a6

commit r11-6919-g96253f069ead0736536de803b06a8053a85039a6
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jan 26 16:04:24 2021 -0500

    c++: Invisible refs are not restrict [PR97474]
    
    In this testcase, we refer to the a parameter through a reference in its own
    member, which we asserted couldn't happen by marking the parameter as
    'restrict'.  This assumption could also be broken if the address escapes
    from the constructor.
    
    gcc/cp/ChangeLog:
    
            PR c++/97474
            * call.c (type_passed_as): Don't mark invisiref restrict.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/97474
            * g++.dg/torture/pr97474.C: New test.

Diff:
---
 gcc/cp/call.c                          |  6 +-----
 gcc/testsuite/g++.dg/torture/pr97474.C | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 5977582e279..87a7af12796 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8263,11 +8263,7 @@ type_passed_as (tree type)
 {
   /* Pass classes with copy ctors by invisible reference.  */
   if (TREE_ADDRESSABLE (type))
-    {
-      type = build_reference_type (type);
-      /* There are no other pointers to this temporary.  */
-      type = cp_build_qualified_type (type, TYPE_QUAL_RESTRICT);
-    }
+    type = build_reference_type (type);
   else if (targetm.calls.promote_prototypes (NULL_TREE)
 	   && INTEGRAL_TYPE_P (type)
 	   && COMPLETE_TYPE_P (type)
diff --git a/gcc/testsuite/g++.dg/torture/pr97474.C b/gcc/testsuite/g++.dg/torture/pr97474.C
new file mode 100644
index 00000000000..6ce117e43a5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr97474.C
@@ -0,0 +1,28 @@
+// PR c++/97474
+// { dg-do run }
+
+extern "C" int printf (const char *, ...);
+extern "C" void abort ();
+
+struct A {
+    int a;
+    int& b;
+
+    A(int x) : a(x), b(a) {}
+    A(const A& other) : a(other.a), b(a) {}
+    A() : a(0), b(a) {}
+};
+
+int foo(A a) {
+    a.a *= a.b;
+    return a.b;
+}
+
+
+int main() {
+    A a(3);
+
+    int r = foo (a);
+    if (r != 9)
+      abort ();
+}


                 reply	other threads:[~2021-01-26 22:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210126221149.134593860C3E@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).