clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name AffectedRangeManager.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/tools/clang/lib/Format -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -D CLANG_ROUND_TRIP_CC1_ARGS=ON -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/tools/clang/lib/Format -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Format -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/include -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/include -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/llvm/include -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/tools/clang/lib/Format -fdebug-prefix-map=/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0=. -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2021-08-28-193554-24367-1 -x c++ /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/clang/lib/Format/AffectedRangeManager.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #include "AffectedRangeManager.h" |
15 | |
16 | #include "FormatToken.h" |
17 | #include "TokenAnnotator.h" |
18 | |
19 | namespace clang { |
20 | namespace format { |
21 | |
22 | bool AffectedRangeManager::computeAffectedLines( |
23 | SmallVectorImpl<AnnotatedLine *> &Lines) { |
24 | SmallVectorImpl<AnnotatedLine *>::iterator I = Lines.begin(); |
25 | SmallVectorImpl<AnnotatedLine *>::iterator E = Lines.end(); |
26 | bool SomeLineAffected = false; |
27 | const AnnotatedLine *PreviousLine = nullptr; |
28 | while (I != E) { |
| 1 | Assuming 'I' is not equal to 'E' | |
|
| 2 | | Loop condition is true. Entering loop body | |
|
29 | AnnotatedLine *Line = *I; |
30 | Line->LeadingEmptyLinesAffected = affectsLeadingEmptyLines(*Line->First); |
31 | |
32 | |
33 | |
34 | if (Line->InPPDirective) { |
| 3 | | Assuming field 'InPPDirective' is false | |
|
| |
35 | FormatToken *Last = Line->Last; |
36 | SmallVectorImpl<AnnotatedLine *>::iterator PPEnd = I + 1; |
37 | while (PPEnd != E && !(*PPEnd)->First->HasUnescapedNewline) { |
38 | Last = (*PPEnd)->Last; |
39 | ++PPEnd; |
40 | } |
41 | |
42 | if (affectsTokenRange(*Line->First, *Last, |
43 | false)) { |
44 | SomeLineAffected = true; |
45 | markAllAsAffected(I, PPEnd); |
46 | } |
47 | I = PPEnd; |
48 | continue; |
49 | } |
50 | |
51 | if (nonPPLineAffected(Line, PreviousLine, Lines)) |
| 5 | | Calling 'AffectedRangeManager::nonPPLineAffected' | |
|
52 | SomeLineAffected = true; |
53 | |
54 | PreviousLine = Line; |
55 | ++I; |
56 | } |
57 | return SomeLineAffected; |
58 | } |
59 | |
60 | bool AffectedRangeManager::affectsCharSourceRange( |
61 | const CharSourceRange &Range) { |
62 | for (SmallVectorImpl<CharSourceRange>::const_iterator I = Ranges.begin(), |
63 | E = Ranges.end(); |
64 | I != E; ++I) { |
65 | if (!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(), I->getBegin()) && |
66 | !SourceMgr.isBeforeInTranslationUnit(I->getEnd(), Range.getBegin())) |
67 | return true; |
68 | } |
69 | return false; |
70 | } |
71 | |
72 | bool AffectedRangeManager::affectsTokenRange(const FormatToken &First, |
73 | const FormatToken &Last, |
74 | bool IncludeLeadingNewlines) { |
75 | SourceLocation Start = First.WhitespaceRange.getBegin(); |
76 | if (!IncludeLeadingNewlines) |
77 | Start = Start.getLocWithOffset(First.LastNewlineOffset); |
78 | SourceLocation End = Last.getStartOfNonWhitespace(); |
79 | End = End.getLocWithOffset(Last.TokenText.size()); |
80 | CharSourceRange Range = CharSourceRange::getCharRange(Start, End); |
81 | return affectsCharSourceRange(Range); |
82 | } |
83 | |
84 | bool AffectedRangeManager::affectsLeadingEmptyLines(const FormatToken &Tok) { |
85 | CharSourceRange EmptyLineRange = CharSourceRange::getCharRange( |
86 | Tok.WhitespaceRange.getBegin(), |
87 | Tok.WhitespaceRange.getBegin().getLocWithOffset(Tok.LastNewlineOffset)); |
88 | return affectsCharSourceRange(EmptyLineRange); |
89 | } |
90 | |
91 | void AffectedRangeManager::markAllAsAffected( |
92 | SmallVectorImpl<AnnotatedLine *>::iterator I, |
93 | SmallVectorImpl<AnnotatedLine *>::iterator E) { |
94 | while (I != E) { |
95 | (*I)->Affected = true; |
96 | markAllAsAffected((*I)->Children.begin(), (*I)->Children.end()); |
97 | ++I; |
98 | } |
99 | } |
100 | |
101 | bool AffectedRangeManager::nonPPLineAffected( |
102 | AnnotatedLine *Line, const AnnotatedLine *PreviousLine, |
103 | SmallVectorImpl<AnnotatedLine *> &Lines) { |
104 | bool SomeLineAffected = false; |
105 | Line->ChildrenAffected = computeAffectedLines(Line->Children); |
| 6 | | Value assigned to field 'First' | |
|
106 | if (Line->ChildrenAffected) |
| 7 | | Assuming field 'ChildrenAffected' is false | |
|
| |
107 | SomeLineAffected = true; |
108 | |
109 | |
110 | bool SomeTokenAffected = false; |
111 | |
112 | |
113 | bool IncludeLeadingNewlines = false; |
114 | |
115 | |
116 | |
117 | bool SomeFirstChildAffected = false; |
118 | |
119 | for (FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) { |
| 9 | | Assuming pointer value is null | |
|
120 | |
121 | if (affectsTokenRange(*Tok, *Tok, IncludeLeadingNewlines)) |
122 | SomeTokenAffected = true; |
123 | |
124 | |
125 | if (!Tok->Children.empty() && Tok->Children.front()->Affected) |
126 | SomeFirstChildAffected = true; |
127 | |
128 | IncludeLeadingNewlines = Tok->Children.empty(); |
129 | } |
130 | |
131 | |
132 | |
133 | bool LineMoved = PreviousLine && PreviousLine->Affected && |
134 | Line->First->NewlinesBefore == 0; |
135 | |
136 | bool IsContinuedComment = |
137 | Line->First->is(tok::comment) && Line->First->Next == nullptr && |
| 10 | | Called C++ object pointer is null |
|
138 | Line->First->NewlinesBefore < 2 && PreviousLine && |
139 | PreviousLine->Affected && PreviousLine->Last->is(tok::comment); |
140 | |
141 | bool IsAffectedClosingBrace = |
142 | Line->First->is(tok::r_brace) && |
143 | Line->MatchingOpeningBlockLineIndex != UnwrappedLine::kInvalidIndex && |
144 | Lines[Line->MatchingOpeningBlockLineIndex]->Affected; |
145 | |
146 | if (SomeTokenAffected || SomeFirstChildAffected || LineMoved || |
147 | IsContinuedComment || IsAffectedClosingBrace) { |
148 | Line->Affected = true; |
149 | SomeLineAffected = true; |
150 | } |
151 | return SomeLineAffected; |
152 | } |
153 | |
154 | } |
155 | } |