[PATCH] Don't crash when dumping objc_bridge_related attributes

Joe Ranieri via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 25 15:13:13 PST 2015


Clang's AST dumping currently crashes when dumping objc_bridge_related
attributes where the class method and instance method fields are left
empty. The attached patch marks the two arguments as optional and
updates TableGen to understand the optional flag for identifier
attribute arguments when generating the dump function.

-- Joe Ranieri
-------------- next part --------------
Index: include/clang/Basic/Attr.td
===================================================================
--- include/clang/Basic/Attr.td	(revision 254076)
+++ include/clang/Basic/Attr.td	(working copy)
@@ -1071,8 +1071,8 @@
   let Spellings = [GNU<"objc_bridge_related">];
   let Subjects = SubjectList<[Record], ErrorDiag>;
   let Args = [IdentifierArgument<"RelatedClass">,
-          IdentifierArgument<"ClassMethod">,
-          IdentifierArgument<"InstanceMethod">];
+          IdentifierArgument<"ClassMethod", 1>,
+          IdentifierArgument<"InstanceMethod", 1>];
   let HasCustomParsing = 1;
   let Documentation = [Undocumented];
 }
Index: test/Misc/ast-dump-attr.cpp
===================================================================
--- test/Misc/ast-dump-attr.cpp	(revision 254076)
+++ test/Misc/ast-dump-attr.cpp	(working copy)
@@ -150,3 +150,7 @@
   // CHECK: DeprecatedAttr
 }
 }
+
+struct __attribute__((objc_bridge_related(NSParagraphStyle,,))) TestBridgedRef;
+// CHECK: CXXRecordDecl{{.*}} struct TestBridgedRef
+// CHECK-NEXT: ObjCBridgeRelatedAttr{{.*}} NSParagraphStyle
Index: utils/TableGen/ClangAttrEmitter.cpp
===================================================================
--- utils/TableGen/ClangAttrEmitter.cpp	(revision 254076)
+++ utils/TableGen/ClangAttrEmitter.cpp	(working copy)
@@ -279,6 +279,8 @@
         OS << "    OS << \" \";\n";
         OS << "    dumpBareDeclRef(SA->get" << getUpperName() << "());\n"; 
       } else if (type == "IdentifierInfo *") {
+        if (isOptional())
+          OS << "    if (SA->get" << getUpperName() << "())\n  ";
         OS << "    OS << \" \" << SA->get" << getUpperName()
            << "()->getName();\n";
       } else if (type == "TypeSourceInfo *") {


More information about the cfe-commits mailing list