diff options
author | David Majnemer <david.majnemer@gmail.com> | 2013-08-09 08:56:20 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2013-08-09 08:56:20 +0000 |
commit | 89085340befe24dee8c6084f24d3fa3316823073 (patch) | |
tree | 8a6c50ddf755cd13268d13b38050b68ce2899049 | |
parent | cf963cece85290bdafed4f0d607ab8d899510711 (diff) | |
download | bcm5719-llvm-89085340befe24dee8c6084f24d3fa3316823073.tar.gz bcm5719-llvm-89085340befe24dee8c6084f24d3fa3316823073.zip |
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.
llvm-svn: 188061
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 31 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/microsoft-uuidof.cpp | 8 |
2 files changed, 18 insertions, 21 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d5844f4dbc5..cae855e0065 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/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/clang/test/CodeGenCXX/microsoft-uuidof.cpp b/clang/test/CodeGenCXX/microsoft-uuidof.cpp index 22e750183d5..38ffafc0074 100644 --- a/clang/test/CodeGenCXX/microsoft-uuidof.cpp +++ b/clang/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); |