Skip to content

[MemCpyOpt] Slot optimization miscompilation #163455

@tmiasko

Description

@tmiasko

Running opt --passes=memcpyopt on

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @f(ptr dead_on_unwind noalias noundef writable dereferenceable(80) %a) {
start:
  %b = alloca [80 x i8]
  call void @g(ptr %b)
  call void @llvm.memcpy.p0.p0.i64(ptr %a, ptr %b, i64 80, i1 false)
  ret void
}

declare void @g(ptr)

results in

define void @f(ptr dead_on_unwind noalias noundef writable dereferenceable(80) %a) {
start:
  %b = alloca [80 x i8], align 1
  call void @g(ptr %a)
  ret void
}

In the resulting program, pointer passed to g can be incorrectly observed to equal %a, even though it was impossible originally.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions