r209196 - XCore target: sort typestring enum fields alphabetically

Robert Lytton robert at xmos.com
Tue May 20 00:19:33 PDT 2014


Author: rlytton
Date: Tue May 20 02:19:33 2014
New Revision: 209196

URL: http://llvm.org/viewvc/llvm-project?rev=209196&view=rev
Log:
XCore target: sort typestring enum fields alphabetically

Modified:
    cfe/trunk/lib/CodeGen/TargetInfo.cpp
    cfe/trunk/test/CodeGen/xcore-stringtype.c

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=209196&r1=209195&r2=209196&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Tue May 20 02:19:33 2014
@@ -6131,7 +6131,7 @@ public:
   StringRef lookupStr(const IdentifierInfo *ID);
 };
 
-/// TypeString encodings for union fields must be order.
+/// TypeString encodings for enum & union fields must be order.
 /// FieldEncoding is a helper for this ordering process.
 class FieldEncoding {
   bool HasName;
@@ -6390,12 +6390,12 @@ static bool appendRecordType(SmallString
 
   // We collect all encoded fields and order as necessary.
   bool IsRecursive = false;
-  SmallVector<FieldEncoding, 16> FE;
   const RecordDecl *RD = RT->getDecl()->getDefinition();
   if (RD && !RD->field_empty()) {
     // An incomplete TypeString stub is placed in the cache for this RecordType
     // so that recursive calls to this RecordType will use it whilst building a
     // complete TypeString for this RecordType.
+    SmallVector<FieldEncoding, 16> FE;
     std::string StubEnc(Enc.substr(Start).str());
     StubEnc += '}';  // StubEnc now holds a valid incomplete TypeString.
     TSC.addIncomplete(ID, std::move(StubEnc));
@@ -6408,15 +6408,14 @@ static bool appendRecordType(SmallString
     // See FieldEncoding::operator< for sort algorithm.
     if (RT->isUnionType())
       std::sort(FE.begin(), FE.end());
-  }
-
-  // We can now complete the TypeString.
-  if (unsigned E = FE.size())
+    // We can now complete the TypeString.
+    unsigned E = FE.size();
     for (unsigned I = 0; I != E; ++I) {
       if (I)
         Enc += ',';
       Enc += FE[I].str();
     }
+  }
   Enc += '}';
   TSC.addIfComplete(ID, Enc.substr(Start), IsRecursive);
   return true;
@@ -6438,18 +6437,26 @@ static bool appendEnumType(SmallStringEn
   if (ID)
     Enc += ID->getName();
   Enc += "){";
+
+  // We collect all encoded enumerations and order them alphanumerically.
   if (const EnumDecl *ED = ET->getDecl()->getDefinition()) {
-    auto I = ED->enumerator_begin();
-    auto E = ED->enumerator_end();
-    while (I != E) {
-      Enc += "m(";
-      Enc += I->getName();
-      Enc += "){";
-      I->getInitVal().toString(Enc);
-      Enc += '}';
-      ++I;
-      if (I != E)
+    SmallVector<FieldEncoding, 16> FE;
+    for (auto I = ED->enumerator_begin(), E = ED->enumerator_end(); I != E;
+         ++I) {
+      SmallStringEnc EnumEnc;
+      EnumEnc += "m(";
+      EnumEnc += I->getName();
+      EnumEnc += "){";
+      I->getInitVal().toString(EnumEnc);
+      EnumEnc += '}';
+      FE.push_back(FieldEncoding(!I->getName().empty(), EnumEnc));
+    }
+    std::sort(FE.begin(), FE.end());
+    unsigned E = FE.size();
+    for (unsigned I = 0; I != E; ++I) {
+      if (I)
         Enc += ',';
+      Enc += FE[I].str();
     }
   }
   Enc += '}';

Modified: cfe/trunk/test/CodeGen/xcore-stringtype.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/xcore-stringtype.c?rev=209196&r1=209195&r2=209196&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/xcore-stringtype.c (original)
+++ cfe/trunk/test/CodeGen/xcore-stringtype.c Tue May 20 02:19:33 2014
@@ -163,7 +163,7 @@ int unionTypeB(union UB ub) {return Unio
 // test EnumType
 // CHECK: !33 = metadata !{i32* @EnumAnon, metadata !"e(){m(EA){3}}"}
 // CHECK: !34 = metadata !{i32 (i32)* @enumType, metadata
-// CHECK:       !"f{si}(e(E){m(A){0},m(B){1},m(C){5},m(D){6}})"}
-enum E {A, B, C=5, D};
+// CHECK:       !"f{si}(e(E){m(A){7},m(B){6},m(C){5},m(D){0}})"}
+enum E {D, C=5, B, A};
 enum {EA=3} EnumAnon = EA;
 int enumType(enum E e) {return EnumAnon;}





More information about the cfe-commits mailing list