aprantl created this revision. aprantl added a reviewer: vsk. aprantl added a project: debug-info.
Set a source location for Objective-C accessor stubs even when there is no explicit synthesize statement. This fixes a regression introduced in https://reviews.llvm.org/D68108 that could lead to missing debug locations in cleanup code in synthesized Objective-C++ properties. https://reviews.llvm.org/D71084 Files: clang/lib/Sema/SemaObjCProperty.cpp clang/test/SemaObjC/default-synthesize-sourceloc.m Index: clang/test/SemaObjC/default-synthesize-sourceloc.m =================================================================== --- /dev/null +++ clang/test/SemaObjC/default-synthesize-sourceloc.m @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -ast-dump %s | FileCheck %s + +// Test that accessor stubs for default-synthesized ObjC accessors +// have a valid source location. + +__attribute__((objc_root_class)) +@interface NSObject ++ (id)alloc; +@end + +@interface NSString : NSObject +@end + +@interface MyData : NSObject +struct Data { + NSString *name; +}; +@property struct Data data; +@end +// CHECK: ObjCImplementationDecl {{.*}}line:[[@LINE+2]]{{.*}} MyData +// CHECK: ObjCMethodDecl {{.*}}col:23 implicit - setData: 'void' +@implementation MyData +@end Index: clang/lib/Sema/SemaObjCProperty.cpp =================================================================== --- clang/lib/Sema/SemaObjCProperty.cpp +++ clang/lib/Sema/SemaObjCProperty.cpp @@ -1058,11 +1058,13 @@ SourceLocation PropertyLoc) { ObjCMethodDecl *Decl = AccessorDecl; ObjCMethodDecl *ImplDecl = ObjCMethodDecl::Create( - Context, AtLoc, PropertyLoc, Decl->getSelector(), Decl->getReturnType(), + Context, AtLoc.isValid() ? AtLoc : Decl->getBeginLoc(), + PropertyLoc.isValid() ? PropertyLoc : Decl->getEndLoc(), + Decl->getSelector(), Decl->getReturnType(), Decl->getReturnTypeSourceInfo(), Impl, Decl->isInstanceMethod(), - Decl->isVariadic(), Decl->isPropertyAccessor(), /* isSynthesized*/ true, - Decl->isImplicit(), Decl->isDefined(), Decl->getImplementationControl(), - Decl->hasRelatedResultType()); + Decl->isVariadic(), Decl->isPropertyAccessor(), + /* isSynthesized*/ true, Decl->isImplicit(), Decl->isDefined(), + Decl->getImplementationControl(), Decl->hasRelatedResultType()); ImplDecl->getMethodFamily(); if (Decl->hasAttrs()) ImplDecl->setAttrs(Decl->getAttrs());
Index: clang/test/SemaObjC/default-synthesize-sourceloc.m =================================================================== --- /dev/null +++ clang/test/SemaObjC/default-synthesize-sourceloc.m @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -ast-dump %s | FileCheck %s + +// Test that accessor stubs for default-synthesized ObjC accessors +// have a valid source location. + +__attribute__((objc_root_class)) +@interface NSObject ++ (id)alloc; +@end + +@interface NSString : NSObject +@end + +@interface MyData : NSObject +struct Data { + NSString *name; +}; +@property struct Data data; +@end +// CHECK: ObjCImplementationDecl {{.*}}line:[[@LINE+2]]{{.*}} MyData +// CHECK: ObjCMethodDecl {{.*}}col:23 implicit - setData: 'void' +@implementation MyData +@end Index: clang/lib/Sema/SemaObjCProperty.cpp =================================================================== --- clang/lib/Sema/SemaObjCProperty.cpp +++ clang/lib/Sema/SemaObjCProperty.cpp @@ -1058,11 +1058,13 @@ SourceLocation PropertyLoc) { ObjCMethodDecl *Decl = AccessorDecl; ObjCMethodDecl *ImplDecl = ObjCMethodDecl::Create( - Context, AtLoc, PropertyLoc, Decl->getSelector(), Decl->getReturnType(), + Context, AtLoc.isValid() ? AtLoc : Decl->getBeginLoc(), + PropertyLoc.isValid() ? PropertyLoc : Decl->getEndLoc(), + Decl->getSelector(), Decl->getReturnType(), Decl->getReturnTypeSourceInfo(), Impl, Decl->isInstanceMethod(), - Decl->isVariadic(), Decl->isPropertyAccessor(), /* isSynthesized*/ true, - Decl->isImplicit(), Decl->isDefined(), Decl->getImplementationControl(), - Decl->hasRelatedResultType()); + Decl->isVariadic(), Decl->isPropertyAccessor(), + /* isSynthesized*/ true, Decl->isImplicit(), Decl->isDefined(), + Decl->getImplementationControl(), Decl->hasRelatedResultType()); ImplDecl->getMethodFamily(); if (Decl->hasAttrs()) ImplDecl->setAttrs(Decl->getAttrs());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits