Hi,<br><br><br>I encountered a problem about volatile quantifier when using llvm-gcc, here is the example:<br><br>#define N 10<br><br>int sum(volatile int a[N]) {<br> int sum = 0;<br> unsigned i = 0;<br> for (i = 0; i < N; ++i)<br>
sum += a[i];<br><br> return sum;<br>}<br><br><br>If I compile it as C code, then llvm-gcc will dump:<br><br>define i32 @sum(i32* nocapture %a) nounwind {<br>bb1.thread:<br> %0 = volatile load i32* %a, align 4 ; <i32> [#uses=1]<br>
%1 = getelementptr i32* %a, i32 1 ; <i32*> [#uses=1]<br> %2 = volatile load i32* %1, align 4 ; <i32> [#uses=1]<br> %3 = add i32 %2, %0 ; <i32> [#uses=1]<br> ...<br>}<br><br>We can see the load is "volatile", this is correct and expected.<br>
<br><br>But when I compile the example as C++ code, then llvm-gcc dump:<br><br>define i32 @_Z3sumPVi(i32* nocapture %a) nounwind readonly {<br>bb1.thread:<br> %0 = load i32* %a, align 4 ; <i32> [#uses=1]<br>
%1 = getelementptr i32* %a, i32 1 ; <i32*> [#uses=1]<br> %2 = load i32* %1, align 4 ; <i32> [#uses=1]<br> %3 = add i32 %2, %0 ; <i32> [#uses=1]<br> ...<br>}<br><br>No volatile keeps, is it expected or a bug for llvm-gcc?<br>
<br>Anyone can help me? Thanks in advance.<br><br><br>Sheng.<br>