[PATCH] Sema: Assertion failure during CodeGen in CodeGenModule::EmitUuidofInitializer

David Majnemer david.majnemer at gmail.com
Thu Aug 8 04:19:45 PDT 2013


    - Simplify the function as recommened in Richard's review.

Hi rsmith, thakis,

http://llvm-reviews.chandlerc.com/D1319

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1319?vs=3271&id=3280#toc

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/microsoft-uuidof.cpp

Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4567,43 +4567,32 @@
     return;
   }
 
+  // GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or
+  // "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}", normalize to the former.
   StringRef StrRef = Str->getString();
-
-  bool IsCurly = StrRef.size() > 1 && StrRef.front() == '{' &&
-                 StrRef.back() == '}';
+  if (StrRef.size() == 38 && StrRef.front() == '{' && StrRef.back() == '}')
+    StrRef = StrRef.drop_front().drop_back();
 
   // Validate GUID length.
-  if (IsCurly && StrRef.size() != 38) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
-    return;
-  }
-  if (!IsCurly && StrRef.size() != 36) {
+  if (StrRef.size() != 36) {
     S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
     return;
   }
 
-  // GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or
-  // "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
-  StringRef::iterator I = StrRef.begin();
-  if (IsCurly) // Skip the optional '{'
-     ++I;
-
-  for (int i = 0; i < 36; ++i) {
+  for (unsigned i = 0; i < 36; ++i) {
     if (i == 8 || i == 13 || i == 18 || i == 23) {
-      if (*I != '-') {
+      if (StrRef[i] != '-') {
         S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
         return;
       }
-    } else if (!isHexDigit(*I)) {
+    } else if (!isHexDigit(StrRef[i])) {
       S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
       return;
     }
-    I++;
   }
 
-  D->addAttr(::new (S.Context)
-             UuidAttr(Attr.getRange(), S.Context, Str->getString(),
-                      Attr.getAttributeSpellingListIndex()));
+  D->addAttr(::new (S.Context) UuidAttr(Attr.getRange(), S.Context, StrRef,
+                                        Attr.getAttributeSpellingListIndex()));
 }
 
 static void handleInheritanceAttr(Sema &S, Decl *D, const AttributeList &Attr) {
Index: test/CodeGenCXX/microsoft-uuidof.cpp
===================================================================
--- test/CodeGenCXX/microsoft-uuidof.cpp
+++ test/CodeGenCXX/microsoft-uuidof.cpp
@@ -10,6 +10,11 @@
 
 struct __declspec(uuid("12345678-1234-1234-1234-1234567890ab")) S1 { } s1;
 struct __declspec(uuid("87654321-4321-4321-4321-ba0987654321")) S2 { };
+struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly;
+
+// Make sure we can properly generate code when the UUID has curly braces on it.
+GUID thing = __uuidof(Curly);
+// CHECK: @thing = global %struct._GUID zeroinitializer, align 4
 
 // This gets initialized in a static initializer.
 // CHECK: @g = global %struct._GUID zeroinitializer, align 4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1319.2.patch
Type: text/x-patch
Size: 2746 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130808/088b8c86/attachment.bin>


More information about the cfe-commits mailing list