llvm.org GIT mirror llvm / e5c8c5a
[msan] Check return value of main(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190782 91177308-0d34-0410-b5e6-96231b3b80d8 Evgeniy Stepanov 7 years ago
2 changed file(s) with 31 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
426426 bool LoadShadow;
427427 bool PoisonStack;
428428 bool PoisonUndef;
429 bool CheckReturnValue;
429430 OwningPtr VAHelper;
430431
431432 struct ShadowOriginAndInsertPoint {
448449 LoadShadow = SanitizeFunction;
449450 PoisonStack = SanitizeFunction && ClPoisonStack;
450451 PoisonUndef = SanitizeFunction && ClPoisonUndef;
452 // FIXME: Consider using SpecialCaseList to specify a list of functions that
453 // must always return fully initialized values. For now, we hardcode "main".
454 CheckReturnValue = SanitizeFunction && (F.getName() == "main");
451455
452456 DEBUG(if (!InsertChecks)
453457 dbgs() << "MemorySanitizer is not inserting checks into '"
16851689
16861690 void visitReturnInst(ReturnInst &I) {
16871691 IRBuilder<> IRB(&I);
1688 if (Value *RetVal = I.getReturnValue()) {
1689 // Set the shadow for the RetVal.
1692 Value *RetVal = I.getReturnValue();
1693 if (!RetVal) return;
1694 Value *ShadowPtr = getShadowPtrForRetval(RetVal, IRB);
1695 if (CheckReturnValue) {
1696 insertCheck(RetVal, &I);
1697 Value *Shadow = getCleanShadow(RetVal);
1698 IRB.CreateAlignedStore(Shadow, ShadowPtr, kShadowTLSAlignment);
1699 } else {
16901700 Value *Shadow = getShadow(RetVal);
1691 Value *ShadowPtr = getShadowPtrForRetval(RetVal, IRB);
1692 DEBUG(dbgs() << "Return: " << *Shadow << "\n" << *ShadowPtr << "\n");
16931701 IRB.CreateAlignedStore(Shadow, ShadowPtr, kShadowTLSAlignment);
1702 // FIXME: make it conditional if ClStoreCleanOrigin==0
16941703 if (MS.TrackOrigins)
16951704 IRB.CreateStore(getOrigin(RetVal), getOriginPtrForRetval(IRB));
16961705 }
0 ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s
1 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
2 target triple = "x86_64-unknown-linux-gnu"
3
4 define i32 @main() sanitize_memory {
5 entry:
6 %call = tail call i32 @f()
7 ret i32 %call
8 }
9
10 declare i32 @f() sanitize_memory
11
12 ; CHECK: @main
13 ; CHECK: call i32 @f()
14 ; CHECK: store i32 0, {{.*}} @__msan_retval_tls
15 ; CHECK: br i1
16 ; CHECK: call void @__msan_warning_noreturn()
17 ; CHECK: ret i32