[clang] a1a9aa1 - Set a source location for Objective-C accessor stubs
Adrian Prantl via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 5 12:45:29 PST 2019
Author: Adrian Prantl
Date: 2019-12-05T12:45:10-08:00
New Revision: a1a9aa17b4db08937e458cdda85327b9eff307df
URL: https://github.com/llvm/llvm-project/commit/a1a9aa17b4db08937e458cdda85327b9eff307df
DIFF: https://github.com/llvm/llvm-project/commit/a1a9aa17b4db08937e458cdda85327b9eff307df.diff
LOG: 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.
rdar://57630879
Differential Revision: https://reviews.llvm.org/D71084
Added:
clang/test/SemaObjC/default-synthesize-sourceloc.m
Modified:
clang/lib/Sema/SemaObjCProperty.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp
index 87f7baaf568f..2d91ea1f5fd0 100644
--- a/clang/lib/Sema/SemaObjCProperty.cpp
+++ b/clang/lib/Sema/SemaObjCProperty.cpp
@@ -1058,11 +1058,13 @@ RedeclarePropertyAccessor(ASTContext &Context, ObjCImplementationDecl *Impl,
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());
diff --git a/clang/test/SemaObjC/default-synthesize-sourceloc.m b/clang/test/SemaObjC/default-synthesize-sourceloc.m
new file mode 100644
index 000000000000..bd549fff17c1
--- /dev/null
+++ b/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))
+ at interface NSObject
++ (id)alloc;
+ at end
+
+ at interface NSString : NSObject
+ at end
+
+ at interface MyData : NSObject
+struct Data {
+ NSString *name;
+};
+ at property struct Data data;
+ at end
+// CHECK: ObjCImplementationDecl {{.*}}line:[[@LINE+2]]{{.*}} MyData
+// CHECK: ObjCMethodDecl {{.*}}col:23 implicit - setData: 'void'
+ at implementation MyData
+ at end
More information about the cfe-commits
mailing list