Skip to content

Commit c0d51dd

Browse files
committed
Fixing issue when the return value is WILD inside the function
1 parent 10304b5 commit c0d51dd

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

tools/checked-c-convert/ProgramInfo.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void ProgramInfo::print_stats(std::set<std::string> &F, raw_ostream &O, bool onl
167167
varC += foundVars.size();
168168
for (const auto &N : foundVars) {
169169
VarAtom *V = CS.getVar(N);
170-
assert(V != NULL);
170+
assert(V != nullptr);
171171
auto K = env.find(V);
172172
assert(K != env.end());
173173

@@ -240,10 +240,7 @@ bool ProgramInfo::checkStructuralEquality(QualType D, QualType S) {
240240
if (D == S)
241241
return true;
242242

243-
if (D->isPointerType() == S->isPointerType())
244-
return true;
245-
246-
return false;
243+
return D->isPointerType() == S->isPointerType();
247244
}
248245

249246
bool ProgramInfo::isExternOkay(std::string ext) {

tools/checked-c-convert/RewriteUtils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,11 @@ bool CastPlacementVisitor::VisitFunctionDecl(FunctionDecl *FD) {
512512
}
513513
}
514514

515+
// this means inside the function, the return value is WILD
516+
// so the return type is what was originally declared.
515517
if(!returnHandled) {
516518
// If we used to implement a bounds-safe interface, continue to do that.
517-
returnVar = Decl->mkString(Info.getConstraints().getVariables());
519+
returnVar = Decl->getOriginalTy() + " ";
518520

519521
endStuff = getExistingIType(Decl, Defn, Declaration);
520522
if(!endStuff.empty()) {

tools/checked-c-convert/functests/ntarr/basic_field_local.expected.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// we will use b as an NTArr
55
typedef struct {
66
int a;
7-
_Nt_array_ptrchar> b;
7+
_Nt_array_ptr<char> b;
88
} foo;
99
// here we use b in a safe way as an array, hence
1010
// it will be a array ptr
@@ -21,7 +21,7 @@ typedef struct {
2121

2222
int main() {
2323
foo obj;
24-
_Nt_array_ptrchar> bp;
24+
_Nt_array_ptr<char> bp;
2525
float b;
2626
foo2 obj2;
2727
int hel;

tools/checked-c-convert/functests/ntarr/basic_inter.expected.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// we test propagation with and without function
66
// declaration.
77
// here, ntiptr will be an itype(Nt_ptr)
8-
int funcdecl(char *ntiptr : itype(_Nt_array_ptrchar> ) , int *iptr : itype(_Ptr<int> ) , int *wild);
9-
int funcdecl(char *ntiptr : itype(_Nt_array_ptrchar> ) , int *iptr : itype(_Ptr<int> ) , int *wild) {
8+
int funcdecl(char *ntiptr : itype(_Nt_array_ptr<char> ) , int *iptr : itype(_Ptr<int> ) , int *wild);
9+
int funcdecl(char *ntiptr : itype(_Nt_array_ptr<char> ) , int *iptr : itype(_Ptr<int> ) , int *wild) {
1010
if(ntiptr != 0) {
1111
ntiptr = strstr("Hello", "world");
1212
}

tools/checked-c-convert/functests/ntarr/basic_inter_field.expected.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
// within the fields of structure.
44
typedef struct {
55
_Ptr<int> ptr;
6-
_Nt_array_ptrchar> ntptr;
6+
_Nt_array_ptr<char> ntptr;
77
} foo;
88

99
foo obj1;
1010

11-
_Ptr<int> func(_Ptr<int> ptr, _Nt_array_ptrchar> ntptr) {
11+
_Ptr<int> func(_Ptr<int> ptr, _Nt_array_ptr<char> ntptr) {
1212
obj1.ptr = ptr;
1313
obj1.ntptr = strstr(ntptr, "world");
1414
return ptr;
@@ -17,7 +17,7 @@ _Ptr<int> func(_Ptr<int> ptr, _Nt_array_ptrchar> ntptr) {
1717
int main() {
1818
int a;
1919
_Ptr<int> b;
20-
_Nt_array_ptrchar> wil;
20+
_Nt_array_ptr<char> wil;
2121
a = strlen(wil);
2222
b = func(&a, wil);
2323
}

tools/checked-c-convert/functests/ntarr/basic_local.expected.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ int main() {
66
// as NTArr
77
// we use this as an argument
88
// to string function.
9-
_Nt_array_ptrchar> a;
9+
_Nt_array_ptr<char> a;
1010
// c should be identified as
1111
// ARR as we assign it the return value of
1212
// string function use it.
13-
_Nt_array_ptrchar> c;
13+
_Nt_array_ptr<char> c;
1414
// we will make this wild.
1515
int *d;
1616
int b;

0 commit comments

Comments
 (0)