/* Jacob Egner */ /* Includes ------------------------------------------------------------------*/ //#include "91x_type.h" //#include "91x_map.h" typedef unsigned long u32; typedef volatile unsigned short vu16; typedef struct { vu16 CRR; vu16 EMPTY1; vu16 CMR; vu16 EMPTY2; vu16 M1R; vu16 EMPTY3; vu16 M2R; vu16 EMPTY4; vu16 A1R; vu16 EMPTY5; vu16 A2R; vu16 EMPTY6; vu16 MCR; vu16 EMPTY7; vu16 DA1R; vu16 EMPTY8; vu16 DA2R; vu16 EMPTY9; vu16 DB1R; vu16 EMPTY10; vu16 DB2R; vu16 EMPTY11[27]; } CAN_MsgObj_TypeDef; typedef struct { vu16 CR; vu16 EMPTY1; vu16 SR; vu16 EMPTY2; vu16 ERR; vu16 EMPTY3; vu16 BTR; vu16 EMPTY4; vu16 IDR; vu16 EMPTY5; vu16 TESTR; vu16 EMPTY6; vu16 BRPR; vu16 EMPTY7[3]; CAN_MsgObj_TypeDef sMsgObj[2]; vu16 EMPTY8[16]; vu16 TXR1R; vu16 EMPTY9; vu16 TXR2R; vu16 EMPTY10[13]; vu16 ND1R; vu16 EMPTY11; vu16 ND2R; vu16 EMPTY12[13]; vu16 IP1R; vu16 EMPTY13; vu16 IP2R; vu16 EMPTY14[13]; vu16 MV1R; vu16 EMPTY15; vu16 MV2R; vu16 EMPTY16; } CAN_TypeDef; #define CAN ((CAN_TypeDef *) 0x5c009000) // some requirements to show local variables incorrectly: // 1: function must return a value; can not be a void function; // 2: must have the if-then statement for localVar // 3: must have 2 lines writing to a CAN->sMsgObj element with the use of localVar; // one line won't create the issue; // writing to CAN->sMsgObj[0] won't create the issue; // // perhaps you can create another bad function very different from this // function without meeting any of the requirements above, but my experiments // show that having a similar function that breaks any of the requirements will // not lead to the local variable display issue u32 badFunction(u32 passedArg) { u32 localVar = 0; if (localVar) { localVar++; } CAN->sMsgObj[localVar].DA1R = 0; CAN->sMsgObj[localVar].DB1R = 0; return 0; } u32 goodFunction(u32 passedArg) { u32 localVar = 0; if (localVar) { localVar++; } CAN->sMsgObj[0].DA1R = 0; // note the lack of localVar CAN->sMsgObj[0].DB1R = 0; // note the lack of localVar return 0; } int main() { while(1) { badFunction(3); goodFunction(4); } return 0; }