Skip to content

Commit 1b5adb8

Browse files
committed
Fix the dtor location issues in PR20038 harder.
Originally committed in r211722, this fixed one case of dtor calls being emitted without locations (this causes problems for debug info if the call is then inlined), this caught only some of the cases. Instead of trying to re-enable the location before the cleanup, simply re-enable the location immediately after the unconditional branches in question using a scoped device to ensure the no-location state doesn't leak out arbitrarily. llvm-svn: 212761
1 parent 026861b commit 1b5adb8

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,7 @@ class ScalarExprEmitter
358358
Value *VisitExprWithCleanups(ExprWithCleanups *E) {
359359
CGF.enterFullExpression(E);
360360
CodeGenFunction::RunCleanupsScope Scope(CGF);
361-
auto *V = Visit(E->getSubExpr());
362-
if (CGDebugInfo *DI = CGF.getDebugInfo())
363-
DI->EmitLocation(Builder, E->getLocEnd(), false);
364-
return V;
361+
return Visit(E->getSubExpr());
365362
}
366363
Value *VisitCXXNewExpr(const CXXNewExpr *E) {
367364
return CGF.EmitCXXNewExpr(E);
@@ -2942,12 +2939,13 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
29422939
// Reaquire the RHS block, as there may be subblocks inserted.
29432940
RHSBlock = Builder.GetInsertBlock();
29442941

2945-
// Emit an unconditional branch from this block to ContBlock. Insert an entry
2946-
// into the phi node for the edge with the value of RHSCond.
2947-
if (CGF.getDebugInfo())
2942+
// Emit an unconditional branch from this block to ContBlock.
2943+
{
29482944
// There is no need to emit line number for unconditional branch.
2949-
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
2950-
CGF.EmitBlock(ContBlock);
2945+
SuppressDebugLocation S(Builder);
2946+
CGF.EmitBlock(ContBlock);
2947+
}
2948+
// Insert an entry into the phi node for the edge with the value of RHSCond.
29512949
PN->addIncoming(RHSCond, RHSBlock);
29522950

29532951
// ZExt result to int.

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,18 +524,20 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
524524

525525
// Emit the 'else' code if present.
526526
if (const Stmt *Else = S.getElse()) {
527-
// There is no need to emit line number for unconditional branch.
528-
if (getDebugInfo())
529-
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
530-
EmitBlock(ElseBlock);
527+
{
528+
// There is no need to emit line number for unconditional branch.
529+
SuppressDebugLocation S(Builder);
530+
EmitBlock(ElseBlock);
531+
}
531532
{
532533
RunCleanupsScope ElseScope(*this);
533534
EmitStmt(Else);
534535
}
535-
// There is no need to emit line number for unconditional branch.
536-
if (getDebugInfo())
537-
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
538-
EmitBranch(ContBlock);
536+
{
537+
// There is no need to emit line number for unconditional branch.
538+
SuppressDebugLocation S(Builder);
539+
EmitBranch(ContBlock);
540+
}
539541
}
540542

541543
// Emit the continuation block for code after the if.

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ enum TypeEvaluationKind {
9393
TEK_Aggregate
9494
};
9595

96+
class SuppressDebugLocation {
97+
llvm::DebugLoc CurLoc;
98+
llvm::IRBuilderBase &Builder;
99+
public:
100+
SuppressDebugLocation(llvm::IRBuilderBase &Builder)
101+
: CurLoc(Builder.getCurrentDebugLocation()), Builder(Builder) {
102+
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
103+
}
104+
~SuppressDebugLocation() {
105+
Builder.SetCurrentDebugLocation(CurLoc);
106+
}
107+
};
108+
96109
/// CodeGenFunction - This class organizes the per-function state that is used
97110
/// while generating LLVM code.
98111
class CodeGenFunction : public CodeGenTypeCache {

clang/test/CodeGenCXX/PR20038.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ struct C {
44
~C();
55
};
66
extern bool b;
7-
// CHECK: call {{.*}}, !dbg [[DTOR_CALL_LOC:![0-9]*]]
8-
// CHECK: [[FUN4:.*]] = {{.*}}; [ DW_TAG_subprogram ] {{.*}} [def] [fun4]
9-
// CHECK: [[DTOR_CALL_LOC]] = metadata !{i32 [[@LINE+2]], i32 0, metadata [[FUN4_BLOCK:.*]], null}
10-
// CHECK: [[FUN4_BLOCK]] = metadata !{{{[^,]*}}, {{[^,]*}}, metadata [[FUN4]],
11-
void fun4() { b && (C(), 1); }
7+
// CHECK: call {{.*}}, !dbg [[DTOR_CALL1_LOC:![0-9]*]]
8+
// CHECK: call {{.*}}, !dbg [[DTOR_CALL2_LOC:![0-9]*]]
9+
// CHECK: [[FUN1:.*]] = {{.*}}; [ DW_TAG_subprogram ] {{.*}} [def] [fun1]
10+
// CHECK: [[FUN2:.*]] = {{.*}}; [ DW_TAG_subprogram ] {{.*}} [def] [fun2]
11+
// CHECK: [[DTOR_CALL1_LOC]] = metadata !{i32 [[@LINE+2]], i32 0, metadata [[FUN1_BLOCK:.*]], null}
12+
// CHECK: [[FUN1_BLOCK]] = metadata !{{{[^,]*}}, {{[^,]*}}, metadata [[FUN1]],
13+
void fun1() { b && (C(), 1); }
14+
// CHECK: [[DTOR_CALL2_LOC]] = metadata !{i32 [[@LINE+2]], i32 0, metadata [[FUN2_BLOCK1:.*]], null}
15+
// CHECK: [[FUN2_BLOCK1]] = metadata !{{{[^,]*}}, {{[^,]*}}, metadata [[FUN2]],
16+
bool fun2() { return (C(), b) && 0; }

0 commit comments

Comments
 (0)