Skip to content

Commit bea4abd

Browse files
committed
fix
1 parent 0165704 commit bea4abd

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

clang/lib/Analysis/ExprMutationAnalyzer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "clang/ASTMatchers/ASTMatchers.h"
1414
#include "clang/ASTMatchers/ASTMatchersMacros.h"
1515
#include "llvm/ADT/STLExtras.h"
16-
#include "llvm/Support/Casting.h"
1716

1817
namespace clang {
1918
using namespace ast_matchers;
@@ -116,10 +115,14 @@ AST_MATCHER_P(Stmt, canResolveToExpr, const Stmt *, Inner) {
116115
return canExprResolveTo(Exp, Target);
117116
}
118117

118+
// use class member to store data can reduce stack usage to avoid stack overflow
119+
// when recursive call.
119120
class ExprPointeeResolve {
120121
const Expr *T;
121122

122123
bool resolveExpr(const Expr *E) {
124+
if (E == nullptr)
125+
return false;
123126
if (E == T)
124127
return true;
125128

clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,7 @@ TEST(ExprMutationAnalyzerTest, PointeeMutatedByPassAsArgumentInConstruct) {
17791779
TEST(ExprMutationAnalyzerTest,
17801780
PointeeMutatedByPassAsArgumentInTemplateConstruct) {
17811781
const std::string Code = "template<class T> void f() { int *x; new T(x); }";
1782-
auto AST = buildASTFromCodeWithArgs(Code, {});
1782+
auto AST = buildASTFromCodeWithArgs(Code, {"-fno-delayed-template-parsing"});
17831783
auto Results =
17841784
match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
17851785
EXPECT_TRUE(isPointeeMutated(Results, AST.get()));
@@ -1793,7 +1793,8 @@ TEST(ExprMutationAnalyzerTest, PointeeMutatedByPassAsArgumentInInitList) {
17931793
"struct initializer_list{ T const* begin; T const* end; };"
17941794
"}"
17951795
"void f() { int *x; std::initializer_list<int*> a{x, x, x}; }";
1796-
auto AST = buildASTFromCodeWithArgs(Code, {});
1796+
auto AST =
1797+
buildASTFromCodeWithArgs(Code, {"-fno-delayed-template-parsing"});
17971798
auto Results =
17981799
match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
17991800
EXPECT_TRUE(isPointeeMutated(Results, AST.get()));
@@ -1942,4 +1943,16 @@ TEST(ExprMutationAnalyzerTest, PointeeMutatedByPointerArithmeticSubElement) {
19421943
EXPECT_TRUE(isPointeeMutated(Results, AST.get()));
19431944
}
19441945

1946+
TEST(ExprMutationAnalyzerTest, PointeeMutatedByConditionOperator) {
1947+
const std::string Code = R"(
1948+
void f() {
1949+
int* x;
1950+
int* y = 1 ? nullptr : x;
1951+
})";
1952+
auto AST = buildASTFromCodeWithArgs(Code, {"-Wno-everything"});
1953+
auto Results =
1954+
match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());
1955+
EXPECT_TRUE(isPointeeMutated(Results, AST.get()));
1956+
}
1957+
19451958
} // namespace clang

0 commit comments

Comments
 (0)