38
38
using namespace clang ;
39
39
using namespace CodeGen ;
40
40
41
+ // / shouldEmitLifetimeMarkers - Decide whether we need emit the life-time
42
+ // / markers.
43
+ static bool shouldEmitLifetimeMarkers (const CodeGenOptions &CGOpts,
44
+ const LangOptions &LangOpts) {
45
+ // Asan uses markers for use-after-scope checks.
46
+ if (CGOpts.SanitizeAddressUseAfterScope )
47
+ return true ;
48
+
49
+ // Disable lifetime markers in msan builds.
50
+ // FIXME: Remove this when msan works with lifetime markers.
51
+ if (LangOpts.Sanitize .has (SanitizerKind::Memory))
52
+ return false ;
53
+
54
+ // For now, only in optimized builds.
55
+ return CGOpts.OptimizationLevel != 0 ;
56
+ }
57
+
41
58
CodeGenFunction::CodeGenFunction (CodeGenModule &cgm, bool suppressNewContext)
42
59
: CodeGenTypeCache(cgm), CGM(cgm), Target(cgm.getTarget()),
43
60
Builder(cgm, cgm.getModule().getContext(), llvm::ConstantFolder(),
44
61
CGBuilderInserterTy(this )),
45
62
CurFn(nullptr ), ReturnValue(Address::invalid()),
46
- CapturedStmtInfo(nullptr ),
47
- SanOpts(CGM.getLangOpts().Sanitize), IsSanitizerScope(false ),
48
- CurFuncIsThunk(false ), AutoreleaseResult(false ), SawAsmBlock(false ),
49
- IsOutlinedSEHHelper(false ),
50
- BlockInfo(nullptr ), BlockPointer(nullptr ),
51
- LambdaThisCaptureField(nullptr ), NormalCleanupDest(nullptr ),
52
- NextCleanupDestIndex(1 ), FirstBlockInfo(nullptr ), EHResumeBlock(nullptr ),
53
- ExceptionSlot(nullptr ), EHSelectorSlot(nullptr ),
54
- DebugInfo(CGM.getModuleDebugInfo()),
63
+ CapturedStmtInfo(nullptr ), SanOpts(CGM.getLangOpts().Sanitize),
64
+ IsSanitizerScope(false ), CurFuncIsThunk(false ), AutoreleaseResult(false ),
65
+ SawAsmBlock(false ), IsOutlinedSEHHelper(false ), BlockInfo(nullptr ),
66
+ BlockPointer(nullptr ), LambdaThisCaptureField(nullptr ),
67
+ NormalCleanupDest(nullptr ), NextCleanupDestIndex(1 ),
68
+ FirstBlockInfo(nullptr ), EHResumeBlock(nullptr ), ExceptionSlot(nullptr ),
69
+ EHSelectorSlot(nullptr ), DebugInfo(CGM.getModuleDebugInfo()),
55
70
DisableDebugInfo(false ), DidCallStackSave(false ), IndirectBranch(nullptr ),
56
71
PGO(cgm), SwitchInsn(nullptr ), SwitchWeights(nullptr ),
57
72
CaseRangeBlock(nullptr ), UnreachableBlock(nullptr ), NumReturnExprs(0 ),
@@ -60,7 +75,9 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext)
60
75
CXXStructorImplicitParamDecl(nullptr ),
61
76
CXXStructorImplicitParamValue(nullptr ), OutermostConditional(nullptr ),
62
77
CurLexicalScope(nullptr ), TerminateLandingPad(nullptr ),
63
- TerminateHandler(nullptr ), TrapBB(nullptr ) {
78
+ TerminateHandler(nullptr ), TrapBB(nullptr ),
79
+ ShouldEmitLifetimeMarkers(
80
+ shouldEmitLifetimeMarkers (CGM.getCodeGenOpts(), CGM.getLangOpts())) {
64
81
if (!suppressNewContext)
65
82
CGM.getCXXABI ().getMangleContext ().startNewFunction ();
66
83
0 commit comments