Index: lib/CodeGen/CGDecl.cpp =================================================================== --- lib/CodeGen/CGDecl.cpp +++ lib/CodeGen/CGDecl.cpp @@ -1946,6 +1946,9 @@ } } + // Set artificial debug location in order to preserve the scope + auto DL = ApplyDebugLocation::CreateArtificial(*this); + Address DeclPtr = Address::invalid(); bool DoStore = false; bool IsScalar = hasScalarEvaluationKind(Ty); Index: test/CodeGen/debug-info-preserve-scope.c =================================================================== --- /dev/null +++ test/CodeGen/debug-info-preserve-scope.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s + +static int a; + +// CHECK-LABEL: define void @f +void f(int b) { + a = b; +} + +// CHECK: store i32 {{.*}} !dbg ![[artificialDbgLoc:[0-9]+]] + +// CHECK: ![[artificialDbgLoc]] = !DILocation(line: 0