[PATCH] D87102: [Sema] Fix a -Warc-repeated-use-of-weak false-positive by only calling CheckPlaceholderExpr once
Erik Pilkington via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 3 10:59:32 PDT 2020
erik.pilkington created this revision.
erik.pilkington added reviewers: rjmccall, ahatanak, fhahn.
Herald added subscribers: ributzka, dexonsmith, jkorous.
erik.pilkington requested review of this revision.
Previously, this code discarded the result of CheckPlaceholderExpr for non-matrix subexpressions. Not only is this wasteful, but it was creating a Warc-repeated-use-of-weak false-positive on the attached testcase, since the discarded expression was still registered as a use of the weak property. (This was introduced in D76791 <https://reviews.llvm.org/D76791>)
rdar://66162246
https://reviews.llvm.org/D87102
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaObjC/arc-repeated-weak.mm
Index: clang/test/SemaObjC/arc-repeated-weak.mm
===================================================================
--- clang/test/SemaObjC/arc-repeated-weak.mm
+++ clang/test/SemaObjC/arc-repeated-weak.mm
@@ -485,3 +485,17 @@
@class NSString;
static NSString* const kGlobal = @"";
+
+ at interface NSDictionary
+- (id)objectForKeyedSubscript:(id)key;
+ at end
+
+ at interface WeakProp
+ at property (weak) NSDictionary *nd;
+ at end
+
+ at implementation WeakProp
+-(void)m {
+ (void)self.nd[@""]; // no warning
+}
+ at end
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -4607,34 +4607,13 @@
return CreateBuiltinMatrixSubscriptExpr(
matSubscriptE->getBase(), matSubscriptE->getRowIdx(), idx, rbLoc);
}
- Expr *matrixBase = base;
- bool IsMSPropertySubscript = isMSPropertySubscriptExpr(*this, base);
- if (!IsMSPropertySubscript) {
- ExprResult result = CheckPlaceholderExpr(base);
- if (!result.isInvalid())
- matrixBase = result.get();
- }
- if (matrixBase->getType()->isMatrixType()) {
- if (CheckAndReportCommaError(idx))
- return ExprError();
-
- return CreateBuiltinMatrixSubscriptExpr(matrixBase, idx, nullptr, rbLoc);
- }
-
- // A comma-expression as the index is deprecated in C++2a onwards.
- if (getLangOpts().CPlusPlus20 &&
- ((isa<BinaryOperator>(idx) && cast<BinaryOperator>(idx)->isCommaOp()) ||
- (isa<CXXOperatorCallExpr>(idx) &&
- cast<CXXOperatorCallExpr>(idx)->getOperator() == OO_Comma))) {
- Diag(idx->getExprLoc(), diag::warn_deprecated_comma_subscript)
- << SourceRange(base->getBeginLoc(), rbLoc);
- }
// Handle any non-overload placeholder types in the base and index
// expressions. We can't handle overloads here because the other
// operand might be an overloadable type, in which case the overload
// resolution for the operator overload should get the first crack
// at the overload.
+ bool IsMSPropertySubscript = false;
if (base->getType()->isNonOverloadPlaceholderType()) {
IsMSPropertySubscript = isMSPropertySubscriptExpr(*this, base);
if (!IsMSPropertySubscript) {
@@ -4644,6 +4623,23 @@
base = result.get();
}
}
+
+ if (base->getType()->isMatrixType()) {
+ if (CheckAndReportCommaError(idx))
+ return ExprError();
+
+ return CreateBuiltinMatrixSubscriptExpr(base, idx, nullptr, rbLoc);
+ }
+
+ // A comma-expression as the index is deprecated in C++2a onwards.
+ if (getLangOpts().CPlusPlus20 &&
+ ((isa<BinaryOperator>(idx) && cast<BinaryOperator>(idx)->isCommaOp()) ||
+ (isa<CXXOperatorCallExpr>(idx) &&
+ cast<CXXOperatorCallExpr>(idx)->getOperator() == OO_Comma))) {
+ Diag(idx->getExprLoc(), diag::warn_deprecated_comma_subscript)
+ << SourceRange(base->getBeginLoc(), rbLoc);
+ }
+
if (idx->getType()->isNonOverloadPlaceholderType()) {
ExprResult result = CheckPlaceholderExpr(idx);
if (result.isInvalid()) return ExprError();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87102.289764.patch
Type: text/x-patch
Size: 3059 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200903/38b18828/attachment.bin>
More information about the cfe-commits
mailing list