[llvm-dev] Hoisting in the presence of volatile loads.

Sanjoy Das via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 20 11:37:46 PST 2017


Hi,

On Wed, Dec 20, 2017 at 9:50 AM, Alina Sbirlea <alina.sbirlea at gmail.com> wrote:
>> The testcase was inspired by a situation that a customer reported to us a
>> while back.
>> There was a function taking two pointers, one was used to load something
>> from device-mapped memory (volatile), while the other was accessing regular
>> memory.  These two pointers were aliased (in LLVM), but not because they
>> were proven to alias, but because they weren't proved to be different.
>> However, according to the C rules, accessing a volatile object through a
>> non-volatile pointer results in an undefined behavior, so we could have
>> assumed that the program was well-formed and thus that the pointers didn't
>> alias after all.

Fwiw, I was under the impression that regular loads could *not* be
reordered with volatile loads since we could have e.g.:

  int *normal = &global_variable;
  volatile int* ptr = 0;
  int k = *ptr; // segfaults, and the signal handler writes to *normal
  int value = *normal;

and that we'd have to treat volatile loads and stores essentially as
calls to unknown functions.

-- Sanjoy


More information about the llvm-dev mailing list