public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code
@ 2023-02-08 10:29 daniel at eyoman dot com
  2023-02-08 10:30 ` [Bug c/108715] " daniel at eyoman dot com
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: daniel at eyoman dot com @ 2023-02-08 10:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

            Bug ID: 108715
           Summary: Infinite loop in the generated assembly with -Os when
                    strlen is defined in the code
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel at eyoman dot com
  Target Milestone: ---

Created attachment 54426
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54426&action=edit
C file

Hi,

The attached source file is compiled on GCC 12.2.1 with the following command:
gcc -save-temps -Wall -Wextra -Os strlen_bug.c -o strlen_bug

The assembly file, obtained with objdump -d strlen_bug, shows that:
- the for loop dealing with the length calculation has been removed by strlen
- the strlen label jumps to itself
- the program never ends

If the strlen function is removed from the code, the problem doesn't occur.

I wanted to attach the assembly and preprocessed files but I could attach only
one.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
@ 2023-02-08 10:30 ` daniel at eyoman dot com
  2023-02-08 10:30 ` daniel at eyoman dot com
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: daniel at eyoman dot com @ 2023-02-08 10:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

--- Comment #1 from Daniel Zaoui <daniel at eyoman dot com> ---
Created attachment 54427
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54427&action=edit
Preprocessed file

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
  2023-02-08 10:30 ` [Bug c/108715] " daniel at eyoman dot com
@ 2023-02-08 10:30 ` daniel at eyoman dot com
  2023-02-08 10:32 ` daniel at eyoman dot com
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: daniel at eyoman dot com @ 2023-02-08 10:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

--- Comment #2 from Daniel Zaoui <daniel at eyoman dot com> ---
Created attachment 54428
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54428&action=edit
Assembly file

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
  2023-02-08 10:30 ` [Bug c/108715] " daniel at eyoman dot com
  2023-02-08 10:30 ` daniel at eyoman dot com
@ 2023-02-08 10:32 ` daniel at eyoman dot com
  2023-02-08 10:33 ` daniel at eyoman dot com
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: daniel at eyoman dot com @ 2023-02-08 10:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

Daniel Zaoui <daniel at eyoman dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #54427|0                           |1
        is obsolete|                            |

--- Comment #3 from Daniel Zaoui <daniel at eyoman dot com> ---
Comment on attachment 54427
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54427
Preprocessed file

I attached the wrong file by mistake

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (2 preceding siblings ...)
  2023-02-08 10:32 ` daniel at eyoman dot com
@ 2023-02-08 10:33 ` daniel at eyoman dot com
  2023-02-08 10:34 ` daniel at eyoman dot com
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: daniel at eyoman dot com @ 2023-02-08 10:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

Daniel Zaoui <daniel at eyoman dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #54428|0                           |1
        is obsolete|                            |

--- Comment #4 from Daniel Zaoui <daniel at eyoman dot com> ---
Comment on attachment 54428
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54428
Assembly file

I attached the wrong file by mistake

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (3 preceding siblings ...)
  2023-02-08 10:33 ` daniel at eyoman dot com
@ 2023-02-08 10:34 ` daniel at eyoman dot com
  2023-02-08 10:34 ` daniel at eyoman dot com
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: daniel at eyoman dot com @ 2023-02-08 10:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

--- Comment #5 from Daniel Zaoui <daniel at eyoman dot com> ---
Created attachment 54429
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54429&action=edit
Preprocessed file

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (4 preceding siblings ...)
  2023-02-08 10:34 ` daniel at eyoman dot com
@ 2023-02-08 10:34 ` daniel at eyoman dot com
  2023-02-08 10:38 ` daniel at eyoman dot com
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: daniel at eyoman dot com @ 2023-02-08 10:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

--- Comment #6 from Daniel Zaoui <daniel at eyoman dot com> ---
Created attachment 54430
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54430&action=edit
Assembly file

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug c/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (5 preceding siblings ...)
  2023-02-08 10:34 ` daniel at eyoman dot com
@ 2023-02-08 10:38 ` daniel at eyoman dot com
  2023-02-08 11:27 ` [Bug middle-end/108715] " pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: daniel at eyoman dot com @ 2023-02-08 10:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

--- Comment #7 from Daniel Zaoui <daniel at eyoman dot com> ---
With the -fno-builtin option, the assembly is correct and the program behaves
as expected.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (6 preceding siblings ...)
  2023-02-08 10:38 ` daniel at eyoman dot com
@ 2023-02-08 11:27 ` pinskia at gcc dot gnu.org
  2023-02-08 11:34 ` daniel at eyoman dot com
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-08 11:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There is a dup of this bug already filed. And a related bug when defining
"memcpy" too.

C is special.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (7 preceding siblings ...)
  2023-02-08 11:27 ` [Bug middle-end/108715] " pinskia at gcc dot gnu.org
@ 2023-02-08 11:34 ` daniel at eyoman dot com
  2023-02-08 11:38 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: daniel at eyoman dot com @ 2023-02-08 11:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

--- Comment #9 from Daniel Zaoui <daniel at eyoman dot com> ---
(In reply to Andrew Pinski from comment #8)
> There is a dup of this bug already filed. And a related bug when defining
> "memcpy" too.
> 
> C is special.

Do you have any bug ID? I searched before opening the bug without success.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (8 preceding siblings ...)
  2023-02-08 11:34 ` daniel at eyoman dot com
@ 2023-02-08 11:38 ` jakub at gcc dot gnu.org
  2023-02-08 12:22 ` daniel at eyoman dot com
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-08 11:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
PR56888 ?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (9 preceding siblings ...)
  2023-02-08 11:38 ` jakub at gcc dot gnu.org
@ 2023-02-08 12:22 ` daniel at eyoman dot com
  2023-02-08 12:37 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: daniel at eyoman dot com @ 2023-02-08 12:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

--- Comment #11 from Daniel Zaoui <daniel at eyoman dot com> ---
I checked on GCC 5.2.0 and 10.2 (RISC-V toolchain) and it doesn't happen.

I didn't understand what is the conclusion for the duplicate tickets. In
107415, it seems to be an expected behavior. Although I don't see how strlen
invoking strlen is a correct behavior.

Isn't there supposed to be a fix in GCC for that?

Thanks

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (10 preceding siblings ...)
  2023-02-08 12:22 ` daniel at eyoman dot com
@ 2023-02-08 12:37 ` jakub at gcc dot gnu.org
  2023-02-08 17:45 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-08 12:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
While the strlen pattern recognition has been added later than memcpy/memset,
it is really the same thing.  With -ffreestanding which you are supposed to use
when you are providing C library yourself (or parts thereof as in this case)
they aren't recognized for years.  Without -ffreestanding,
-fno-tree-loop-distribute-patterns turns off those pattern recognitions.  As
mentioned in the other PR, while disabling pattern recognition of say memcpy
within function named memcpy and similarly for strlen wouldn't be that hard
(where currently without any of the above options we end up with tail
recursion), there is always the case where say memcpy could be implemented by
calling say memcpy_impl and only that one would contain the recognized pattern.
 Such indirect recursion would be much harder to deal with.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (11 preceding siblings ...)
  2023-02-08 12:37 ` jakub at gcc dot gnu.org
@ 2023-02-08 17:45 ` pinskia at gcc dot gnu.org
  2023-02-08 17:48 ` jakub at gcc dot gnu.org
  2023-02-08 17:52 ` pinskia at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-08 17:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 102725.

*** This bug has been marked as a duplicate of bug 102725 ***

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (12 preceding siblings ...)
  2023-02-08 17:45 ` pinskia at gcc dot gnu.org
@ 2023-02-08 17:48 ` jakub at gcc dot gnu.org
  2023-02-08 17:52 ` pinskia at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-08 17:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

--- Comment #14 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It isn't really a dup, that other PR is about strlen pattern in some function
with a different name.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug middle-end/108715] Infinite loop in the generated assembly with -Os when strlen is defined in the code
  2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
                   ` (13 preceding siblings ...)
  2023-02-08 17:48 ` jakub at gcc dot gnu.org
@ 2023-02-08 17:52 ` pinskia at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-08 17:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108715

--- Comment #15 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #14)
> It isn't really a dup, that other PR is about strlen pattern in some
> function with a different name.

PR 103858 was also marked as a dup much earlier.
I think the original code in valgrind (which PR 102725 is about) used strlen as
the name of the function and the reporter change the name just to show what was
happening ...

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-02-08 17:52 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-08 10:29 [Bug c/108715] New: Infinite loop in the generated assembly with -Os when strlen is defined in the code daniel at eyoman dot com
2023-02-08 10:30 ` [Bug c/108715] " daniel at eyoman dot com
2023-02-08 10:30 ` daniel at eyoman dot com
2023-02-08 10:32 ` daniel at eyoman dot com
2023-02-08 10:33 ` daniel at eyoman dot com
2023-02-08 10:34 ` daniel at eyoman dot com
2023-02-08 10:34 ` daniel at eyoman dot com
2023-02-08 10:38 ` daniel at eyoman dot com
2023-02-08 11:27 ` [Bug middle-end/108715] " pinskia at gcc dot gnu.org
2023-02-08 11:34 ` daniel at eyoman dot com
2023-02-08 11:38 ` jakub at gcc dot gnu.org
2023-02-08 12:22 ` daniel at eyoman dot com
2023-02-08 12:37 ` jakub at gcc dot gnu.org
2023-02-08 17:45 ` pinskia at gcc dot gnu.org
2023-02-08 17:48 ` jakub at gcc dot gnu.org
2023-02-08 17:52 ` pinskia at gcc dot gnu.org

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).