From: Daniel Berlin Date: Tue, 18 Mar 2008 22:22:53 +0000 (+0000) Subject: Fix PR 2160 by making sure arguments to external functions get marked as pointing... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d3bf1aef3f1bfba362b71e72f416100a82d5b5db;p=oota-llvm.git Fix PR 2160 by making sure arguments to external functions get marked as pointing to anything git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48509 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp index a66a6faf1c5..49c6edd6207 100644 --- a/lib/Analysis/IPA/Andersens.cpp +++ b/lib/Analysis/IPA/Andersens.cpp @@ -647,9 +647,13 @@ Andersens::getModRefInfo(CallSite CS, Value *P, unsigned Size) { if (N1->PointsTo->empty()) return NoModRef; - +#if FULL_UNIVERSAL + if (!UniversalSet->PointsTo->test(FindNode(getNode(P)))) + return NoModRef; // Universal set does not contain P +#else if (!N1->PointsTo->test(UniversalSet)) return NoModRef; // P doesn't point to the universal set. +#endif } return AliasAnalysis::getModRefInfo(CS, P, Size); @@ -1266,29 +1270,43 @@ void Andersens::AddConstraintsForCall(CallSite CS, Function *F) { } CallSite::arg_iterator ArgI = CS.arg_begin(), ArgE = CS.arg_end(); + bool external = !F || F->isDeclaration(); if (F) { // Direct Call Function::arg_iterator AI = F->arg_begin(), AE = F->arg_end(); - for (; AI != AE && ArgI != ArgE; ++AI, ++ArgI) - if (isa(AI->getType())) { - if (isa((*ArgI)->getType())) { - // Copy the actual argument into the formal argument. - Constraints.push_back(Constraint(Constraint::Copy, getNode(AI), - getNode(*ArgI))); - } else { - Constraints.push_back(Constraint(Constraint::Copy, getNode(AI), - UniversalSet)); - } - } else if (isa((*ArgI)->getType())) { + for (; AI != AE && ArgI != ArgE; ++AI, ++ArgI) + { +#if !FULL_UNIVERSAL + if (external && isa((*ArgI)->getType())) + { + // Add constraint that ArgI can now point to anything due to + // escaping, as can everything it points to. The second portion of + // this should be taken care of by universal = *universal + Constraints.push_back(Constraint(Constraint::Copy, + getNode(*ArgI), + UniversalSet)); + } +#endif + if (isa(AI->getType())) { + if (isa((*ArgI)->getType())) { + // Copy the actual argument into the formal argument. + Constraints.push_back(Constraint(Constraint::Copy, getNode(AI), + getNode(*ArgI))); + } else { + Constraints.push_back(Constraint(Constraint::Copy, getNode(AI), + UniversalSet)); + } + } else if (isa((*ArgI)->getType())) { #if FULL_UNIVERSAL - Constraints.push_back(Constraint(Constraint::Copy, - UniversalSet, - getNode(*ArgI))); + Constraints.push_back(Constraint(Constraint::Copy, + UniversalSet, + getNode(*ArgI))); #else - Constraints.push_back(Constraint(Constraint::Copy, - getNode(*ArgI), - UniversalSet)); + Constraints.push_back(Constraint(Constraint::Copy, + getNode(*ArgI), + UniversalSet)); #endif + } } } else { //Indirect Call diff --git a/test/Analysis/Andersens/modreftest2.ll b/test/Analysis/Andersens/modreftest2.ll new file mode 100644 index 00000000000..2bb21673676 --- /dev/null +++ b/test/Analysis/Andersens/modreftest2.ll @@ -0,0 +1,14 @@ +; RUN: llvm-as < %s | opt -anders-aa -gvn | llvm-dis \ +; RUN: | not grep {ret i32 undef} + +;; From PR 2160 +declare void @f(i32*) + +define i32 @g() { +entry: + %tmp = alloca i32 ; [#uses=2] + call void @f( i32* %tmp ) + %tmp2 = load i32* %tmp ; [#uses=1] + ret i32 %tmp2 +} +