@@ -45,6 +45,26 @@ static void insertCallAtAllFunctionExitPoints(Function &Fn,
45
45
insertCallBeforeInstruction (Fn, I, InsertFnName);
46
46
}
47
47
48
+ static PreservedAnalyses rtsanPreservedAnalyses () {
49
+ PreservedAnalyses PA;
50
+ PA.preserveSet <CFGAnalyses>();
51
+ return PA;
52
+ }
53
+
54
+ static void transformRealtimeUnsafeFunction (Function &F) {
55
+ IRBuilder<> Builder (&F.front ().front ());
56
+ Value *NameArg = Builder.CreateGlobalString (F.getName ());
57
+
58
+ FunctionType *FuncType =
59
+ FunctionType::get (Type::getVoidTy (F.getContext ()),
60
+ {PointerType::getUnqual (F.getContext ())}, false );
61
+
62
+ FunctionCallee Func = F.getParent ()->getOrInsertFunction (
63
+ " __rtsan_expect_not_realtime" , FuncType);
64
+
65
+ Builder.CreateCall (Func, {NameArg});
66
+ }
67
+
48
68
RealtimeSanitizerPass::RealtimeSanitizerPass (
49
69
const RealtimeSanitizerOptions &Options) {}
50
70
@@ -53,10 +73,12 @@ PreservedAnalyses RealtimeSanitizerPass::run(Function &F,
53
73
if (F.hasFnAttribute (Attribute::SanitizeRealtime)) {
54
74
insertCallAtFunctionEntryPoint (F, " __rtsan_realtime_enter" );
55
75
insertCallAtAllFunctionExitPoints (F, " __rtsan_realtime_exit" );
76
+ return rtsanPreservedAnalyses ();
77
+ }
56
78
57
- PreservedAnalyses PA;
58
- PA. preserveSet <CFGAnalyses>( );
59
- return PA ;
79
+ if (F. hasFnAttribute (Attribute::SanitizeRealtimeUnsafe)) {
80
+ transformRealtimeUnsafeFunction (F );
81
+ return rtsanPreservedAnalyses () ;
60
82
}
61
83
62
84
return PreservedAnalyses::all ();
0 commit comments