[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 13:57:44 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f1be87e2947: [Sema] Fix a -Warc-repeated-use-of-weak false-positive by only calling… (authored by erik.pilkington).
Herald added a project: clang.
Changed prior to commit:
https://reviews.llvm.org/D87102?vs=289764&id=289806#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87102/new/
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
@@ -4595,8 +4595,8 @@
<< SourceRange(base->getBeginLoc(), rbLoc);
return ExprError();
}
- // If the base is either a MatrixSubscriptExpr or a matrix type, try to create
- // a new MatrixSubscriptExpr.
+ // If the base is a MatrixSubscriptExpr, try to create a new
+ // MatrixSubscriptExpr.
auto *matSubscriptE = dyn_cast<MatrixSubscriptExpr>(base);
if (matSubscriptE) {
if (CheckAndReportCommaError(idx))
@@ -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,24 @@
base = result.get();
}
}
+
+ // If the base is a matrix type, try to create a new MatrixSubscriptExpr.
+ 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.289806.patch
Type: text/x-patch
Size: 3573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200903/d1afebf0/attachment.bin>
More information about the cfe-commits
mailing list