[PATCH] D142799: [Clang] Fix unconditional access to Attr pointer when checking if _Nullable is applicable to a type

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 30 13:07:02 PST 2023


shafik updated this revision to Diff 493389.
shafik marked an inline comment as done.
shafik added a comment.

- Fix up release notes


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142799/new/

https://reviews.llvm.org/D142799

Files:
  clang/docs/ReleaseNotes.rst
  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/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -57,6 +57,9 @@
 - Fix crash on invalid code when looking up a destructor in a templated class
   inside a namespace. This fixes
   `Issue 59446 <https://github.com/llvm/llvm-project/issues/59446>`_.
+- Fix crash when diagnosing incorrect usage of ``_Nullable`` involving alias
+  templates. This fixes
+  `Issue 60344 <https://github.com/llvm/llvm-project/issues/60344>`_.
 
 Improvements to Clang's diagnostics
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142799.493389.patch
Type: text/x-patch
Size: 1893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230130/54716f2b/attachment.bin>


More information about the cfe-commits mailing list