MPC55xx Warning for Undefined Behavior

Peter Dufault dufault at hda.com
Mon Oct 13 17:07:16 UTC 2014


On Oct 13, 2014, at 12:05 , Joel Sherrill <Joel.Sherrill at oarcorp.com> wrote:

> Hi
> 
> I noticed this going over the logs and wanted help resolving it.
> 
>      5 c/src/lib/libcpu/powerpc/mpc55xx/irq/irq.c:170:27: warning:
> iteration 474ul invokes undefined behavior [-Waggressive-loop-optimizations]
> 
> $ grep "undefined be"  log/*
> log/powerpc-mpc5674f_ecu508_app.log:../../../../../../../rtems/c/src/lib/libcpu/powerpc/mpc55xx/irq/irq.c:170:27:
> warning: iteration 474ul invokes undefined behavior
> [-Waggressive-loop-optimizations]
> log/powerpc-mpc5674f_ecu508_boot.log:../../../../../../../rtems/c/src/lib/libcpu/powerpc/mpc55xx/irq/irq.c:170:27:
> warning: iteration 474ul invokes undefined behavior
> [-Waggressive-loop-optimizations]
> log/powerpc-mpc5674fevb.log:../../../../../../../rtems/c/src/lib/libcpu/powerpc/mpc55xx/irq/irq.c:170:27:
> warning: iteration 474ul invokes undefined behavior
> [-Waggressive-loop-optimizations]
> log/powerpc-mpc5674fevb_spe.log:../../../../../../../rtems/c/src/lib/libcpu/powerpc/mpc55xx/irq/irq.c:170:27:
> warning: iteration 474ul invokes undefined behavior
> [-Waggressive-loop-optimizations]
> log/powerpc-mpc5674f_rsm6.log:../../../../../../../rtems/c/src/lib/libcpu/powerpc/mpc55xx/irq/irq.c:170:27:
> warning: iteration 474ul invokes undefined behavior
> [-Waggressive-loop-optimizations]
> 
> -- 

Something is wrong.  The code is initializing these PSRs and for the MPC567X it is sized to 474 (libcpu/powerpc/mpc55xx/include/fsl-mpc567x.h):

   union {             /* Software Set/Clear Interrupt Register */
            uint8_t R;
            struct {
                uint8_t:4;
                uint8_t PRI:4;
            } B;
        } PSR[474]

but the upper limit of loop is #defined to 479:

  #if MPC55XX_CHIP_FAMILY == 555
    #define MPC55XX_IRQ_MAX 307U
  #elif MPC55XX_CHIP_FAMILY == 556
    #define MPC55XX_IRQ_MAX 360U
  #elif MPC55XX_CHIP_FAMILY == 567
    #define MPC55XX_IRQ_MAX 479U
  #else
    #error "unsupported chip type"
  #endif

The code will go on and step on a reserved area.

-----------------
Peter Dufault
HD Associates, Inc.      Software and System Engineering




More information about the devel mailing list