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.