ellis created this revision. ellis added a reviewer: dblaikie. ellis published this revision for review. ellis added inline comments. Herald added a project: clang. Herald added a subscriber: cfe-commits.
================ Comment at: clang/lib/AST/TypePrinter.cpp:242 case Type::ObjCObjectPointer: CanPrefixQualifiers = T->isObjCIdType() || T->isObjCClassType() || T->isObjCQualifiedIdType() || T->isObjCQualifiedClassType(); ---------------- Hi @dblaikie, I'm not familiar with this code but I'm wondering if these uses of `T` should actually be `UnderlyingType`. Will this cause a crash similar to what I found? 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 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D116342 Files: clang/lib/AST/TypePrinter.cpp clang/test/Sema/nullability.c Index: clang/test/Sema/nullability.c =================================================================== --- clang/test/Sema/nullability.c +++ clang/test/Sema/nullability.c @@ -125,6 +125,7 @@ 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'}} } Index: clang/lib/AST/TypePrinter.cpp =================================================================== --- clang/lib/AST/TypePrinter.cpp +++ clang/lib/AST/TypePrinter.cpp @@ -280,7 +280,7 @@ 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; } }
Index: clang/test/Sema/nullability.c =================================================================== --- clang/test/Sema/nullability.c +++ clang/test/Sema/nullability.c @@ -125,6 +125,7 @@ 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'}} } Index: clang/lib/AST/TypePrinter.cpp =================================================================== --- clang/lib/AST/TypePrinter.cpp +++ clang/lib/AST/TypePrinter.cpp @@ -280,7 +280,7 @@ 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; } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits