testsuite: Fix test failing with -fimplicit-constexpr [PR118277]

Message ID 010201945a352e92-1d0bc84a-203f-4643-ab1d-06d830a2e89d-000000@eu-west-1.amazonses.com
State New
Headers
Series testsuite: Fix test failing with -fimplicit-constexpr [PR118277] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed

Commit Message

Simon Martin Jan. 12, 2025, 11:10 a.m. UTC
  While testing an unrelated C++ patch with "make check-c++-all", I
noticed that r15-6760-g38a13ea4117b96 added a test case that fails with
-fimplicit-constexpr.

The problem is that this test unconditionally expects an error stating
that a non-constexpr function is called, but that function is
auto-magically constexpr'd under -fimplicit-constexpr.

This patch adapts the test to also pass with -fimplicit-constexpr.

Successfully tested on x86_64-apple-darwin19.6.0 with
  make check-c++-all RUNTESTFLAGS="dg.exp=constexpr-asm-5.C"

	PR c++/118277

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1z/constexpr-asm-5.C: Fix with -fimplicit-constexpr.

---
 gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
  

Comments

Simon Martin Jan. 20, 2025, 8:52 a.m. UTC | #1
Hi,

On 12 Jan 2025, at 12:10, Simon Martin wrote:

> While testing an unrelated C++ patch with "make check-c++-all", I
> noticed that r15-6760-g38a13ea4117b96 added a test case that fails 
> with
> -fimplicit-constexpr.
>
> The problem is that this test unconditionally expects an error stating
> that a non-constexpr function is called, but that function is
> auto-magically constexpr'd under -fimplicit-constexpr.
>
> This patch adapts the test to also pass with -fimplicit-constexpr.
>
> Successfully tested on x86_64-apple-darwin19.6.0 with
>   make check-c++-all RUNTESTFLAGS="dg.exp=constexpr-asm-5.C"
Ping? This is borderline obvious but since I’ve never played with 
inline assembly, I’d appreciate a second pair of eyes.

Thanks, Simon
>
> 	PR c++/118277
>
> gcc/testsuite/ChangeLog:
>
> 	* g++.dg/cpp1z/constexpr-asm-5.C: Fix with -fimplicit-constexpr.
>
> ---
>  gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C 
> b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C
> index 1c20b9dfec1..84faacc9b83 100644
> --- a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C
> +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C
> @@ -107,10 +107,10 @@ foo ()
>  				// { dg-error "conversion from 'const char\\\*' to '\[^']*' in a 
> converted constant expression" "" { target *-*-* } .-2 }
>    asm ("" : : : (G {}));	// { dg-error "constexpr string 
> 'data\\\(\\\)' must be implicitly convertible to 'const char\\\*'" }
>  				// { dg-error "could not convert 'G\\\(\\\).G::data\\\(\\\)' from 
> 'float' to 'const char\\\*'" "" { target *-*-* } .-1 }
> -  asm ("" : "=r" (v1), (H {}) (v2)); // { dg-error "call to 
> non-'constexpr' function 'short int H::size\\\(\\\) const'" }
> -				// { dg-error "constexpr string 'size\\\(\\\)' must be a constant 
> expression" "" { target *-*-* } .-1 }
> -  asm ((I {}));			// { dg-error "call to non-'constexpr' function 
> 'const char\\\* I::data\\\(\\\) const'" }
> -				// { dg-error "constexpr string 'data\\\(\\\)' must be a core 
> constant expression" "" { target *-*-* } .-1 }
> +  asm ("" : "=r" (v1) : (H {}) (v2)); // { dg-error "call to 
> non-'constexpr' function 'short int H::size\\\(\\\) const'" "" { 
> target { ! implicit_constexpr } } }
> +				// { dg-error "constexpr string 'size\\\(\\\)' must be a constant 
> expression" "" { target { ! implicit_constexpr } } .-1 }
> +  asm ((I {}));			// { dg-error "call to non-'constexpr' function 
> 'const char\\\* I::data\\\(\\\) const'" "" { target { ! 
> implicit_constexpr } } }
> +				// { dg-error "constexpr string 'data\\\(\\\)' must be a core 
> constant expression" "" { target { ! implicit_constexpr } } .-1 }
>
>    asm ((J (0)));
>    asm ("" :: (J (1)) (1));	// { dg-error "constexpr string 
> 'size\\\(\\\)' must be a constant expression" }
> @@ -180,10 +180,10 @@ bar ()
>  				// { dg-error "conversion from 'const char\\\*' to '\[^']*' in a 
> converted constant expression" "" { target *-*-* } .-2 }
>    asm ("" : : : (G {}));	// { dg-error "constexpr string 
> 'data\\\(\\\)' must be implicitly convertible to 'const char\\\*'" }
>  				// { dg-error "could not convert 'G\\\(\\\).G::data\\\(\\\)' from 
> 'float' to 'const char\\\*'" "" { target *-*-* } .-1 }
> -  asm ("" : "=r" (v1), (H {}) (v2)); // { dg-error "call to 
> non-'constexpr' function 'short int H::size\\\(\\\) const'" }
> -				// { dg-error "constexpr string 'size\\\(\\\)' must be a constant 
> expression" "" { target *-*-* } .-1 }
> -  asm ((I {}));			// { dg-error "call to non-'constexpr' function 
> 'const char\\\* I::data\\\(\\\) const'" }
> -				// { dg-error "constexpr string 'data\\\(\\\)' must be a core 
> constant expression" "" { target *-*-* } .-1 }
> +  asm ("" : "=r" (v1) : (H {}) (v2)); // { dg-error "call to 
> non-'constexpr' function 'short int H::size\\\(\\\) const'" "" { 
> target { ! implicit_constexpr } } }
> +				// { dg-error "constexpr string 'size\\\(\\\)' must be a constant 
> expression" "" { target { ! implicit_constexpr } } .-1 }
> +  asm ((I {}));			// { dg-error "call to non-'constexpr' function 
> 'const char\\\* I::data\\\(\\\) const'" "" { target { ! 
> implicit_constexpr } } }
> +				// { dg-error "constexpr string 'data\\\(\\\)' must be a core 
> constant expression" "" { target { ! implicit_constexpr } } .-1 }
>
>    asm ((J (0)));
>    asm ("" :: (J (1)) (1));	// { dg-error "constexpr string 
> 'size\\\(\\\)' must be a constant expression" }
> -- 
> 2.44.0
  
Jakub Jelinek Jan. 20, 2025, 9:15 a.m. UTC | #2
On Mon, Jan 20, 2025 at 08:52:17AM +0000, Simon Martin wrote:
> On 12 Jan 2025, at 12:10, Simon Martin wrote:
> 
> > While testing an unrelated C++ patch with "make check-c++-all", I
> > noticed that r15-6760-g38a13ea4117b96 added a test case that fails 
> > with
> > -fimplicit-constexpr.
> >
> > The problem is that this test unconditionally expects an error stating
> > that a non-constexpr function is called, but that function is
> > auto-magically constexpr'd under -fimplicit-constexpr.

Is that the only testcase that regresses with -fimplicit-constexpr?
I'd expect tons of others...

> > This patch adapts the test to also pass with -fimplicit-constexpr.
> >
> > Successfully tested on x86_64-apple-darwin19.6.0 with
> >   make check-c++-all RUNTESTFLAGS="dg.exp=constexpr-asm-5.C"
> Ping? This is borderline obvious but since I’ve never played with 
> inline assembly, I’d appreciate a second pair of eyes.

Wouldn't it be easier to just add -fno-implicit-constexpr to
dg-additional-options?

	Jakub
  
Simon Martin Jan. 20, 2025, 9:28 a.m. UTC | #3
Hi Jakub,

On 20 Jan 2025, at 10:15, Jakub Jelinek wrote:

> On Mon, Jan 20, 2025 at 08:52:17AM +0000, Simon Martin wrote:
>> On 12 Jan 2025, at 12:10, Simon Martin wrote:
>>
>>> While testing an unrelated C++ patch with "make check-c++-all", I
>>> noticed that r15-6760-g38a13ea4117b96 added a test case that fails
>>> with
>>> -fimplicit-constexpr.
>>>
>>> The problem is that this test unconditionally expects an error 
>>> stating
>>> that a non-constexpr function is called, but that function is
>>> auto-magically constexpr'd under -fimplicit-constexpr.
>
> Is that the only testcase that regresses with -fimplicit-constexpr?
> I'd expect tons of others...
Actually yes, I test all my patches with check-c++-all and this is the 
only case that fails in that mode and does not with standard make check.

>>> This patch adapts the test to also pass with -fimplicit-constexpr.
>>>
>>> Successfully tested on x86_64-apple-darwin19.6.0 with
>>>   make check-c++-all RUNTESTFLAGS="dg.exp=constexpr-asm-5.C"
>> Ping? This is borderline obvious but since I’ve never played with
>> inline assembly, I’d appreciate a second pair of eyes.
>
> Wouldn't it be easier to just add -fno-implicit-constexpr to
> dg-additional-options?
That would work indeed, and it’s true that it’s probably more in the 
spirit of that test. I’m happy to do that instead - I’ll do another 
testsuite run with that and I can merge it later today if that works for 
you.

Thanks, Simon
  
Simon Martin Jan. 20, 2025, 8:10 p.m. UTC | #4
Hi Jakub,

On 20 Jan 2025, at 10:28, Simon Martin wrote:

> Hi Jakub,
>
> On 20 Jan 2025, at 10:15, Jakub Jelinek wrote:
>
>> On Mon, Jan 20, 2025 at 08:52:17AM +0000, Simon Martin wrote:
>>> On 12 Jan 2025, at 12:10, Simon Martin wrote:
>>>
>>>> While testing an unrelated C++ patch with "make check-c++-all", I
>>>> noticed that r15-6760-g38a13ea4117b96 added a test case that fails
>>>> with
>>>> -fimplicit-constexpr.
>>>>
>>>> The problem is that this test unconditionally expects an error
>>>> stating
>>>> that a non-constexpr function is called, but that function is
>>>> auto-magically constexpr'd under -fimplicit-constexpr.
>>
>> Is that the only testcase that regresses with -fimplicit-constexpr?

>> I'd expect tons of others...
> Actually yes, I test all my patches with check-c++-all and this is the

> only case that fails in that mode and does not with standard make 
> check.
>
>>>> This patch adapts the test to also pass with -fimplicit-constexpr.
>>>>
>>>> Successfully tested on x86_64-apple-darwin19.6.0 with
>>>>   make check-c++-all RUNTESTFLAGS="dg.exp=constexpr-asm-5.C"
>>> Ping? This is borderline obvious but since I’ve never played with
>>> inline assembly, I’d appreciate a second pair of eyes.
>>
>> Wouldn't it be easier to just add -fno-implicit-constexpr to
>> dg-additional-options?
> That would work indeed, and it’s true that it’s probably more in 
> the
> spirit of that test. I’m happy to do that instead - I’ll do 
> another
> testsuite run with that and I can merge it later today if that works 
> for
> you.
Here’s the updated patch, successfully tested on x86_64-pc-linux-gnu 
with “make check-c++-all”. OK?

Thanks, Simon
From eccf73af1b3555be3e02ea2f3b1ca0be32c81cc1 Mon Sep 17 00:00:00 2001
From: Simon Martin <simon@nasilyan.com>
Date: Mon, 20 Jan 2025 20:30:59 +0100
Subject: [PATCH] testsuite: Fix test failing with -fimplicit-constexpr
 [PR118277]

While testing an unrelated C++ patch with "make check-c++-all", I
noticed that r15-6760-g38a13ea4117b96 added a test case that fails with
-fimplicit-constexpr.

The problem is that this test unconditionally expects an error stating
that a non-constexpr function is called, but that function is
auto-magically constexpr'd under -fimplicit-constexpr.

As suggested by Jakub, this patch simply passes -fno-implicit-constexpr
in that test.

Successfully tested on x86_64-pc-linux-gnu with "make check-c++-all".
gcc/testsuite/ChangeLog:

	* g++.dg/cpp1z/constexpr-asm-5.C: Pass -fno-implicit-constexpr.

---
 gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C
index 1c20b9dfec1..bcecea9d6b5 100644
--- a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C
@@ -2,7 +2,7 @@
 // { dg-do compile { target c++11 } }
 // { dg-options "" }
 // Override any default-'-fno-exceptions':
-// { dg-additional-options -fexceptions }
+// { dg-additional-options "-fexceptions -fno-implicit-constexpr" }
 
 struct A {};
 struct B { int size; };
-- 
2.44.0
  
Jakub Jelinek Jan. 20, 2025, 9:55 p.m. UTC | #5
On Mon, Jan 20, 2025 at 08:10:31PM +0000, Simon Martin wrote:
> Successfully tested on x86_64-pc-linux-gnu with "make check-c++-all".
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp1z/constexpr-asm-5.C: Pass -fno-implicit-constexpr.

LGTM.

	Jakub
  

Patch

diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C
index 1c20b9dfec1..84faacc9b83 100644
--- a/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-asm-5.C
@@ -107,10 +107,10 @@  foo ()
 				// { dg-error "conversion from 'const char\\\*' to '\[^']*' in a converted constant expression" "" { target *-*-* } .-2 }
   asm ("" : : : (G {}));	// { dg-error "constexpr string 'data\\\(\\\)' must be implicitly convertible to 'const char\\\*'" }
 				// { dg-error "could not convert 'G\\\(\\\).G::data\\\(\\\)' from 'float' to 'const char\\\*'" "" { target *-*-* } .-1 }
-  asm ("" : "=r" (v1), (H {}) (v2)); // { dg-error "call to non-'constexpr' function 'short int H::size\\\(\\\) const'" }
-				// { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" "" { target *-*-* } .-1 }
-  asm ((I {}));			// { dg-error "call to non-'constexpr' function 'const char\\\* I::data\\\(\\\) const'" }
-				// { dg-error "constexpr string 'data\\\(\\\)' must be a core constant expression" "" { target *-*-* } .-1 }
+  asm ("" : "=r" (v1) : (H {}) (v2)); // { dg-error "call to non-'constexpr' function 'short int H::size\\\(\\\) const'" "" { target { ! implicit_constexpr } } }
+				// { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" "" { target { ! implicit_constexpr } } .-1 }
+  asm ((I {}));			// { dg-error "call to non-'constexpr' function 'const char\\\* I::data\\\(\\\) const'" "" { target { ! implicit_constexpr } } }
+				// { dg-error "constexpr string 'data\\\(\\\)' must be a core constant expression" "" { target { ! implicit_constexpr } } .-1 }
 
   asm ((J (0)));
   asm ("" :: (J (1)) (1));	// { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" }
@@ -180,10 +180,10 @@  bar ()
 				// { dg-error "conversion from 'const char\\\*' to '\[^']*' in a converted constant expression" "" { target *-*-* } .-2 }
   asm ("" : : : (G {}));	// { dg-error "constexpr string 'data\\\(\\\)' must be implicitly convertible to 'const char\\\*'" }
 				// { dg-error "could not convert 'G\\\(\\\).G::data\\\(\\\)' from 'float' to 'const char\\\*'" "" { target *-*-* } .-1 }
-  asm ("" : "=r" (v1), (H {}) (v2)); // { dg-error "call to non-'constexpr' function 'short int H::size\\\(\\\) const'" }
-				// { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" "" { target *-*-* } .-1 }
-  asm ((I {}));			// { dg-error "call to non-'constexpr' function 'const char\\\* I::data\\\(\\\) const'" }
-				// { dg-error "constexpr string 'data\\\(\\\)' must be a core constant expression" "" { target *-*-* } .-1 }
+  asm ("" : "=r" (v1) : (H {}) (v2)); // { dg-error "call to non-'constexpr' function 'short int H::size\\\(\\\) const'" "" { target { ! implicit_constexpr } } }
+				// { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" "" { target { ! implicit_constexpr } } .-1 }
+  asm ((I {}));			// { dg-error "call to non-'constexpr' function 'const char\\\* I::data\\\(\\\) const'" "" { target { ! implicit_constexpr } } }
+				// { dg-error "constexpr string 'data\\\(\\\)' must be a core constant expression" "" { target { ! implicit_constexpr } } .-1 }
 
   asm ((J (0)));
   asm ("" :: (J (1)) (1));	// { dg-error "constexpr string 'size\\\(\\\)' must be a constant expression" }