[PATCH] D159479: [ASTImport]enhance statement comparing
Qizhi Hu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 7 03:40:47 PDT 2023
jcsxky created this revision.
jcsxky added projects: clang, clang-c.
Herald added a subscriber: martong.
Herald added a project: All.
jcsxky requested review of this revision.
Herald added a subscriber: cfe-commits.
Return statement comparing should consider return value.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159479
Files:
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/unittests/AST/StructuralEquivalenceTest.cpp
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===================================================================
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1798,6 +1798,25 @@
TU, cxxRecordDecl(hasName("B"), unless(isImplicit())))));
}
+TEST_F(StructuralEquivalenceCacheTest, ReturnStmtNonEq) {
+ auto TU = makeTuDecls(
+ R"(
+ bool x(){ return true; }
+ )",
+ R"(
+ bool x(){ return false; }
+ )",
+ Lang_CXX03);
+
+ StructuralEquivalenceContext Ctx(
+ get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
+ NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+
+ auto X = findDeclPair<FunctionDecl>(TU, functionDecl(hasName("x")));
+ EXPECT_FALSE(Ctx.IsEquivalent(X.first->getBody(), X.second->getBody()));
+
+}
+
TEST_F(StructuralEquivalenceCacheTest, SpecialNonEq) {
auto TU = makeTuDecls(
R"(
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===================================================================
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -366,6 +366,10 @@
return true;
}
+ bool IsStmtEquivalent(const CXXBoolLiteralExpr *E1, const CXXBoolLiteralExpr *E2) {
+ return E1->getValue() == E2->getValue();
+ }
+
/// End point of the traversal chain.
bool TraverseStmt(const Stmt *S1, const Stmt *S2) { return true; }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159479.556124.patch
Type: text/x-patch
Size: 1483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230907/0b0a8c8e/attachment.bin>
More information about the cfe-commits
mailing list