Tool/software: TI C/C++ Compiler
hi, with gcc 9.2.0.50, the following code is miscompiled. this was only observed due to it generating an infinite loop.
the test case below is a stripped-down version of my application (which doesn't actually count vectors; this is just the minimum test case that demonstrates miscompilation)
the writes to gpio are not actually necessary - it was just helpful for me to marry up objdump output with source code
i can coerce the compiler into emitting correct code by disabling certain optimisations (see below), which may give a clue as to where things are going wrong. or maybe not - i'm not a compiler expert!
if anyone digs into this, i'd appreciate a heads-up as i don't habitually hang out on these forums
/* ----------------------------------------------------------------------
* compile with:
* msp430-gcc -Os -mmcu=msp430f149 -Ic:/ti/msp430_gcc/include test.c
*
* the compiler turns the function vectors_used incorrectly into an
* infinite loop
*
* a liberal sprinkling of volatile qualifiers will cause correct (but
* suboptimal) code to be generated. adding "-fno-tree-dominator-opts
* -fno-tree-vrp" to the compiler switches will also cause correct
* code to be generated
* -------------------------------------------------------------------- */
#include <msp430.h>
#include <stdio.h>
typedef unsigned int u16;
u16 __attribute__((used)) vectors_used( void )
{
const u16 *addr;
u16 used = 0;
for (addr=(const u16 *)0xffe0; addr; addr++) {
if ( *addr != 0xffff ) {
P5OUT = 1;
used++;
P5OUT = 0;
}
}
return used;
}
int main( void )
{
for (;;) {
P4OUT = vectors_used();
}
return 0;
}