Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Miscompilation of load from nocapture argument that is indirectly copied to a local alloca #13809

Closed Quuxplusone closed 11 years ago

Quuxplusone commented 12 years ago
Bugzilla Link PR14045
Status RESOLVED FIXED
Importance P enhancement
Reported by Richard Osborne (richard@xmos.com)
Reported on 2012-10-09 04:24:12 -0700
Last modified on 2012-11-05 04:55:39 -0800
Version trunk
Hardware PC Linux
CC baldrick@free.fr, geek4civic@gmail.com, llvm-bugs@lists.llvm.org, llvm@sunfishcode.online, nicholas@mxc.ca, pawel@32bitmicro.com, rafael@espindo.la
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Regarding the nocapture attribute the language ref says: "the callee does not
make any copies of the pointer that outlive the callee itself". Therefore it
should be OK for the callee to make a copy of the pointer that doesn't outlive
the call. Consider the following example:

1  declare void @g(i32** %p, i32* %q) nounwind
2
3  define i32 @f(i32* noalias nocapture %p) nounwind {
4  entry:
5    %q = alloca i32*
6    call void @g(i32** %q, i32* %p) nounwind
7    store i32 0, i32* %p
8    %0 = load i32** %q
9    store i32 1, i32* %0
10   %1 = load i32* %p
11   ret i32 %1
12 }

The store on line 9 might write to %p since g() might store the value of its
second argument to its first argument. While this creates a copy of %p it
doesn't violate the nocapture attribute as the copy wouldn't outlive the
function.

However if I run the following example through opt -basicaa -gvn I get the
following:

declare void @g(i32**, i32*) nounwind

define i32 @f(i32* noalias nocapture %p) nounwind {
entry:
  %q = alloca i32*
  call void @g(i32** %q, i32* %p) nounwind
  store i32 0, i32* %p
  %0 = load i32** %q
  store i32 1, i32* %0
  ret i32 0
}

The return has been optimized to a return 0, indicating that basic alias
analysis has incorrectly concluded that there is no possible alias between the
load on line 10 and and the store on line 9.
Quuxplusone commented 11 years ago

This is fixed in r167381:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20121105/155155.html