Skip to content

Commit 3b6d63c

Browse files
authored
Revert "[clang][dataflow] Retrieve members from accessors called using member…" (#74299)
Reverts #73978
1 parent 8171eac commit 3b6d63c

File tree

2 files changed

+2
-56
lines changed

2 files changed

+2
-56
lines changed

clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,9 @@ static void insertIfFunction(const Decl &D,
300300
}
301301

302302
static MemberExpr *getMemberForAccessor(const CXXMemberCallExpr &C) {
303-
// Use getCalleeDecl instead of getMethodDecl in order to handle
304-
// pointer-to-member calls.
305-
const auto *MethodDecl = dyn_cast_or_null<CXXMethodDecl>(C.getCalleeDecl());
306-
if (!MethodDecl)
303+
if (!C.getMethodDecl())
307304
return nullptr;
308-
auto *Body = dyn_cast_or_null<CompoundStmt>(MethodDecl->getBody());
305+
auto *Body = dyn_cast_or_null<CompoundStmt>(C.getMethodDecl()->getBody());
309306
if (!Body || Body->size() != 1)
310307
return nullptr;
311308
if (auto *RS = dyn_cast<ReturnStmt>(*Body->body_begin()))

clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace {
2525
using namespace clang;
2626
using namespace dataflow;
2727
using ::clang::dataflow::test::getFieldValue;
28-
using ::testing::Contains;
2928
using ::testing::IsNull;
3029
using ::testing::NotNull;
3130

@@ -312,56 +311,6 @@ TEST_F(EnvironmentTest, InitGlobalVarsConstructor) {
312311
EXPECT_THAT(Env.getValue(*Var), NotNull());
313312
}
314313

315-
// Pointers to Members are a tricky case of accessor calls, complicated further
316-
// when using templates where the pointer to the member is a template argument.
317-
// This is a repro of a failure case seen in the wild.
318-
TEST_F(EnvironmentTest,
319-
ModelMemberForAccessorUsingMethodPointerThroughTemplate) {
320-
using namespace ast_matchers;
321-
322-
std::string Code = R"cc(
323-
struct S {
324-
int accessor() {return member;}
325-
326-
int member = 0;
327-
};
328-
329-
template <auto method>
330-
int Target(S* S) {
331-
return (S->*method)();
332-
}
333-
334-
// We want to analyze the instantiation of Target for the accessor.
335-
int Instantiator () {S S; return Target<&S::accessor>(&S); }
336-
)cc";
337-
338-
auto Unit =
339-
// C++17 for the simplifying use of auto in the template declaration.
340-
tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++17"});
341-
auto &Context = Unit->getASTContext();
342-
343-
ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U);
344-
345-
auto Results = match(
346-
decl(anyOf(functionDecl(hasName("Target"), isTemplateInstantiation())
347-
.bind("target"),
348-
fieldDecl(hasName("member")).bind("member"),
349-
recordDecl(hasName("S")).bind("struct"))),
350-
Context);
351-
const auto *Fun = selectFirst<FunctionDecl>("target", Results);
352-
const auto *Struct = selectFirst<RecordDecl>("struct", Results);
353-
const auto *Member = selectFirst<FieldDecl>("member", Results);
354-
ASSERT_THAT(Fun, NotNull());
355-
ASSERT_THAT(Struct, NotNull());
356-
ASSERT_THAT(Member, NotNull());
357-
358-
// Verify that `member` is modeled for `S` when we analyze
359-
// `Target<&S::accessor>`.
360-
Environment Env(DAContext, *Fun);
361-
EXPECT_THAT(DAContext.getModeledFields(QualType(Struct->getTypeForDecl(), 0)),
362-
Contains(Member));
363-
}
364-
365314
TEST_F(EnvironmentTest, RefreshRecordValue) {
366315
using namespace ast_matchers;
367316

0 commit comments

Comments
 (0)