diff options
-rw-r--r-- | lib/Analysis/Lint.cpp | 6 | ||||
-rw-r--r-- | test/Other/lint.ll | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/Analysis/Lint.cpp b/lib/Analysis/Lint.cpp index a031cbc65b..8119debdaf 100644 --- a/lib/Analysis/Lint.cpp +++ b/lib/Analysis/Lint.cpp @@ -310,6 +310,12 @@ void Lint::visitReturnInst(ReturnInst &I) { 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 diff --git a/test/Other/lint.ll b/test/Other/lint.ll index 1f9efe3ad9..d0d3c7e186 100644 --- a/test/Other/lint.ll +++ b/test/Other/lint.ll @@ -97,3 +97,10 @@ define void @use_tail(i8* %valist) { 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 +} |