You still are not guaranteed to clear the buffer like that.
for (int i=0; i<len; i++){
sensitiveBuffer[i]=random();
}
int sum=0;
for (int i=0; i<len; i++){
sum+=sensitiveBuffer[i];
}
volitileVar=sum;
Using loop fusion, the compiler can optimize this to:
int sum=0;
for (int i=0; i<len; i++){
sensitiveBuffer[i]=random();
sum+=sensitiveBuffer[i];
}
volitileVar=sum;
Which it can then optimize to:
int sum=0;
for (int i=0; i<len; i++){
sum+=random();
}
volitileVar=sum;
In fact, as the article points out, the compiler can legally transform:
reallyZeroBuffer(sensitiveBuffer);
into
pointlesslyCopy(sensitiveBuffer);
reallyZeroBuffer(sensitiveBuffer);