@@ -36,15 +36,14 @@ void DeclRewriter::buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl,
36
36
std::string &Type, std::string &IType,
37
37
ProgramInfo &Info, ArrayBoundsRewriter &ABR,
38
38
std::vector<std::string> &SDecls) {
39
- // TODO: Is this sufficient to get the bounds key? More complex logic is used
40
- // elsewhere.
41
39
bool NeedsRangeBound =
42
40
Defn->hasBoundsKey () &&
43
41
Info.getABoundsInfo ().needsRangeBound (Defn->getBoundsKey ());
44
42
45
43
std::string DeclName = Decl ? Decl->getNameAsString () : " " ;
46
44
if (NeedsRangeBound) {
47
45
// TODO: Think about this assert. When is Decl null? When is the name empty?
46
+ // One case that comes to mind if unnamed parameter declaration.
48
47
assert (!DeclName.empty ());
49
48
DeclName = " __3c_tmp_" + DeclName;
50
49
}
@@ -98,7 +97,7 @@ void DeclRewriter::buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl,
98
97
Type = qtyToStr (Decl->getType (), DeclName);
99
98
else {
100
99
// FIXME: This assert will probably fail. Need to handle field and global
101
- // decls and maybe returns. Also param decls without names.
100
+ // decls, function returns and param decls without names.
102
101
assert (!NeedsRangeBound);
103
102
Type = Defn->getOriginalTypeWithName ();
104
103
}
@@ -110,31 +109,8 @@ void DeclRewriter::buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl,
110
109
UnmaskTypedef = IsUncheckedTypedef));
111
110
IType += " )" + ABR.getBoundsString (Defn, Decl, true , false );
112
111
113
- // FIXME: The parameter has an itype because it's used unsafely somewhere. Now
114
- // we copy it into a local variable with a fully checked type. The
115
- // unsafe use that made the parameter an itype will now be an error.
116
- // Solutions:
117
- // - Leave it how it is. There's a compiler error that needs to be
118
- // fixed, but this is already expected. This error is not an bounds
119
- // error however, so we still want to avoid it.
120
- // - Prohibit pointer arithmetic on itypes. Loses bounds on parameter.
121
- // - Make the copy unchecked. Looses bounds on the local. Note that the
122
- // itype parameter was already treated as unchecked inside the
123
- // function, so this should be a correct rewriting. Maybe add bounds
124
- // in a comment.
125
- // - Real solution: Use the internal type of the typedef (after fixing)
126
- // #704. [ leaning towards this ]
112
+ // We don't insert a bounds string because this is an unchecked pointer.
127
113
if (NeedsRangeBound)
128
- // FIXME: This isn't an itype base; although, it's an unchecked alias for a
129
- // itype which is conceptually kind of the same thing. ForItypeBase
130
- // needs a better name, but it can't just be `EmitUnchecked` because
131
- // it also controls function pointer parameter rewriting with extra
132
- // parens.
133
- // We don't insert a bounds string because this is an unchecked pointer.
134
- // TODO: If #704 is fixed, then we call mkString on the internal constraint
135
- // variable without ForItypeBase=true. Then, if the top level of the
136
- // internal constraint is checked (inner pointer levels don't matter),
137
- // we can add the bounds string.
138
114
SDecls.push_back (Defn->mkString (Info.getConstraints (),
139
115
MKSTRING_OPTS (ForItypeBase = true )) +
140
116
" = " + DeclName + " ;" );
@@ -150,9 +126,6 @@ void DeclRewriter::rewriteDecls(ASTContext &Context, ProgramInfo &Info,
150
126
// as well as their rewriten types in a map.
151
127
RSet RewriteThese;
152
128
153
- //
154
- std::map<Decl *, std::string> DuplicatedDecls;
155
-
156
129
FunctionDeclBuilder *TRV = nullptr ;
157
130
#ifdef FIVE_C
158
131
auto TRV5C = FunctionDeclBuilder5C (&Context, Info, RewriteThese, ABRewriter);
@@ -261,8 +234,6 @@ void DeclRewriter::rewriteDecls(ASTContext &Context, ProgramInfo &Info,
261
234
NewTy += Type + IType;
262
235
} else {
263
236
264
- // TODO: Same question about getBoundsKey as above. Also, copy-pasted
265
- // code.
266
237
bool NeedsRangeBounds =
267
238
PV->hasBoundsKey () &&
268
239
Info.getABoundsInfo ().needsRangeBound (PV->getBoundsKey ());
@@ -529,8 +500,7 @@ void DeclRewriter::rewriteMultiDecl(DeclReplacement *N, RSet &ToRewrite,
529
500
// Common rewriting logic used to replace a single decl either on its own or as
530
501
// part of a multi decl. The primary responsibility of this method (aside from
531
502
// invoking the rewriter) is to add any required initializer expression.
532
- void DeclRewriter::doDeclRewrite (SourceRange SR, DeclReplacement *N) {
533
- // Save original end of source range in case it changes
503
+ void DeclRewriter::doDeclRewrite (SourceRange &SR, DeclReplacement *N) {
534
504
std::string Replacement = N->getReplacement ();
535
505
if (isa<TypedefDecl>(N->getDecl ()))
536
506
Replacement = " typedef " + Replacement;
@@ -561,12 +531,6 @@ void DeclRewriter::doDeclRewrite(SourceRange SR, DeclReplacement *N) {
561
531
// Lexer::findNextToken can fail (why?). Rather than adding extra error
562
532
// handling here, pass an invalid location to emitSupplementryDeclaration so
563
533
// that it can emit an error.
564
- // TODO: Is worth emitting a separate error here? We would be able to log the
565
- // the location passed to the failed findNextToken call. If adding an
566
- // error here, consider that it should only be emitted if rewriting
567
- // would actually need to happen. For test macro_rewrite_error.c, the
568
- // findNextToken call fails, but the invalid source location is never
569
- // used by emitSupplementaryDeclarations, so there is no error.
570
534
Optional<Token> NextToken = Lexer::findNextToken (
571
535
N->getSourceRange (A.getSourceManager ()).getEnd (), A.getSourceManager (),
572
536
A.getLangOpts ());
@@ -921,8 +885,6 @@ void FunctionDeclBuilder::buildCheckedDecl(
921
885
std::string &IType, std::string UseName, bool &RewriteParm,
922
886
bool &RewriteRet, std::vector<std::string> &SDecls) {
923
887
924
- // TODO: What does it mean for a defn to not have a bounds key? Presumably it
925
- // can't have bounds, and therefore can't need range bounds.
926
888
bool NeedsRangeBound =
927
889
Defn->hasBoundsKey () &&
928
890
Info.getABoundsInfo ().needsRangeBound (Defn->getBoundsKey ());
0 commit comments