Author: Ellis Hoag Date: 2022-01-02T18:03:42-08:00 New Revision: e27b5f9371382952eb5482ad151bb6fcb4cd0d7c
URL: https://github.com/llvm/llvm-project/commit/e27b5f9371382952eb5482ad151bb6fcb4cd0d7c DIFF: https://github.com/llvm/llvm-project/commit/e27b5f9371382952eb5482ad151bb6fcb4cd0d7c.diff LOG: [clang][AST] Fix crash when printing error Clang will crash if it tries to compile the following code. This commit fixes it. ``` $ cat foo.c void foo(_Nullable int *ptr) { __auto_type _Nonnull a = ptr; }; $ clang foo.c -c -Wnullable-to-nonnull-conversion ``` Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D116342 Added: Modified: clang/lib/AST/TypePrinter.cpp clang/test/Sema/nullability.c Removed: ################################################################################ diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 2a33a69f288d4..cf520fcb037ed 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -280,7 +280,7 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, case Type::Attributed: { // We still want to print the address_space before the type if it is an // address_space attribute. - const auto *AttrTy = cast<AttributedType>(T); + const auto *AttrTy = cast<AttributedType>(UnderlyingType); CanPrefixQualifiers = AttrTy->getAttrKind() == attr::AddressSpace; } } diff --git a/clang/test/Sema/nullability.c b/clang/test/Sema/nullability.c index d462886de0436..977b29e9bf9dd 100644 --- a/clang/test/Sema/nullability.c +++ b/clang/test/Sema/nullability.c @@ -125,6 +125,7 @@ void nullable_to_nonnull(_Nullable int *ptr) { int *a = ptr; // okay _Nonnull int *b = ptr; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}} b = ptr; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}} + __auto_type _Nonnull c = ptr; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nullable _Nonnull'}} accepts_nonnull_1(ptr); // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}} } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits