RFC: Patch for CFA on Darwin

Bill,

The reason for it: when going to calculate the CFA in LLVM, the
original code was adding an offset of type i32 to a pointer. This is
fine if pointers are 32-bits, but we get an assert if the types are
different. By converting the cfa_offset to a pointer, we get it to be
that size.

Please ignore my prev. e-mail. The code breaks at least 32-bit stuff.
The arg of eh_dwarf_cfa is i32, how it can be pointer?

Hi Anton,

> The reason for it: when going to calculate the CFA in LLVM, the
> original code was adding an offset of type i32 to a pointer. This is
> fine if pointers are 32-bits, but we get an assert if the types are
> different. By converting the cfa_offset to a pointer, we get it to be
> that size.
Please ignore my prev. e-mail. The code breaks at least 32-bit stuff.
The arg of eh_dwarf_cfa is i32, how it can be pointer?

The built-in dwarf_cfa doesn't take an argument. It returns a pointer.
But there's an offset associated with the CFA. So it looks like LLVM
is taking the pointer and adding the offset to it to synthesize what
GCC is doing. I was running it on a 64-bit machine (I didn't know that
EH was broken on it), so that's why I had these problems. I thought
that there could be 32-bit pointers on a 32-bit system, but maybe I'm
wrong? :slight_smile:

-bw

Bill,

The built-in dwarf_cfa doesn't take an argument. It returns a pointer.

Ah. Sorry for confusion:
gcc's __builtin_draft_cfa doesn't have any argument
LLVM's eh_dwarf_cfa intrinsic has extra "offset" argument, which is
i32, because we have to propagate some information from GCC to LLVM.

But there's an offset associated with the CFA. So it looks like LLVM
is taking the pointer and adding the offset to it to synthesize what
GCC is doing.

Exactly. The only problem is that offset is platform-dependent and is
available on on gcc side. Thus extra argument of LLVM intrinsic.

One question, can the offset be >32-bit? If not, then this patch looks
good (though I haven't tested it yet). But if the offset can be
>32-bit, then we'll have trouble with the offset being truncated in
the front-end...

I expect offset to fit into i32 on every sane platform :slight_smile: In almost all
cases it should be something like +-4 or +-8.

Hi Anton,

One question, can the offset be >32-bit? If not, then this patch looks
good (though I haven't tested it yet). But if the offset can be

32-bit, then we'll have trouble with the offset being truncated in

the front-end...

I expect offset to fit into i32 on every sane platform :slight_smile: In almost all
cases it should be something like +-4 or +-8.

That sounds okay then. I'm hoping that we won't need an offset >2^32 either. :wink: If you're happy with your patch, then I'm okay with it too.

For the record, I forgot a part of the patch I sent out. The change in the LLVM tree that's needed is this:

Index: include/llvm/Intrinsics.td