public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110728] New: should __attribute__((cleanup())) callback get invoked for indirect edges of asm goto
@ 2023-07-18 21:23 ndesaulniers at google dot com
  2023-07-18 21:29 ` [Bug c/110728] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: ndesaulniers at google dot com @ 2023-07-18 21:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110728
           Summary: should __attribute__((cleanup())) callback get invoked
                    for indirect edges of asm goto
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ndesaulniers at google dot com
  Target Milestone: ---

Consider the following test case:

```c
void test4cleanup(int*);
// No errors expected.
void test4(void) {
l0:;
    int x __attribute__((cleanup(test4cleanup)));
    asm goto("# %l0"::::l0);
}

```

gcc trunk today generates effectively the following control flow:
```
test4:
.LFB0:
        subq    $24, %rsp
.L2:
#APP
        # .L2
#NO_APP
        leaq    12(%rsp), %rdi
        call    test4cleanup
        addq    $24, %rsp
        ret
```
so if the inline asm blob jumps to `l0`, then the cleanup function is not run.

That seemed surprising, at least when we discussed it on this thread.
https://reviews.llvm.org/D155342#4511887

A fellow Linux kernel dev (who introduced the usage of
__attribute__((cleanup())) (and asm goto, coincidentally) to the kernel) agreed
(on IRC).

For now in clang, we produce a diagnostic since the behavior seems surprising. 
If this gets changed in GCC, I'd be happy to modify clang to match that updated
behavior.

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

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

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 21:23 [Bug c/110728] New: should __attribute__((cleanup())) callback get invoked for indirect edges of asm goto ndesaulniers at google dot com
2023-07-18 21:29 ` [Bug c/110728] " pinskia at gcc dot gnu.org
2023-07-18 21:32 ` pinskia at gcc dot gnu.org
2023-07-18 21:33 ` pinskia at gcc dot gnu.org
2023-07-18 21:48 ` pinskia at gcc dot gnu.org
2023-07-18 23:22 ` rjmccall at gmail dot com
2023-07-19  7:01 ` rguenth at gcc dot gnu.org
2023-07-19 16:46 ` [Bug middle-end/110728] " ndesaulniers at google dot com
2023-07-19 17:16 ` rjmccall at gmail dot com
2023-08-03 14:38 ` matz at gcc dot gnu.org
2023-08-03 16:00 ` ndesaulniers at google dot com
2023-08-03 16:11 ` matz at gcc dot gnu.org
2023-08-03 17:07 ` rjmccall at gmail dot com

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