Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ Changes in existing checks
<clang-tidy/checks/misc/const-correctness>` check to avoid false
positives when pointers is transferred to non-const references
and avoid false positives of function pointer and fix false
positives on return of non-const pointer.
positives on return of non-const pointer and fix false positives on
pointer-to-member operator.

- Improved :doc:`misc-header-include-cycle
<clang-tidy/checks/misc/header-include-cycle>` check performance.
Expand Down
13 changes: 8 additions & 5 deletions clang/lib/Analysis/ExprMutationAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,11 +746,14 @@ ExprMutationAnalyzer::Analyzer::findPointeeMemberMutation(const Expr *Exp) {
Stm, Context));
if (MemberCallExpr)
return MemberCallExpr;
const auto Matches =
match(stmt(forEachDescendant(
memberExpr(hasObjectExpression(canResolveToExprPointee(Exp)))
.bind(NodeID<Expr>::value))),
Stm, Context);
const auto Matches = match(
stmt(forEachDescendant(
expr(anyOf(memberExpr(
hasObjectExpression(canResolveToExprPointee(Exp))),
binaryOperator(hasOperatorName("->*"),
hasLHS(canResolveToExprPointee(Exp)))))
.bind(NodeID<Expr>::value))),
Stm, Context);
return findExprMutation(Matches);
}

Expand Down
15 changes: 15 additions & 0 deletions clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2076,4 +2076,19 @@ TEST(ExprMutationAnalyzerTest, PointeeMutatedByReturn) {
}
}

TEST(ExprMutationAnalyzerTest, PointeeMutatedByPointerToMemberOperator) {
// GH161913
const std::string Code = R"(
struct S { int i; };
void f(S s) {
S *x = &s;
(x->*(&S::i))++;
}
)";
auto AST = buildASTFromCodeWithArgs(Code, {"-Wno-everything"});
auto Results =
match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
EXPECT_TRUE(isPointeeMutated(Results, AST.get()));
}

} // namespace clang
Loading