From bb0ed290428223ac1441ff45bd9ae801adfb455d Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Fri, 9 Aug 2013 08:56:20 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188061 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclAttr.cpp | 31 +++++++++------------------- test/CodeGenCXX/microsoft-uuidof.cpp | 8 +++++++ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index d5844f4dbc..cae855e006 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -4567,43 +4567,32 @@ static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr) { 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) { diff --git a/test/CodeGenCXX/microsoft-uuidof.cpp b/test/CodeGenCXX/microsoft-uuidof.cpp index 22e750183d..38ffafc007 100644 --- a/test/CodeGenCXX/microsoft-uuidof.cpp +++ b/test/CodeGenCXX/microsoft-uuidof.cpp @@ -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); -- 2.40.0