Skip to content

Commit 1c94332

Browse files
committedOct 26, 2016
[CodeGen] Move shouldEmitLifetimeMarkers into more convenient place
Summary: D24693 will need access to it from other places Reviewers: eugenis Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D24695 llvm-svn: 285158
1 parent 8b6af7a commit 1c94332

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed
 

‎clang/lib/CodeGen/CGDecl.cpp

+1-18
Original file line numberDiff line numberDiff line change
@@ -885,29 +885,12 @@ void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D) {
885885
EmitAutoVarCleanups(emission);
886886
}
887887

888-
/// shouldEmitLifetimeMarkers - Decide whether we need emit the life-time
889-
/// markers.
890-
static bool shouldEmitLifetimeMarkers(const CodeGenOptions &CGOpts,
891-
const LangOptions &LangOpts) {
892-
// Asan uses markers for use-after-scope checks.
893-
if (CGOpts.SanitizeAddressUseAfterScope)
894-
return true;
895-
896-
// Disable lifetime markers in msan builds.
897-
// FIXME: Remove this when msan works with lifetime markers.
898-
if (LangOpts.Sanitize.has(SanitizerKind::Memory))
899-
return false;
900-
901-
// For now, only in optimized builds.
902-
return CGOpts.OptimizationLevel != 0;
903-
}
904-
905888
/// Emit a lifetime.begin marker if some criteria are satisfied.
906889
/// \return a pointer to the temporary size Value if a marker was emitted, null
907890
/// otherwise
908891
llvm::Value *CodeGenFunction::EmitLifetimeStart(uint64_t Size,
909892
llvm::Value *Addr) {
910-
if (!shouldEmitLifetimeMarkers(CGM.getCodeGenOpts(), getLangOpts()))
893+
if (!ShouldEmitLifetimeMarkers)
911894
return nullptr;
912895

913896
llvm::Value *SizeV = llvm::ConstantInt::get(Int64Ty, Size);

‎clang/lib/CodeGen/CodeGenFunction.cpp

+27-10
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,35 @@
3838
using namespace clang;
3939
using namespace CodeGen;
4040

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+
4158
CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext)
4259
: CodeGenTypeCache(cgm), CGM(cgm), Target(cgm.getTarget()),
4360
Builder(cgm, cgm.getModule().getContext(), llvm::ConstantFolder(),
4461
CGBuilderInserterTy(this)),
4562
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()),
5570
DisableDebugInfo(false), DidCallStackSave(false), IndirectBranch(nullptr),
5671
PGO(cgm), SwitchInsn(nullptr), SwitchWeights(nullptr),
5772
CaseRangeBlock(nullptr), UnreachableBlock(nullptr), NumReturnExprs(0),
@@ -60,7 +75,9 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext)
6075
CXXStructorImplicitParamDecl(nullptr),
6176
CXXStructorImplicitParamValue(nullptr), OutermostConditional(nullptr),
6277
CurLexicalScope(nullptr), TerminateLandingPad(nullptr),
63-
TerminateHandler(nullptr), TrapBB(nullptr) {
78+
TerminateHandler(nullptr), TrapBB(nullptr),
79+
ShouldEmitLifetimeMarkers(
80+
shouldEmitLifetimeMarkers(CGM.getCodeGenOpts(), CGM.getLangOpts())) {
6481
if (!suppressNewContext)
6582
CGM.getCXXABI().getMangleContext().startNewFunction();
6683

‎clang/lib/CodeGen/CodeGenFunction.h

+3
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,9 @@ class CodeGenFunction : public CodeGenTypeCache {
11861186
llvm::BasicBlock *TerminateHandler;
11871187
llvm::BasicBlock *TrapBB;
11881188

1189+
/// True if we need emit the life-time markers.
1190+
const bool ShouldEmitLifetimeMarkers;
1191+
11891192
/// Add a kernel metadata node to the named metadata node 'opencl.kernels'.
11901193
/// In the kernel metadata node, reference the kernel function and metadata
11911194
/// nodes for its optional attribute qualifiers (OpenCL 1.1 6.7.2):

0 commit comments

Comments
 (0)
Please sign in to comment.