[PATCH] D112101: [AST] Fix the EndLoc calculation for ObjCObjectPointer

Luke Petre via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 25 06:05:04 PDT 2021


lpetre created this revision.
lpetre updated this revision to Diff 381958.
lpetre added a comment.
lpetre updated this revision to Diff 381960.
lpetre retitled this revision from "Fix the EndLoc calculation for ObjCObjectPointer" to "[AST] Fix the EndLoc calculation for ObjCObjectPointer".
lpetre edited the summary of this revision.
lpetre added a reviewer: rsmith.
lpetre added a project: clang.
lpetre published this revision for review.
Herald added a subscriber: cfe-commits.

Updating diff with full commit range

My initial arc diff only picked up the final commit, now running for all commits


lpetre added a comment.

Trying again to include both commits


There is an issue where the AST code does not compute the correct SourceRange for a ObjCObjectPointer.

>From Richard Smith (ie @zygoloid) in discord:

> I think the problem is that we set an invalid location for the * (because there isn't one): https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaType.cpp#L1121
> And then we use the default getLocalSourceRangeImpl for a PointerLikeTypeLoc that just assumes the * location is the type's end location: https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/TypeLoc.h#L1293
> Possibly we should be special-casing that here: https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/TypeLoc.cpp#L228

My change:

- introduces a AST dump test to show the issue in the first commit
- special cases ObjCObjectPointerType in the second commit to correctly compute the end location


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112101

Files:
  clang/lib/AST/TypeLoc.cpp
  clang/test/AST/ast-dump-decl.mm


Index: clang/test/AST/ast-dump-decl.mm
===================================================================
--- clang/test/AST/ast-dump-decl.mm
+++ clang/test/AST/ast-dump-decl.mm
@@ -55,4 +55,11 @@
     // CHECK-NEXT:               CXXThisExpr {{.*}} <col:8> 'Test *' this
   }
   void yada();
+  // CHECK:      CXXMethodDecl {{.*}} <line:[[@LINE-1]]:3, col:13> col:8 used yada 'void ()'
 };
+
+ at protocol P
+ at end;
+
+using TestAlias = id<P>;
+// CHECK:      TypeAliasDecl {{.+}} <{{.+}}:[[@LINE-1]]:1, col:23> col:7 TestAlias 'id<P>'
Index: clang/lib/AST/TypeLoc.cpp
===================================================================
--- clang/lib/AST/TypeLoc.cpp
+++ clang/lib/AST/TypeLoc.cpp
@@ -257,6 +257,7 @@
       if (!Last)
         Last = Cur;
       break;
+    case ObjCObjectPointer:
     case Qualified:
     case Elaborated:
       break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112101.381960.patch
Type: text/x-patch
Size: 854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211025/bb996840/attachment.bin>


More information about the cfe-commits mailing list