[LLVMbugs] [Bug 1647] New: volatile attribute lost on pointer array dereferences
bugzilla-daemon at cs.uiuc.edu
bugzilla-daemon at cs.uiuc.edu
Mon Sep 10 03:27:52 PDT 2007
http://llvm.org/bugs/show_bug.cgi?id=1647
Summary: volatile attribute lost on pointer array dereferences
Product: tools
Version: trunk
Platform: PC
OS/Version: Linux
Status: NEW
Severity: major
Priority: P2
Component: llvm-gcc
AssignedTo: unassignedbugs at nondot.org
ReportedBy: giuma.cordes at gmail.com
CC: llvmbugs at cs.uiuc.edu
Looks like the volatile attribute is lost in the llvm-gcc translator when
building an array reference out of a front-end pointer type, for example the
following trivial piece of code:
void foo(volatile int *p)
{
p[0] = 0;
}
produces the following llvm assembly:
; ModuleID = '/tmp/webcompile/_24474_0.bc'
target datalayout =
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
target triple = "i686-pc-linux-gnu"
define void @foo(i32* %p) {
entry:
store i32 0, i32* %p
ret void
}
while expressing the pointer dereference via the pointer dereference op works
ok:
void foo(volatile int *p)
{
*p = 0;
}
define void @foo(i32* %p) {
entry:
volatile store i32 0, i32* %p
ret void
}
I believe the problem originates from llv-gcc/gcc/c-typeck.c in function
build_array_ref near conditionally compiled LLVM section line 1893 were the
following piece of code:
{
tree ty = TREE_TYPE(TREE_TYPE(ar));
if (TREE_CODE(ty) != ARRAY_TYPE)
ty = TYPE_MAIN_VARIANT (ty);
return build4 (ARRAY_REF, ty, ar, index, NULL_TREE, NULL_TREE);
}
uses the main variant of the elements pointed to to build an array reference
instead in case of pointer indexed arithmetics.
Look like in doing so the volatile flag attached to the pointer type itself is
lost and not propagated to the array reference (along with possibly some other
attributes I'm not sure about, like side effects etc.)
Replacing the code above with the following one seems to fix the problem:
{
tree ty = TREE_TYPE(TREE_TYPE(ar));
if (TREE_CODE(ty) != ARRAY_TYPE) {
tree newty = TYPE_MAIN_VARIANT (ty);
tree ret = build4 (ARRAY_REF, newty, ar, index, NULL_TREE,
NULL_TREE);
/* we know it's a reference */
TREE_THIS_VOLATILE(ret) = TREE_THIS_VOLATILE(ty);
return ret;
}
return build4 (ARRAY_REF, ty, ar, index, NULL_TREE, NULL_TRE
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list