float vs. mcmodel=large

Hi All,

First time poster here. I ran into an interesting issue today where clang generates a code which crashes. I know it’s a very common thing among programmers to blame the compiler for their own mistakes, but I think it’s not applicable for this case. I have managed to narrow down the problem to a few lines of code and two compiler options. Here is the code:

int main()
float f = 1.0f;
return 0;

And if you compile it like this:
clang -fPIC -mcmodel=large -o main main.c

Then the resulting executable will sigsev on the line trying to assing 1.0 to f;
This affects all versions of clang 7-11 on a PC 64bit. I have managed to try a clang-12 on a mac as well, that was also affected.
Clang-6.0 works.
It also works if you replace float with int.

I am puzzled now as this seems like a very obvious error. Is -mcmodel=large supported at all? Am I doing something wrong?

Thanks for your help

That's not really a common combination, so I'm not surprised that you
run into issues.


The unreleased clang-12 should be good.

I have fixed the bug in https://reviews.llvm.org/D86024
It should work on ELF platforms, but I don't know much about macOS.