This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

F29H850TU: Compiler stops compilation of function

Part Number: F29H850TU


Tool/software:

We have observed that the compiler does not continue compiling functions if the address 0x00000000 (NULL) is written within them.
This behaviour occurs when compiling with optimization level "-O1" (we have not tested with higher optimization levels):

The optimization level "-O0" is not affected by this:

We are aware that writing to the address 0x00000000 (reset vector) is not allowed, but we do not assume such behavior.
In particular, the compiler does not report any warnings or errors in this case.

To reproduce this issue on your side, we have modified the example "led_ex1_blinky.c" of the SDK:

#include "board.h"

int main (void)
{
    Device_init();
    Board_init();
    
    /* Compiler stops compilation of `main()` at this point when compiling with optimization level `-O1`.
     * No compilation warning or error is reported. However, compiling with `-O0` works as expected. */
    uint32_t *const addr = NULL;
    (*addr) = 0xdeadbeef;
    
    for(;;)
    {
        GPIO_writePin(myBoardLED1_GPIO, 0);
        DEVICE_DELAY_US(1000000);
        GPIO_writePin(myBoardLED1_GPIO, 1);
        DEVICE_DELAY_US(1000000);
    }
}

We use the makefile-based build to build the example: "gmake -s led_ex1_blinky.c PROFILE={debug_O0|debug_O1} CONFIG=FLASH"
Used compiler: "TI C29 Clang Compiler 1.0.0.LTS"

Many thanks in advance.

  • Dereferencing a NULL pointer is an example of undefined behavior.  When undefined behavior occurs, the compiler is not required to behave in any particular way.  What happens in this case is the compiler does not generate code for:

    • the statement that contains the undefined behavior
    • the return instruction of the function
    • and everything in between

    This is typical behavior for clang compilers.  Consider this example I created in compiler explorer.  Try it out with other clang compilers.  The result is similar.

    All the same, I filed the entry EXT_EP-12697 to request a change in compiler behavior.  Please understand this is only a request.  Do not view it as a guarantee the compiler gets changed.

    Thanks and regards,

    -George

  • Here is a workaround to consider.  Add the option -fno-delete-null-pointer-checks.  That disables this behavior ...

    the compiler does not continue compiling functions if the address 0x00000000 (NULL) is written within them

    For more details, search for the option on this page.

    Thanks and regards,

    -George