Skip to content

Commit a37f835

Browse files
author
Andrew Ruef
committed
Now locals work too.
1 parent 2dbc6f0 commit a37f835

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

test/CheckedCRewriter/const_tests.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
// RUN: checked-c-convert %s -- | %clang_cc1 -verify -fcheckedc-extension -x c -
77
// expected-no-diagnostics
88

9-
// Have something so that we always get some output.
10-
void a0(void) {
11-
int q = 0;
12-
int *k = &q;
13-
*k = 0;
14-
}
15-
//CHECK: int q = 0;
16-
//CHECK-NEXT: _Ptr<int> k = &q;
17-
//CHECK-NEXT: *k = 0;
18-
//CHECK-NEXT: }
19-
209
void cst1(const int *a) {
2110
int b = *a;
2211
}
@@ -32,3 +21,13 @@ void cst3(const int *a, int i) {
3221
}
3322
//CHECK: void cst3(const int *a, int i) {
3423
//CHECK-NEXT: int c = *(a+i);
24+
25+
void cst4(const int *b) {
26+
int c = *b;
27+
const int *d = b;
28+
int e = *d;
29+
}
30+
//CHECK: void cst4(_Ptr<const int> b) {
31+
//CHECK-NEXT: int c = *b;
32+
//CHECK-NEXT: _Ptr<const int> d;
33+
//CHECK-NEXT: int e = *d;

tools/checked-c-convert/CheckedCConvert.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ void rewrite(Rewriter &R, std::set<DAndReplace> &toRewrite, SourceManager &S,
162162
errs() << "VarDecl at:\n";
163163
Where->dump();
164164
}
165-
SourceRange TR = VD->getTypeSourceInfo()->getTypeLoc().getSourceRange();
165+
SourceRange TR = VD->getSourceRange();
166+
std::string sRewrite = N.second + " " + VD->getNameAsString();
166167

167168
// Is it a variable type? This is the easy case, we can re-write it
168169
// locally, at the site of the declaration.
@@ -173,7 +174,7 @@ void rewrite(Rewriter &R, std::set<DAndReplace> &toRewrite, SourceManager &S,
173174
Files.insert(FSL.getFileID());
174175
if (Where->isSingleDecl()) {
175176
if (canRewrite(R, TR)) {
176-
R.ReplaceText(TR, N.second);
177+
R.ReplaceText(TR, sRewrite);
177178
} else {
178179
// This can happen if SR is within a macro. If that is the case,
179180
// maybe there is still something we can do because Decl refers

0 commit comments

Comments
 (0)