Skip to content

Commit e5d5073

Browse files
Merge branch 'main' of github.com:correctcomputation/checkedc-clang
2 parents 73d9265 + ad4c801 commit e5d5073

22 files changed

+288
-257
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ class _3CInterface {
104104
const std::vector<std::string> &SourceFileList,
105105
clang::tooling::CompilationDatabase *CompDB);
106106

107-
// Constraint Building.
107+
// Call clang to provide the data
108+
bool parseASTs();
109+
110+
// Constraints
108111

109112
// Create ConstraintVariables to hold constraints
110113
bool addVariables();
@@ -134,14 +137,15 @@ class _3CInterface {
134137
// Write all converted versions of the files in the source file list
135138
// to disk
136139
bool writeAllConvertedFilesToDisk();
137-
// Write the current converted state of the provided file.
138-
bool writeConvertedFileToDisk(const std::string &FilePath);
139140

140141
private:
141142
_3CInterface(const struct _3COptions &CCopt,
142143
const std::vector<std::string> &SourceFileList,
143144
clang::tooling::CompilationDatabase *CompDB, bool &Failed);
144145

146+
// saved ASTs
147+
std::vector< std::unique_ptr< ASTUnit >> ASTs;
148+
145149
// Are constraints already built?
146150
bool ConstraintsBuilt;
147151
void invalidateAllConstraintsWithReason(Constraint *ConstraintToRemove);

clang/include/clang/3C/ConstraintVariables.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ConstraintVariable {
8484
// the name of the variable, false for just the type.
8585
// The 'forIType' parameter is true when the generated string is expected
8686
// to be used inside an itype.
87-
virtual std::string mkString(const EnvironmentMap &E, bool EmitName = true,
87+
virtual std::string mkString(Constraints &CS, bool EmitName = true,
8888
bool ForItype = false, bool EmitPointee = false,
8989
bool UnmaskTypedef = false) const = 0;
9090

@@ -399,7 +399,7 @@ class PointerVariableConstraint : public ConstraintVariable {
399399

400400
std::string gatherQualStrings(void) const;
401401

402-
std::string mkString(const EnvironmentMap &E, bool EmitName = true,
402+
std::string mkString(Constraints &CS, bool EmitName = true,
403403
bool ForItype = false, bool EmitPointee = false,
404404
bool UnmaskTypedef = false) const override;
405405

@@ -470,9 +470,15 @@ class FVComponentVariable {
470470

471471
void mergeDeclaration(FVComponentVariable *From, ProgramInfo &I,
472472
std::string &ReasonFailed);
473-
std::string mkItypeStr(const EnvironmentMap &E) const;
474-
std::string mkTypeStr(const EnvironmentMap &E, bool EmitName) const;
475-
std::string mkString(const EnvironmentMap &E) const;
473+
std::string mkItypeStr(Constraints &CS) const;
474+
std::string mkTypeStr(Constraints &CS, bool EmitName) const;
475+
std::string mkString(Constraints &CS) const;
476+
477+
bool hasItypeSolution(Constraints &CS) const;
478+
bool hasCheckedSolution(Constraints &CS) const;
479+
480+
PVConstraint *getInternal() const { return InternalConstraint; }
481+
PVConstraint *getExternal() const { return ExternalConstraint; }
476482
};
477483

478484
// Constraints on a function type. Also contains a 'name' parameter for
@@ -524,6 +530,10 @@ class FunctionVariableConstraint : public ConstraintVariable {
524530
return ReturnVar.InternalConstraint;
525531
}
526532

533+
const FVComponentVariable *getCombineReturn() const {
534+
return &ReturnVar;
535+
}
536+
527537
size_t numParams() const { return ParamVars.size(); }
528538

529539
bool hasProtoType() const { return Hasproto; }
@@ -548,6 +558,11 @@ class FunctionVariableConstraint : public ConstraintVariable {
548558
return ParamVars.at(I).InternalConstraint;
549559
}
550560

561+
const FVComponentVariable *getCombineParam(unsigned I) const {
562+
assert(I < ParamVars.size());
563+
return &ParamVars.at(I);
564+
}
565+
551566
bool srcHasItype() const override;
552567
bool srcHasBounds() const override;
553568

@@ -558,7 +573,7 @@ class FunctionVariableConstraint : public ConstraintVariable {
558573
bool solutionEqualTo(Constraints &CS, const ConstraintVariable *CV,
559574
bool ComparePtyp = true) const override;
560575

561-
std::string mkString(const EnvironmentMap &E, bool EmitName = true,
576+
std::string mkString(Constraints &CS, bool EmitName = true,
562577
bool ForItype = false, bool EmitPointee = false,
563578
bool UnmaskTypedef = false) const override;
564579
void print(llvm::raw_ostream &O) const override;

clang/include/clang/3C/DeclRewriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class FunctionDeclBuilder : public RecursiveASTVisitor<FunctionDeclBuilder> {
112112
// Get existing itype string from constraint variables.
113113
std::string getExistingIType(ConstraintVariable *DeclC);
114114

115-
virtual void buildDeclVar(PVConstraint *IntCV, PVConstraint *ExtCV,
115+
virtual void buildDeclVar(const FVComponentVariable *CV,
116116
DeclaratorDecl *Decl, std::string &Type,
117117
std::string &IType, bool &RewriteParm,
118118
bool &RewriteRet);

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,12 @@ bool hasFunctionBody(clang::Decl *D);
104104

105105
std::string getStorageQualifierString(clang::Decl *D);
106106

107-
// Use this version for user input that has not yet been validated.
108107
std::error_code tryGetCanonicalFilePath(const std::string &FileName,
109108
std::string &AbsoluteFp);
110109

111-
// This version asserts success. It may be used for convenience for files we are
112-
// already accessing and thus believe should exist, modulo race conditions and
113-
// the like.
114-
void getCanonicalFilePath(const std::string &FileName, std::string &AbsoluteFp);
115-
116110
// This compares entire path components: it's smart enough to know that "foo.c"
117111
// does not start with "foo". It's not smart about anything else, so you should
118-
// probably put both paths through getCanonicalFilePath first.
112+
// probably put both paths through tryGetCanonicalFilePath first.
119113
bool filePathStartsWith(const std::string &Path, const std::string &Prefix);
120114

121115
bool isNULLExpression(clang::Expr *E, clang::ASTContext &C);
@@ -169,8 +163,8 @@ bool isCastSafe(clang::QualType DstType, clang::QualType SrcType);
169163
// Check if the provided file path belongs to the input project
170164
// and can be rewritten.
171165
//
172-
// For accurate results, the path must have gone through getCanonicalFilePath.
173-
// Note that the file name of a PersistentSourceLoc is always canonical.
166+
// For accurate results, the path must be canonical. The file name of a
167+
// PersistentSourceLoc can normally be assumed to be canonical.
174168
bool canWrite(const std::string &FilePath);
175169

176170
// Check if the provided variable has void as one of its type.

0 commit comments

Comments
 (0)