Skip to content

Commit 65938dc

Browse files
Constrain pointers in non-canWrite files to not change. (WIP)
Intended to fix #387.
1 parent 128c8b8 commit 65938dc

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

clang/include/clang/3C/Utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ bool isCastSafe(clang::QualType DstType, clang::QualType SrcType);
149149
// and can be rewritten.
150150
bool canWrite(const std::string &FilePath);
151151

152+
// Check if the provided location can be rewritten: equivalent to
153+
// canWrite(PSL->getFileName()) && Rewriter::isRewritable(Location).
154+
bool canRewriteLocation(clang::SourceLocation Location, const PersistentSourceLoc &PSL);
155+
152156
// Check if the provided variable has void as one of its type.
153157
bool hasVoidType(clang::ValueDecl *D);
154158
// Check if the provided type has void as one of its type

clang/lib/3C/ProgramInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ void ProgramInfo::addVariable(clang::DeclaratorDecl *D,
532532
// declared inside the same macro expansion. The first instance of the
533533
// source location will have been constrained to WILD, so it's safe to bail
534534
// without doing anymore work.
535-
if (!Rewriter::isRewritable(D->getLocation())) {
535+
if (!canRewriteLocation(D->getLocation(), PLoc)) {
536536
// If we're not in a macro, we should make the constraint variable WILD
537537
// anyways. This happens if the name of the variable is a macro defined
538538
// differently is different parts of the program.
@@ -693,7 +693,7 @@ void ProgramInfo::storePersistentConstraints(Expr *E, const CVarSet &Vars,
693693
// have been computed and cached when the expression has not in fact been
694694
// visited before. To avoid this, the expression is not cached and instead is
695695
// recomputed each time it's needed.
696-
if (PSL.valid() && Rewriter::isRewritable(E->getBeginLoc())) {
696+
if (PSL.valid() && canRewriteLocation(E->getBeginLoc(), PSL)) {
697697
auto &ExprMap = isa<ImplicitCastExpr>(E) ? ImplicitCastConstraintVars
698698
: ExprConstraintVars;
699699
ExprMap[PSL].insert(Vars.begin(), Vars.end());
@@ -709,7 +709,7 @@ void ProgramInfo::constrainWildIfMacro(ConstraintVariable *CV,
709709
SourceLocation Location,
710710
PersistentSourceLoc *PSL) {
711711
std::string Rsn = "Pointer in Macro declaration.";
712-
if (!Rewriter::isRewritable(Location))
712+
if (!canRewriteLocation(Location, *PSL))
713713
CV->constrainToWild(CS, Rsn, PSL);
714714
}
715715

clang/lib/3C/Utils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ bool canWrite(const std::string &FilePath) {
343343
return FileAbsPath.rfind(BaseDir, 0) == 0;
344344
}
345345

346+
bool canRewriteLocation(SourceLocation Location, const PersistentSourceLoc &PSL) {
347+
return canWrite(PSL.getFileName()) && Rewriter::isRewritable(Location);
348+
}
349+
346350
bool isInSysHeader(clang::Decl *D) {
347351
if (D != nullptr) {
348352
auto &C = D->getASTContext();

0 commit comments

Comments
 (0)