[PATCH] Sema: Assertion failure during CodeGen in CodeGenModule::EmitUuidofInitializer
David Majnemer
david.majnemer at gmail.com
Thu Aug 8 22:08:21 PDT 2013
- Make sure we emit the right value during CodeGen.
Hi rsmith, thakis,
http://llvm-reviews.chandlerc.com/D1319
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1319?vs=3280&id=3308#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
@@ -23,6 +28,9 @@
// CHECK: @gp = global %struct._GUID* @__uuid_12345678-1234-1234-1234-1234567890ab, align 4
const GUID* gp = &__uuidof(S1);
+// CHECK: @cp = global %struct._GUID* @__uuid_12345678-1234-1234-1234-1234567890ac, align 4
+const GUID* cp = &__uuidof(Curly);
+
// Special case: _uuidof(0)
// CHECK: @zeroiid = constant %struct._GUID* @__uuid_00000000-0000-0000-0000-000000000000, align 4
const GUID& zeroiid = __uuidof(0);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1319.3.patch
Type: text/x-patch
Size: 3188 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130808/71c0446a/attachment.bin>
More information about the cfe-commits
mailing list