llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.8k stars 11.9k forks source link

[AArch64] UnwindInfo cannot be emitted if inline asm with align or fill are used #47432

Open RIscRIpt opened 3 years ago

RIscRIpt commented 3 years ago
Bugzilla Link 48088
Version 11.0
OS Windows NT
CC @RIscRIpt

Extended Description

For more info see FIXME in ARM64EmitUnwindInfo (llvm/lib/MC/MCWin64EH.cpp) https://github.com/llvm/llvm-project/blob/f69e090/llvm/lib/MC/MCWin64EH.cpp#L918-L943

Reproducible example:

void test() { __asm__(".balign 1");  }

Compiling with:

clang.exe --target=x86_64-pc-windows -c test.cpp

Gives no error, however, compiling with

clang.exe --target=aarch64-pc-windows -c test.cpp

Crashes:

fatal error: error in backend: Failed to evaluate function length in SEH unwind info Stack dump:

0.      Program arguments: clang.exe --target=aarch64-pc-windows -c test.cpp
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'test.cpp'.
4.      Running pass 'AArch64 Assembly Printer' on function '@"?test@@YAXXZ"'

Related bug report: llvm/llvm-project#40926

duk-37 commented 1 year ago

LLVM may generate alignment directives without using inline assembly at all when loops are involved due to either an explicit command line option or cpu-specific defaults.

The following will, at the time of writing, crash on trunk with the same error as above:

// clang test.c --target=aarch64-pc-windows-gnu -falign-loops=2 -O1
// clang test.c --target=aarch64-pc-windows-gnu -mtune=cortex-a72 -O2
void opaque();
void test(int x) {
    for (int i = 0; i < x; ++i)  opaque();
}

Workaround is to explicitly remove loop alignment hints through the command line via -falign-loops=1 or -mllvm -align-loops=1.