[clang] 68ffcd5 - Properly determine the end location of an ObjCObjectPointerType.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 29 13:16:06 PDT 2021
Author: Richard Smith
Date: 2021-10-29T13:15:53-07:00
New Revision: 68ffcd521347e3c8b97ca233239d503beff239f4
URL: https://github.com/llvm/llvm-project/commit/68ffcd521347e3c8b97ca233239d503beff239f4
DIFF: https://github.com/llvm/llvm-project/commit/68ffcd521347e3c8b97ca233239d503beff239f4.diff
LOG: Properly determine the end location of an ObjCObjectPointerType.
After rGa9db0a804a53, we correctly determined the end for pointer types
like `id` that are spelled without a `*`, but incorrectly determined the
end for pointer types spelled with a `*`.
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 712fcac26c95c..c3ed08d5a8b3e 100644
--- a/clang/lib/AST/TypeLoc.cpp
+++ b/clang/lib/AST/TypeLoc.cpp
@@ -240,6 +240,8 @@ SourceLocation TypeLoc::getEndLoc() const {
case IncompleteArray:
case VariableArray:
case FunctionNoProto:
+ // The innermost type with suffix syntax always determines the end of the
+ // type.
Last = Cur;
break;
case FunctionProto:
@@ -248,16 +250,22 @@ SourceLocation TypeLoc::getEndLoc() const {
else
Last = Cur;
break;
+ case ObjCObjectPointer:
+ // `id` and `id<...>` have no star location.
+ if (Cur.castAs<ObjCObjectPointerTypeLoc>().getStarLoc().isInvalid())
+ break;
+ LLVM_FALLTHROUGH;
case Pointer:
case BlockPointer:
case MemberPointer:
case LValueReference:
case RValueReference:
case PackExpansion:
+ // Types with prefix syntax only determine the end of the type if there
+ // is no suffix type.
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 26756722bfdd8..16ca27e3b139c 100644
--- a/clang/test/AST/ast-dump-decl.mm
+++ b/clang/test/AST/ast-dump-decl.mm
@@ -61,5 +61,8 @@ void f() {
@protocol P
@end;
-using TestAlias = id<P>;
-// CHECK: TypeAliasDecl {{.+}} <{{.+}}:[[@LINE-1]]:1, col:23> col:7 TestAlias 'id<P>'
+using TestObjCPointerWithoutStar = id<P>;
+// CHECK: TypeAliasDecl {{.+}} <{{.+}}:[[@LINE-1]]:1, col:40> col:7 TestObjCPointerWithoutStar 'id<P>'
+
+using TestObjCPointerWithStar = A *;
+// CHECK: TypeAliasDecl {{.+}} <{{.+}}:[[@LINE-1]]:1, col:35> col:7 TestObjCPointerWithStar 'A *'
More information about the cfe-commits
mailing list