clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Diagnostic.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 -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangBasic/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libclangBasic/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/libclangBasic/../../../llvm/clang/lib/Basic -I /usr/src/gnu/usr.bin/clang/libclangBasic/../../../llvm/clang/lib/Basic/Targets -I /usr/src/gnu/usr.bin/clang/libclangBasic/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libclangBasic/../include -I /usr/src/gnu/usr.bin/clang/libclangBasic/obj -I /usr/src/gnu/usr.bin/clang/libclangBasic/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangBasic/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libclangBasic/../../../llvm/clang/lib/Basic/Diagnostic.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #include "clang/Basic/Diagnostic.h" |
14 | #include "clang/Basic/CharInfo.h" |
15 | #include "clang/Basic/DiagnosticError.h" |
16 | #include "clang/Basic/DiagnosticIDs.h" |
17 | #include "clang/Basic/DiagnosticOptions.h" |
18 | #include "clang/Basic/IdentifierTable.h" |
19 | #include "clang/Basic/PartialDiagnostic.h" |
20 | #include "clang/Basic/SourceLocation.h" |
21 | #include "clang/Basic/SourceManager.h" |
22 | #include "clang/Basic/Specifiers.h" |
23 | #include "clang/Basic/TokenKinds.h" |
24 | #include "llvm/ADT/SmallString.h" |
25 | #include "llvm/ADT/SmallVector.h" |
26 | #include "llvm/ADT/StringExtras.h" |
27 | #include "llvm/ADT/StringRef.h" |
28 | #include "llvm/Support/CrashRecoveryContext.h" |
29 | #include "llvm/Support/Locale.h" |
30 | #include "llvm/Support/raw_ostream.h" |
31 | #include <algorithm> |
32 | #include <cassert> |
33 | #include <cstddef> |
34 | #include <cstdint> |
35 | #include <cstring> |
36 | #include <limits> |
37 | #include <string> |
38 | #include <utility> |
39 | #include <vector> |
40 | |
41 | using namespace clang; |
42 | |
43 | const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB, |
44 | DiagNullabilityKind nullability) { |
45 | StringRef string; |
46 | switch (nullability.first) { |
47 | case NullabilityKind::NonNull: |
48 | string = nullability.second ? "'nonnull'" : "'_Nonnull'"; |
49 | break; |
50 | |
51 | case NullabilityKind::Nullable: |
52 | string = nullability.second ? "'nullable'" : "'_Nullable'"; |
53 | break; |
54 | |
55 | case NullabilityKind::Unspecified: |
56 | string = nullability.second ? "'null_unspecified'" : "'_Null_unspecified'"; |
57 | break; |
58 | |
59 | case NullabilityKind::NullableResult: |
60 | assert(!nullability.second && |
61 | "_Nullable_result isn't supported as context-sensitive keyword"); |
62 | string = "_Nullable_result"; |
63 | break; |
64 | } |
65 | |
66 | DB.AddString(string); |
67 | return DB; |
68 | } |
69 | |
70 | const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB, |
71 | llvm::Error &&E) { |
72 | DB.AddString(toString(std::move(E))); |
73 | return DB; |
74 | } |
75 | |
76 | static void DummyArgToStringFn(DiagnosticsEngine::ArgumentKind AK, intptr_t QT, |
77 | StringRef Modifier, StringRef Argument, |
78 | ArrayRef<DiagnosticsEngine::ArgumentValue> PrevArgs, |
79 | SmallVectorImpl<char> &Output, |
80 | void *Cookie, |
81 | ArrayRef<intptr_t> QualTypeVals) { |
82 | StringRef Str = "<can't format argument>"; |
83 | Output.append(Str.begin(), Str.end()); |
84 | } |
85 | |
86 | DiagnosticsEngine::DiagnosticsEngine( |
87 | IntrusiveRefCntPtr<DiagnosticIDs> diags, |
88 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, DiagnosticConsumer *client, |
89 | bool ShouldOwnClient) |
90 | : Diags(std::move(diags)), DiagOpts(std::move(DiagOpts)) { |
91 | setClient(client, ShouldOwnClient); |
92 | ArgToStringFn = DummyArgToStringFn; |
93 | |
94 | Reset(); |
95 | } |
96 | |
97 | DiagnosticsEngine::~DiagnosticsEngine() { |
98 | |
99 | |
100 | setClient(nullptr); |
101 | } |
102 | |
103 | void DiagnosticsEngine::dump() const { |
104 | DiagStatesByLoc.dump(*SourceMgr); |
105 | } |
106 | |
107 | void DiagnosticsEngine::dump(StringRef DiagName) const { |
108 | DiagStatesByLoc.dump(*SourceMgr, DiagName); |
109 | } |
110 | |
111 | void DiagnosticsEngine::setClient(DiagnosticConsumer *client, |
112 | bool ShouldOwnClient) { |
113 | Owner.reset(ShouldOwnClient ? client : nullptr); |
114 | Client = client; |
115 | } |
116 | |
117 | void DiagnosticsEngine::pushMappings(SourceLocation Loc) { |
118 | DiagStateOnPushStack.push_back(GetCurDiagState()); |
119 | } |
120 | |
121 | bool DiagnosticsEngine::popMappings(SourceLocation Loc) { |
122 | if (DiagStateOnPushStack.empty()) |
123 | return false; |
124 | |
125 | if (DiagStateOnPushStack.back() != GetCurDiagState()) { |
126 | |
127 | PushDiagStatePoint(DiagStateOnPushStack.back(), Loc); |
128 | } |
129 | DiagStateOnPushStack.pop_back(); |
130 | return true; |
131 | } |
132 | |
133 | void DiagnosticsEngine::Reset() { |
134 | ErrorOccurred = false; |
135 | UncompilableErrorOccurred = false; |
136 | FatalErrorOccurred = false; |
137 | UnrecoverableErrorOccurred = false; |
138 | |
139 | NumWarnings = 0; |
140 | NumErrors = 0; |
141 | TrapNumErrorsOccurred = 0; |
142 | TrapNumUnrecoverableErrorsOccurred = 0; |
143 | |
144 | CurDiagID = std::numeric_limits<unsigned>::max(); |
145 | LastDiagLevel = DiagnosticIDs::Ignored; |
146 | DelayedDiagID = 0; |
147 | |
148 | |
149 | DiagStates.clear(); |
150 | DiagStatesByLoc.clear(); |
151 | DiagStateOnPushStack.clear(); |
152 | |
153 | |
154 | |
155 | DiagStates.emplace_back(); |
156 | DiagStatesByLoc.appendFirst(&DiagStates.back()); |
157 | } |
158 | |
159 | void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1, |
160 | StringRef Arg2, StringRef Arg3) { |
161 | if (DelayedDiagID) |
162 | return; |
163 | |
164 | DelayedDiagID = DiagID; |
165 | DelayedDiagArg1 = Arg1.str(); |
166 | DelayedDiagArg2 = Arg2.str(); |
167 | DelayedDiagArg3 = Arg3.str(); |
168 | } |
169 | |
170 | void DiagnosticsEngine::ReportDelayed() { |
171 | unsigned ID = DelayedDiagID; |
172 | DelayedDiagID = 0; |
173 | Report(ID) << DelayedDiagArg1 << DelayedDiagArg2 << DelayedDiagArg3; |
174 | } |
175 | |
176 | void DiagnosticsEngine::DiagStateMap::appendFirst(DiagState *State) { |
177 | assert(Files.empty() && "not first"); |
178 | FirstDiagState = CurDiagState = State; |
179 | CurDiagStateLoc = SourceLocation(); |
180 | } |
181 | |
182 | void DiagnosticsEngine::DiagStateMap::append(SourceManager &SrcMgr, |
183 | SourceLocation Loc, |
184 | DiagState *State) { |
185 | CurDiagState = State; |
186 | CurDiagStateLoc = Loc; |
187 | |
188 | std::pair<FileID, unsigned> Decomp = SrcMgr.getDecomposedLoc(Loc); |
189 | unsigned Offset = Decomp.second; |
190 | for (File *F = getFile(SrcMgr, Decomp.first); F; |
191 | Offset = F->ParentOffset, F = F->Parent) { |
192 | F->HasLocalTransitions = true; |
193 | auto &Last = F->StateTransitions.back(); |
194 | assert(Last.Offset <= Offset && "state transitions added out of order"); |
195 | |
196 | if (Last.Offset == Offset) { |
197 | if (Last.State == State) |
198 | break; |
199 | Last.State = State; |
200 | continue; |
201 | } |
202 | |
203 | F->StateTransitions.push_back({State, Offset}); |
204 | } |
205 | } |
206 | |
207 | DiagnosticsEngine::DiagState * |
208 | DiagnosticsEngine::DiagStateMap::lookup(SourceManager &SrcMgr, |
209 | SourceLocation Loc) const { |
210 | |
211 | if (Files.empty()) |
212 | return FirstDiagState; |
213 | |
214 | std::pair<FileID, unsigned> Decomp = SrcMgr.getDecomposedLoc(Loc); |
215 | const File *F = getFile(SrcMgr, Decomp.first); |
216 | return F->lookup(Decomp.second); |
217 | } |
218 | |
219 | DiagnosticsEngine::DiagState * |
220 | DiagnosticsEngine::DiagStateMap::File::lookup(unsigned Offset) const { |
221 | auto OnePastIt = |
222 | llvm::partition_point(StateTransitions, [=](const DiagStatePoint &P) { |
223 | return P.Offset <= Offset; |
224 | }); |
225 | assert(OnePastIt != StateTransitions.begin() && "missing initial state"); |
226 | return OnePastIt[-1].State; |
227 | } |
228 | |
229 | DiagnosticsEngine::DiagStateMap::File * |
230 | DiagnosticsEngine::DiagStateMap::getFile(SourceManager &SrcMgr, |
231 | FileID ID) const { |
232 | |
233 | auto Range = Files.equal_range(ID); |
234 | if (Range.first != Range.second) |
235 | return &Range.first->second; |
236 | auto &F = Files.insert(Range.first, std::make_pair(ID, File()))->second; |
237 | |
238 | |
239 | |
240 | if (ID.isValid()) { |
241 | std::pair<FileID, unsigned> Decomp = SrcMgr.getDecomposedIncludedLoc(ID); |
242 | F.Parent = getFile(SrcMgr, Decomp.first); |
243 | F.ParentOffset = Decomp.second; |
244 | F.StateTransitions.push_back({F.Parent->lookup(Decomp.second), 0}); |
245 | } else { |
246 | |
247 | |
248 | |
249 | |
250 | |
251 | |
252 | |
253 | F.StateTransitions.push_back({FirstDiagState, 0}); |
254 | } |
255 | return &F; |
256 | } |
257 | |
258 | void DiagnosticsEngine::DiagStateMap::dump(SourceManager &SrcMgr, |
259 | StringRef DiagName) const { |
260 | llvm::errs() << "diagnostic state at "; |
261 | CurDiagStateLoc.print(llvm::errs(), SrcMgr); |
262 | llvm::errs() << ": " << CurDiagState << "\n"; |
263 | |
264 | for (auto &F : Files) { |
265 | FileID ID = F.first; |
266 | File &File = F.second; |
267 | |
268 | bool PrintedOuterHeading = false; |
269 | auto PrintOuterHeading = [&] { |
270 | if (PrintedOuterHeading) return; |
271 | PrintedOuterHeading = true; |
272 | |
273 | llvm::errs() << "File " << &File << " <FileID " << ID.getHashValue() |
274 | << ">: " << SrcMgr.getBufferOrFake(ID).getBufferIdentifier(); |
275 | |
276 | if (F.second.Parent) { |
277 | std::pair<FileID, unsigned> Decomp = |
278 | SrcMgr.getDecomposedIncludedLoc(ID); |
279 | assert(File.ParentOffset == Decomp.second); |
280 | llvm::errs() << " parent " << File.Parent << " <FileID " |
281 | << Decomp.first.getHashValue() << "> "; |
282 | SrcMgr.getLocForStartOfFile(Decomp.first) |
283 | .getLocWithOffset(Decomp.second) |
284 | .print(llvm::errs(), SrcMgr); |
285 | } |
286 | if (File.HasLocalTransitions) |
287 | llvm::errs() << " has_local_transitions"; |
288 | llvm::errs() << "\n"; |
289 | }; |
290 | |
291 | if (DiagName.empty()) |
292 | PrintOuterHeading(); |
293 | |
294 | for (DiagStatePoint &Transition : File.StateTransitions) { |
295 | bool PrintedInnerHeading = false; |
296 | auto PrintInnerHeading = [&] { |
297 | if (PrintedInnerHeading) return; |
298 | PrintedInnerHeading = true; |
299 | |
300 | PrintOuterHeading(); |
301 | llvm::errs() << " "; |
302 | SrcMgr.getLocForStartOfFile(ID) |
303 | .getLocWithOffset(Transition.Offset) |
304 | .print(llvm::errs(), SrcMgr); |
305 | llvm::errs() << ": state " << Transition.State << ":\n"; |
306 | }; |
307 | |
308 | if (DiagName.empty()) |
309 | PrintInnerHeading(); |
310 | |
311 | for (auto &Mapping : *Transition.State) { |
312 | StringRef Option = |
313 | DiagnosticIDs::getWarningOptionForDiag(Mapping.first); |
314 | if (!DiagName.empty() && DiagName != Option) |
315 | continue; |
316 | |
317 | PrintInnerHeading(); |
318 | llvm::errs() << " "; |
319 | if (Option.empty()) |
320 | llvm::errs() << "<unknown " << Mapping.first << ">"; |
321 | else |
322 | llvm::errs() << Option; |
323 | llvm::errs() << ": "; |
324 | |
325 | switch (Mapping.second.getSeverity()) { |
326 | case diag::Severity::Ignored: llvm::errs() << "ignored"; break; |
327 | case diag::Severity::Remark: llvm::errs() << "remark"; break; |
328 | case diag::Severity::Warning: llvm::errs() << "warning"; break; |
329 | case diag::Severity::Error: llvm::errs() << "error"; break; |
330 | case diag::Severity::Fatal: llvm::errs() << "fatal"; break; |
331 | } |
332 | |
333 | if (!Mapping.second.isUser()) |
334 | llvm::errs() << " default"; |
335 | if (Mapping.second.isPragma()) |
336 | llvm::errs() << " pragma"; |
337 | if (Mapping.second.hasNoWarningAsError()) |
338 | llvm::errs() << " no-error"; |
339 | if (Mapping.second.hasNoErrorAsFatal()) |
340 | llvm::errs() << " no-fatal"; |
341 | if (Mapping.second.wasUpgradedFromWarning()) |
342 | llvm::errs() << " overruled"; |
343 | llvm::errs() << "\n"; |
344 | } |
345 | } |
346 | } |
347 | } |
348 | |
349 | void DiagnosticsEngine::PushDiagStatePoint(DiagState *State, |
350 | SourceLocation Loc) { |
351 | assert(Loc.isValid() && "Adding invalid loc point"); |
352 | DiagStatesByLoc.append(*SourceMgr, Loc, State); |
353 | } |
354 | |
355 | void DiagnosticsEngine::setSeverity(diag::kind Diag, diag::Severity Map, |
356 | SourceLocation L) { |
357 | assert(Diag < diag::DIAG_UPPER_LIMIT && |
358 | "Can only map builtin diagnostics"); |
359 | assert((Diags->isBuiltinWarningOrExtension(Diag) || |
360 | (Map == diag::Severity::Fatal || Map == diag::Severity::Error)) && |
361 | "Cannot map errors into warnings!"); |
362 | assert((L.isInvalid() || SourceMgr) && "No SourceMgr for valid location"); |
363 | |
364 | |
365 | bool WasUpgradedFromWarning = false; |
366 | if (Map == diag::Severity::Warning) { |
367 | DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); |
368 | if (Info.getSeverity() == diag::Severity::Error || |
369 | Info.getSeverity() == diag::Severity::Fatal) { |
370 | Map = Info.getSeverity(); |
371 | WasUpgradedFromWarning = true; |
372 | } |
373 | } |
374 | DiagnosticMapping Mapping = makeUserMapping(Map, L); |
375 | Mapping.setUpgradedFromWarning(WasUpgradedFromWarning); |
376 | |
377 | |
378 | if ((L.isInvalid() || L == DiagStatesByLoc.getCurDiagStateLoc()) && |
379 | DiagStatesByLoc.getCurDiagState()) { |
380 | |
381 | |
382 | |
383 | |
384 | DiagStatesByLoc.getCurDiagState()->setMapping(Diag, Mapping); |
385 | return; |
386 | } |
387 | |
388 | |
389 | |
390 | |
391 | DiagStates.push_back(*GetCurDiagState()); |
392 | DiagStates.back().setMapping(Diag, Mapping); |
393 | PushDiagStatePoint(&DiagStates.back(), L); |
394 | } |
395 | |
396 | bool DiagnosticsEngine::setSeverityForGroup(diag::Flavor Flavor, |
397 | StringRef Group, diag::Severity Map, |
398 | SourceLocation Loc) { |
399 | |
400 | SmallVector<diag::kind, 256> GroupDiags; |
401 | if (Diags->getDiagnosticsInGroup(Flavor, Group, GroupDiags)) |
402 | return true; |
403 | |
404 | |
405 | for (diag::kind Diag : GroupDiags) |
406 | setSeverity(Diag, Map, Loc); |
407 | |
408 | return false; |
409 | } |
410 | |
411 | bool DiagnosticsEngine::setDiagnosticGroupWarningAsError(StringRef Group, |
412 | bool Enabled) { |
413 | |
414 | |
415 | if (Enabled) |
416 | return setSeverityForGroup(diag::Flavor::WarningOrError, Group, |
417 | diag::Severity::Error); |
418 | |
419 | |
420 | |
421 | |
422 | |
423 | SmallVector<diag::kind, 8> GroupDiags; |
424 | if (Diags->getDiagnosticsInGroup(diag::Flavor::WarningOrError, Group, |
425 | GroupDiags)) |
426 | return true; |
427 | |
428 | |
429 | for (diag::kind Diag : GroupDiags) { |
430 | DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); |
431 | |
432 | if (Info.getSeverity() == diag::Severity::Error || |
433 | Info.getSeverity() == diag::Severity::Fatal) |
434 | Info.setSeverity(diag::Severity::Warning); |
435 | |
436 | Info.setNoWarningAsError(true); |
437 | } |
438 | |
439 | return false; |
440 | } |
441 | |
442 | bool DiagnosticsEngine::setDiagnosticGroupErrorAsFatal(StringRef Group, |
443 | bool Enabled) { |
444 | |
445 | |
446 | if (Enabled) |
447 | return setSeverityForGroup(diag::Flavor::WarningOrError, Group, |
448 | diag::Severity::Fatal); |
449 | |
450 | |
451 | |
452 | |
453 | |
454 | SmallVector<diag::kind, 8> GroupDiags; |
455 | if (Diags->getDiagnosticsInGroup(diag::Flavor::WarningOrError, Group, |
456 | GroupDiags)) |
457 | return true; |
458 | |
459 | |
460 | for (diag::kind Diag : GroupDiags) { |
461 | DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); |
462 | |
463 | if (Info.getSeverity() == diag::Severity::Fatal) |
464 | Info.setSeverity(diag::Severity::Error); |
465 | |
466 | Info.setNoErrorAsFatal(true); |
467 | } |
468 | |
469 | return false; |
470 | } |
471 | |
472 | void DiagnosticsEngine::setSeverityForAll(diag::Flavor Flavor, |
473 | diag::Severity Map, |
474 | SourceLocation Loc) { |
475 | |
476 | std::vector<diag::kind> AllDiags; |
477 | DiagnosticIDs::getAllDiagnostics(Flavor, AllDiags); |
478 | |
479 | |
480 | for (diag::kind Diag : AllDiags) |
481 | if (Diags->isBuiltinWarningOrExtension(Diag)) |
482 | setSeverity(Diag, Map, Loc); |
483 | } |
484 | |
485 | void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) { |
486 | assert(CurDiagID == std::numeric_limits<unsigned>::max() && |
487 | "Multiple diagnostics in flight at once!"); |
488 | |
489 | CurDiagLoc = storedDiag.getLocation(); |
490 | CurDiagID = storedDiag.getID(); |
491 | DiagStorage.NumDiagArgs = 0; |
492 | |
493 | DiagStorage.DiagRanges.clear(); |
494 | DiagStorage.DiagRanges.append(storedDiag.range_begin(), |
495 | storedDiag.range_end()); |
496 | |
497 | DiagStorage.FixItHints.clear(); |
498 | DiagStorage.FixItHints.append(storedDiag.fixit_begin(), |
499 | storedDiag.fixit_end()); |
500 | |
501 | assert(Client && "DiagnosticConsumer not set!"); |
502 | Level DiagLevel = storedDiag.getLevel(); |
503 | Diagnostic Info(this, storedDiag.getMessage()); |
504 | Client->HandleDiagnostic(DiagLevel, Info); |
505 | if (Client->IncludeInDiagnosticCounts()) { |
506 | if (DiagLevel == DiagnosticsEngine::Warning) |
507 | ++NumWarnings; |
508 | } |
509 | |
510 | CurDiagID = std::numeric_limits<unsigned>::max(); |
511 | } |
512 | |
513 | bool DiagnosticsEngine::EmitCurrentDiagnostic(bool Force) { |
514 | assert(getClient() && "DiagnosticClient not set!"); |
515 | |
516 | bool Emitted; |
517 | if (Force) { |
518 | Diagnostic Info(this); |
519 | |
520 | |
521 | DiagnosticIDs::Level DiagLevel |
522 | = Diags->getDiagnosticLevel(Info.getID(), Info.getLocation(), *this); |
523 | |
524 | Emitted = (DiagLevel != DiagnosticIDs::Ignored); |
525 | if (Emitted) { |
526 | |
527 | Diags->EmitDiag(*this, DiagLevel); |
528 | } |
529 | } else { |
530 | |
531 | |
532 | Emitted = ProcessDiag(); |
533 | } |
534 | |
535 | |
536 | Clear(); |
537 | |
538 | |
539 | if (!Force && DelayedDiagID) |
540 | ReportDelayed(); |
541 | |
542 | return Emitted; |
543 | } |
544 | |
545 | DiagnosticConsumer::~DiagnosticConsumer() = default; |
546 | |
547 | void DiagnosticConsumer::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
548 | const Diagnostic &Info) { |
549 | if (!IncludeInDiagnosticCounts()) |
550 | return; |
551 | |
552 | if (DiagLevel == DiagnosticsEngine::Warning) |
553 | ++NumWarnings; |
554 | else if (DiagLevel >= DiagnosticsEngine::Error) |
555 | ++NumErrors; |
556 | } |
557 | |
558 | |
559 | template <std::size_t StrLen> |
560 | static bool ModifierIs(const char *Modifier, unsigned ModifierLen, |
561 | const char (&Str)[StrLen]) { |
562 | return StrLen-1 == ModifierLen && memcmp(Modifier, Str, StrLen-1) == 0; |
563 | } |
564 | |
565 | |
566 | |
567 | static const char *ScanFormat(const char *I, const char *E, char Target) { |
568 | unsigned Depth = 0; |
569 | |
570 | for ( ; I != E; ++I) { |
571 | if (Depth == 0 && *I == Target) return I; |
572 | if (Depth != 0 && *I == '}') Depth--; |
573 | |
574 | if (*I == '%') { |
575 | I++; |
576 | if (I == E) break; |
577 | |
578 | |
579 | |
580 | |
581 | if (!isDigit(*I) && !isPunctuation(*I)) { |
582 | for (I++; I != E && !isDigit(*I) && *I != '{'; I++) ; |
583 | if (I == E) break; |
584 | if (*I == '{') |
585 | Depth++; |
586 | } |
587 | } |
588 | } |
589 | return E; |
590 | } |
591 | |
592 | |
593 | |
594 | |
595 | |
596 | |
597 | static void HandleSelectModifier(const Diagnostic &DInfo, unsigned ValNo, |
598 | const char *Argument, unsigned ArgumentLen, |
599 | SmallVectorImpl<char> &OutStr) { |
600 | const char *ArgumentEnd = Argument+ArgumentLen; |
601 | |
602 | |
603 | while (ValNo) { |
604 | const char *NextVal = ScanFormat(Argument, ArgumentEnd, '|'); |
605 | assert(NextVal != ArgumentEnd && "Value for integer select modifier was" |
606 | " larger than the number of options in the diagnostic string!"); |
607 | Argument = NextVal+1; |
608 | --ValNo; |
609 | } |
610 | |
611 | |
612 | const char *EndPtr = ScanFormat(Argument, ArgumentEnd, '|'); |
613 | |
614 | |
615 | DInfo.FormatDiagnostic(Argument, EndPtr, OutStr); |
616 | } |
617 | |
618 | |
619 | |
620 | |
621 | static void HandleIntegerSModifier(unsigned ValNo, |
622 | SmallVectorImpl<char> &OutStr) { |
623 | if (ValNo != 1) |
624 | OutStr.push_back('s'); |
625 | } |
626 | |
627 | |
628 | |
629 | |
630 | |
631 | static void HandleOrdinalModifier(unsigned ValNo, |
632 | SmallVectorImpl<char> &OutStr) { |
633 | assert(ValNo != 0 && "ValNo must be strictly positive!"); |
634 | |
635 | llvm::raw_svector_ostream Out(OutStr); |
636 | |
637 | |
638 | |
639 | Out << ValNo << llvm::getOrdinalSuffix(ValNo); |
640 | } |
641 | |
642 | |
643 | static unsigned PluralNumber(const char *&Start, const char *End) { |
644 | |
645 | unsigned Val = 0; |
| |
646 | while (Start != End && *Start >= '0' && *Start <= '9') { |
647 | Val *= 10; |
648 | Val += *Start - '0'; |
649 | ++Start; |
650 | } |
651 | return Val; |
| 13 | | Returning zero (loaded from 'Val') | |
|
652 | } |
653 | |
654 | |
655 | static bool TestPluralRange(unsigned Val, const char *&Start, const char *End) { |
656 | if (*Start != '[') { |
657 | unsigned Ref = PluralNumber(Start, End); |
658 | return Ref == Val; |
659 | } |
660 | |
661 | ++Start; |
662 | unsigned Low = PluralNumber(Start, End); |
663 | assert(*Start == ',' && "Bad plural expression syntax: expected ,"); |
664 | ++Start; |
665 | unsigned High = PluralNumber(Start, End); |
666 | assert(*Start == ']' && "Bad plural expression syntax: expected )"); |
667 | ++Start; |
668 | return Low <= Val && Val <= High; |
669 | } |
670 | |
671 | |
672 | static bool EvalPluralExpr(unsigned ValNo, const char *Start, const char *End) { |
673 | |
674 | if (*Start == ':') |
| |
675 | return true; |
676 | |
677 | while (true) { |
| 8 | | Loop condition is true. Entering loop body | |
|
678 | char C = *Start; |
679 | if (C == '%') { |
| 9 | | Assuming the condition is true | |
|
| |
680 | |
681 | ++Start; |
682 | unsigned Arg = PluralNumber(Start, End); |
| |
| 14 | | Returning from 'PluralNumber' | |
|
| |
683 | assert(*Start == '=' && "Bad plural expression syntax: expected ="); |
684 | ++Start; |
685 | unsigned ValMod = ValNo % Arg; |
| |
686 | if (TestPluralRange(ValMod, Start, End)) |
687 | return true; |
688 | } else { |
689 | assert((C == '[' || (C >= '0' && C <= '9')) && |
690 | "Bad plural expression syntax: unexpected character"); |
691 | |
692 | if (TestPluralRange(ValNo, Start, End)) |
693 | return true; |
694 | } |
695 | |
696 | |
697 | Start = std::find(Start, End, ','); |
698 | if (Start == End) |
699 | break; |
700 | ++Start; |
701 | } |
702 | return false; |
703 | } |
704 | |
705 | |
706 | |
707 | |
708 | |
709 | |
710 | |
711 | |
712 | |
713 | |
714 | |
715 | |
716 | |
717 | |
718 | |
719 | |
720 | |
721 | |
722 | |
723 | |
724 | |
725 | |
726 | |
727 | |
728 | |
729 | |
730 | |
731 | |
732 | |
733 | |
734 | |
735 | |
736 | |
737 | |
738 | static void HandlePluralModifier(const Diagnostic &DInfo, unsigned ValNo, |
739 | const char *Argument, unsigned ArgumentLen, |
740 | SmallVectorImpl<char> &OutStr) { |
741 | const char *ArgumentEnd = Argument + ArgumentLen; |
742 | while (true) { |
| 1 | Loop condition is true. Entering loop body | |
|
743 | assert(Argument < ArgumentEnd && "Plural expression didn't match."); |
744 | const char *ExprEnd = Argument; |
745 | while (*ExprEnd != ':') { |
| 2 | | Assuming the condition is true | |
|
| 3 | | Loop condition is true. Entering loop body | |
|
| 4 | | Assuming the condition is false | |
|
| 5 | | Loop condition is false. Execution continues on line 749 | |
|
746 | assert(ExprEnd != ArgumentEnd && "Plural missing expression end"); |
747 | ++ExprEnd; |
748 | } |
749 | if (EvalPluralExpr(ValNo, Argument, ExprEnd)) { |
| 6 | | Calling 'EvalPluralExpr' | |
|
750 | Argument = ExprEnd + 1; |
751 | ExprEnd = ScanFormat(Argument, ArgumentEnd, '|'); |
752 | |
753 | |
754 | |
755 | DInfo.FormatDiagnostic(Argument, ExprEnd, OutStr); |
756 | return; |
757 | } |
758 | Argument = ScanFormat(Argument, ArgumentEnd - 1, '|') + 1; |
759 | } |
760 | } |
761 | |
762 | |
763 | |
764 | |
765 | static const char *getTokenDescForDiagnostic(tok::TokenKind Kind) { |
766 | switch (Kind) { |
767 | case tok::identifier: |
768 | return "identifier"; |
769 | default: |
770 | return nullptr; |
771 | } |
772 | } |
773 | |
774 | |
775 | |
776 | |
777 | void Diagnostic:: |
778 | FormatDiagnostic(SmallVectorImpl<char> &OutStr) const { |
779 | if (!StoredDiagMessage.empty()) { |
780 | OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end()); |
781 | return; |
782 | } |
783 | |
784 | StringRef Diag = |
785 | getDiags()->getDiagnosticIDs()->getDescription(getID()); |
786 | |
787 | FormatDiagnostic(Diag.begin(), Diag.end(), OutStr); |
788 | } |
789 | |
790 | void Diagnostic:: |
791 | FormatDiagnostic(const char *DiagStr, const char *DiagEnd, |
792 | SmallVectorImpl<char> &OutStr) const { |
793 | |
794 | |
795 | |
796 | if (DiagEnd - DiagStr == 2 && |
797 | StringRef(DiagStr, DiagEnd - DiagStr).equals("%0") && |
798 | getArgKind(0) == DiagnosticsEngine::ak_std_string) { |
799 | const std::string &S = getArgStdStr(0); |
800 | for (char c : S) { |
801 | if (llvm::sys::locale::isPrint(c) || c == '\t') { |
802 | OutStr.push_back(c); |
803 | } |
804 | } |
805 | return; |
806 | } |
807 | |
808 | |
809 | |
810 | |
811 | |
812 | SmallVector<DiagnosticsEngine::ArgumentValue, 8> FormattedArgs; |
813 | |
814 | |
815 | |
816 | SmallVector<intptr_t, 2> QualTypeVals; |
817 | SmallString<64> Tree; |
818 | |
819 | for (unsigned i = 0, e = getNumArgs(); i < e; ++i) |
820 | if (getArgKind(i) == DiagnosticsEngine::ak_qualtype) |
821 | QualTypeVals.push_back(getRawArg(i)); |
822 | |
823 | while (DiagStr != DiagEnd) { |
824 | if (DiagStr[0] != '%') { |
825 | |
826 | const char *StrEnd = std::find(DiagStr, DiagEnd, '%'); |
827 | OutStr.append(DiagStr, StrEnd); |
828 | DiagStr = StrEnd; |
829 | continue; |
830 | } else if (isPunctuation(DiagStr[1])) { |
831 | OutStr.push_back(DiagStr[1]); |
832 | DiagStr += 2; |
833 | continue; |
834 | } |
835 | |
836 | |
837 | ++DiagStr; |
838 | |
839 | |
840 | |
841 | |
842 | |
843 | |
844 | const char *Modifier = nullptr, *Argument = nullptr; |
845 | unsigned ModifierLen = 0, ArgumentLen = 0; |
846 | |
847 | |
848 | if (!isDigit(DiagStr[0])) { |
849 | Modifier = DiagStr; |
850 | while (DiagStr[0] == '-' || |
851 | (DiagStr[0] >= 'a' && DiagStr[0] <= 'z')) |
852 | ++DiagStr; |
853 | ModifierLen = DiagStr-Modifier; |
854 | |
855 | |
856 | if (DiagStr[0] == '{') { |
857 | ++DiagStr; |
858 | Argument = DiagStr; |
859 | |
860 | DiagStr = ScanFormat(DiagStr, DiagEnd, '}'); |
861 | assert(DiagStr != DiagEnd && "Mismatched {}'s in diagnostic string!"); |
862 | ArgumentLen = DiagStr-Argument; |
863 | ++DiagStr; |
864 | } |
865 | } |
866 | |
867 | assert(isDigit(*DiagStr) && "Invalid format for argument in diagnostic"); |
868 | unsigned ArgNo = *DiagStr++ - '0'; |
869 | |
870 | |
871 | unsigned ArgNo2 = ArgNo; |
872 | |
873 | DiagnosticsEngine::ArgumentKind Kind = getArgKind(ArgNo); |
874 | if (ModifierIs(Modifier, ModifierLen, "diff")) { |
875 | assert(*DiagStr == ',' && isDigit(*(DiagStr + 1)) && |
876 | "Invalid format for diff modifier"); |
877 | ++DiagStr; |
878 | ArgNo2 = *DiagStr++ - '0'; |
879 | DiagnosticsEngine::ArgumentKind Kind2 = getArgKind(ArgNo2); |
880 | if (Kind == DiagnosticsEngine::ak_qualtype && |
881 | Kind2 == DiagnosticsEngine::ak_qualtype) |
882 | Kind = DiagnosticsEngine::ak_qualtype_pair; |
883 | else { |
884 | |
885 | |
886 | |
887 | |
888 | |
889 | const char *ArgumentEnd = Argument + ArgumentLen; |
890 | const char *Pipe = ScanFormat(Argument, ArgumentEnd, '|'); |
891 | assert(ScanFormat(Pipe + 1, ArgumentEnd, '|') == ArgumentEnd && |
892 | "Found too many '|'s in a %diff modifier!"); |
893 | const char *FirstDollar = ScanFormat(Argument, Pipe, '$'); |
894 | const char *SecondDollar = ScanFormat(FirstDollar + 1, Pipe, '$'); |
895 | const char ArgStr1[] = { '%', static_cast<char>('0' + ArgNo) }; |
896 | const char ArgStr2[] = { '%', static_cast<char>('0' + ArgNo2) }; |
897 | FormatDiagnostic(Argument, FirstDollar, OutStr); |
898 | FormatDiagnostic(ArgStr1, ArgStr1 + 2, OutStr); |
899 | FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr); |
900 | FormatDiagnostic(ArgStr2, ArgStr2 + 2, OutStr); |
901 | FormatDiagnostic(SecondDollar + 1, Pipe, OutStr); |
902 | continue; |
903 | } |
904 | } |
905 | |
906 | switch (Kind) { |
907 | |
908 | case DiagnosticsEngine::ak_std_string: { |
909 | const std::string &S = getArgStdStr(ArgNo); |
910 | assert(ModifierLen == 0 && "No modifiers for strings yet"); |
911 | OutStr.append(S.begin(), S.end()); |
912 | break; |
913 | } |
914 | case DiagnosticsEngine::ak_c_string: { |
915 | const char *S = getArgCStr(ArgNo); |
916 | assert(ModifierLen == 0 && "No modifiers for strings yet"); |
917 | |
918 | |
919 | if (!S) |
920 | S = "(null)"; |
921 | |
922 | OutStr.append(S, S + strlen(S)); |
923 | break; |
924 | } |
925 | |
926 | case DiagnosticsEngine::ak_sint: { |
927 | int Val = getArgSInt(ArgNo); |
928 | |
929 | if (ModifierIs(Modifier, ModifierLen, "select")) { |
930 | HandleSelectModifier(*this, (unsigned)Val, Argument, ArgumentLen, |
931 | OutStr); |
932 | } else if (ModifierIs(Modifier, ModifierLen, "s")) { |
933 | HandleIntegerSModifier(Val, OutStr); |
934 | } else if (ModifierIs(Modifier, ModifierLen, "plural")) { |
935 | HandlePluralModifier(*this, (unsigned)Val, Argument, ArgumentLen, |
936 | OutStr); |
937 | } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) { |
938 | HandleOrdinalModifier((unsigned)Val, OutStr); |
939 | } else { |
940 | assert(ModifierLen == 0 && "Unknown integer modifier"); |
941 | llvm::raw_svector_ostream(OutStr) << Val; |
942 | } |
943 | break; |
944 | } |
945 | case DiagnosticsEngine::ak_uint: { |
946 | unsigned Val = getArgUInt(ArgNo); |
947 | |
948 | if (ModifierIs(Modifier, ModifierLen, "select")) { |
949 | HandleSelectModifier(*this, Val, Argument, ArgumentLen, OutStr); |
950 | } else if (ModifierIs(Modifier, ModifierLen, "s")) { |
951 | HandleIntegerSModifier(Val, OutStr); |
952 | } else if (ModifierIs(Modifier, ModifierLen, "plural")) { |
953 | HandlePluralModifier(*this, (unsigned)Val, Argument, ArgumentLen, |
954 | OutStr); |
955 | } else if (ModifierIs(Modifier, ModifierLen, "ordinal")) { |
956 | HandleOrdinalModifier(Val, OutStr); |
957 | } else { |
958 | assert(ModifierLen == 0 && "Unknown integer modifier"); |
959 | llvm::raw_svector_ostream(OutStr) << Val; |
960 | } |
961 | break; |
962 | } |
963 | |
964 | case DiagnosticsEngine::ak_tokenkind: { |
965 | tok::TokenKind Kind = static_cast<tok::TokenKind>(getRawArg(ArgNo)); |
966 | assert(ModifierLen == 0 && "No modifiers for token kinds yet"); |
967 | |
968 | llvm::raw_svector_ostream Out(OutStr); |
969 | if (const char *S = tok::getPunctuatorSpelling(Kind)) |
970 | |
971 | Out << '\'' << S << '\''; |
972 | else if (const char *S = tok::getKeywordSpelling(Kind)) |
973 | |
974 | Out << S; |
975 | else if (const char *S = getTokenDescForDiagnostic(Kind)) |
976 | |
977 | Out << S; |
978 | else if (const char *S = tok::getTokenName(Kind)) |
979 | |
980 | Out << '<' << S << '>'; |
981 | else |
982 | Out << "(null)"; |
983 | break; |
984 | } |
985 | |
986 | case DiagnosticsEngine::ak_identifierinfo: { |
987 | const IdentifierInfo *II = getArgIdentifier(ArgNo); |
988 | assert(ModifierLen == 0 && "No modifiers for strings yet"); |
989 | |
990 | |
991 | if (!II) { |
992 | const char *S = "(null)"; |
993 | OutStr.append(S, S + strlen(S)); |
994 | continue; |
995 | } |
996 | |
997 | llvm::raw_svector_ostream(OutStr) << '\'' << II->getName() << '\''; |
998 | break; |
999 | } |
1000 | case DiagnosticsEngine::ak_addrspace: |
1001 | case DiagnosticsEngine::ak_qual: |
1002 | case DiagnosticsEngine::ak_qualtype: |
1003 | case DiagnosticsEngine::ak_declarationname: |
1004 | case DiagnosticsEngine::ak_nameddecl: |
1005 | case DiagnosticsEngine::ak_nestednamespec: |
1006 | case DiagnosticsEngine::ak_declcontext: |
1007 | case DiagnosticsEngine::ak_attr: |
1008 | getDiags()->ConvertArgToString(Kind, getRawArg(ArgNo), |
1009 | StringRef(Modifier, ModifierLen), |
1010 | StringRef(Argument, ArgumentLen), |
1011 | FormattedArgs, |
1012 | OutStr, QualTypeVals); |
1013 | break; |
1014 | case DiagnosticsEngine::ak_qualtype_pair: { |
1015 | |
1016 | TemplateDiffTypes TDT; |
1017 | TDT.FromType = getRawArg(ArgNo); |
1018 | TDT.ToType = getRawArg(ArgNo2); |
1019 | TDT.ElideType = getDiags()->ElideType; |
1020 | TDT.ShowColors = getDiags()->ShowColors; |
1021 | TDT.TemplateDiffUsed = false; |
1022 | intptr_t val = reinterpret_cast<intptr_t>(&TDT); |
1023 | |
1024 | const char *ArgumentEnd = Argument + ArgumentLen; |
1025 | const char *Pipe = ScanFormat(Argument, ArgumentEnd, '|'); |
1026 | |
1027 | |
1028 | |
1029 | if (getDiags()->PrintTemplateTree && Tree.empty()) { |
1030 | TDT.PrintFromType = true; |
1031 | TDT.PrintTree = true; |
1032 | getDiags()->ConvertArgToString(Kind, val, |
1033 | StringRef(Modifier, ModifierLen), |
1034 | StringRef(Argument, ArgumentLen), |
1035 | FormattedArgs, |
1036 | Tree, QualTypeVals); |
1037 | |
1038 | if (!Tree.empty()) { |
1039 | FormatDiagnostic(Pipe + 1, ArgumentEnd, OutStr); |
1040 | break; |
1041 | } |
1042 | } |
1043 | |
1044 | |
1045 | |
1046 | const char *FirstDollar = ScanFormat(Argument, ArgumentEnd, '$'); |
1047 | const char *SecondDollar = ScanFormat(FirstDollar + 1, ArgumentEnd, '$'); |
1048 | |
1049 | |
1050 | FormatDiagnostic(Argument, FirstDollar, OutStr); |
1051 | |
1052 | |
1053 | TDT.PrintTree = false; |
1054 | TDT.PrintFromType = true; |
1055 | getDiags()->ConvertArgToString(Kind, val, |
1056 | StringRef(Modifier, ModifierLen), |
1057 | StringRef(Argument, ArgumentLen), |
1058 | FormattedArgs, |
1059 | OutStr, QualTypeVals); |
1060 | if (!TDT.TemplateDiffUsed) |
1061 | FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype, |
1062 | TDT.FromType)); |
1063 | |
1064 | |
1065 | FormatDiagnostic(FirstDollar + 1, SecondDollar, OutStr); |
1066 | |
1067 | |
1068 | TDT.PrintFromType = false; |
1069 | getDiags()->ConvertArgToString(Kind, val, |
1070 | StringRef(Modifier, ModifierLen), |
1071 | StringRef(Argument, ArgumentLen), |
1072 | FormattedArgs, |
1073 | OutStr, QualTypeVals); |
1074 | if (!TDT.TemplateDiffUsed) |
1075 | FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_qualtype, |
1076 | TDT.ToType)); |
1077 | |
1078 | |
1079 | FormatDiagnostic(SecondDollar + 1, Pipe, OutStr); |
1080 | break; |
1081 | } |
1082 | } |
1083 | |
1084 | |
1085 | |
1086 | |
1087 | if (Kind == DiagnosticsEngine::ak_qualtype_pair) |
1088 | continue; |
1089 | else if (Kind != DiagnosticsEngine::ak_std_string) |
1090 | FormattedArgs.push_back(std::make_pair(Kind, getRawArg(ArgNo))); |
1091 | else |
1092 | FormattedArgs.push_back(std::make_pair(DiagnosticsEngine::ak_c_string, |
1093 | (intptr_t)getArgStdStr(ArgNo).c_str())); |
1094 | } |
1095 | |
1096 | |
1097 | OutStr.append(Tree.begin(), Tree.end()); |
1098 | } |
1099 | |
1100 | StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID, |
1101 | StringRef Message) |
1102 | : ID(ID), Level(Level), Message(Message) {} |
1103 | |
1104 | StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, |
1105 | const Diagnostic &Info) |
1106 | : ID(Info.getID()), Level(Level) { |
1107 | assert((Info.getLocation().isInvalid() || Info.hasSourceManager()) && |
1108 | "Valid source location without setting a source manager for diagnostic"); |
1109 | if (Info.getLocation().isValid()) |
1110 | Loc = FullSourceLoc(Info.getLocation(), Info.getSourceManager()); |
1111 | SmallString<64> Message; |
1112 | Info.FormatDiagnostic(Message); |
1113 | this->Message.assign(Message.begin(), Message.end()); |
1114 | this->Ranges.assign(Info.getRanges().begin(), Info.getRanges().end()); |
1115 | this->FixIts.assign(Info.getFixItHints().begin(), Info.getFixItHints().end()); |
1116 | } |
1117 | |
1118 | StoredDiagnostic::StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID, |
1119 | StringRef Message, FullSourceLoc Loc, |
1120 | ArrayRef<CharSourceRange> Ranges, |
1121 | ArrayRef<FixItHint> FixIts) |
1122 | : ID(ID), Level(Level), Loc(Loc), Message(Message), |
1123 | Ranges(Ranges.begin(), Ranges.end()), FixIts(FixIts.begin(), FixIts.end()) |
1124 | { |
1125 | } |
1126 | |
1127 | |
1128 | |
1129 | |
1130 | |
1131 | bool DiagnosticConsumer::IncludeInDiagnosticCounts() const { return true; } |
1132 | |
1133 | void IgnoringDiagConsumer::anchor() {} |
1134 | |
1135 | ForwardingDiagnosticConsumer::~ForwardingDiagnosticConsumer() = default; |
1136 | |
1137 | void ForwardingDiagnosticConsumer::HandleDiagnostic( |
1138 | DiagnosticsEngine::Level DiagLevel, |
1139 | const Diagnostic &Info) { |
1140 | Target.HandleDiagnostic(DiagLevel, Info); |
1141 | } |
1142 | |
1143 | void ForwardingDiagnosticConsumer::clear() { |
1144 | DiagnosticConsumer::clear(); |
1145 | Target.clear(); |
1146 | } |
1147 | |
1148 | bool ForwardingDiagnosticConsumer::IncludeInDiagnosticCounts() const { |
1149 | return Target.IncludeInDiagnosticCounts(); |
1150 | } |
1151 | |
1152 | PartialDiagnostic::DiagStorageAllocator::DiagStorageAllocator() { |
1153 | for (unsigned I = 0; I != NumCached; ++I) |
1154 | FreeList[I] = Cached + I; |
1155 | NumFreeListEntries = NumCached; |
1156 | } |
1157 | |
1158 | PartialDiagnostic::DiagStorageAllocator::~DiagStorageAllocator() { |
1159 | |
1160 | |
1161 | assert((NumFreeListEntries == NumCached || |
1162 | llvm::CrashRecoveryContext::isRecoveringFromCrash()) && |
1163 | "A partial is on the lam"); |
1164 | } |
1165 | |
1166 | char DiagnosticError::ID; |