[PATCH] D19385: [scan-build] fix logic error warnings emitted on clang code base
Apelete Seketeli via cfe-commits
cfe-commits at lists.llvm.org
Thu May 5 03:40:03 PDT 2016
apelete updated this revision to Diff 56259.
apelete added a comment.
[scan-build] fix warnings emitted on Clang Format code base
Changes since last revision:
- split patch into Format unit to ease review process.
http://reviews.llvm.org/D19385
Files:
lib/Format/AffectedRangeManager.cpp
lib/Format/AffectedRangeManager.h
Index: lib/Format/AffectedRangeManager.h
===================================================================
--- lib/Format/AffectedRangeManager.h
+++ lib/Format/AffectedRangeManager.h
@@ -54,7 +54,7 @@
// Determines whether 'Line' is affected by the SourceRanges given as input.
// Returns \c true if line or one if its children is affected.
- bool nonPPLineAffected(AnnotatedLine *Line,
+ bool nonPPLineAffected(AnnotatedLine &Line,
const AnnotatedLine *PreviousLine);
const SourceManager &SourceMgr;
Index: lib/Format/AffectedRangeManager.cpp
===================================================================
--- lib/Format/AffectedRangeManager.cpp
+++ lib/Format/AffectedRangeManager.cpp
@@ -48,7 +48,7 @@
continue;
}
- if (nonPPLineAffected(Line, PreviousLine))
+ if (nonPPLineAffected(*Line, PreviousLine))
SomeLineAffected = true;
PreviousLine = Line;
@@ -99,24 +99,27 @@
}
bool AffectedRangeManager::nonPPLineAffected(
- AnnotatedLine *Line, const AnnotatedLine *PreviousLine) {
+ AnnotatedLine &Line, const AnnotatedLine *PreviousLine) {
bool SomeLineAffected = false;
- Line->ChildrenAffected =
- computeAffectedLines(Line->Children.begin(), Line->Children.end());
- if (Line->ChildrenAffected)
+ Line.ChildrenAffected =
+ computeAffectedLines(Line.Children.begin(), Line.Children.end());
+ if (Line.ChildrenAffected)
SomeLineAffected = true;
- // Stores whether one of the line's tokens is directly affected.
- bool SomeTokenAffected = false;
// Stores whether we need to look at the leading newlines of the next token
// in order to determine whether it was affected.
bool IncludeLeadingNewlines = false;
// Stores whether the first child line of any of this line's tokens is
// affected.
bool SomeFirstChildAffected = false;
- for (FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) {
+ // Stores whether one of the line's tokens is directly affected.
+ bool SomeTokenAffected = false;
+ if (Line.First == nullptr)
+ return SomeTokenAffected;
+
+ for (FormatToken *Tok = Line.First; Tok; Tok = Tok->Next) {
// Determine whether 'Tok' was affected.
if (affectsTokenRange(*Tok, *Tok, IncludeLeadingNewlines))
SomeTokenAffected = true;
@@ -131,16 +134,16 @@
// Was this line moved, i.e. has it previously been on the same line as an
// affected line?
bool LineMoved = PreviousLine && PreviousLine->Affected &&
- Line->First->NewlinesBefore == 0;
+ Line.First->NewlinesBefore == 0;
bool IsContinuedComment =
- Line->First->is(tok::comment) && Line->First->Next == nullptr &&
- Line->First->NewlinesBefore < 2 && PreviousLine &&
+ Line.First->is(tok::comment) && Line.First->Next == nullptr &&
+ Line.First->NewlinesBefore < 2 && PreviousLine &&
PreviousLine->Affected && PreviousLine->Last->is(tok::comment);
if (SomeTokenAffected || SomeFirstChildAffected || LineMoved ||
IsContinuedComment) {
- Line->Affected = true;
+ Line.Affected = true;
SomeLineAffected = true;
}
return SomeLineAffected;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19385.56259.patch
Type: text/x-patch
Size: 3174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160505/0c08a14f/attachment.bin>
More information about the cfe-commits
mailing list