r281132 - [tablegen] Check that an optional IdentifierArgument of an attribute is

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 9 20:29:44 PDT 2016


Author: ahatanak
Date: Fri Sep  9 22:29:43 2016
New Revision: 281132

URL: http://llvm.org/viewvc/llvm-project?rev=281132&view=rev
Log:
[tablegen] Check that an optional IdentifierArgument of an attribute is
provided before trying to print it.

This fixes a segfault that occurs when function printPretty generated by
tablegen tries to print an optional argument of attribute
objc_bridge_related.

rdar://problem/28155469

Modified:
    cfe/trunk/test/Misc/ast-print-objectivec.m
    cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/test/Misc/ast-print-objectivec.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-print-objectivec.m?rev=281132&r1=281131&r2=281132&view=diff
==============================================================================
--- cfe/trunk/test/Misc/ast-print-objectivec.m (original)
+++ cfe/trunk/test/Misc/ast-print-objectivec.m Fri Sep  9 22:29:43 2016
@@ -39,3 +39,9 @@
 // CHECK: }
 
 // CHECK: @end
+
+ at class C1;
+struct __attribute__((objc_bridge_related(C1,,))) S1;
+
+// CHECK: @class C1;
+// CHECK: struct __attribute__((objc_bridge_related(C1, , ))) S1;

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=281132&r1=281131&r2=281132&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Fri Sep  9 22:29:43 2016
@@ -299,7 +299,13 @@ namespace {
         OS << "\" << get" << getUpperName()
            << "()->getNameInfo().getAsString() << \"";
       } else if (type == "IdentifierInfo *") {
-        OS << "\" << get" << getUpperName() << "()->getName() << \"";
+        OS << "\";\n";
+        if (isOptional())
+          OS << "    if (get" << getUpperName() << "()) ";
+        else
+          OS << "    ";
+        OS << "OS << get" << getUpperName() << "()->getName();\n";
+        OS << "    OS << \"";
       } else if (type == "TypeSourceInfo *") {
         OS << "\" << get" << getUpperName() << "().getAsString() << \"";
       } else {




More information about the cfe-commits mailing list