From: Karl-Johan Karlsson Date: Wed, 6 Sep 2017 08:47:18 +0000 (+0000) Subject: Debug info: Fixed faulty debug locations for attributed statements X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f0db6ed816c5fae9bf6a7b2b1711e8fc57b8589;p=clang Debug info: Fixed faulty debug locations for attributed statements Summary: As the attributed statements are considered simple statements no stoppoint was generated before emitting attributed do/while/for/range- statement. This lead to faulty debug locations. Reviewers: echristo, aaron.ballman, dblaikie Reviewed By: dblaikie Subscribers: bjope, aprantl, cfe-commits Differential Revision: https://reviews.llvm.org/D37428 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312623 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index a13c386461..3bc68899dd 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -45,7 +45,7 @@ void CodeGenFunction::EmitStopPoint(const Stmt *S) { } } -void CodeGenFunction::EmitStmt(const Stmt *S) { +void CodeGenFunction::EmitStmt(const Stmt *S, ArrayRef Attrs) { assert(S && "Null statement?"); PGO.setCurrentStmt(S); @@ -131,16 +131,16 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { case Stmt::IndirectGotoStmtClass: EmitIndirectGotoStmt(cast(*S)); break; - case Stmt::IfStmtClass: EmitIfStmt(cast(*S)); break; - case Stmt::WhileStmtClass: EmitWhileStmt(cast(*S)); break; - case Stmt::DoStmtClass: EmitDoStmt(cast(*S)); break; - case Stmt::ForStmtClass: EmitForStmt(cast(*S)); break; + case Stmt::IfStmtClass: EmitIfStmt(cast(*S)); break; + case Stmt::WhileStmtClass: EmitWhileStmt(cast(*S), Attrs); break; + case Stmt::DoStmtClass: EmitDoStmt(cast(*S), Attrs); break; + case Stmt::ForStmtClass: EmitForStmt(cast(*S), Attrs); break; - case Stmt::ReturnStmtClass: EmitReturnStmt(cast(*S)); break; + case Stmt::ReturnStmtClass: EmitReturnStmt(cast(*S)); break; - case Stmt::SwitchStmtClass: EmitSwitchStmt(cast(*S)); break; - case Stmt::GCCAsmStmtClass: // Intentional fall-through. - case Stmt::MSAsmStmtClass: EmitAsmStmt(cast(*S)); break; + case Stmt::SwitchStmtClass: EmitSwitchStmt(cast(*S)); break; + case Stmt::GCCAsmStmtClass: // Intentional fall-through. + case Stmt::MSAsmStmtClass: EmitAsmStmt(cast(*S)); break; case Stmt::CoroutineBodyStmtClass: EmitCoroutineBody(cast(*S)); break; @@ -178,7 +178,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { EmitCXXTryStmt(cast(*S)); break; case Stmt::CXXForRangeStmtClass: - EmitCXXForRangeStmt(cast(*S)); + EmitCXXForRangeStmt(cast(*S), Attrs); break; case Stmt::SEHTryStmtClass: EmitSEHTryStmt(cast(*S)); @@ -555,23 +555,7 @@ void CodeGenFunction::EmitLabelStmt(const LabelStmt &S) { } void CodeGenFunction::EmitAttributedStmt(const AttributedStmt &S) { - const Stmt *SubStmt = S.getSubStmt(); - switch (SubStmt->getStmtClass()) { - case Stmt::DoStmtClass: - EmitDoStmt(cast(*SubStmt), S.getAttrs()); - break; - case Stmt::ForStmtClass: - EmitForStmt(cast(*SubStmt), S.getAttrs()); - break; - case Stmt::WhileStmtClass: - EmitWhileStmt(cast(*SubStmt), S.getAttrs()); - break; - case Stmt::CXXForRangeStmtClass: - EmitCXXForRangeStmt(cast(*SubStmt), S.getAttrs()); - break; - default: - EmitStmt(SubStmt); - } + EmitStmt(S.getSubStmt(), S.getAttrs()); } void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) { diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index da68074a70..70346e4b5c 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -2534,7 +2534,7 @@ public: /// This function may clear the current insertion point; callers should use /// EnsureInsertPoint if they wish to subsequently generate code without first /// calling EmitBlock, EmitBranch, or EmitStmt. - void EmitStmt(const Stmt *S); + void EmitStmt(const Stmt *S, ArrayRef Attrs = None); /// EmitSimpleStmt - Try to emit a "simple" statement which does not /// necessarily require an insertion point or debug information; typically diff --git a/test/CodeGen/debug-info-attributed-stmt.c b/test/CodeGen/debug-info-attributed-stmt.c new file mode 100644 index 0000000000..43fda6a54f --- /dev/null +++ b/test/CodeGen/debug-info-attributed-stmt.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple x86_64-unk-unk -debug-info-kind=limited -emit-llvm %s -o - | FileCheck %s + +void f(_Bool b) +{ +#pragma nounroll + while (b); +} + +// CHECK: br label %while.cond, !dbg ![[NUM:[0-9]+]] +// CHECK: br i1 %tobool, label %while.body, label %while.end, !dbg ![[NUM]] +// CHECK: br label %while.cond, !dbg ![[NUM]], !llvm.loop +// CHECK: ![[NUM]] = !DILocation(line: 6,