[refactor][extract-repeated] Don't add extraneous base 'self'/'this'
expression
rdar://34202062
(cherry picked from commit 56c0ea86d3309b272dadd2061e7a98ba5ef43cc0)
diff --git a/lib/Tooling/Refactor/ExtractRepeatedExpressionIntoVariable.cpp b/lib/Tooling/Refactor/ExtractRepeatedExpressionIntoVariable.cpp
index dc90d9e..7e796b6 100644
--- a/lib/Tooling/Refactor/ExtractRepeatedExpressionIntoVariable.cpp
+++ b/lib/Tooling/Refactor/ExtractRepeatedExpressionIntoVariable.cpp
@@ -266,7 +266,10 @@
PP.SuppressUnwrittenScope = true;
T.print(OS, PP, /*PlaceHolder*/ Name);
OS << " = ";
- E->printPretty(OS, /*Helper=*/nullptr, Context.getPrintingPolicy());
+ PrintingPolicy ExprPP = Context.getPrintingPolicy();
+ ExprPP.SuppressStrongLifetime = true;
+ ExprPP.SuppressImplicitBase = true;
+ E->printPretty(OS, /*Helper=*/nullptr, ExprPP);
OS << ";\n";
Replacements.emplace_back(SourceRange(InsertionLoc, InsertionLoc), OS.str());
diff --git a/test/Refactor/ExtractRepeatedExpression/extract-repeated-expr-perform.cpp b/test/Refactor/ExtractRepeatedExpression/extract-repeated-expr-perform.cpp
index 4d8c400..f5ddc8a 100644
--- a/test/Refactor/ExtractRepeatedExpression/extract-repeated-expr-perform.cpp
+++ b/test/Refactor/ExtractRepeatedExpression/extract-repeated-expr-perform.cpp
@@ -98,3 +98,19 @@
}
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=%s:94:5 %s | FileCheck --check-prefix=CHECK6 %s
+
+class ImplicitThisRewrite {
+ AWrapper &ref;
+ ImplicitThisRewrite(AWrapper &ref) : ref(ref) {}
+
+ void method() {
+ // implicit-this: +1:5 // IMPLICIT-THIS: "AClass &object = this->ref.object(1);\nobject" [[@LINE+1]]:5 -> [[@LINE+1]]:18
+ ref.object(1).method(); // IMPLICIT-NO-THIS: "AClass &object = ref.object(1);\nobject" [[@LINE]]:5 -> [[@LINE]]:18
+ ref.object(1).constMethod(); // IMPLICIT-THIS-ME: "object" [[@LINE]]:5 -> [[@LINE]]:18
+ // implicit-this2: +1:5
+ this->ref.object(1).method(); // IMPLICIT-THIS-MENEXT: "object" [[@LINE]]:5 -> [[@LINE]]:24
+ }
+};
+
+// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=implicit-this %s | FileCheck --check-prefixes=IMPLICIT-NO-THIS,IMPLICIT-THIS-ME %s
+// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=implicit-this2 %s | FileCheck --check-prefixes=IMPLICIT-THIS,IMPLICIT-THIS-ME %s
diff --git a/test/Refactor/ExtractRepeatedExpression/extract-repeated-expr-perform.m b/test/Refactor/ExtractRepeatedExpression/extract-repeated-expr-perform.m
index 23ed359..cc14c23 100644
--- a/test/Refactor/ExtractRepeatedExpression/extract-repeated-expr-perform.m
+++ b/test/Refactor/ExtractRepeatedExpression/extract-repeated-expr-perform.m
@@ -96,3 +96,24 @@
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=macro-arg1 %s | FileCheck --check-prefix=MACRO-ARG1 %s
// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=macro-arg2 %s | FileCheck --check-prefix=MACRO-ARG2 %s
+
+@interface IVarSelf {
+ Wrapper *ref;
+}
+
+@end
+
+@implementation IVarSelf
+
+- (void)foo {
+ // ivar-self: +1:3 // IVAR-SELF: "Object *object = self->ref.object;\nobject" [[@LINE+1]]:3 -> [[@LINE+1]]:13
+ ref.object.prop = 0; // IVAR-NO-SELF: "Object *object = ref.object;\nobject" [[@LINE]]:3 -> [[@LINE]]:13
+ ref.object->ivar = 1; // IVAR: "object" [[@LINE]]:3 -> [[@LINE]]:13
+ // ivar-self2: +1:3
+ self->ref.object.prop = 2; // IVAR-NEXT: "object" [[@LINE]]:3 -> [[@LINE]]:19
+}
+
+@end
+
+// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=ivar-self %s | FileCheck --check-prefixes=IVAR-NO-SELF,IVAR %s
+// RUN: clang-refactor-test perform -action extract-repeated-expr-into-var -at=ivar-self2 %s | FileCheck --check-prefixes=IVAR-SELF,IVAR %s