@@ -4438,19 +4438,27 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
4438
4438
StringRef Name = VD->getName ();
4439
4439
llvm::DIType *Ty = getOrCreateType (VD->getType (), Unit);
4440
4440
4441
- // Do not use global variables for enums, unless in CodeView.
4442
4441
if (const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
4443
4442
const auto *ED = cast<EnumDecl>(ECD->getDeclContext ());
4444
4443
assert (isa<EnumType>(ED->getTypeForDecl ()) && " Enum without EnumType?" );
4445
- (void )ED;
4446
-
4447
- // If CodeView, emit enums as global variables, unless they are defined
4448
- // inside a class. We do this because MSVC doesn't emit S_CONSTANTs for
4449
- // enums in classes, and because it is difficult to attach this scope
4450
- // information to the global variable.
4451
- if (!CGM.getCodeGenOpts ().EmitCodeView ||
4452
- isa<RecordDecl>(ED->getDeclContext ()))
4444
+
4445
+ if (CGM.getCodeGenOpts ().EmitCodeView ) {
4446
+ // If CodeView, emit enums as global variables, unless they are defined
4447
+ // inside a class. We do this because MSVC doesn't emit S_CONSTANTs for
4448
+ // enums in classes, and because it is difficult to attach this scope
4449
+ // information to the global variable.
4450
+ if (isa<RecordDecl>(ED->getDeclContext ()))
4451
+ return ;
4452
+ } else {
4453
+ // If not CodeView, emit DW_TAG_enumeration_type if necessary. For
4454
+ // example: for "enum { ZERO };", a DW_TAG_enumeration_type is created the
4455
+ // first time `ZERO` is referenced in a function.
4456
+ llvm::DIType *EDTy =
4457
+ getOrCreateType (QualType (ED->getTypeForDecl (), 0 ), Unit);
4458
+ assert (EDTy->getTag () == llvm::dwarf::DW_TAG_enumeration_type);
4459
+ (void )EDTy;
4453
4460
return ;
4461
+ }
4454
4462
}
4455
4463
4456
4464
llvm::DIScope *DContext = nullptr ;
0 commit comments