r188061 - Sema: Assertion failure during CodeGen in CodeGenModule::EmitUuidofInitializer

David Majnemer david.majnemer at gmail.com
Fri Aug 9 01:56:21 PDT 2013


Author: majnemer
Date: Fri Aug  9 03:56:20 2013
New Revision: 188061

URL: http://llvm.org/viewvc/llvm-project?rev=188061&view=rev
Log:
Sema: Assertion failure during CodeGen in CodeGenModule::EmitUuidofInitializer

Make sure we can properly generate code when the UUID has curly braces
on it, strip the curly braces at the sema layer.

This fixes PR16813.

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-uuidof.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=188061&r1=188060&r2=188061&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Aug  9 03:56:20 2013
@@ -4567,43 +4567,32 @@ static void handleUuidAttr(Sema &S, Decl
     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) {
+  if (StrRef.size() != 36) {
     S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
     return;
   }
-  if (!IsCurly && 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) {

Modified: cfe/trunk/test/CodeGenCXX/microsoft-uuidof.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-uuidof.cpp?rev=188061&r1=188060&r2=188061&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-uuidof.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-uuidof.cpp Fri Aug  9 03:56:20 2013
@@ -10,6 +10,11 @@ typedef struct _GUID
 
 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
@@ -23,6 +28,9 @@ const GUID& gr = __uuidof(S1);
 // CHECK: @gp = global %struct._GUID* @_GUID_12345678_1234_1234_1234_1234567890ab, align 4
 const GUID* gp = &__uuidof(S1);
 
+// CHECK: @cp = global %struct._GUID* @_GUID_12345678_1234_1234_1234_1234567890ac, align 4
+const GUID* cp = &__uuidof(Curly);
+
 // Special case: _uuidof(0)
 // CHECK: @zeroiid = constant %struct._GUID* @_GUID_00000000_0000_0000_0000_000000000000, align 4
 const GUID& zeroiid = __uuidof(0);





More information about the cfe-commits mailing list