Skip to content

[checked-c-convert] Minor fixes to the checked-c-convert #679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 185 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
185 commits
Select commit Hold shift + click to select a range
f399ffb
Update DeclStmt to Stmt inside DAndReplace
rchyena Feb 20, 2019
f613ef1
Refectoring Utils and ConstraintVariables
Machiry Jun 7, 2019
99bdeea
Minor edits
Machiry Jun 7, 2019
837b310
Finishing up refactoring
Machiry Jun 7, 2019
60ccc70
initial template
Machiry Jun 10, 2019
67dee76
Initial prototype
Machiry Jun 10, 2019
28242d3
Minor fixes
Machiry Jun 11, 2019
cbc2926
Minor refactoring and fixed unit tests
Machiry Jun 18, 2019
8088147
Fixing minor
Machiry Jun 12, 2019
0624728
Modified lattice
Machiry Jun 18, 2019
9b83b6c
Fixing the void * issue
Machiry Jun 12, 2019
73c979a
Clean up and refactoring
Machiry Jun 19, 2019
2059105
Adding NT Array contraint type
Machiry Jun 13, 2019
a1d19b8
Finalizing NT_array detection
Machiry Jun 16, 2019
59007a4
Minor refactoring
Machiry Jun 16, 2019
199169c
Adidng unit tests
Machiry Jun 17, 2019
6d320e4
Finalizing NT array implementation
Machiry Jun 19, 2019
7549b88
Minor fixes
Machiry Jun 17, 2019
53d89a5
Merge branch 'master' into debuggingNT
Machiry Jun 19, 2019
f0b4186
Merge pull request #2 from Machiry/debuggingNT
Machiry Jun 19, 2019
4a9ddb3
Refactoring
Machiry Jun 19, 2019
5fe6109
Minor fix
Machiry Jun 20, 2019
58625d3
WIP/getVariable
Machiry Jun 21, 2019
1a6a981
WIP/Fixed constraint generation of CallExpression
Machiry Jun 21, 2019
4b564c0
Fixing Adding equality constraints
Machiry Jun 21, 2019
ae77493
Fixing local assignement'
Machiry Jun 21, 2019
7303dc2
Refactored Rewriter
Machiry Jun 21, 2019
a216d16
Minor fixes
Machiry Jun 21, 2019
74ad2ce
Fix: Never store information based on AST objects
Machiry Jun 22, 2019
feed080
Adding return type handling for itypes
Machiry Jun 23, 2019
bf51aaf
Minor fixes
Machiry Jun 24, 2019
647daf9
Efficient constraint propagation: check before we propogatte based on…
Machiry Jun 24, 2019
f3eddb7
Avoid getting inscope variables for external functions:
Machiry Jun 24, 2019
cad93b9
Minor fir for handling function pointers
Machiry Jun 25, 2019
4f997df
Handling passing of functions as variables (for function pointers)
Machiry Jun 25, 2019
ad987a1
Fixing handling of compiler args
Machiry Jun 26, 2019
d0c9c02
Removing unnecessary debug output
Machiry Jun 26, 2019
04fc0ca
Minor
Machiry Jun 26, 2019
dbc77ba
Ensuring function declaration to be used for all CallExpressions and …
Machiry Jun 26, 2019
c897a98
Adding flag to control the merging of types from multiple declarations
Machiry Jun 23, 2019
b5329c1
Added functionality tests
Machiry Jun 24, 2019
cfec0d9
Added readme for functionality tests
Machiry Jun 24, 2019
6fd0082
Fixed the addition of storage qualifiers (i.e., static and extern)
Machiry Jun 25, 2019
683a5ec
Added to json methods
Machiry Jun 20, 2019
057d8c8
Adding dump to json functionality
Machiry Jun 20, 2019
cfa3405
Mark expected state after PRs are accepted.
rchyena Jul 14, 2019
ee375ab
Avoid Rewriting function return type, if it was handled by cast rewri…
Machiry Jun 27, 2019
bb1891c
Using absolute paths for files - this is needed to consistently displ…
Machiry Jun 27, 2019
4234c36
Handling NULL assignment, fixing rewriter, fixing duplicate constrain…
Machiry Jun 28, 2019
2d007eb
Adding base_dir argument to be passed to the tool
Machiry Jun 28, 2019
f7f739a
Fixing script to produce valid checked-c-convert commands
Machiry Jun 28, 2019
0746f25
Fixing minor regression
Machiry Jun 28, 2019
cfada81
Ensuring that we do not make an itype constraint variable to be WILD
Machiry Jun 28, 2019
48afac8
Small and cute constraint debugger
Machiry Jun 29, 2019
8b6a637
Flag to enable handling of varargs
Machiry Jun 29, 2019
72bbeb6
Fixing missing * in the return type during itype
Machiry Jun 30, 2019
dc3b085
Mark expected state after PRs are accepted.
rchyena Jul 14, 2019
9004cc1
Ignoring varargs and handling of itypes, Huge Improvement (Ptr: 27%, …
Machiry Jun 30, 2019
59bf5a9
Removing unused variables
Machiry Jun 30, 2019
fa90953
Adding correct type
Machiry Jul 9, 2019
e925d78
Adding correct NT array type
Machiry Jul 9, 2019
77994f5
Marks expected state after 'major_refactor' PRs are accepted.
rchyena Jul 14, 2019
b7ad028
Fixing space issue with tests
Machiry Jul 23, 2019
1c0a3b0
Fixing correct handling of function arguments
Machiry Jul 23, 2019
f298796
[FIXING TESTS] Fixing an invalid cast
Machiry Jul 24, 2019
683e9da
[FIXING TESTS] Handling of function pointers
Machiry Jul 24, 2019
aaa9993
[FIXING TESTS]: Added function subtyping
Machiry Jul 25, 2019
8eb818e
[FIXING TESTS] Finishing cleaning up
Machiry Jul 25, 2019
af5f5e5
initial template
Machiry Jun 10, 2019
1520428
Initial prototype
Machiry Jun 10, 2019
0736b10
Minor fixes
Machiry Jun 11, 2019
7c437a6
Fixing minor
Machiry Jun 12, 2019
2779086
Adding NT Array contraint type
Machiry Jun 13, 2019
77ae4e1
Finalizing NT_array detection
Machiry Jun 16, 2019
13b295d
Minor refactoring
Machiry Jun 16, 2019
e4be104
Adidng unit tests
Machiry Jun 17, 2019
bd4f8bf
Fixing the void * issue
Machiry Jun 12, 2019
3e00328
Minor fixes
Machiry Jun 17, 2019
4c2b7da
Minor refactoring and fixed unit tests
Machiry Jun 18, 2019
77dab59
Modified lattice
Machiry Jun 18, 2019
112e923
Clean up and refactoring
Machiry Jun 19, 2019
c4cff69
Finalizing NT array implementation
Machiry Jun 19, 2019
8a66b4b
Obsolete the other NT_array detector.
rchyena Jul 25, 2019
30f7159
Refactoring
Machiry Jun 19, 2019
94144ab
Added to json methods
Machiry Jun 20, 2019
490d377
Minor fix
Machiry Jun 20, 2019
1d037fb
Adding dump to json functionality
Machiry Jun 20, 2019
fc6740b
WIP/getVariable
Machiry Jun 21, 2019
bb86826
WIP/Fixed constraint generation of CallExpression
Machiry Jun 21, 2019
ab17351
Fixing Adding equality constraints
Machiry Jun 21, 2019
770cdd8
Fixing local assignement'
Machiry Jun 21, 2019
799a7d0
Refactored Rewriter
Machiry Jun 21, 2019
44bf8a4
Minor fixes
Machiry Jun 21, 2019
b6e7256
Fix: Never store information based on AST objects
Machiry Jun 22, 2019
9c2239e
Adding return type handling for itypes
Machiry Jun 23, 2019
37282f0
Adding flag to control the merging of types from multiple declarations
Machiry Jun 23, 2019
10d3e51
Minor fixes
Machiry Jun 24, 2019
79456c1
Efficient constraint propagation: check before we propogatte based on…
Machiry Jun 24, 2019
42ba45d
Avoid getting inscope variables for external functions:
Machiry Jun 24, 2019
533c39e
Added functionality tests
Machiry Jun 24, 2019
f182f83
Added readme for functionality tests
Machiry Jun 24, 2019
fe46a6d
Minor fir for handling function pointers
Machiry Jun 25, 2019
a868efb
Fixed the addition of storage qualifiers (i.e., static and extern)
Machiry Jun 25, 2019
f1479fe
Handling passing of functions as variables (for function pointers)
Machiry Jun 25, 2019
18636a2
Fixing handling of compiler args
Machiry Jun 26, 2019
6e6c3c4
Minor
Machiry Jun 26, 2019
d597b85
Removing unnecessary debug output
Machiry Jun 26, 2019
6c1b417
Merge branch 'major_refactor' of github.com:plum-umd/checkedc-clang i…
Machiry Jun 26, 2019
d2a7eb5
Ensuring function declaration to be used for all CallExpressions and …
Machiry Jun 26, 2019
a588f7c
Merge branch 'major_refactor' of github.com:plum-umd/checkedc-clang i…
Machiry Jun 26, 2019
ba8d103
Avoid Rewriting function return type, if it was handled by cast rewri…
Machiry Jun 27, 2019
d07a6e2
Using absolute paths for files - this is needed to consistently displ…
Machiry Jun 27, 2019
3661785
Handling NULL assignment, fixing rewriter, fixing duplicate constrain…
Machiry Jun 28, 2019
22e5d95
Adding base_dir argument to be passed to the tool
Machiry Jun 28, 2019
9d51b28
Fixing script to produce valid checked-c-convert commands
Machiry Jun 28, 2019
ed3b563
Fixing minor regression
Machiry Jun 28, 2019
171f383
Ensuring that we do not make an itype constraint variable to be WILD
Machiry Jun 28, 2019
d5b3402
Small and cute constraint debugger
Machiry Jun 29, 2019
86c61b1
Flag to enable handling of varargs
Machiry Jun 29, 2019
dc99e92
Ignoring varargs and handling of itypes, Huge Improvement (Ptr: 27%, …
Machiry Jun 30, 2019
32a1b39
Removing unused variables
Machiry Jun 30, 2019
fd7408a
Fixing missing * in the return type during itype
Machiry Jun 30, 2019
c30d661
Adding correct type
Machiry Jul 9, 2019
be80784
Adding correct NT array type
Machiry Jul 9, 2019
8809547
Minor refactoring
Machiry Jul 25, 2019
36a28cf
Fixing functionality tests
Machiry Jul 25, 2019
01eef26
Fixing space issue with tests
Machiry Jul 23, 2019
740e746
Fixing correct handling of function arguments
Machiry Jul 23, 2019
7fd6eaa
[FIXING TESTS] Fixing an invalid cast
Machiry Jul 24, 2019
b1b1748
[FIXING TESTS] Handling of function pointers
Machiry Jul 24, 2019
6346c41
[FIXING TESTS]: Added function subtyping
Machiry Jul 25, 2019
8d23d59
[FIXING TESTS] Finishing cleaning up
Machiry Jul 25, 2019
083f79c
Minor refactoring
Machiry Jul 25, 2019
89eacb1
Fixing functionality tests
Machiry Jul 25, 2019
f438b71
Merge PR #642 into dev to bring it up to date.
rchyena Jul 25, 2019
3b960d9
Fixing var args, Fixing issue: https://github.com/plum-umd/checkedc-c…
Machiry Jul 11, 2019
03002e5
Fixing issue: https://github.com/plum-umd/checkedc-clang/issues/3, Ad…
Machiry Jul 13, 2019
f0d2866
Minor fix
Machiry Jul 26, 2019
8d08f4b
Minor fix
Machiry Jul 26, 2019
5b6826e
Minor fix
Machiry Jul 26, 2019
76b2cda
Fix for inconsistent function signature issue
Machiry Jul 11, 2019
6bdcacd
Fix for the issue: https://github.com/plum-umd/checkedc-clang/issues/3
Machiry Jul 13, 2019
a8e9dc4
Fixing the allocator issue, https://github.com/plum-umd/checkedc-clan…
Machiry Jul 12, 2019
7a3e468
Creating Nt_array_ptr constraint for constant strings
Machiry Jul 11, 2019
34650b9
Fixing issue when the return value is WILD inside the function
Machiry Jul 12, 2019
4d1c277
Fixing strlen test
Machiry Jul 28, 2019
c86e647
Fixing strlen test
Machiry Jul 28, 2019
b6c1b74
More safe handling of WILD types in function subtying
Machiry Jul 29, 2019
5cefa6f
More safe handling of WILD types in function subtying
Machiry Jul 29, 2019
ae23678
More safe handling of WILD types in function subtying
Machiry Jul 29, 2019
d624a2c
Fixing nits and adding cache for absolute file paths
Machiry Aug 5, 2019
06be7d6
Adding simpler way to get itype pointer kind
Machiry Aug 5, 2019
53c3c7f
Adding more comments
Machiry Aug 5, 2019
b98ef4d
Efficient way to check NULL Ptr expression
Machiry Aug 5, 2019
0619d8c
Removing isNULLExpression function and replacing it with a general fu…
Machiry Aug 5, 2019
689ddbb
Adding comments
Machiry Aug 5, 2019
bc88178
Converting all tests to llvm-lit tests
Machiry Aug 6, 2019
88f24b0
Fixing coding style issues
Machiry Aug 6, 2019
47f4b5a
Adding comments
Machiry Aug 6, 2019
2be4860
Adding spaces
Machiry Aug 7, 2019
a801916
Fixing spaces
Machiry Aug 7, 2019
70f35f3
Adding space after if
Machiry Aug 10, 2019
6cf3819
Fixing space issue in itype
Machiry Aug 11, 2019
0b4a1ea
Removing unnecessary functions and replacing with clang functions
Machiry Aug 11, 2019
585d3f3
Fixing spelling issues and code clean up
Machiry Aug 11, 2019
b5808bd
Fixing comments length
Machiry Aug 11, 2019
c015941
Fixing typos in comments
Machiry Aug 11, 2019
c973489
Adding space for if
Machiry Aug 11, 2019
daff74f
Adding space
Machiry Aug 11, 2019
9ff5b3f
Fixing typos in comments
Machiry Aug 12, 2019
a910eda
Adding documentation for the pull request
Machiry Aug 12, 2019
c826a17
Fixing link.
Machiry Aug 12, 2019
23d3609
Minor fix in the documentation.
Machiry Aug 12, 2019
ad94795
Add an AST identifier to PersistentSourceLocation.
rchyena Aug 12, 2019
e15b437
Merge accepted PR branch 'PR/aravind-all' into dev.
rchyena Aug 15, 2019
eca4529
Bring 'dev' up-to-date with Microsoft's 'master'.
rchyena Aug 15, 2019
0641e8d
Merge branch 'dev' into dev-fixes.
rchyena Aug 21, 2019
71fc4c4
Merge remote branch 'microsoft/master' into dev.
rchyena Aug 21, 2019
14c3447
Merge branch 'dev' into dev-fixes
rchyena Aug 21, 2019
1ff694a
Limit AST ID to FunctionDecl objects.
rchyena Aug 28, 2019
f9d1d17
Merge branch 'microsoft/master' into dev.
rchyena Sep 3, 2019
eee525f
Revert changes to PersistentSourceLoc.
rchyena Sep 3, 2019
247f2d2
Merge branch 'dev' into dev-fixes
rchyena Sep 3, 2019
f18f476
Fixing minor coding style related issues
Machiry Sep 4, 2019
725147c
Resolving issues
Machiry Sep 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/CheckedCRewriter/bounds_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@


extern void bar(int *q : itype(_Ptr<int>));
//CHECK: extern void bar(int* q : itype(_Ptr<int>));
//CHECK: extern void bar(int *q : itype(_Ptr<int>));

extern void bar2(int *q : itype(_Ptr<int>), int *z : itype(_Ptr<int>));
//CHECK: extern void bar2(int* q : itype(_Ptr<int>), int* z : itype(_Ptr<int>));
//CHECK: extern void bar2(int *q : itype(_Ptr<int>), int *z : itype(_Ptr<int>));

extern int *baz(void) : itype(_Ptr<int>);
//CHECK: extern int *baz(void) : itype(_Ptr<int>);
Expand Down
18 changes: 18 additions & 0 deletions test/CheckedCRewriter/regression_tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Tests for Checked C rewriter tool.
//
// Tests checked-c-convert tool for any regressions.
//
// RUN: checked-c-convert %s -- | FileCheck -match-full-lines %s
//

#include <stdlib_checked.h>

int main() {

char *ptr1 = NULL;

ptr1 = (char *) calloc(1, sizeof(char));

return 0;
}
//CHECK: _Ptr<char> ptr1 = NULL;
5 changes: 5 additions & 0 deletions tools/checked-c-convert/CheckedCConvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ cl::opt<bool> enablePropThruIType( "enable-itypeprop",
cl::init(false),
cl::cat(ConvertCategory));

cl::opt<bool> considerAllocUnsafe( "alloc-unsafe",
cl::desc("Consider the allocators (i.e., malloc/calloc) as unsafe."),
cl::init(false),
cl::cat(ConvertCategory));

static cl::opt<std::string>
BaseDir("base-dir",
cl::desc("Base directory for the code we're translating"),
Expand Down
47 changes: 26 additions & 21 deletions tools/checked-c-convert/ConstraintBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,27 +268,32 @@ class FunctionVisitor : public RecursiveASTVisitor<FunctionVisitor> {
// to a NamedDecl?
FunctionDecl *calleeDecl =
dyn_cast<FunctionDecl>(CA->getCalleeDecl());
if (calleeDecl && calleeDecl->getName() == "malloc") {
// It's a call to malloc. What about the parameter to the call?
if (CA->getNumArgs() > 0) {
UnaryExprOrTypeTraitExpr *arg =
dyn_cast<UnaryExprOrTypeTraitExpr>(CA->getArg(0));
if (arg && arg->isArgumentType()) {
// Check that the argument is a sizeof.
if (arg->getKind() == UETT_SizeOf) {
QualType argTy = arg->getArgumentType();
// argTy should be made a pointer, then compared for
// equality to lhsType and rhsTy.
QualType argPTy = Context->getPointerType(argTy);

if (Info.checkStructuralEquality(V, RHSConstraints, argPTy, lhsType) &&
Info.checkStructuralEquality(V, RHSConstraints, argPTy, rhsTy)) {
rulesFired = true;
// At present, I don't think we need to add an
// implication based constraint since this rule only
// fires if there is a cast from a call to malloc.
// Since malloc is an external, there's no point in
// adding constraints to it.
if (calleeDecl) {
// this is an allocator, should we treat it as safe?
if (!considerAllocUnsafe && isFunctionAllocator(calleeDecl->getName()))
rulesFired = true;
else if (calleeDecl->getName().equals("malloc")) {
// It's a call to malloc. What about the parameter to the call?
if (CA->getNumArgs() > 0) {
UnaryExprOrTypeTraitExpr *arg =
dyn_cast<UnaryExprOrTypeTraitExpr>(CA->getArg(0));
if (arg && arg->isArgumentType()) {
// Check that the argument is a sizeof.
if (arg->getKind() == UETT_SizeOf) {
QualType argTy = arg->getArgumentType();
// argTy should be made a pointer, then compared for
// equality to lhsType and rhsTy.
QualType argPTy = Context->getPointerType(argTy);

if (Info.checkStructuralEquality(V, RHSConstraints, argPTy, lhsType) &&
Info.checkStructuralEquality(V, RHSConstraints, argPTy, rhsTy)) {
rulesFired = true;
// At present, I don't think we need to add an
// implication based constraint since this rule
// only fires if there is a cast from a call to malloc.
// Since malloc is an external, there's no point in
// adding constraints to it.
}
}
}
}
Expand Down
18 changes: 5 additions & 13 deletions tools/checked-c-convert/ConstraintVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,15 @@

using namespace clang;

// Helper method to print a Type in a way that can be represented in the source.
static
std::string
tyToStr(const Type *T) {
QualType QT(T, 0);

return QT.getAsString();
}

PointerVariableConstraint::PointerVariableConstraint(DeclaratorDecl *D,
ConstraintKey &K, Constraints &CS, const ASTContext &C) :
PointerVariableConstraint(D->getType(), K, D, D->getName(), CS, C) { }

PointerVariableConstraint::PointerVariableConstraint(const QualType &QT, ConstraintKey &K,
DeclaratorDecl *D, std::string N, Constraints &CS, const ASTContext &C) :
DeclaratorDecl *D, std::string N, Constraints &CS,
const ASTContext &C, bool partOfFunc) :
ConstraintVariable(ConstraintVariable::PointerVariable,
tyToStr(QT.getTypePtr()),N),FV(nullptr)
tyToStr(QT.getTypePtr()),N), partOFFuncPrototype(partOfFunc), FV(nullptr)
{
QualType QTy = QT;
const Type *Ty = QTy.getTypePtr();
Expand Down Expand Up @@ -490,7 +482,7 @@ FunctionVariableConstraint::FunctionVariableConstraint(const Type *Ty,
}

std::set<ConstraintVariable*> C;
C.insert(new PVConstraint(QT, K, tmpD, paramName, CS, Ctx));
C.insert(new PVConstraint(QT, K, tmpD, paramName, CS, Ctx, true));
paramVars.push_back(C);
}

Expand All @@ -513,7 +505,7 @@ FunctionVariableConstraint::FunctionVariableConstraint(const Type *Ty,
// as a type, then we will need the types for all the parameters and the
// return values

returnVars.insert(new PVConstraint(returnType, K, D, "", CS, Ctx));
returnVars.insert(new PVConstraint(returnType, K, D, "", CS, Ctx, true));
for ( const auto &V : returnVars) {
if (PVConstraint *PVC = dyn_cast<PVConstraint>(V)) {
if (PVC->getFV())
Expand Down
11 changes: 9 additions & 2 deletions tools/checked-c-convert/ConstraintVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,15 @@ class PointerVariableConstraint : public ConstraintVariable {
// get the qualifier string (e.g., const, etc) for the provided constraint var (targetCvar)
// into the provided string stream (ss)
void getQualString(ConstraintKey targetCVar, std::ostringstream &ss);
// flag to indicate that this constraint is a part of function prototype
// e.g., Parameters or Return
bool partOFFuncPrototype;
public:
// Constructor for when we know a CVars and a type string.
PointerVariableConstraint(CVars V, std::string T, std::string Name,
FunctionVariableConstraint *F, bool isArr, bool isItype, std::string is) :
ConstraintVariable(PointerVariable, T, Name)
,vars(V),FV(F),arrPresent(isArr), itypeStr(is) {}
,vars(V),FV(F),arrPresent(isArr), itypeStr(is), partOFFuncPrototype(false) {}

bool getArrPresent() { return arrPresent; }

Expand All @@ -179,7 +182,9 @@ class PointerVariableConstraint : public ConstraintVariable {
// Constructor for when we only have a Type. Needs a string name
// N for the name of the variable that this represents.
PointerVariableConstraint(const clang::QualType &QT, ConstraintKey &K,
clang::DeclaratorDecl *D, std::string N, Constraints &CS, const clang::ASTContext &C);
clang::DeclaratorDecl *D, std::string N,
Constraints &CS,
const clang::ASTContext &C, bool partOfFunc = false);

const CVars &getCvars() const { return vars; }

Expand All @@ -201,6 +206,8 @@ class PointerVariableConstraint : public ConstraintVariable {
// get the highest type assigned to the cvars of this constraint variable
ConstAtom *getHighestType(Constraints::EnvironmentMap &E);

bool isPartOfFunctionPrototype() const { return partOFFuncPrototype; }

bool isLt(const ConstraintVariable &other, ProgramInfo &P) const;
bool isEq(const ConstraintVariable &other, ProgramInfo &P) const;
bool isEmpty(void) const { return vars.size() == 0; }
Expand Down
12 changes: 8 additions & 4 deletions tools/checked-c-convert/PersistentSourceLoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@ PersistentSourceLoc::mkPSL(const Decl *D, ASTContext &C) {
SL = C.getSourceManager().getSpellingLoc(PV->getLocation());
else if (const VarDecl *V = dyn_cast<VarDecl>(D))
SL = C.getSourceManager().getExpansionLoc(V->getLocation());

return mkPSL(D->getSourceRange(), SL, C);
}


// Create a PersistentSourceLoc for a Stmt.
PersistentSourceLoc
PersistentSourceLoc::mkPSL(const Stmt *S, ASTContext &Context) {
return mkPSL(S->getSourceRange(), S->getBeginLoc(), Context);
return mkPSL(S->getSourceRange(),
S->getBeginLoc(),
Context);
}

// Use the PresumedLoc infrastructure to get the absolute file name, expansion
// line and column number for a SourceLocation and corresponding SourceRange
PersistentSourceLoc
PersistentSourceLoc::mkPSL(clang::SourceRange SR, SourceLocation SL, ASTContext &Context) {
PersistentSourceLoc
PersistentSourceLoc::mkPSL(clang::SourceRange SR,
SourceLocation SL,
ASTContext &Context) {
SourceManager &SM = Context.getSourceManager();
PresumedLoc PL = SM.getPresumedLoc(SL);

Expand Down
8 changes: 5 additions & 3 deletions tools/checked-c-convert/PersistentSourceLoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@ class PersistentSourceLoc {
void dump() const { print(llvm::errs()); }

static
PersistentSourceLoc mkPSL(const clang::Decl *D, clang::ASTContext &Context);
PersistentSourceLoc mkPSL(const clang::Decl *D, clang::ASTContext &Context);

static
PersistentSourceLoc mkPSL(const clang::Stmt *S, clang::ASTContext &Context);
PersistentSourceLoc mkPSL(const clang::Stmt *S, clang::ASTContext &Context);

private:
// Create a PersistentSourceLoc based on absolute file path
// from the given SourceRange and SourceLocation.
static
PersistentSourceLoc mkPSL(clang::SourceRange SR, clang::SourceLocation SL, clang::ASTContext &Context);
PersistentSourceLoc mkPSL(clang::SourceRange SR,
clang::SourceLocation SL,
clang::ASTContext &Context);
std::string fileName;
uint32_t lineNo;
uint32_t colNo;
Expand Down
20 changes: 16 additions & 4 deletions tools/checked-c-convert/ProgramInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ bool ProgramInfo::checkStructuralEquality(QualType D, QualType S) {
if (D == S)
return true;

if (D->isPointerType() == S->isPointerType())
return true;

return false;
return D->isPointerType() == S->isPointerType();
}

bool ProgramInfo::isExternOkay(std::string ext) {
Expand Down Expand Up @@ -729,6 +726,21 @@ ProgramInfo::getVariableHelper( Expr *E,
T = getVariableHelper(CO->getRHS(), V, C, ifc);
R.insert(T.begin(), T.end());
return R;
} else if (StringLiteral *exr = dyn_cast<StringLiteral>(E)) {
// if this is a string literal. i.e., "foo"
// we create a new constraint variable and constrain it to be an Nt_array
std::set<ConstraintVariable *> T;
CVars V;
V.insert(freeKey);
CS.getOrCreateVar(freeKey);
freeKey++;
ConstraintVariable *newC = new PointerVariableConstraint(V, "const char*", exr->getBytes(),
nullptr, false, false, "");
// constrain the newly created variable to be NTArray.
newC->constrainTo(CS, CS.getNTArr());
T.insert(newC);
return T;

} else {
return std::set<ConstraintVariable*>();
}
Expand Down
3 changes: 1 addition & 2 deletions tools/checked-c-convert/ProgramInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ class ProgramInfo {

std::set<Decl *> &getIdentifiedArrayVars() {
#ifdef ARRDEBUG
for(auto currD: IdentifiedArrayDecls) {
for (auto currD: IdentifiedArrayDecls)
currD->dump();
}
#endif
return IdentifiedArrayDecls;
}
Expand Down
Loading