return;
}
- // Do not emit separate definitions for function local const/statics.
+ llvm::DIScope *DContext = nullptr;
+
+ // Do not emit separate definitions for function local consts.
if (isa<FunctionDecl>(VD->getDeclContext()))
return;
+
+ // Emit definition for static members in CodeView.
VD = cast<ValueDecl>(VD->getCanonicalDecl());
auto *VarD = cast<VarDecl>(VD);
if (VarD->isStaticDataMember()) {
// through its scope.
RetainedTypes.push_back(
CGM.getContext().getRecordType(RD).getAsOpaquePtr());
- return;
- }
- llvm::DIScope *DContext = getDeclContextDescriptor(VD);
+ if (!CGM.getCodeGenOpts().EmitCodeView)
+ return;
+
+ // Use the global scope for static members.
+ DContext = getContextDescriptor(
+ cast<Decl>(CGM.getContext().getTranslationUnitDecl()), TheCU);
+ } else {
+ DContext = getDeclContextDescriptor(VD);
+ }
auto &GV = DeclCache[VD];
if (GV)
// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s
// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S -o - | FileCheck %s
// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -gcodeview -debug-info-kind=limited %s -emit-llvm -o - | FileCheck --check-prefix MSVC %s
// PR14471
// CHECK: @_ZN1C1aE = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
// CHECK: [[A]] = !DIGlobalVariableExpression(var: [[AV:.*]], expr: !DIExpression())
// CHECK: [[AV]] = distinct !DIGlobalVariable(name: "a",
// CHECK-SAME: declaration: ![[DECL_A:[0-9]+]])
+// MSVC: distinct !DIGlobalVariable(name: "a"
//
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, identifier: "_ZTS1X")
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "anon_static_decl_struct"
// CHECK: [[B]] = !DIGlobalVariableExpression(var: [[BV:.*]], expr: !DIExpression())
// CHECK: [[BV]] = distinct !DIGlobalVariable(name: "b",
// CHECK-SAME: declaration: ![[DECL_B:[0-9]+]])
+// MSVC: distinct !DIGlobalVariable(name: "b"
// CHECK: ![[DECL_B]] = !DIDerivedType(tag: DW_TAG_member, name: "b"
// CHECK-NOT: size:
// CHECK-NOT: align:
int C::b = 2;
// CHECK: [[C]] = !DIGlobalVariableExpression(var: [[CV:.*]], expr: !DIExpression())
// CHECK: [[CV]] = distinct !DIGlobalVariable(name: "c", {{.*}} declaration: ![[DECL_C]])
+// MSVC: distinct !DIGlobalVariable(name: "c"
int C::c = 1;
int main()
};
}
-
int ref() {
return anon_static_decl_struct::anon_static_decl_var;
}
+// In MSVC, static data members should be emitted as global variables when used.
+// MSVC: !DIGlobalVariableExpression(var: [[ANON_STATIC_DECL:![0-9]+]],
+// MSVC-SAME: !DIExpression(DW_OP_constu, 117, DW_OP_stack_value)
+// MSVC: [[ANON_STATIC_DECL]] = distinct !DIGlobalVariable(name: "anon_static_decl_var"
+// MSVC: !DIGlobalVariableExpression(var: [[STATIC_DECL_TEMPL:![0-9]+]]
+// MSVC-SAME: !DIExpression(DW_OP_constu, 7, DW_OP_stack_value)
+// MSVC: [[STATIC_DECL_TEMPL]] = distinct !DIGlobalVariable(name: "static_decl_templ_var"
+
template<typename T>
struct static_decl_templ {
static const int static_decl_templ_var = 7;