Issue 100868
Summary `[[gnu::cleanup()]]` function executed before return value evaluation
Labels new issue
Assignees
Reporter fuhsnn
    The code use the `[[gnu::cleanup()]]` attribute to register a cleanup function. The cleanup function should be called after the return value being determined.

godbolt link: https://godbolt.org/z/zY5abr361

```
#include <stdio.h>

typedef struct {
    int i;
} S;

void inc(S *obj) {
    obj->i += 7;
}

S test(void) {
    S s [[gnu::cleanup(inc)]];

    printf("returning %d\n", s.i = 22);
 return s;
}

int main()
{
  printf("returned  %d\n", test().i);
  return 0;
}
```
GCC print:
```
returning 22
returned  22
```
Clang print:
```
returning 22
returned 29
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to