]> granicus.if.org Git - llvm/commitdiff
[CodeView] Refactor enumerator emission
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 17 Jun 2016 16:13:21 +0000 (16:13 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 17 Jun 2016 16:13:21 +0000 (16:13 +0000)
This addresses Amjad's review comments on D21442.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273010 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
test/DebugInfo/COFF/enum.ll

index 47adfc731fd5e125c10c84e69715361e3f5df36b..ce0f7ae39039bd53d141982b434e717cf3051b63 100644 (file)
@@ -1095,14 +1095,26 @@ static ClassOptions getRecordUniqueNameOption(const DICompositeType *Ty) {
 TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
   ClassOptions CO = ClassOptions::None | getRecordUniqueNameOption(Ty);
   TypeIndex FTI;
-  unsigned FieldCount = 0;
+  unsigned EnumeratorCount = 0;
 
-  if (Ty->isForwardDecl())
+  if (Ty->isForwardDecl()) {
     CO |= ClassOptions::ForwardReference;
-  else
-    std::tie(FTI, FieldCount) = lowerRecordFieldList(Ty);
+  } else {
+    FieldListRecordBuilder Fields;
+    for (const DINode *Element : Ty->getElements()) {
+      // We assume that the frontend provides all members in source declaration
+      // order, which is what MSVC does.
+      if (auto *Enumerator = dyn_cast_or_null<DIEnumerator>(Element)) {
+        Fields.writeEnumerator(EnumeratorRecord(
+            MemberAccess::Public, APSInt::getUnsigned(Enumerator->getValue()),
+            Enumerator->getName()));
+        EnumeratorCount++;
+      }
+    }
+    FTI = TypeTable.writeFieldList(Fields);
+  }
 
-  return TypeTable.writeEnum(EnumRecord(FieldCount, CO, FTI, Ty->getName(),
+  return TypeTable.writeEnum(EnumRecord(EnumeratorCount, CO, FTI, Ty->getName(),
                                         Ty->getIdentifier(),
                                         getTypeIndex(Ty->getBaseType())));
 }
@@ -1198,10 +1210,6 @@ CodeViewDebug::lowerRecordFieldList(const DICompositeType *Ty) {
       }
       // FIXME: Get clang to emit nested types here and do something with
       // them.
-    } else if (auto *Enumerator = dyn_cast<DIEnumerator>(Element)) {
-      Fields.writeEnumerator(EnumeratorRecord(
-          MemberAccess::Public, APSInt::getUnsigned(Enumerator->getValue()),
-          Enumerator->getName()));
     }
     // Skip other unrecognized kinds of elements.
   }
index 6e511663f1d7f1100d16c68283a9271df62adf8f..ca177deb64dbe80d3d30f24bf79b51d6029b33c3 100644 (file)
@@ -15,7 +15,7 @@
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:  Enum (0x1001) {
 ; CHECK-NEXT:    TypeLeafKind: LF_ENUM (0x1507)
-; CHECK-NEXT:    NumEnumerators: 0
+; CHECK-NEXT:    NumEnumerators: 1
 ; CHECK-NEXT:    Properties [ (0x0)
 ; CHECK-NEXT:    ]
 ; CHECK-NEXT:    UnderlyingType: int (0x74)