Question about compiling exit and clang assert

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about compiling exit and clang assert

Sumner, Brian via cfe-dev
I have a simulator for a target machine that I wrote an llvm port for
The simulator detects a return to address zero as returning from “main"
and that ends the simulation, with main's return value then being printed out
(and finally returned from the simulator to the shell).

I tried to implement “exit” in C rather than in assembly with the following


void * __builtin_frame_address (unsigned int level);

int exit (int X)
{
((int*)__builtin_frame_address(0))[1] = 0; // simulator termination magic
return X; // put result code in R0, as though returning X from main
}


After some warnings about redeclaration and about noreturn
clang crashes with an assert,

So my question is, isn’t the clang assertion too conservative ?
Why crash after warnings, why not let it go through ?


TIA,
Peter Lawrence.



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about compiling exit and clang assert

Sumner, Brian via cfe-dev
Ooops, my apologies for that question. my target, like MSP430 has 16-bit ints,
but unlike MSP430, does not support 32-bit ints at all, so the actual crash
is in the call to __builtin_frame_address(0) which expects i32, but is being
passed i16 because that’s all my target supports.

If I change clang so that __builtin_frame_address / __builtin_return_address
take “native” size ints rather than being hard wired to i32
is that the sort of thing that a patch would be accepted for ?


TIA,
Peter Lawrence.

On Jul 23, 2017, at 11:04 AM, Peter Lawrence <[hidden email]> wrote:

I have a simulator for a target machine that I wrote an llvm port for
The simulator detects a return to address zero as returning from “main"
and that ends the simulation, with main's return value then being printed out
(and finally returned from the simulator to the shell).

I tried to implement “exit” in C rather than in assembly with the following


void * __builtin_frame_address (unsigned int level);

int exit (int X)
{
((int*)__builtin_frame_address(0))[1] = 0; // simulator termination magic
return X; // put result code in R0, as though returning X from main
}


After some warnings about redeclaration and about noreturn
clang crashes with an assert,

So my question is, isn’t the clang assertion too conservative ?
Why crash after warnings, why not let it go through ?


TIA,
Peter Lawrence.




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...