shafik created this revision. shafik added reviewers: aaron.ballman, erichkeane. Herald added a project: All. shafik requested review of this revision.
In `TransformAttributedType(...)` when checking if `_Nullable` can be applied to a type it dereferences `TL.getAttr()` unconditionally which we can see from the code earlier in the function is not correct since it is expected to be `nullptr` in some cases. It looks like the correct course of action is to use `TL.getModifiedLoc()` over `TL.getAttr()->getLocation()` in the case that `TL.getAttr()` returns a `nullptr`. Fixes: https://github.com/llvm/llvm-project/issues/60344 https://reviews.llvm.org/D142799 Files: clang/lib/Sema/TreeTransform.h clang/test/SemaCXX/nullability.cpp Index: clang/test/SemaCXX/nullability.cpp =================================================================== --- clang/test/SemaCXX/nullability.cpp +++ clang/test/SemaCXX/nullability.cpp @@ -136,3 +136,9 @@ void testNullabilityCompletenessWithTemplate() { Template<int*> tip; } + +namespace GH60344 { +class a; +template <typename b> using c = b _Nullable; // expected-error {{'_Nullable' cannot be applied to non-pointer type 'GH60344::a'}} +c<a>; // expected-note {{in instantiation of template type alias 'c' requested here}} +} Index: clang/lib/Sema/TreeTransform.h =================================================================== --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -6992,7 +6992,8 @@ // type sugar, and therefore cannot be diagnosed in any other way. if (auto nullability = oldType->getImmediateNullability()) { if (!modifiedType->canHaveNullability()) { - SemaRef.Diag(TL.getAttr()->getLocation(), + SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation() + : TL.getModifiedLoc().getBeginLoc()), diag::err_nullability_nonpointer) << DiagNullabilityKind(*nullability, false) << modifiedType; return QualType();
Index: clang/test/SemaCXX/nullability.cpp =================================================================== --- clang/test/SemaCXX/nullability.cpp +++ clang/test/SemaCXX/nullability.cpp @@ -136,3 +136,9 @@ void testNullabilityCompletenessWithTemplate() { Template<int*> tip; } + +namespace GH60344 { +class a; +template <typename b> using c = b _Nullable; // expected-error {{'_Nullable' cannot be applied to non-pointer type 'GH60344::a'}} +c<a>; // expected-note {{in instantiation of template type alias 'c' requested here}} +} Index: clang/lib/Sema/TreeTransform.h =================================================================== --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -6992,7 +6992,8 @@ // type sugar, and therefore cannot be diagnosed in any other way. if (auto nullability = oldType->getImmediateNullability()) { if (!modifiedType->canHaveNullability()) { - SemaRef.Diag(TL.getAttr()->getLocation(), + SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation() + : TL.getModifiedLoc().getBeginLoc()), diag::err_nullability_nonpointer) << DiagNullabilityKind(*nullability, false) << modifiedType; return QualType();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits