[PATCH] D41788: [DeclPrinter] Fix two cases that crash clang -ast-print.
This revision was automatically updated to reflect the committed changes. Closed by commit rL322742: [DeclPrinter] Fix two cases that crash clang -ast-print. (authored by tra, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D41788?vs=128813=130233#toc Repository: rL LLVM https://reviews.llvm.org/D41788 Files: cfe/trunk/lib/AST/DeclPrinter.cpp cfe/trunk/test/Sema/ast-print.c cfe/trunk/test/SemaCXX/ast-print-crash.cpp Index: cfe/trunk/lib/AST/DeclPrinter.cpp === --- cfe/trunk/lib/AST/DeclPrinter.cpp +++ cfe/trunk/lib/AST/DeclPrinter.cpp @@ -128,9 +128,7 @@ // FIXME: This should be on the Type class! QualType BaseType = T; while (!BaseType->isSpecifierType()) { -if (isa(BaseType)) - break; -else if (const PointerType* PTy = BaseType->getAs()) +if (const PointerType *PTy = BaseType->getAs()) BaseType = PTy->getPointeeType(); else if (const BlockPointerType *BPy = BaseType->getAs()) BaseType = BPy->getPointeeType(); @@ -144,8 +142,11 @@ BaseType = RTy->getPointeeType(); else if (const AutoType *ATy = BaseType->getAs()) BaseType = ATy->getDeducedType(); +else if (const ParenType *PTy = BaseType->getAs()) + BaseType = PTy->desugar(); else - llvm_unreachable("Unknown declarator!"); + // This must be a syntax error. + break; } return BaseType; } Index: cfe/trunk/test/SemaCXX/ast-print-crash.cpp === --- cfe/trunk/test/SemaCXX/ast-print-crash.cpp +++ cfe/trunk/test/SemaCXX/ast-print-crash.cpp @@ -0,0 +1,12 @@ +// RUN: not %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 \ +// RUN: | FileCheck %s + +// The test compiles a file with a syntax error which used to cause a crash with +// -ast-print. Compilation fails due to the syntax error, but compiler should +// not crash and print out whatever it manager to parse. + +// CHECK: struct { +// CHECK-NEXT: } dont_crash_on_syntax_error; +// CHECK-NEXT: decltype(nullptr) p; +struct { +} dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p; Index: cfe/trunk/test/Sema/ast-print.c === --- cfe/trunk/test/Sema/ast-print.c +++ cfe/trunk/test/Sema/ast-print.c @@ -15,6 +15,10 @@ }; }; +// This used to crash clang. +struct { +}(s1); + int foo(const struct blah *b) { // CHECK: return b->b; return b->b; Index: cfe/trunk/lib/AST/DeclPrinter.cpp === --- cfe/trunk/lib/AST/DeclPrinter.cpp +++ cfe/trunk/lib/AST/DeclPrinter.cpp @@ -128,9 +128,7 @@ // FIXME: This should be on the Type class! QualType BaseType = T; while (!BaseType->isSpecifierType()) { -if (isa(BaseType)) - break; -else if (const PointerType* PTy = BaseType->getAs()) +if (const PointerType *PTy = BaseType->getAs()) BaseType = PTy->getPointeeType(); else if (const BlockPointerType *BPy = BaseType->getAs()) BaseType = BPy->getPointeeType(); @@ -144,8 +142,11 @@ BaseType = RTy->getPointeeType(); else if (const AutoType *ATy = BaseType->getAs()) BaseType = ATy->getDeducedType(); +else if (const ParenType *PTy = BaseType->getAs()) + BaseType = PTy->desugar(); else - llvm_unreachable("Unknown declarator!"); + // This must be a syntax error. + break; } return BaseType; } Index: cfe/trunk/test/SemaCXX/ast-print-crash.cpp === --- cfe/trunk/test/SemaCXX/ast-print-crash.cpp +++ cfe/trunk/test/SemaCXX/ast-print-crash.cpp @@ -0,0 +1,12 @@ +// RUN: not %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 \ +// RUN: | FileCheck %s + +// The test compiles a file with a syntax error which used to cause a crash with +// -ast-print. Compilation fails due to the syntax error, but compiler should +// not crash and print out whatever it manager to parse. + +// CHECK: struct { +// CHECK-NEXT: } dont_crash_on_syntax_error; +// CHECK-NEXT: decltype(nullptr) p; +struct { +} dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p; Index: cfe/trunk/test/Sema/ast-print.c === --- cfe/trunk/test/Sema/ast-print.c +++ cfe/trunk/test/Sema/ast-print.c @@ -15,6 +15,10 @@ }; }; +// This used to crash clang. +struct { +}(s1); + int foo(const struct blah *b) { // CHECK: return b->b; return b->b; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41788: [DeclPrinter] Fix two cases that crash clang -ast-print.
bkramer accepted this revision. bkramer added a comment. This revision is now accepted and ready to land. This should be fine. https://reviews.llvm.org/D41788 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41788: [DeclPrinter] Fix two cases that crash clang -ast-print.
tra added a comment. @bkramer Can you take a look at the patch? https://reviews.llvm.org/D41788 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41788: [DeclPrinter] Fix two cases that crash clang -ast-print.
tra added a comment. @arphaman: ping. https://reviews.llvm.org/D41788 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41788: [DeclPrinter] Fix two cases that crash clang -ast-print.
jlebar added a comment. I strongly approve of fixing these crashes, but I don't think I can say with confidence whether this change is correct. https://reviews.llvm.org/D41788 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41788: [DeclPrinter] Fix two cases that crash clang -ast-print.
tra created this revision. tra added a reviewer: arphaman. Herald added subscribers: jlebar, sanjoy. Both crashes are related to handling anonymous structures. - clang didn't handle () around an anonymous struct variable. - clang also crashed on syntax errors that could lead to other syntactic constructs following the declaration of an anonymous struct. While the code is invalid, that's not a good reason to panic compiler. https://reviews.llvm.org/D41788 Files: clang/lib/AST/DeclPrinter.cpp clang/test/Sema/ast-print.c clang/test/SemaCXX/ast-print-crash.cpp Index: clang/test/SemaCXX/ast-print-crash.cpp === --- /dev/null +++ clang/test/SemaCXX/ast-print-crash.cpp @@ -0,0 +1,12 @@ +// RUN: not %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 \ +// RUN: | FileCheck %s + +// The test compiles a file with a syntax error which used to cause a crash with +// -ast-print. Compilation fails due to the syntax error, but compiler should +// not crash and print out whatever it manager to parse. + +// CHECK: struct { +// CHECK-NEXT: } dont_crash_on_syntax_error; +// CHECK-NEXT: decltype(nullptr) p; +struct { +} dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p; Index: clang/test/Sema/ast-print.c === --- clang/test/Sema/ast-print.c +++ clang/test/Sema/ast-print.c @@ -15,6 +15,10 @@ }; }; +// This used to crash clang. +struct { +}(s1); + int foo(const struct blah *b) { // CHECK: return b->b; return b->b; Index: clang/lib/AST/DeclPrinter.cpp === --- clang/lib/AST/DeclPrinter.cpp +++ clang/lib/AST/DeclPrinter.cpp @@ -128,9 +128,7 @@ // FIXME: This should be on the Type class! QualType BaseType = T; while (!BaseType->isSpecifierType()) { -if (isa(BaseType)) - break; -else if (const PointerType* PTy = BaseType->getAs()) +if (const PointerType *PTy = BaseType->getAs()) BaseType = PTy->getPointeeType(); else if (const BlockPointerType *BPy = BaseType->getAs()) BaseType = BPy->getPointeeType(); @@ -144,8 +142,11 @@ BaseType = RTy->getPointeeType(); else if (const AutoType *ATy = BaseType->getAs()) BaseType = ATy->getDeducedType(); +else if (const ParenType *PTy = BaseType->getAs()) + BaseType = PTy->desugar(); else - llvm_unreachable("Unknown declarator!"); + // This must be a syntax error. + break; } return BaseType; } Index: clang/test/SemaCXX/ast-print-crash.cpp === --- /dev/null +++ clang/test/SemaCXX/ast-print-crash.cpp @@ -0,0 +1,12 @@ +// RUN: not %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 \ +// RUN: | FileCheck %s + +// The test compiles a file with a syntax error which used to cause a crash with +// -ast-print. Compilation fails due to the syntax error, but compiler should +// not crash and print out whatever it manager to parse. + +// CHECK: struct { +// CHECK-NEXT: } dont_crash_on_syntax_error; +// CHECK-NEXT: decltype(nullptr) p; +struct { +} dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p; Index: clang/test/Sema/ast-print.c === --- clang/test/Sema/ast-print.c +++ clang/test/Sema/ast-print.c @@ -15,6 +15,10 @@ }; }; +// This used to crash clang. +struct { +}(s1); + int foo(const struct blah *b) { // CHECK: return b->b; return b->b; Index: clang/lib/AST/DeclPrinter.cpp === --- clang/lib/AST/DeclPrinter.cpp +++ clang/lib/AST/DeclPrinter.cpp @@ -128,9 +128,7 @@ // FIXME: This should be on the Type class! QualType BaseType = T; while (!BaseType->isSpecifierType()) { -if (isa(BaseType)) - break; -else if (const PointerType* PTy = BaseType->getAs()) +if (const PointerType *PTy = BaseType->getAs()) BaseType = PTy->getPointeeType(); else if (const BlockPointerType *BPy = BaseType->getAs()) BaseType = BPy->getPointeeType(); @@ -144,8 +142,11 @@ BaseType = RTy->getPointeeType(); else if (const AutoType *ATy = BaseType->getAs()) BaseType = ATy->getDeducedType(); +else if (const ParenType *PTy = BaseType->getAs()) + BaseType = PTy->desugar(); else - llvm_unreachable("Unknown declarator!"); + // This must be a syntax error. + break; } return BaseType; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits