Page MenuHomePhabricator

Fix "Got assumption for the wrong function!" assert

Authored by apilipenko on Sep 18 2015, 3:49 AM.



define void @main(i8* %a) {

call i8 @foo(i8* %a)
ret void


declare void @llvm.assume(i1 %cond)
define i8 @foo(i8* align 8 %a) {

call void @llvm.assume(i1 1)
%res = load i8, i8* %a
ret i8 %res


opt -S -inline for the piece of code above fails with an assertion:
opt: /home/apilipenko/llvm-upstream/llvm/lib/Analysis/ValueTracking.cpp:719: void computeKnownBitsFromAssume(llvm::Value*, llvm::APInt&, llvm::APInt&, const llvm::DataLayout&, unsigned int, const {anonymous}::Query&): Assertion `I->getParent()->getParent() == Q.CxtI->getParent()->getParent() && "Got assumption for the wrong function!"' failed.

That happens because InlineFunction AddAlignmentAssumptions passes incorrect assumption cache to getKnownAlignment. It asks about caller's value alignment, but passes callee AC. Caller's AC must be passed instead.

This bug was introduced by "[PM] Split the AssumptionTracker immutable pass into two separate APIs" patch (

Diff Detail

Event Timeline

apilipenko updated this revision to Diff 35071.Sep 18 2015, 3:49 AM
apilipenko retitled this revision from to Fix "Got assumption for the wrong function!" assert.
apilipenko updated this object.
apilipenko added a reviewer: chandlerc.
apilipenko added a subscriber: llvm-commits.
sanjoy added a subscriber: sanjoy.Sep 18 2015, 10:40 AM

Please add a test case.

apilipenko updated this revision to Diff 35262.Sep 21 2015, 8:29 AM

Testcase added.

hfinkel accepted this revision.Sep 23 2015, 1:21 AM
hfinkel added a reviewer: hfinkel.
hfinkel added a subscriber: hfinkel.


This revision is now accepted and ready to land.Sep 23 2015, 1:21 AM
apilipenko closed this revision.Sep 24 2015, 9:13 AM