Skip to content

Commit b0ea279

Browse files
jcsxkywangpc-pp
authored andcommitted
[ASTImport]CXXBoolLiteralExpr should be handled explicitly in statement comparation
In the comparation of return statement, return value(if it is CXXBoolLiteralExpr) should be handled explicitly, otherwise an incorrect result would be returned. Reviewed By: steakhal, donat.nagy Differential Revision: https://reviews.llvm.org/D159479
1 parent 11c3b97 commit b0ea279

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clang/lib/AST/ASTStructuralEquivalence.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ class StmtComparer {
366366
return true;
367367
}
368368

369+
bool IsStmtEquivalent(const CXXBoolLiteralExpr *E1, const CXXBoolLiteralExpr *E2) {
370+
return E1->getValue() == E2->getValue();
371+
}
372+
369373
/// End point of the traversal chain.
370374
bool TraverseStmt(const Stmt *S1, const Stmt *S2) { return true; }
371375

clang/unittests/AST/StructuralEquivalenceTest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,25 @@ TEST_F(StructuralEquivalenceCacheTest, SimpleNonEq) {
17981798
TU, cxxRecordDecl(hasName("B"), unless(isImplicit())))));
17991799
}
18001800

1801+
TEST_F(StructuralEquivalenceCacheTest, ReturnStmtNonEq) {
1802+
auto TU = makeTuDecls(
1803+
R"(
1804+
bool x(){ return true; }
1805+
)",
1806+
R"(
1807+
bool x(){ return false; }
1808+
)",
1809+
Lang_CXX03);
1810+
1811+
StructuralEquivalenceContext Ctx(
1812+
get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
1813+
NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
1814+
1815+
auto X = findDeclPair<FunctionDecl>(TU, functionDecl(hasName("x")));
1816+
EXPECT_FALSE(Ctx.IsEquivalent(X.first->getBody(), X.second->getBody()));
1817+
1818+
}
1819+
18011820
TEST_F(StructuralEquivalenceCacheTest, SpecialNonEq) {
18021821
auto TU = makeTuDecls(
18031822
R"(

0 commit comments

Comments
 (0)