llvm.org GIT mirror llvm / 054cec0
DataFlowSanitizer: Replace non-instrumented aliases of instrumented functions, and vice versa, with wrappers. Differential Revision: http://llvm-reviews.chandlerc.com/D1442 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189054 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 7 years ago
3 changed file(s) with 28 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
469469 FnsToInstrument.push_back(&*i);
470470 }
471471
472 // Give function aliases prefixes when necessary.
472 // Give function aliases prefixes when necessary, and build wrappers where the
473 // instrumentedness is inconsistent.
473474 for (Module::alias_iterator i = M.alias_begin(), e = M.alias_end(); i != e;) {
474475 GlobalAlias *GA = &*i;
475476 ++i;
480481 bool GAInst = isInstrumented(GA), FInst = isInstrumented(F);
481482 if (GAInst && FInst) {
482483 addGlobalNamePrefix(GA);
484 } else if (GAInst != FInst) {
485 // Non-instrumented alias of an instrumented function, or vice versa.
486 // Replace the alias with a native-ABI wrapper of the aliasee. The pass
487 // below will take care of instrumenting it.
488 Function *NewF =
489 buildWrapperFunction(F, "", GA->getLinkage(), F->getFunctionType());
490 GA->replaceAllUsesWith(NewF);
491 NewF->takeName(GA);
492 GA->eraseFromParent();
493 FnsToInstrument.push_back(NewF);
483494 }
484495 }
485496 }
None fun:discard=uninstrumented
1 fun:discard=discard
0 fun:discard*=uninstrumented
1 fun:discard*=discard
22
33 fun:functional=uninstrumented
44 fun:functional=functional
2828 ret void
2929 }
3030
31 ; CHECK: define i32 (i32, i32)* @discardg(i32)
32 ; CHECK: %[[CALL:.*]] = call { i32 (i32, i32)*, i16 } @"dfs$g"(i32 %0, i16 0)
33 ; CHECK: %[[XVAL:.*]] = extractvalue { i32 (i32, i32)*, i16 } %[[CALL]], 0
34 ; CHECK: ret {{.*}} %[[XVAL]]
35 @discardg = alias i32 (i32, i32)* (i32)* @g
36
3137 ; CHECK: define linkonce_odr { i32, i16 } @"dfsw$custom2"(i32, i32, i16, i16)
3238 ; CHECK: %[[LABELRETURN2:.*]] = alloca i16
3339 ; CHECK: %[[RV:.*]] = call i32 @__dfsw_custom2
3743 ; CHECK: ret { i32, i16 }
3844
3945 ; CHECK: @"dfs$g"
40 define i32 (i32, i32)* @g() {
46 define i32 (i32, i32)* @g(i32) {
4147 ; CHECK: ret {{.*}} @"dfsw$custom2"
4248 ret i32 (i32, i32)* @custom2
4349 }
4450
51 ; CHECK: define { i32, i16 } @"dfs$adiscard"(i32, i32, i16, i16)
52 ; CHECK: %[[CALL:.*]] = call i32 @discard(i32 %0, i32 %1)
53 ; CHECK: %[[IVAL0:.*]] = insertvalue { i32, i16 } undef, i32 %[[CALL]], 0
54 ; CHECK: %[[IVAL1:.*]] = insertvalue { i32, i16 } %[[IVAL0]], i16 0, 1
55 ; CHECK: ret { i32, i16 } %[[IVAL1]]
56 @adiscard = alias i32 (i32, i32)* @discard
57
4558 ; CHECK: declare void @__dfsw_custom1(i32, i32, i16, i16)
4659 ; CHECK: declare i32 @__dfsw_custom2(i32, i32, i16, i16, i16*)