When undefined behavior is detected, do not optimize away the rest of the function

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Implement
    • Priority: Not Prioritized

      This example code intentionally dereferences a NULL pointer.

      #include <stdlib.h>
      
      void external_call();
      void ub_example()
      {
          external_call();
      
          unsigned int *const addr = NULL;
          (*addr) = 0xdeadbeef;
      
          external_call();
      }
      

      Build it with optimization -O1 or higher ...

      c29clang -O1 -S file.c
      

      Inspect the assembly file to see a very minimal function ...

      ub_example:                             ; @ub_example
      ; %bb.0:
              CALL    @external_call
      

      The rest of the function, including the return instruction, is optimized away.

      Consider changing the compiler to only optimize away the expression that contains undefined behavior. Or something else that is more friendly.

            Assignee:
            TI User
            Reporter:
            TI User
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Connection: Intermediate to External PROD System
                EXTSYNC-5666 - When undefined behavior is detected...
                SYNCHRONIZED
                • Last Sync Date: