Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit e03812c

Browse files
committed
Revert "DebugInfo: Generalize debug info location handling"
Fails an ASan bootstrap - I'll try to reproduce locally & sort that out before recommitting. This reverts commit r224385. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224441 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 377ece4 commit e03812c

17 files changed

+195
-101
lines changed

Diff for: lib/CodeGen/CGBlocks.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) {
874874
// locations of subexpressions in the initialization.
875875
EmitExprAsInit(&l2r, &blockFieldPseudoVar,
876876
MakeAddrLValue(blockField, type, align),
877-
/*captured by init*/ false);
877+
/*captured by init*/ false, SourceLocation());
878878
}
879879

880880
// Activate the cleanup if layout pushed one.
@@ -1175,7 +1175,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
11751175
Alloca->setAlignment(Align);
11761176
// Set the DebugLocation to empty, so the store is recognized as a
11771177
// frame setup instruction by llvm::DwarfDebug::beginFunction().
1178-
ApplyDebugLocation NL(*this);
1178+
NoLocation NL(*this, Builder);
11791179
Builder.CreateAlignedStore(BlockPointer, Alloca, Align);
11801180
BlockPointerDbgLoc = Alloca;
11811181
}
@@ -1326,9 +1326,9 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) {
13261326
false,
13271327
false);
13281328
// Create a scope with an artificial location for the body of this function.
1329-
ApplyDebugLocation NL(*this);
1329+
ArtificialLocation AL(*this, Builder);
13301330
StartFunction(FD, C.VoidTy, Fn, FI, args);
1331-
ArtificialLocation AL(*this);
1331+
AL.Emit();
13321332

13331333
llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
13341334

@@ -1497,9 +1497,9 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) {
14971497
nullptr, SC_Static,
14981498
false, false);
14991499
// Create a scope with an artificial location for the body of this function.
1500-
ApplyDebugLocation NL(*this);
1500+
ArtificialLocation AL(*this, Builder);
15011501
StartFunction(FD, C.VoidTy, Fn, FI, args);
1502-
ArtificialLocation AL(*this);
1502+
AL.Emit();
15031503

15041504
llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
15051505

Diff for: lib/CodeGen/CGClass.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ static void EmitMemberInitializer(CodeGenFunction &CGF,
544544
CXXCtorInitializer *MemberInit,
545545
const CXXConstructorDecl *Constructor,
546546
FunctionArgList &Args) {
547-
ApplyDebugLocation Loc(CGF, MemberInit->getMemberLocation());
548547
assert(MemberInit->isAnyMemberInitializer() &&
549548
"Must have member initializer!");
550549
assert(MemberInit->getInit() && "Must have initializer!");
@@ -598,25 +597,26 @@ static void EmitMemberInitializer(CodeGenFunction &CGF,
598597
ArrayRef<VarDecl *> ArrayIndexes;
599598
if (MemberInit->getNumArrayIndices())
600599
ArrayIndexes = MemberInit->getArrayIndexes();
601-
ApplyDebugLocation DL(CGF, MemberInit->getMemberLocation());
602-
CGF.EmitInitializerForField(Field, LHS, MemberInit->getInit(), ArrayIndexes);
600+
CGF.EmitInitializerForField(Field, LHS, MemberInit->getInit(), ArrayIndexes,
601+
MemberInit->getMemberLocation());
603602
}
604603

605-
void CodeGenFunction::EmitInitializerForField(
606-
FieldDecl *Field, LValue LHS, Expr *Init,
607-
ArrayRef<VarDecl *> ArrayIndexes) {
604+
void CodeGenFunction::EmitInitializerForField(FieldDecl *Field, LValue LHS,
605+
Expr *Init,
606+
ArrayRef<VarDecl *> ArrayIndexes,
607+
SourceLocation DbgLoc) {
608608
QualType FieldType = Field->getType();
609609
switch (getEvaluationKind(FieldType)) {
610610
case TEK_Scalar:
611611
if (LHS.isSimple()) {
612-
EmitExprAsInit(Init, Field, LHS, false);
612+
EmitExprAsInit(Init, Field, LHS, false, DbgLoc);
613613
} else {
614614
RValue RHS = RValue::get(EmitScalarExpr(Init));
615615
EmitStoreThroughLValue(RHS, LHS);
616616
}
617617
break;
618618
case TEK_Complex:
619-
EmitComplexExprIntoLValue(Init, LHS, /*isInit*/ true);
619+
EmitComplexExprIntoLValue(Init, LHS, /*isInit*/ true, DbgLoc);
620620
break;
621621
case TEK_Aggregate: {
622622
llvm::Value *ArrayIndexVar = nullptr;
@@ -783,6 +783,8 @@ void CodeGenFunction::EmitConstructorBody(FunctionArgList &Args) {
783783
// delegation optimization.
784784
if (CtorType == Ctor_Complete && IsConstructorDelegationValid(Ctor) &&
785785
CGM.getTarget().getCXXABI().hasConstructorVariants()) {
786+
if (CGDebugInfo *DI = getDebugInfo())
787+
DI->EmitLocation(Builder, Ctor->getLocEnd());
786788
EmitDelegateCXXConstructorCall(Ctor, Ctor_Base, Args, Ctor->getLocEnd());
787789
return;
788790
}

Diff for: lib/CodeGen/CGCleanup.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,10 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
861861

862862
// Emit the EH cleanup if required.
863863
if (RequiresEHCleanup) {
864-
ApplyDebugLocation AutoRestoreLocation(*this, CurEHLocation);
864+
CGDebugInfo *DI = getDebugInfo();
865+
SaveAndRestoreLocation AutoRestoreLocation(*this, Builder);
866+
if (DI)
867+
DI->EmitLocation(Builder, CurEHLocation);
865868

866869
CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();
867870

Diff for: lib/CodeGen/CGDebugInfo.cpp

+40-21
Original file line numberDiff line numberDiff line change
@@ -52,35 +52,54 @@ CGDebugInfo::~CGDebugInfo() {
5252
"Region stack mismatch, stack not empty!");
5353
}
5454

55-
ArtificialLocation::ArtificialLocation(CodeGenFunction &CGF)
56-
: ApplyDebugLocation(CGF) {
57-
if (auto *DI = CGF.getDebugInfo()) {
58-
// Construct a location that has a valid scope, but no line info.
59-
assert(!DI->LexicalBlockStack.empty());
60-
llvm::DIDescriptor Scope(DI->LexicalBlockStack.back());
61-
CGF.Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(0, 0, Scope));
55+
SaveAndRestoreLocation::SaveAndRestoreLocation(CodeGenFunction &CGF,
56+
CGBuilderTy &B)
57+
: DI(CGF.getDebugInfo()), Builder(B) {
58+
if (DI) {
59+
SavedLoc = DI->getLocation();
60+
DI->CurLoc = SourceLocation();
6261
}
6362
}
6463

65-
ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF,
66-
SourceLocation TemporaryLocation,
67-
bool ForceColumnInfo)
68-
: CGF(CGF) {
69-
if (auto *DI = CGF.getDebugInfo()) {
70-
OriginalLocation = CGF.Builder.getCurrentDebugLocation();
71-
if (TemporaryLocation.isInvalid())
72-
CGF.Builder.SetCurrentDebugLocation(llvm::DebugLoc());
73-
else
74-
DI->EmitLocation(CGF.Builder, TemporaryLocation, ForceColumnInfo);
64+
SaveAndRestoreLocation::~SaveAndRestoreLocation() {
65+
if (DI)
66+
DI->EmitLocation(Builder, SavedLoc);
67+
}
68+
69+
NoLocation::NoLocation(CodeGenFunction &CGF, CGBuilderTy &B)
70+
: SaveAndRestoreLocation(CGF, B) {
71+
if (DI)
72+
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
73+
}
74+
75+
NoLocation::~NoLocation() {
76+
if (DI)
77+
assert(Builder.getCurrentDebugLocation().isUnknown());
78+
}
79+
80+
ArtificialLocation::ArtificialLocation(CodeGenFunction &CGF, CGBuilderTy &B)
81+
: SaveAndRestoreLocation(CGF, B) {
82+
if (DI)
83+
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
84+
}
85+
86+
void ArtificialLocation::Emit() {
87+
if (DI) {
88+
// Sync the Builder.
89+
DI->EmitLocation(Builder, SavedLoc);
90+
DI->CurLoc = SourceLocation();
91+
// Construct a location that has a valid scope, but no line info.
92+
assert(!DI->LexicalBlockStack.empty());
93+
llvm::DIDescriptor Scope(DI->LexicalBlockStack.back());
94+
Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(0, 0, Scope));
7595
}
7696
}
7797

78-
ApplyDebugLocation::~ApplyDebugLocation() {
79-
CGF.Builder.SetCurrentDebugLocation(OriginalLocation);
98+
ArtificialLocation::~ArtificialLocation() {
99+
if (DI)
100+
assert(Builder.getCurrentDebugLocation().getLine() == 0);
80101
}
81102

82-
/// ArtificialLocation - An RAII object that temporarily switches to
83-
/// an artificial debug location that has a valid scope, but no line
84103
void CGDebugInfo::setLocation(SourceLocation Loc) {
85104
// If the new location isn't valid return.
86105
if (Loc.isInvalid())

Diff for: lib/CodeGen/CGDebugInfo.h

+27-9
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,27 @@ class CGDebugInfo {
448448
}
449449
};
450450

451-
class ApplyDebugLocation {
451+
/// SaveAndRestoreLocation - An RAII object saves the current location
452+
/// and automatically restores it to the original value.
453+
class SaveAndRestoreLocation {
452454
protected:
453-
llvm::DebugLoc OriginalLocation;
454-
CodeGenFunction &CGF;
455+
SourceLocation SavedLoc;
456+
CGDebugInfo *DI;
457+
CGBuilderTy &Builder;
458+
public:
459+
SaveAndRestoreLocation(CodeGenFunction &CGF, CGBuilderTy &B);
460+
/// Autorestore everything back to normal.
461+
~SaveAndRestoreLocation();
462+
};
455463

464+
/// NoLocation - An RAII object that temporarily disables debug
465+
/// locations. This is useful for emitting instructions that should be
466+
/// counted towards the function prologue.
467+
class NoLocation : public SaveAndRestoreLocation {
456468
public:
457-
ApplyDebugLocation(CodeGenFunction &CGF,
458-
SourceLocation TemporaryLocation = SourceLocation(),
459-
bool ForceColumnInfo = false);
460-
~ApplyDebugLocation();
469+
NoLocation(CodeGenFunction &CGF, CGBuilderTy &B);
470+
/// Autorestore everything back to normal.
471+
~NoLocation();
461472
};
462473

463474
/// ArtificialLocation - An RAII object that temporarily switches to
@@ -471,9 +482,16 @@ class ApplyDebugLocation {
471482
/// This is necessary because passing an empty SourceLocation to
472483
/// CGDebugInfo::setLocation() will result in the last valid location
473484
/// being reused.
474-
class ArtificialLocation : public ApplyDebugLocation {
485+
class ArtificialLocation : public SaveAndRestoreLocation {
475486
public:
476-
ArtificialLocation(CodeGenFunction &CGF);
487+
ArtificialLocation(CodeGenFunction &CGF, CGBuilderTy &B);
488+
489+
/// Set the current location to line 0, but within the current scope
490+
/// (= the top of the LexicalBlockStack).
491+
void Emit();
492+
493+
/// Autorestore everything back to normal.
494+
~ArtificialLocation();
477495
};
478496

479497

Diff for: lib/CodeGen/CGDecl.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,14 @@ static void drillIntoBlockVariable(CodeGenFunction &CGF,
597597
}
598598

599599
void CodeGenFunction::EmitScalarInit(const Expr *init, const ValueDecl *D,
600-
LValue lvalue, bool capturedByInit) {
600+
LValue lvalue, bool capturedByInit,
601+
SourceLocation DbgLoc) {
601602
Qualifiers::ObjCLifetime lifetime = lvalue.getObjCLifetime();
602603
if (!lifetime) {
603604
llvm::Value *value = EmitScalarExpr(init);
604605
if (capturedByInit)
605606
drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D));
606-
EmitStoreThroughLValue(RValue::get(value), lvalue, true);
607+
EmitStoreThroughLValue(RValue::get(value), lvalue, true, DbgLoc);
607608
return;
608609
}
609610

@@ -1087,7 +1088,6 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
10871088
if (emission.wasEmittedAsGlobal()) return;
10881089

10891090
const VarDecl &D = *emission.Variable;
1090-
ApplyDebugLocation DL(*this, D.getLocation());
10911091
QualType type = D.getType();
10921092

10931093
// If this local has an initializer, emit it now.
@@ -1126,7 +1126,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
11261126
if (!constant) {
11271127
LValue lv = MakeAddrLValue(Loc, type, alignment);
11281128
lv.setNonGC(true);
1129-
return EmitExprAsInit(Init, &D, lv, capturedByInit);
1129+
return EmitExprAsInit(Init, &D, lv, capturedByInit, D.getLocation());
11301130
}
11311131

11321132
if (!emission.IsConstantAggregate) {
@@ -1192,25 +1192,26 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
11921192
/// \param capturedByInit true if the variable is a __block variable
11931193
/// whose address is potentially changed by the initializer
11941194
void CodeGenFunction::EmitExprAsInit(const Expr *init, const ValueDecl *D,
1195-
LValue lvalue, bool capturedByInit) {
1195+
LValue lvalue, bool capturedByInit,
1196+
SourceLocation DbgLoc) {
11961197
QualType type = D->getType();
11971198

11981199
if (type->isReferenceType()) {
11991200
RValue rvalue = EmitReferenceBindingToExpr(init);
12001201
if (capturedByInit)
12011202
drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D));
1202-
EmitStoreThroughLValue(rvalue, lvalue, true);
1203+
EmitStoreThroughLValue(rvalue, lvalue, true, DbgLoc);
12031204
return;
12041205
}
12051206
switch (getEvaluationKind(type)) {
12061207
case TEK_Scalar:
1207-
EmitScalarInit(init, D, lvalue, capturedByInit);
1208+
EmitScalarInit(init, D, lvalue, capturedByInit, DbgLoc);
12081209
return;
12091210
case TEK_Complex: {
12101211
ComplexPairTy complex = EmitComplexExpr(init);
12111212
if (capturedByInit)
12121213
drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D));
1213-
EmitStoreOfComplex(complex, lvalue, /*init*/ true);
1214+
EmitStoreOfComplex(complex, lvalue, /*init*/ true, DbgLoc);
12141215
return;
12151216
}
12161217
case TEK_Aggregate:

Diff for: lib/CodeGen/CGDeclCXX.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,11 @@ CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
474474
ArrayRef<llvm::Function *> Decls,
475475
llvm::GlobalVariable *Guard) {
476476
{
477-
ApplyDebugLocation NL(*this);
477+
ArtificialLocation AL(*this, Builder);
478478
StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
479479
getTypes().arrangeNullaryFunction(), FunctionArgList());
480480
// Emit an artificial location for this function.
481-
ArtificialLocation AL(*this);
481+
AL.Emit();
482482

483483
llvm::BasicBlock *ExitBlock = nullptr;
484484
if (Guard) {
@@ -525,11 +525,11 @@ void CodeGenFunction::GenerateCXXGlobalDtorsFunc(llvm::Function *Fn,
525525
const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> >
526526
&DtorsAndObjects) {
527527
{
528-
ApplyDebugLocation NL(*this);
528+
ArtificialLocation AL(*this, Builder);
529529
StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
530530
getTypes().arrangeNullaryFunction(), FunctionArgList());
531531
// Emit an artificial location for this function.
532-
ArtificialLocation AL(*this);
532+
AL.Emit();
533533

534534
// Emit the dtors, in reverse order from construction.
535535
for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {

Diff for: lib/CodeGen/CGException.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@ llvm::BasicBlock *CodeGenFunction::EmitLandingPad() {
734734

735735
// Save the current IR generation state.
736736
CGBuilderTy::InsertPoint savedIP = Builder.saveAndClearIP();
737-
ApplyDebugLocation AutoRestoreLocation(*this, CurEHLocation);
737+
SaveAndRestoreLocation AutoRestoreLocation(*this, Builder);
738+
if (CGDebugInfo *DI = getDebugInfo())
739+
DI->EmitLocation(Builder, CurEHLocation);
738740

739741
const EHPersonality &personality = EHPersonality::get(CGM);
740742

0 commit comments

Comments
 (0)