Add a lint check for returning the address of stack memory.
llvm-svn: 104936
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index a031cbc..8119deb 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -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