[pushed,1/4] c++: copy location to AGGR_INIT_EXPR

Message ID 20231213164740.1591535-1-jason@redhat.com
State Committed
Commit 52b4b7d7f5c7c09f5aaf3934978de9702d8c214b
Headers
Series [pushed,1/4] c++: copy location to AGGR_INIT_EXPR |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm warning Patch is already merged

Commit Message

Jason Merrill Dec. 13, 2023, 4:47 p.m. UTC
  Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

When building an AGGR_INIT_EXPR from a CALL_EXPR, we shouldn't lose location
information.

gcc/cp/ChangeLog:

	* tree.cc (build_aggr_init_expr): Copy EXPR_LOCATION.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1y/constexpr-nsdmi7b.C: Adjust line.
	* g++.dg/template/copy1.C: Likewise.
---
 gcc/cp/tree.cc                                 | 1 +
 gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7b.C | 4 ++--
 gcc/testsuite/g++.dg/template/copy1.C          | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)


base-commit: d2b269ce30d77dbfc6c28c75887c330d4698b132
  

Comments

Patrick Palka Dec. 13, 2023, 6:05 p.m. UTC | #1
On Wed, 13 Dec 2023, Jason Merrill wrote:

> Tested x86_64-pc-linux-gnu, applying to trunk.
> 
> -- 8< --
> 
> When building an AGGR_INIT_EXPR from a CALL_EXPR, we shouldn't lose location
> information.
> 
> gcc/cp/ChangeLog:
> 
> 	* tree.cc (build_aggr_init_expr): Copy EXPR_LOCATION.

I made a similar change in the past which caused the debug regression
PR96997 which I fixed by reverting the change in r11-7263-g78a6d0e30d7950
(didn't do much deeper analysis than that).  Unfortunately it seems this
regression is back now.

> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp1y/constexpr-nsdmi7b.C: Adjust line.
> 	* g++.dg/template/copy1.C: Likewise.
> ---
>  gcc/cp/tree.cc                                 | 1 +
>  gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7b.C | 4 ++--
>  gcc/testsuite/g++.dg/template/copy1.C          | 2 +-
>  3 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
> index da4d5c51f07..c4e41fd7b5c 100644
> --- a/gcc/cp/tree.cc
> +++ b/gcc/cp/tree.cc
> @@ -689,6 +689,7 @@ build_aggr_init_expr (tree type, tree init)
>        CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
>        CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
>        CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
> +      SET_EXPR_LOCATION (rval, EXPR_LOCATION (init));
>      }
>    else
>      rval = init;
> diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7b.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7b.C
> index a410e482664..586ee54124c 100644
> --- a/gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7b.C
> +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7b.C
> @@ -20,8 +20,8 @@ bar()
>  {
>    A a = foo();
>    a.p->n = 5;
> -  return a;
> -} // { dg-error "non-.constexpr." "" { target c++20_down } }
> +  return a; // { dg-error "non-.constexpr." "" { target c++20_down } }
> +}
>  
>  constexpr int
>  baz()
> diff --git a/gcc/testsuite/g++.dg/template/copy1.C b/gcc/testsuite/g++.dg/template/copy1.C
> index eacd9e2c025..7e0a3805a77 100644
> --- a/gcc/testsuite/g++.dg/template/copy1.C
> +++ b/gcc/testsuite/g++.dg/template/copy1.C
> @@ -6,10 +6,10 @@
>  
>  struct A
>  {
> -  // { dg-error "reference" "" { target c++14_down } .+1 }
>    A(A&);			// { dg-message "A::A" "" { target c++14_down } }
>    template <class T> A(T); 	// { dg-message "A::A" "" { target c++14_down } }
>  };
>  
> +// { dg-error "reference" "" { target c++14_down } .+1 }
>  A a = 0; // { dg-error "no match" "" { target c++14_down } }
>  
> 
> base-commit: d2b269ce30d77dbfc6c28c75887c330d4698b132
> -- 
> 2.39.3
> 
>
  
Marek Polacek Dec. 14, 2023, midnight UTC | #2
On Wed, Dec 13, 2023 at 11:47:37AM -0500, Jason Merrill wrote:
> Tested x86_64-pc-linux-gnu, applying to trunk.
> 
> -- 8< --
> 
> When building an AGGR_INIT_EXPR from a CALL_EXPR, we shouldn't lose location
> information.

I think the following should be an obvious fix, so I'll check it in.

-- >8 --
Since r14-6505 I see:

FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++23  at line 91 (test for errors, line 89)
FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++23 (test for excess errors)
FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++26  at line 91 (test for errors, line 89)
FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++26 (test for excess errors)

and it wasn't fixed by r14-6511.  So I'm fixing it with the below.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/constexpr-ex1.C: Adjust expected diagnostic line.
---
 gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C
index 383d38a42d4..b26eb5d0c90 100644
--- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C
@@ -88,7 +88,7 @@ struct resource {
 };
 constexpr resource f(resource d)
 { return d; }                  // { dg-error "non-.constexpr." "" { target { { { ! implicit_constexpr } && c++20_down } || c++11_only } } }
-// { dg-error "non-.constexpr." "" { target { c++23 && { ! implicit_constexpr } } } .-2 }
+// { dg-error "non-.constexpr." "" { target { c++23 && { ! implicit_constexpr } } } .-1 }
 constexpr resource d = f(9);   // { dg-message ".constexpr." "" { target { { ! implicit_constexpr } || c++11_only } } }
 
 // 4.4 floating-point constant expressions

base-commit: c535360788e142a92e1d8b1db25bf4452e26f5fb
  
Jason Merrill Dec. 14, 2023, 1:38 a.m. UTC | #3
On 12/13/23 19:00, Marek Polacek wrote:
> On Wed, Dec 13, 2023 at 11:47:37AM -0500, Jason Merrill wrote:
>> Tested x86_64-pc-linux-gnu, applying to trunk.
>>
>> -- 8< --
>>
>> When building an AGGR_INIT_EXPR from a CALL_EXPR, we shouldn't lose location
>> information.
> 
> I think the following should be an obvious fix, so I'll check it in.

Thanks, I wonder why I wasn't seeing that?

> -- >8 --
> Since r14-6505 I see:
> 
> FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++23  at line 91 (test for errors, line 89)
> FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++23 (test for excess errors)
> FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++26  at line 91 (test for errors, line 89)
> FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++26 (test for excess errors)
> 
> and it wasn't fixed by r14-6511.  So I'm fixing it with the below.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp0x/constexpr-ex1.C: Adjust expected diagnostic line.
> ---
>   gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C
> index 383d38a42d4..b26eb5d0c90 100644
> --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C
> +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C
> @@ -88,7 +88,7 @@ struct resource {
>   };
>   constexpr resource f(resource d)
>   { return d; }                  // { dg-error "non-.constexpr." "" { target { { { ! implicit_constexpr } && c++20_down } || c++11_only } } }
> -// { dg-error "non-.constexpr." "" { target { c++23 && { ! implicit_constexpr } } } .-2 }
> +// { dg-error "non-.constexpr." "" { target { c++23 && { ! implicit_constexpr } } } .-1 }
>   constexpr resource d = f(9);   // { dg-message ".constexpr." "" { target { { ! implicit_constexpr } || c++11_only } } }
>   
>   // 4.4 floating-point constant expressions
> 
> base-commit: c535360788e142a92e1d8b1db25bf4452e26f5fb
  
Marek Polacek Dec. 14, 2023, 2:25 p.m. UTC | #4
On Wed, Dec 13, 2023 at 08:38:12PM -0500, Jason Merrill wrote:
> On 12/13/23 19:00, Marek Polacek wrote:
> > On Wed, Dec 13, 2023 at 11:47:37AM -0500, Jason Merrill wrote:
> > > Tested x86_64-pc-linux-gnu, applying to trunk.
> > > 
> > > -- 8< --
> > > 
> > > When building an AGGR_INIT_EXPR from a CALL_EXPR, we shouldn't lose location
> > > information.
> > 
> > I think the following should be an obvious fix, so I'll check it in.
> 
> Thanks, I wonder why I wasn't seeing that?

It must be due to -fimplicit-constexpr.  So if you have
GXX_TESTSUITE_STDS=98,11,14,17,20,impcx
then I think the FAIL won't show up.
 
> > -- >8 --
> > Since r14-6505 I see:
> > 
> > FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++23  at line 91 (test for errors, line 89)
> > FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++23 (test for excess errors)
> > FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++26  at line 91 (test for errors, line 89)
> > FAIL: g++.dg/cpp0x/constexpr-ex1.C  -std=c++26 (test for excess errors)
> > 
> > and it wasn't fixed by r14-6511.  So I'm fixing it with the below.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > 	* g++.dg/cpp0x/constexpr-ex1.C: Adjust expected diagnostic line.
> > ---
> >   gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C
> > index 383d38a42d4..b26eb5d0c90 100644
> > --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C
> > +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C
> > @@ -88,7 +88,7 @@ struct resource {
> >   };
> >   constexpr resource f(resource d)
> >   { return d; }                  // { dg-error "non-.constexpr." "" { target { { { ! implicit_constexpr } && c++20_down } || c++11_only } } }
> > -// { dg-error "non-.constexpr." "" { target { c++23 && { ! implicit_constexpr } } } .-2 }
> > +// { dg-error "non-.constexpr." "" { target { c++23 && { ! implicit_constexpr } } } .-1 }
> >   constexpr resource d = f(9);   // { dg-message ".constexpr." "" { target { { ! implicit_constexpr } || c++11_only } } }
> >   // 4.4 floating-point constant expressions
> > 
> > base-commit: c535360788e142a92e1d8b1db25bf4452e26f5fb
> 

Marek
  

Patch

diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index da4d5c51f07..c4e41fd7b5c 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -689,6 +689,7 @@  build_aggr_init_expr (tree type, tree init)
       CALL_EXPR_OPERATOR_SYNTAX (rval) = CALL_EXPR_OPERATOR_SYNTAX (init);
       CALL_EXPR_ORDERED_ARGS (rval) = CALL_EXPR_ORDERED_ARGS (init);
       CALL_EXPR_REVERSE_ARGS (rval) = CALL_EXPR_REVERSE_ARGS (init);
+      SET_EXPR_LOCATION (rval, EXPR_LOCATION (init));
     }
   else
     rval = init;
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7b.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7b.C
index a410e482664..586ee54124c 100644
--- a/gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7b.C
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-nsdmi7b.C
@@ -20,8 +20,8 @@  bar()
 {
   A a = foo();
   a.p->n = 5;
-  return a;
-} // { dg-error "non-.constexpr." "" { target c++20_down } }
+  return a; // { dg-error "non-.constexpr." "" { target c++20_down } }
+}
 
 constexpr int
 baz()
diff --git a/gcc/testsuite/g++.dg/template/copy1.C b/gcc/testsuite/g++.dg/template/copy1.C
index eacd9e2c025..7e0a3805a77 100644
--- a/gcc/testsuite/g++.dg/template/copy1.C
+++ b/gcc/testsuite/g++.dg/template/copy1.C
@@ -6,10 +6,10 @@ 
 
 struct A
 {
-  // { dg-error "reference" "" { target c++14_down } .+1 }
   A(A&);			// { dg-message "A::A" "" { target c++14_down } }
   template <class T> A(T); 	// { dg-message "A::A" "" { target c++14_down } }
 };
 
+// { dg-error "reference" "" { target c++14_down } .+1 }
 A a = 0; // { dg-error "no match" "" { target c++14_down } }