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 Akos -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210104/d25a2f36/attachment.html>
On Mon, Jan 04, 2021 at 11:51:27AM +0100, Ákos Tompos via llvm-dev wrote:> And if you compile it like this: > clang -fPIC -mcmodel=large -o main main.cThat's not really a common combination, so I'm not surprised that you run into issues. Joerg
On 2021-01-04, Ákos Tompos via llvm-dev wrote:>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 >AkosThe 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.