summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2017-02-03 22:23:11 +0000
committerHans Wennborg <hans@hanshq.net>2017-02-03 22:23:11 +0000
commit870923f42a1b206e80872b6bdd878c345f4e0b68 (patch)
treeee240ca065486a6f1d3cade18b3bc545bcf241e6
parentc1eda1f00cb561893791762a7e2969afc6dfb149 (diff)
Merging r294008:
------------------------------------------------------------------------ r294008 | arphaman | 2017-02-03 06:22:33 -0800 (Fri, 03 Feb 2017) | 14 lines [Sema][ObjC++] Typo correction should handle ivars and properties After r260016 and r260017 disabled typo correction for ivars and properties clang didn't report errors about unresolved identifier in the base of ivar and property ref expressions. This meant that clang invoked CodeGen on invalid AST which then caused a crash. This commit re-enables typo correction for ivars and properites, and fixes the PR25113 & PR26486 (that were originally fixed in r260017 and r260016) in a different manner by transforming the Objective-C ivar reference expression with 'IsFreeIvar' preserved. rdar://30310772 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_40@294059 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExprCXX.cpp8
-rw-r--r--lib/Sema/TreeTransform.h17
-rw-r--r--test/SemaObjCXX/typo-correction.mm15
3 files changed, 24 insertions, 16 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 3de677e37b..3afa95f7d1 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -7190,14 +7190,6 @@ public:
ExprResult TransformBlockExpr(BlockExpr *E) { return Owned(E); }
- ExprResult TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
- return Owned(E);
- }
-
- ExprResult TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
- return Owned(E);
- }
-
ExprResult Transform(Expr *E) {
ExprResult Res;
while (true) {
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 4388ad34e2..f8e65a119c 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -2932,16 +2932,17 @@ public:
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
SourceLocation IvarLoc,
bool IsArrow, bool IsFreeIvar) {
- // FIXME: We lose track of the IsFreeIvar bit.
CXXScopeSpec SS;
DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
- return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
- /*FIXME:*/IvarLoc, IsArrow,
- SS, SourceLocation(),
- /*FirstQualifierInScope=*/nullptr,
- NameInfo,
- /*TemplateArgs=*/nullptr,
- /*S=*/nullptr);
+ ExprResult Result = getSema().BuildMemberReferenceExpr(
+ BaseArg, BaseArg->getType(),
+ /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
+ /*FirstQualifierInScope=*/nullptr, NameInfo,
+ /*TemplateArgs=*/nullptr,
+ /*S=*/nullptr);
+ if (IsFreeIvar && Result.isUsable())
+ cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
+ return Result;
}
/// \brief Build a new Objective-C property reference expression.
diff --git a/test/SemaObjCXX/typo-correction.mm b/test/SemaObjCXX/typo-correction.mm
index a34a7901e8..5e33bfb8cb 100644
--- a/test/SemaObjCXX/typo-correction.mm
+++ b/test/SemaObjCXX/typo-correction.mm
@@ -21,3 +21,18 @@ public:
self.m_prop2 = new ClassB(m_prop1); // expected-error {{use of undeclared identifier 'm_prop1'; did you mean '_m_prop1'?}}
}
@end
+
+// rdar://30310772
+
+@interface InvalidNameInIvarAndPropertyBase
+{
+@public
+ float _a;
+}
+@property float _b;
+@end
+
+void invalidNameInIvarAndPropertyBase() {
+ float a = ((InvalidNameInIvarAndPropertyBase*)node)->_a; // expected-error {{use of undeclared identifier 'node'}}
+ float b = ((InvalidNameInIvarAndPropertyBase*)node)._b; // expected-error {{use of undeclared identifier 'node'}}
+}