Compiler ARMCLAN 6.21 optimization problem

In the following functions, I count the amount of allocated memory.

Getting the alloc size fails with compiler optimization -Os balanced. The variable allocSize keeps always the init value 42. Doing the same access in 2 steps returns the correct value!

And the same 1 step statement works in the osFreeMemTest() function!?

Do I have missed something in the C-syntax or is this a compiler bug?

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdlib.h>
static volatile uint32_t allocCount = 0;
static volatile uint32_t freeCount = 0;
static volatile uint32_t allocFreeDiff = 0;
static volatile uint32_t allocTotal = 0;
static volatile uint32_t allocTotal2 = 0;
void * osAllocMemTest(size_t size)
{
volatile uint32_t allocSize = 42;
volatile uint32_t * pAllocSize = 0;
volatile uint32_t allocSize2 = 0;
volatile void *p = 0;
p = malloc(size);
if (p == NULL) {
//System reset as ultimate fault handling
NVIC_SystemReset();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

0