Optimization flags causing segfault on clang

Hey,

Context: Android native code built with clang using Android Studio.

We have been using GCC(Eclipse) for quite a while, now we are trying to move our huge code base to clang (to AndroidStudio).

With GCC we were using -O3 optimization and everything was working fine, but with clang, even -O1 is causing Android apps to crash on runtime with the seg fault.

Since apps are working fine when compiled with -O0, so my guess is some kind of optimization is not supported for our code base which is/are introduced by O1/2/3 flags.

Is there a way I can disable the flags introduced by -O1 one-by-one to figure out the culprit flag(s)?

Can anyone suggest me such flags to disable optimizations one-by-one? I tried googling but could not find much help.

I am stuck on this issue for quite a while now. I would really appreciate the help. I am looking for a more general advice on flags to disable optimizations one-by-one with -O1, because making changes in the code base would not be possible.

Thanks.

Rohit Kumar

You can use -mllvm -opt-bisect-limit= to bisect where the error occurs. More documentation here http://llvm.org/docs/OptBisect.html

Thanks, Craig.

So with this argument, the build failed on compilation with the last log as

"BISECT: NOT running pass (60626) optimize barriers pass on function … "

It points to a function in a class where we also had a high suspicion for. So it makes sense.

So it is very likely that the way our code is written is not meeting the standards used by clang and one or other optimization is breaking it.

Do you have any idea which flag is doing this “optimize barriers pass on function” which we can ignore?

You got a compilation failure not a runtime failure?

Yes. With this flag, I got compilation failure.

That’s not supposed to happen. What was the failure?

This is weird, I ran the build again and this time it showed error at a different location.

This is weird, I ran the build again and this time it showed error at a different location.

`

This is weird, I ran the build again and this time it showed error at a different location.

Please Ignore other emails with the same content. As the image size was larger the mailing group was blocking it, so compresses the image and resent it.

Error is:
Error: r13 not allowed here – `sub.w sp,r0,#1032

​(a picture)

Please, no pictures when the information is text.

https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_dos_copy.mspx

​Csaba​