]> granicus.if.org Git - clang/commitdiff
FixIt: use getLocForEndOfToken to insert fix-it after a type name.
authorManman Ren <manman.ren@gmail.com>
Thu, 2 Jun 2016 00:11:03 +0000 (00:11 +0000)
committerManman Ren <manman.ren@gmail.com>
Thu, 2 Jun 2016 00:11:03 +0000 (00:11 +0000)
Instead of setting DeclSpec's range end to point to the next token
after the DeclSpec, we use getLocForEndOfToken to insert fix-it after a type
name.

Before this fix, fix-it will change
^(NSView view) to ^(*NSView view)

This commit correctly updates the source to ^(NSView* view).

rdar://21042144
Differential Revision: http://reviews.llvm.org/D20844

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271448 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseObjc.cpp
lib/Sema/SemaDecl.cpp
test/FixIt/fixit-interface-as-param.m

index 4b4494d27bee3dfee83224e5ecde9fa5bc461d75..95a0680994ef1680271f8974507cc06d3b8d1397 100644 (file)
@@ -1277,7 +1277,6 @@ ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS,
     if (context == Declarator::ObjCResultContext)
       dsContext = DSC_objc_method_result;
     ParseSpecifierQualifierList(declSpec, AS_none, dsContext);
-    declSpec.SetRangeEnd(Tok.getLocation());
     Declarator declarator(declSpec, context);
     ParseDeclarator(declarator);
 
index 64da16add18a40e440b8233cccf425fac497df34..fab72f36605e589748af1fda5917d55f3a276bda 100644 (file)
@@ -10954,7 +10954,8 @@ ParmVarDecl *Sema::CheckParameter(DeclContext *DC, SourceLocation StartLoc,
   // Parameter declarators cannot be interface types. All ObjC objects are
   // passed by reference.
   if (T->isObjCObjectType()) {
-    SourceLocation TypeEndLoc = TSInfo->getTypeLoc().getLocEnd();
+    SourceLocation TypeEndLoc =
+        getLocForEndOfToken(TSInfo->getTypeLoc().getLocEnd());
     Diag(NameLoc,
          diag::err_object_cannot_be_passed_returned_by_value) << 1 << T
       << FixItHint::CreateInsertion(TypeEndLoc, "*");
index 75da5720d7f0197467d1ee011e53be754742d357..748d83e07005a4dc556faaefa121fed67b3020fd 100644 (file)
@@ -1,11 +1,20 @@
-// RUN: not %clang_cc1 -triple x86_64-apple-darwin10  -fdiagnostics-parseable-fixits -x objective-c %s 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -fdiagnostics-parseable-fixits -x objective-c %s 2>&1 | FileCheck %s
 // rdar://11311333
 
 @interface NSView @end
 
 @interface INTF
 - (void) drawRect : inView:(NSView)view;
+- (void)test:(NSView )a;
+- (void)foo;
 @end
 
 // CHECK: {7:35-7:35}:"*"
-
+// CHECK: {8:21-8:21}:"*"
+@implementation INTF
+-(void)foo {
+  ^(NSView view) {
+  };
+}
+@end
+// CHECK: {16:11-16:11}:"*"