From 1f6936185b95a45fedeff6267457b68aeeea1578 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 3 Feb 2015 22:37:17 +0000 Subject: [PATCH] DebugInfo: Ensure calls to functions with default arguments which themselves have default arguments, still have locations. To handle default arguments in C++ in the debug info, we disable code updating the debug location during the emission of default arguments. This code was buggy in the case of default arguments which, themselves, have default arguments - the inner default argument would re-enable debug info when it was finished, but before the outer default argument was finished. This was already a bug, but got worse (because a crasher instead of just a quality bug) with the recent improvements to debug info line quality because... The ApplyDebugLocation scoped device would find the debug info disabled and not save any debug location. But then in ~ApplyDebugLocation it would find the debug info had been enabled and would then apply the no-location. Then the outer function call would be emitted without any location. That's bad. Arguably we could /also/ fix the ApplyDebugLocation to assert on this situation (where debug info was disabled in the ctor and enabled in the dtor, or the other way around) but this is at least the necessary fix regardless. (also, I imagine this disabling behavior might need to be in-place for CGExprComplex and CGExprAgg too, maybe... ?) And I seem to recall seeing some weird default arg stepping behavior recently which might be related to this too... I'll have to look into it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228053 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprScalar.cpp | 3 ++- test/CodeGenCXX/debug-info-line.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 49165d550e..951895f5f0 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -3393,11 +3393,12 @@ Value *CodeGenFunction::EmitScalarExpr(const Expr *E, bool IgnoreResultAssign) { assert(E && hasScalarEvaluationKind(E->getType()) && "Invalid scalar expression to emit"); + bool hasDebugInfo = getDebugInfo(); if (isa(E)) disableDebugInfo(); Value *V = ScalarExprEmitter(*this, IgnoreResultAssign) .Visit(const_cast(E)); - if (isa(E)) + if (isa(E) && hasDebugInfo) enableDebugInfo(); return V; } diff --git a/test/CodeGenCXX/debug-info-line.cpp b/test/CodeGenCXX/debug-info-line.cpp index af78f23c0e..5f32f3ff07 100644 --- a/test/CodeGenCXX/debug-info-line.cpp +++ b/test/CodeGenCXX/debug-info-line.cpp @@ -250,6 +250,15 @@ void f20(int a, int b, int c) { ; } +// CHECK-LABEL: define +int f21_a(int = 0); +void f21_b(int = f21_a()); +void f21() { +// CHECK: call {{.*}}f21_b{{.*}}, !dbg [[DBG_F21:![0-9]*]] +#line 2300 + f21_b(); +} + // CHECK: [[DBG_F1]] = !MDLocation(line: 100, // CHECK: [[DBG_FOO_VALUE]] = !MDLocation(line: 200, // CHECK: [[DBG_FOO_REF]] = !MDLocation(line: 202, -- 2.40.0