Skip to content

[clang][AST] fix lack comparison of declRefExpr in ASTStructuralEquivalence #66041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2023
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
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ Bug Fixes in This Version
(`#65156 <https://github.com/llvm/llvm-project/issues/65156>`_)
- Clang no longer considers the loss of ``__unaligned`` qualifier from objects as
an invalid conversion during method function overload resolution.
- Fix lack of comparison of declRefExpr in ASTStructuralEquivalence
(`#66047 <https://github.com/llvm/llvm-project/issues/66047>`_)
- Fix parser crash when dealing with ill-formed objective C++ header code. Fixes
(`#64836 <https://github.com/llvm/llvm-project/issues/64836>`_)
- Clang now allows an ``_Atomic`` qualified integer in a switch statement. Fixes
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/AST/ASTStructuralEquivalence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ class StmtComparer {
return E1->size() == E2->size();
}

bool IsStmtEquivalent(const DeclRefExpr *DRE1, const DeclRefExpr *DRE2) {
const ValueDecl *Decl1 = DRE1->getDecl();
const ValueDecl *Decl2 = DRE2->getDecl();
if (!Decl1 || !Decl2)
return false;
return IsStructurallyEquivalent(Context, const_cast<ValueDecl *>(Decl1),
const_cast<ValueDecl *>(Decl2));
}

bool IsStmtEquivalent(const DependentScopeDeclRefExpr *DE1,
const DependentScopeDeclRefExpr *DE2) {
if (!IsStructurallyEquivalent(Context, DE1->getDeclName(),
Expand Down
9 changes: 9 additions & 0 deletions clang/unittests/AST/StructuralEquivalenceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2393,5 +2393,14 @@ TEST_F(StructuralEquivalenceCacheTest, GotoStmtNoEq) {
EXPECT_FALSE(testStructuralMatch(S));
}

TEST_F(StructuralEquivalenceStmtTest, DeclRefExpr) {
std::string Prefix = "enum Test { AAA, BBB };";
auto t = makeStmts(
Prefix + "void foo(int i) {if (i > 0) {i = AAA;} else {i = BBB;}}",
Prefix + "void foo(int i) {if (i > 0) {i = BBB;} else {i = AAA;}}",
Lang_CXX03, ifStmt());
EXPECT_FALSE(testStructuralMatch(t));
}

} // end namespace ast_matchers
} // end namespace clang