tra created this revision.
tra added a reviewer: arphaman.
Herald added subscribers: jlebar, sanjoy.

Fixes a crash in clang when it crashed with -ast-print on code that contained 
decltype(nullptr).


https://reviews.llvm.org/D41781

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/Sema/ast-print-cxx.cpp


Index: clang/test/Sema/ast-print-cxx.cpp
===================================================================
--- /dev/null
+++ clang/test/Sema/ast-print-cxx.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c++11 %s -ast-print | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 %s -ast-print \
+// RUN:      | %clang_cc1 -std=c++11 -x c++ -fsyntax-only -
+
+// CHECK: typedef decltype(nullptr) nullptr_t;
+typedef decltype(nullptr) nullptr_t;
Index: clang/lib/AST/DeclPrinter.cpp
===================================================================
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -144,6 +144,8 @@
       BaseType = RTy->getPointeeType();
     else if (const AutoType *ATy = BaseType->getAs<AutoType>())
       BaseType = ATy->getDeducedType();
+    else if (isa<BuiltinType>(BaseType))
+      break;
     else
       llvm_unreachable("Unknown declarator!");
   }


Index: clang/test/Sema/ast-print-cxx.cpp
===================================================================
--- /dev/null
+++ clang/test/Sema/ast-print-cxx.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c++11 %s -ast-print | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 %s -ast-print \
+// RUN:      | %clang_cc1 -std=c++11 -x c++ -fsyntax-only -
+
+// CHECK: typedef decltype(nullptr) nullptr_t;
+typedef decltype(nullptr) nullptr_t;
Index: clang/lib/AST/DeclPrinter.cpp
===================================================================
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -144,6 +144,8 @@
       BaseType = RTy->getPointeeType();
     else if (const AutoType *ATy = BaseType->getAs<AutoType>())
       BaseType = ATy->getDeducedType();
+    else if (isa<BuiltinType>(BaseType))
+      break;
     else
       llvm_unreachable("Unknown declarator!");
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D41781: [DeclPrinte... Artem Belevich via Phabricator via cfe-commits

Reply via email to