Skip to content

Commit d923a66

Browse files
Cleanup
1 parent c3241ee commit d923a66

File tree

4 files changed

+7
-55
lines changed

4 files changed

+7
-55
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class DeclRewriter {
6868
std::vector<Decl *> SameLineDecls,
6969
bool ContainsInlineStruct);
7070
void rewriteSingleDecl(DeclReplacement *N, RSet &ToRewrite);
71-
void doDeclRewrite(SourceRange SR, DeclReplacement *N);
71+
void doDeclRewrite(SourceRange &SR, DeclReplacement *N);
7272
void rewriteFunctionDecl(FunctionDeclReplacement *N);
7373
void rewriteTypedefDecl(TypedefDeclReplacement *TDT, RSet &ToRewrite);
7474
void emitSupplementaryDeclarations(const std::vector<std::string> &SDecls,

clang/lib/3C/AVarBoundsInfo.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,6 @@ void AvarBoundsInference::getRelevantBounds(BoundsKey BK,
359359
} else if (ABounds *PrevBounds = BI->getBounds(BK)) {
360360
ResBounds[PrevBounds->getKind()].insert(PrevBounds->getBKey());
361361
}
362-
363-
364-
//for (auto &E : ResBounds) {
365-
// auto Iter = E.second.begin();
366-
// while (Iter != E.second.end()) {
367-
// if (BI->hasPointerArithmetic(*Iter))
368-
// Iter = E.second.erase(Iter);
369-
// else
370-
// ++Iter;
371-
// }
372-
//}
373362
}
374363

375364
bool AvarBoundsInference::areDeclaredBounds(
@@ -1018,6 +1007,8 @@ bool AVarBoundsInfo::hasPointerArithmetic(BoundsKey BK) {
10181007
return ArrPointersWithArithmetic.find(BK) != ArrPointersWithArithmetic.end();
10191008
}
10201009

1010+
// A pointer needs range bounds if it is computed by pointer arithmetic and
1011+
// would otherwise need bounds.
10211012
bool AVarBoundsInfo::needsRangeBound(BoundsKey BK) {
10221013
return hasPointerArithmetic(BK) && getBounds(BK) != nullptr;
10231014
}

clang/lib/3C/DeclRewriter.cpp

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ void DeclRewriter::buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl,
3636
std::string &Type, std::string &IType,
3737
ProgramInfo &Info, ArrayBoundsRewriter &ABR,
3838
std::vector<std::string> &SDecls) {
39-
// TODO: Is this sufficient to get the bounds key? More complex logic is used
40-
// elsewhere.
4139
bool NeedsRangeBound =
4240
Defn->hasBoundsKey() &&
4341
Info.getABoundsInfo().needsRangeBound(Defn->getBoundsKey());
4442

4543
std::string DeclName = Decl ? Decl->getNameAsString() : "";
4644
if (NeedsRangeBound) {
4745
// 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.
4847
assert(!DeclName.empty());
4948
DeclName = "__3c_tmp_" + DeclName;
5049
}
@@ -98,7 +97,7 @@ void DeclRewriter::buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl,
9897
Type = qtyToStr(Decl->getType(), DeclName);
9998
else {
10099
// 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.
102101
assert(!NeedsRangeBound);
103102
Type = Defn->getOriginalTypeWithName();
104103
}
@@ -110,31 +109,8 @@ void DeclRewriter::buildItypeDecl(PVConstraint *Defn, DeclaratorDecl *Decl,
110109
UnmaskTypedef = IsUncheckedTypedef));
111110
IType += ")" + ABR.getBoundsString(Defn, Decl, true, false);
112111

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.
127113
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.
138114
SDecls.push_back(Defn->mkString(Info.getConstraints(),
139115
MKSTRING_OPTS(ForItypeBase = true)) +
140116
" = " + DeclName + ";");
@@ -150,9 +126,6 @@ void DeclRewriter::rewriteDecls(ASTContext &Context, ProgramInfo &Info,
150126
// as well as their rewriten types in a map.
151127
RSet RewriteThese;
152128

153-
//
154-
std::map<Decl *, std::string> DuplicatedDecls;
155-
156129
FunctionDeclBuilder *TRV = nullptr;
157130
#ifdef FIVE_C
158131
auto TRV5C = FunctionDeclBuilder5C(&Context, Info, RewriteThese, ABRewriter);
@@ -261,8 +234,6 @@ void DeclRewriter::rewriteDecls(ASTContext &Context, ProgramInfo &Info,
261234
NewTy += Type + IType;
262235
} else {
263236

264-
// TODO: Same question about getBoundsKey as above. Also, copy-pasted
265-
// code.
266237
bool NeedsRangeBounds =
267238
PV->hasBoundsKey() &&
268239
Info.getABoundsInfo().needsRangeBound(PV->getBoundsKey());
@@ -529,8 +500,7 @@ void DeclRewriter::rewriteMultiDecl(DeclReplacement *N, RSet &ToRewrite,
529500
// Common rewriting logic used to replace a single decl either on its own or as
530501
// part of a multi decl. The primary responsibility of this method (aside from
531502
// 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) {
534504
std::string Replacement = N->getReplacement();
535505
if (isa<TypedefDecl>(N->getDecl()))
536506
Replacement = "typedef " + Replacement;
@@ -561,12 +531,6 @@ void DeclRewriter::doDeclRewrite(SourceRange SR, DeclReplacement *N) {
561531
// Lexer::findNextToken can fail (why?). Rather than adding extra error
562532
// handling here, pass an invalid location to emitSupplementryDeclaration so
563533
// 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.
570534
Optional<Token> NextToken = Lexer::findNextToken(
571535
N->getSourceRange(A.getSourceManager()).getEnd(), A.getSourceManager(),
572536
A.getLangOpts());
@@ -921,8 +885,6 @@ void FunctionDeclBuilder::buildCheckedDecl(
921885
std::string &IType, std::string UseName, bool &RewriteParm,
922886
bool &RewriteRet, std::vector<std::string> &SDecls) {
923887

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.
926888
bool NeedsRangeBound =
927889
Defn->hasBoundsKey() &&
928890
Info.getABoundsInfo().needsRangeBound(Defn->getBoundsKey());

clang/lib/3C/RewriteUtils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,4 +716,3 @@ void RewriteConsumer::HandleTranslationUnit(ASTContext &Context) {
716716
Info.exitCompilationUnit();
717717
return;
718718
}
719-

0 commit comments

Comments
 (0)