Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

llvm.eh.sjlj.setjmp needs returns_twice (to make nested __builtin_setjmp work on PowerPC) #49203

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR50234
Status NEW
Importance P enhancement
Reported by Tee KOBAYASHI (xtkoba@gmail.com)
Reported on 2021-05-05 18:38:42 -0700
Last modified on 2021-09-03 21:11:37 -0700
Version trunk
Hardware PC Linux
CC htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments ppc_bsjlj.c (581 bytes, text/x-csrc)
bug50234-disasm.txt (7559 bytes, text/plain)
Blocks
Blocked by
See also PR51729

Created attachment 24831 Repro

The attached C program (named ppc_bsjlj.c) behaves incorrectly when compiled with optimization level -O1 or higher for PPC targets.

For 32-bit PPC

$ clang --target=powerpc-unknown-linux-gnu -O3 -c ppc_bsjlj.c

results in the output

value = 268566576 value = 268566596

where the two lines should be identical.

Similarly, for ppc64le

$ clang --target=powerpc64le-unknown-linux-gnu -O3 -c ppc_bsjlj.c

results in

value = 268566608 value = 268566648

Note that in the program the value of the local variable n is not changed between __builtin_setjmp and the corresponding __builtin_longjmp. Indeed it is const-qualified.

Quuxplusone commented 3 years ago

Attached ppc_bsjlj.c (581 bytes, text/x-csrc): Repro

Quuxplusone commented 3 years ago
FWIW, it seems that the workaround code in the repro does not work any more
with Clang/LLVM version 12.0.1 or 13.0.0-rc1. With 12.0.1,

$ /usr/lib/llvm/12/bin/clang --target=powerpc64le-unknown-linux-musl -O3
ppc_bsjlj.c -DWORKAROUND=1

results in the hexdump'ed output

00000000  76 61 6c 75 65 20 3d 20  32 37 34 38 37 38 31 30  |value = 27487810|
00000010  37 38 35 36 0a f0 15 83  01 40                    |7856.....@|

and with 13.0.0-rc1,

$ /usr/lib/llvm/13/bin/clang --target=powerpc64le-unknown-linux-musl -O3
ppc_bsjlj.c -DWORKAROUND=1

results in

00000000  76 61 6c 75 65 20 3d 20  32 37 34 38 37 38 31 30  |value = 27487810|
00000010  37 38 35 36 0a e0 15 83  01 40                    |7856.....@|

I have no idea whether this is a separate issue or not. Note that this time
musl is used as a target, and so the generated executable becomes a PIE, which
I am not sure is relevant.
Quuxplusone commented 3 years ago

Attached bug50234-disasm.txt (7559 bytes, text/plain): Disassembly of main (compiled with -O1)

Quuxplusone commented 3 years ago

It seems that __builtin_setjmp needs attribute returns_twice.

Proposed change: https://reviews.llvm.org/D109248