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
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index d5844f4..cae855e 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/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) {