Fix 'gcc.dg/tree-ssa/return-value-range-1.c' for 'char' defaulting to 'unsigned' (was: Propagate value ranges of return values)

Message ID 87r0kiu7f3.fsf@euler.schwinge.homeip.net
State Unresolved
Headers
Series Fix 'gcc.dg/tree-ssa/return-value-range-1.c' for 'char' defaulting to 'unsigned' (was: Propagate value ranges of return values) |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Thomas Schwinge Nov. 21, 2023, 9:24 p.m. UTC
  Hi!

On 2023-11-19T16:05:42+0100, Jan Hubicka <hubicka@ucw.cz> wrote:
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/return-value-range-1.c

Pushed to master branch commit a0240662b22312ffb3e3fefb85f258ab0e7010f4
"Fix 'gcc.dg/tree-ssa/return-value-range-1.c' for 'char' defaulting to
'unsigned'", see attached.  On powerpc64le-linux-gnu ('char' defaulting
to 'unsigned') I still saw:

    /tmp/ccd1xwD7.o: In function `test':
    return-value-range-1.c:(.text+0x50): undefined reference to `link_error'


Grüße
 Thomas


> @@ -0,0 +1,22 @@
> +/* { dg-do ling } */
> +/* { dg-options "-O1 -dump-tree-evrp-details" } */
> +__attribute__ ((__noinline__))
> +int a(char c)
> +{
> +     return c;
> +}
> +void link_error ();
> +
> +void
> +test(int d)
> +{
> +     if (a(d) > 200)
> +             link_error ();
> +}
> +int
> +main(int argc, char **argv)
> +{
> +     test(argc);
> +     return 0;
> +}
> +/* { dg-final { scan-tree-dump-times "Recording return range" 2 "evrp"} } */


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Comments

Christophe Lyon Nov. 22, 2023, 10:51 a.m. UTC | #1
Hi!

On Tue, 21 Nov 2023 at 22:24, Thomas Schwinge <thomas@codesourcery.com> wrote:
>
> Hi!
>
> On 2023-11-19T16:05:42+0100, Jan Hubicka <hubicka@ucw.cz> wrote:
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/tree-ssa/return-value-range-1.c
>
> Pushed to master branch commit a0240662b22312ffb3e3fefb85f258ab0e7010f4
> "Fix 'gcc.dg/tree-ssa/return-value-range-1.c' for 'char' defaulting to
> 'unsigned'", see attached.  On powerpc64le-linux-gnu ('char' defaulting
> to 'unsigned') I still saw:
>
>     /tmp/ccd1xwD7.o: In function `test':
>     return-value-range-1.c:(.text+0x50): undefined reference to `link_error'
>
We do see the same error in our CI (Thomas, normally you have received
a notification because your patch turned ERROR in FAIL)

Thomas, you said in another email that adding -O2 avoids the linker
error with missing link_error(), but I don't see how that would be
possible?
(and hence I expect the error you quoted above to happen)

So should we use dg-compile instead of dg-link? Not sure what the
original intention was?

Thanks,

Christophe

>
> Grüße
>  Thomas
>
>
> > @@ -0,0 +1,22 @@
> > +/* { dg-do ling } */
> > +/* { dg-options "-O1 -dump-tree-evrp-details" } */
> > +__attribute__ ((__noinline__))
> > +int a(char c)
> > +{
> > +     return c;
> > +}
> > +void link_error ();
> > +
> > +void
> > +test(int d)
> > +{
> > +     if (a(d) > 200)
> > +             link_error ();
> > +}
> > +int
> > +main(int argc, char **argv)
> > +{
> > +     test(argc);
> > +     return 0;
> > +}
> > +/* { dg-final { scan-tree-dump-times "Recording return range" 2 "evrp"} } */
>
>
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  
Thomas Schwinge Nov. 22, 2023, 11:05 a.m. UTC | #2
Hi!

On 2023-11-22T11:51:02+0100, Christophe Lyon <christophe.lyon@linaro.org> wrote:
> On Tue, 21 Nov 2023 at 22:24, Thomas Schwinge <thomas@codesourcery.com> wrote:
>> On 2023-11-19T16:05:42+0100, Jan Hubicka <hubicka@ucw.cz> wrote:
>> > --- /dev/null
>> > +++ b/gcc/testsuite/gcc.dg/tree-ssa/return-value-range-1.c
>>
>> Pushed to master branch commit a0240662b22312ffb3e3fefb85f258ab0e7010f4
>> "Fix 'gcc.dg/tree-ssa/return-value-range-1.c' for 'char' defaulting to
>> 'unsigned'", see attached.  On powerpc64le-linux-gnu ('char' defaulting
>> to 'unsigned') I still saw:
>>
>>     /tmp/ccd1xwD7.o: In function `test':
>>     return-value-range-1.c:(.text+0x50): undefined reference to `link_error'
>>
> We do see the same error in our CI (Thomas, normally you have received
> a notification because your patch turned ERROR in FAIL)

Yes, I have; and I even tried to log in there, to point to my commit
mentioned above, which is meant to address this issue -- please let me
know if you're still seeing the FAIL after that commit.

> Thomas, you said in another email that adding -O2 avoids the linker
> error with missing link_error(), but I don't see how that would be
> possible?

That's the gist of Honza's "Propagate value ranges of return values"
optimization, per my understanding: from 'int a(signed char c)' doing
'return c;' figure out that 'a(d) > 200)' is always false (due to
'-128 <= c <= 127)'.

> (and hence I expect the error you quoted above to happen)
>
> So should we use dg-compile instead of dg-link? Not sure what the
> original intention was?

No, the idea really is to prove that the 'link_error ()' call is
unreachable.


Grüße
 Thomas


>> > @@ -0,0 +1,22 @@
>> > +/* { dg-do ling } */
>> > +/* { dg-options "-O1 -dump-tree-evrp-details" } */
>> > +__attribute__ ((__noinline__))
>> > +int a(char c)
>> > +{
>> > +     return c;
>> > +}
>> > +void link_error ();
>> > +
>> > +void
>> > +test(int d)
>> > +{
>> > +     if (a(d) > 200)
>> > +             link_error ();
>> > +}
>> > +int
>> > +main(int argc, char **argv)
>> > +{
>> > +     test(argc);
>> > +     return 0;
>> > +}
>> > +/* { dg-final { scan-tree-dump-times "Recording return range" 2 "evrp"} } */
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Patch

From a0240662b22312ffb3e3fefb85f258ab0e7010f4 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Tue, 21 Nov 2023 22:07:13 +0100
Subject: [PATCH] Fix 'gcc.dg/tree-ssa/return-value-range-1.c' for 'char'
 defaulting to 'unsigned'

... added in recent commit 53ba8d669550d3a1f809048428b97ca607f95cf5
"inter-procedural value range propagation", fixed in
commit 878a860cae78146d98d7a21612f0bcec0930a9c2
"Fix 'gcc.dg/tree-ssa/return-value-range-1.c'".

	gcc/testsuite/
	* gcc.dg/tree-ssa/return-value-range-1.c: Fix.
---
 gcc/testsuite/gcc.dg/tree-ssa/return-value-range-1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/return-value-range-1.c b/gcc/testsuite/gcc.dg/tree-ssa/return-value-range-1.c
index 74f1a5080bb..97294482c05 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/return-value-range-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/return-value-range-1.c
@@ -1,7 +1,7 @@ 
 /* { dg-do link } */
 /* { dg-options "-O2 -fdump-tree-evrp-details" } */
 __attribute__ ((__noinline__))
-int a(char c)
+int a(signed char c)
 {
 	return c;
 }
-- 
2.34.1