[PATCH] D12408: CFL AA Bugfix -- Mark no-args function return values as unknown values

George Burgess IV via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 13:43:49 PDT 2015


george.burgess.iv updated this revision to Diff 33356.
george.burgess.iv marked an inline comment as done.
george.burgess.iv added a comment.

Added `type != void && len(args) == 0` type check


http://reviews.llvm.org/D12408

Files:
  lib/Analysis/CFLAliasAnalysis.cpp
  test/Analysis/CFLAliasAnalysis/opaque-call-alias.ll

Index: test/Analysis/CFLAliasAnalysis/opaque-call-alias.ll
===================================================================
--- /dev/null
+++ test/Analysis/CFLAliasAnalysis/opaque-call-alias.ll
@@ -0,0 +1,20 @@
+; We previously had a case where we would put results from a no-args call in
+; its own stratified set. This would make cases like the one in @test say that
+; nothing (except %Escapes and %Arg) can alias
+
+; RUN: opt < %s -cfl-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
+
+; CHECK:     Function: test
+; CHECK:     MayAlias: i8* %Arg, i8* %Escapes
+; CHECK:     MayAlias: i8* %Arg, i8* %Retrieved
+; CHECK:     MayAlias: i8* %Escapes, i8* %Retrieved
+define void @test(i8* %Arg) {
+  %Noalias = alloca i8
+  %Escapes = alloca i8
+  call void @set_thepointer(i8* %Escapes)
+  %Retrieved = call i8* @get_thepointer()
+  ret void
+}
+
+declare void @set_thepointer(i8* %P)
+declare i8* @get_thepointer()
Index: lib/Analysis/CFLAliasAnalysis.cpp
===================================================================
--- lib/Analysis/CFLAliasAnalysis.cpp
+++ lib/Analysis/CFLAliasAnalysis.cpp
@@ -398,16 +398,26 @@
   }
 
   template <typename InstT> void visitCallLikeInst(InstT &Inst) {
+    // TODO: Add support for noalias args/all the other fun function attributes
+    // that we can tack on.
     SmallVector<Function *, 4> Targets;
     if (getPossibleTargets(&Inst, Targets)) {
       if (tryInterproceduralAnalysis(Targets, &Inst, Inst.arg_operands()))
         return;
       // Cleanup from interprocedural analysis
       Output.clear();
     }
 
+    // Because the function is opaque, we need to note that anything
+    // could have happened to the arguments, and that the result could alias
+    // just about anything, too.
+    // The goal of the loop is in part to unify many Values into one set, so we
+    // don't care if the function is void there.
     for (Value *V : Inst.arg_operands())
       Output.push_back(Edge(&Inst, V, EdgeType::Assign, AttrAll));
+    if (Inst.getNumArgOperands() == 0 &&
+        Inst.getType() != Type::getVoidTy(Inst.getContext()))
+      Output.push_back(Edge(&Inst, &Inst, EdgeType::Assign, AttrAll));
   }
 
   void visitCallInst(CallInst &Inst) { visitCallLikeInst(Inst); }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12408.33356.patch
Type: text/x-patch
Size: 2268 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150827/4e396f7d/attachment.bin>


More information about the llvm-commits mailing list