https://github.com/mzyKi updated https://github.com/llvm/llvm-project/pull/66041
>From a1635d87e4b56b501403f1add333c97b96b30a0f Mon Sep 17 00:00:00 2001 From: miaozhiyuan <miaozhiy...@feysh.com> Date: Tue, 12 Sep 2023 10:51:35 +0800 Subject: [PATCH] [clang][AST] fix lack comparison of declRefExpr in ASTStructuralEquivalence --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/AST/ASTStructuralEquivalence.cpp | 9 +++++++++ clang/unittests/AST/StructuralEquivalenceTest.cpp | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3cdad2f7b9f0e5a..d112a8701d387af 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -218,6 +218,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>`_) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 544420234ef0eb0..560d199620657a5 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -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(), diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp b/clang/unittests/AST/StructuralEquivalenceTest.cpp index 4e9f476659b9ee6..00041a2b2190089 100644 --- a/clang/unittests/AST/StructuralEquivalenceTest.cpp +++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp @@ -2320,5 +2320,14 @@ TEST_F(StructuralEquivalenceStmtTest, UnresolvedLookup) { EXPECT_TRUE(testStructuralMatch(t)); } +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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits