Skip to content

dead store pass ignores memory clobbering asm statement #15867

@llvmbot

Description

@llvmbot
Bugzilla Link 15495
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @echristo,@noloader,@pageexec,@pogo59,@socketpair

Extended Description

Consider this function:

#include <string.h>

void foo(int x) {
  char buf[10];
  int i;
  for (i=0; i<sizeof(buf); ++i)
    buf[i]=x++;
  memset(buf,0,sizeof(buf));
}

llvm removes all the write accesses to buf. OK so far.
Now let's add an asm statement to tell the optimizer that it cannot remove writes to buf:

void foo(int x) {
  char buf[10];
  int i;
  for (i=0; i<sizeof(buf); ++i)
    buf[i]=x++;
  memset(buf,0,sizeof(buf));
  asm("" : : : "memory");
}

llvm ignores the asm statement and still removes all stores to the local buffer.
I think this is a bug. At least gcc and icc honor the asm statement and don't remove the stores if it is present.

I was using:

clang version 3.3 (trunk 176552)
Target: x86_64-unknown-linux-gnu
Thread model: posix

This bug is quite important because it may introduce security problems in crypto code attempting to cleanse keys from memory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions