[clang] a9db0a8 - [AST] Fix the EndLoc calculation for ObjCObjectPointer
    Aaron Ballman via cfe-commits 
    cfe-commits at lists.llvm.org
       
    Tue Oct 26 11:03:45 PDT 2021
    
    
  
Author: Luke Petre
Date: 2021-10-26T14:03:29-04:00
New Revision: a9db0a804a5335b6534995c54ab9d6fcef06e739
URL: https://github.com/llvm/llvm-project/commit/a9db0a804a5335b6534995c54ab9d6fcef06e739
DIFF: https://github.com/llvm/llvm-project/commit/a9db0a804a5335b6534995c54ab9d6fcef06e739.diff
LOG: [AST] Fix the EndLoc calculation for ObjCObjectPointer
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
Added: 
    
Modified: 
    clang/lib/AST/TypeLoc.cpp
    clang/test/AST/ast-dump-decl.mm
Removed: 
    
################################################################################
diff  --git a/clang/lib/AST/TypeLoc.cpp b/clang/lib/AST/TypeLoc.cpp
index e943c873f1fad..712fcac26c95c 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -257,6 +257,7 @@ SourceLocation TypeLoc::getEndLoc() const {
       if (!Last)
         Last = Cur;
       break;
+    case ObjCObjectPointer:
     case Qualified:
     case Elaborated:
       break;
diff  --git a/clang/test/AST/ast-dump-decl.mm b/clang/test/AST/ast-dump-decl.mm
index 7dc60e198aaaa..26756722bfdd8 100644
--- a/clang/test/AST/ast-dump-decl.mm
+++ b/clang/test/AST/ast-dump-decl.mm
@@ -55,4 +55,11 @@ void f() {
     // 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>'
        
    
    
More information about the cfe-commits
mailing list