[llvm-commits] [llvm] r104936 - in /llvm/trunk: lib/Analysis/Lint.cpp test/Other/lint.ll

Dan Gohman gohman at apple.com
Thu May 27 21:33:42 PDT 2010


Author: djg
Date: Thu May 27 23:33:42 2010
New Revision: 104936

URL: http://llvm.org/viewvc/llvm-project?rev=104936&view=rev
Log:
Add a lint check for returning the address of stack memory.

Modified:
    llvm/trunk/lib/Analysis/Lint.cpp
    llvm/trunk/test/Other/lint.ll

Modified: llvm/trunk/lib/Analysis/Lint.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Lint.cpp?rev=104936&r1=104935&r2=104936&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Lint.cpp (original)
+++ llvm/trunk/lib/Analysis/Lint.cpp Thu May 27 23:33:42 2010
@@ -310,6 +310,12 @@
   Assert1(!F->doesNotReturn(),
           "Unusual: Return statement in function with noreturn attribute",
           &I);
+
+  if (Value *V = I.getReturnValue()) {
+    Value *Obj = V->getUnderlyingObject();
+    Assert1(!isa<AllocaInst>(Obj) && !isa<VAArgInst>(Obj),
+            "Unusual: Returning alloca or va_arg value", &I);
+  }
 }
 
 // TODO: Add a length argument and check that the reference is in bounds

Modified: llvm/trunk/test/Other/lint.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/lint.ll?rev=104936&r1=104935&r2=104936&view=diff
==============================================================================
--- llvm/trunk/test/Other/lint.ll (original)
+++ llvm/trunk/test/Other/lint.ll Thu May 27 23:33:42 2010
@@ -97,3 +97,10 @@
   tail call void @tailcallee(i8* %s)
   ret void
 }
+
+; CHECK: Unusual: Returning alloca or va_arg value
+define i8* @return_local(i32 %n, i32 %m) {
+  %t = alloca i8, i32 %n
+  %s = getelementptr i8* %t, i32 %m
+  ret i8* %s
+}





More information about the llvm-commits mailing list