[cfe-dev] SIGILL with clang

John McCall via cfe-dev cfe-dev at lists.llvm.org
Mon Aug 28 11:43:21 PDT 2017


> On Aug 27, 2017, at 7:11 PM, Csaba Raduly via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi,
> foo() has undefined behavior if i==0 (lack of return statement)
> 
> 6.6.3 para 2:
> Flowing off the end of a function is equivalent to a return with no
> value; this results in undefined behavior
> in a value-returning function.
> 
> clang generates an invalid instruction for undefined behavior.
> This is not ARM-specific.

Note that this is C++-specific; it is only undefined behavior in C if the result is used by the caller.

John.

> 
> https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,source:'int+foo(int+i)+%7B%0A+if(i)+%7B%0A+++return+1%3B%0A+%7D%0A%7D%0A%0Aint+main()+%7B%0A+foo(0)%3B%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang400,filters:(___0:(),b:'0',commentOnly:'0',directives:'0',intel:'0',jquery:'3.2.1',length:1,prevObject:(___0:(),length:1,prevObject:(___0:(jQuery3210202339019067484751:(display:'')),length:1)),trim:'0'),options:'-O0',source:1),l:'5',n:'0',o:'x86-64+clang+4.0.0+(Editor+%231,+Compiler+%231)',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4
> 
> That ud2 instruction is the machine code for undefined behavior.
> 
> Csaba
> 
> 
> On Sat, Aug 26, 2017 at 12:32 PM, Raphael Isemann via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>> Glad to help. CCing ML for the record.
>> 
>> On Aug 26, 2017 12:24 PM, "ROHIT KUMAR" <rohitpoddar92 at gmail.com> wrote:
>> 
>> It is as you mentioned. The missing return statement in a function very much
>> similar to your example. Adding it fixed the issue
>> 
>> So, it seems Clang is a little too strict as compared to GCC. I faced many
>> issues earlier and all of them ended up being related to flags, I didn't
>> expect the issue to be this simple.
>> 
>> Thanks for your help
>> 
>> 
>> 
>> 
>> 
>> On Sat, Aug 26, 2017 at 3:14 PM, Raphael Isemann <teemperor at gmail.com>
>> wrote:
>>> 
>>> On a side note that is probably too simple for the ML: Did you check
>>> for missing return statements in the called/callee function? For a
>>> missing return clang generates SIGILL while GCC is returning something
>>> ABI-dependent IIRC.
>>> 
>>> E.g. this causes SIGILL on clang and runs just fine on GCC:
>>> ```
>>> int foo(int i) {
>>> if(i) {
>>>   return 1;
>>> }
>>> }
>>> 
>>> int main() {
>>> foo(0);
>>> }
>>> ```
>>> 
>>> - Raphael
>>> 
>>> 
>>> 2017-08-26 10:34 GMT+02:00 ROHIT KUMAR via cfe-dev
>>> <cfe-dev at lists.llvm.org>:
>>>> Hey folks,
>>>> 
>>>> I am migrating our huge Android code base from GCC(Eclipse IDE) to
>>>> clang(Android Studio).
>>>> 
>>>> Error: SIGILL (signal SIGILL: illegal instruction)
>>>> 
>>>> At a weird line in the code, I am getting this error. which points to a
>>>> closing curly bracket of an if condition. After googling, I am assuming
>>>> it
>>>> is some kind of architecture flag issue. I am using same flags which
>>>> were
>>>> used for GCC.
>>>> 
>>>> Note: I am currently working on Arm build.
>>>> 
>>>> Here are the architecture flags for ARM7:
>>>> 
>>>> -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mtune=cortex-a8
>>>> -mthumb
>>>> -DTARGET_THUMB2
>>>> 
>>>> Can anyone help me debug this issue? Is there any issue with the flags
>>>> with
>>>> clang?
>>>> 
>>>> Thanks,
>>>> Rohit Kumar
>>>> 
>>>> 
>>>> 
>>>> _______________________________________________
>>>> cfe-dev mailing list
>>>> cfe-dev at lists.llvm.org
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>> 
>> 
>> 
>> 
>> 
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>> 
> 
> 
> 
> -- 
> GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
> The Tao of math: The numbers you can count are not the real numbers.
> Life is complex, with real and imaginary parts.
> "Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
> "People disagree with me. I just ignore them." -- Linus Torvalds
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list