[LLVMdev] llvm-gcc doesnt honor volatile quantifier of the array type?

Zhou Sheng
2009-01-13T03:16:20Z

Hi,


I encountered a problem about volatile quantifier when using llvm-gcc, here
is the example:

#define N 10

int sum(volatile int a[N]) {
   int sum = 0;
   unsigned i = 0;
   for (i = 0; i < N; ++i)
       sum += a[i];

   return sum;
}


If I compile it as C code, then llvm-gcc will dump:

define i32 @sum(i32* nocapture %a) nounwind {
bb1.thread:
    %0 = volatile load i32* %a, align 4     ; <i32> [#uses=1]
    %1 = getelementptr i32* %a, i32 1       ; <i32*> [#uses=1]
    %2 = volatile load i32* %1, align 4     ; <i32> [#uses=1]
    %3 = add i32 %2, %0     ; <i32> [#uses=1]
   ...
}

We can see the load is "volatile", this is correct and expected.


But when I compile the example as C++ code, then llvm-gcc dump:

define i32 @_Z3sumPVi(i32* nocapture %a) nounwind readonly {
bb1.thread:
    %0 = load i32* %a, align 4      ; <i32> [#uses=1]
    %1 = getelementptr i32* %a, i32 1       ; <i32*> [#uses=1]
    %2 = load i32* %1, align 4      ; <i32> [#uses=1]
    %3 = add i32 %2, %0     ; <i32> [#uses=1]
    ...
}

No volatile keeps, is it expected or a bug for llvm-gcc?

Anyone can help me?  Thanks in advance.


Sheng.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20090113/b186e753/attachment.html>