LAUNCHXL-F28P55X: Definition/Declaration of _assert in C2000 Compiler Library

Part Number: LAUNCHXL-F28P55X

Tool/software:

I am getting a new linting tool set up to run with my project, and I am running into an issue with the _assert(...) function/definition. From ccs2020\ccs\tools\compiler\ti-cgt-c2000_22.6.2.LTS\lib\src\assert.h, the _assert(...) call is made. However, I cannot find anywhere where this is defined or where it is documented, and so naturally my linter raises an error that it cannot find the declaration of it. Where does _assert(...) come from?


#if defined(NDEBUG)
#define assert(_ignore) ((void)0)
#elif defined(NASSERT)
#define assert(_expr)   _nassert(_expr)
#else
#if (defined(__clang__) && defined(__arm__)) || \
    (defined(_AEABI_PORTABILITY_LEVEL) && _AEABI_PORTABILITY_LEVEL != 0)
     extern void __aeabi_assert(const char *expr, const char *file, int line);
     #define assert(__e) ((__e) ? (void)0 : \
	         __aeabi_assert(#__e, __FILE__, __LINE__))
#else
     #define assert(_expr)   _assert((_expr) != 0,      \
                    "Assertion failed, (" _STR(_expr) "), file " __FILE__ \
                    ", line " _STR(__LINE__) "\n")
#endif /* _AEABI_PORTABILITY_LEVEL, __clang__ */
#endif /* NDEBUG, NASSERT */

  • Where does _assert(...) come from?

    It is an undocumented intrinsic.

    Please consider this example.  

    /* file.c */
    #include <assert.h>
    
    void example(int arg)
    {
        assert(arg > 0);
        /* processing with arg that presumes arg is positive */
    }

    Compile it ...

    cl2000 --opt_level=2 --src_interlist file.c

    Using optimization level 2 makes the generated assembly easier to understand.  (That's not always true, but it is in this case.)  The option --src_interlist causes the assembly file to be kept, and comments are added.  Inspect the resulting file.asm.  These are the key lines ...

            CMPB      AL,#0                 ; [CPU_ALU] |6| 
            B         $C$L1,GT              ; [CPU_ALU] |6| 
            ; branchcc occurs ; [] |6| 
    ;***  	-----------------------    return;
            MOVL      XAR4,#$C$FSL1         ; [CPU_ARAU] |6| 
            LCR       #__abort_msg          ; [CPU_ALU] |6| 
            ; call occurs [#__abort_msg] ; [] |6| 
    $C$L1:

    The argument (in the register AL) is compared against 0.  It if is less than or equal to 0, the function __abort_msg is called.  This function is supplied in the compiler RTS library.

    Thanks and regards,

    -George

  • Thanks George.

    That would explain it, thanks. Stubbing that intrinsic out made my linter happy, so that was the right route to take.