llvm-cbe icon indicating copy to clipboard operation
llvm-cbe copied to clipboard

volatile dropped

Open spth opened this issue 9 years ago • 1 comments

A common idiom for memory-mapped I/O is this:

void f(void)
{
  (*(volatile uint8_t*)42) = 23;
}

clang-3.8 correctly compiles this into a volatile store in LLVM IR:

define void @f() #0 {
  store volatile i8 23, i8* inttoptr (i64 42 to i8*), align 1
  ret void
}

However, the cbe drops the volatile:

void f(void) {
  *((uint8_t*)(uintptr_t)UINT64_C(42)) = 23;
}

Philipp

spth avatar Sep 21 '16 11:09 spth

The problem happens for reading from an address just as for writing to an address.

Philipp

spth avatar Sep 21 '16 11:09 spth