Strange exception code behavior: insertion of trace instructions makes result incorrect

Here is what I did: I took c.C (attached), compiled it into my.ll code with command 'clang++ -O3 -fexceptions -emit-llvm -S -o my.ll c.C' and added tracing command on every line, see attached my.ll

Running my.ll in interpreter with this command 'llvm-as my.ll && lli -jit-enable-eh my.bc', I get this log:
TRACE num=20
TRACE num=22
TRACE num=27
TRACE num=29
TRACE num=31
TRACE num=33
TRACE num=58
TRACE num=60
TRACE num=62
TRACE num=64
TRACE num=66
TRACE num=70
TRACE num=72
Stack dump:
0. Program arguments: lli -jit-enable-eh my.bc
Bus error: 10

The line: TRACE num=72 is the next after _Unwind_Resume_or_Rethrow that is marked noreturn.

Runing the same code as binary also bahaves in a similar way: 'llvm-as my.ll && llc -o my.s my.bc && as -o my.o my.s && g++ -o my my.o && my':
TRACE num=20
TRACE num=22
TRACE num=27
TRACE num=29
TRACE num=31
TRACE num=33
TRACE num=58
TRACE num=60
TRACE num=62
TRACE num=64
TRACE num=66
TRACE num=70
TRACE num=72
TRACE num=134515344
Segmentation fault

Removing all calls to mytrace makes behavior correct.

Why I can't insert trace instructions? What is the state that is saved between commands that causes such crashes?

Also only leaving one 'mytrace ' instruction before or after llvm.eh.exception near the label lpad1 already causes the crash.

I think something is wrong with llvm.eh.exception and/or llvm.eh.selector. Do they pass each other values in registers or something like this?

Yuri

c.C (170 Bytes)

my.ll (5.52 KB)

Hi Yuri, there shouldn't be any non-trivial instructions between the start
of the landing pad and the eh.selector call, except for calls to eh.exception.

Ciao,

Duncan.