clang 19.0.0git
PathDiagnostic.cpp
Go to the documentation of this file.
1//===- PathDiagnostic.cpp - Path-Specific Diagnostic Handling -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the PathDiagnostic-related interfaces.
10//
11//===----------------------------------------------------------------------===//
12
14#include "clang/AST/Decl.h"
15#include "clang/AST/DeclBase.h"
16#include "clang/AST/DeclCXX.h"
17#include "clang/AST/DeclObjC.h"
19#include "clang/AST/Expr.h"
20#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ParentMap.h"
24#include "clang/AST/Stmt.h"
25#include "clang/AST/Type.h"
27#include "clang/Analysis/CFG.h"
30#include "clang/Basic/LLVM.h"
33#include "llvm/ADT/ArrayRef.h"
34#include "llvm/ADT/FoldingSet.h"
35#include "llvm/ADT/STLExtras.h"
36#include "llvm/ADT/SmallString.h"
37#include "llvm/ADT/SmallVector.h"
38#include "llvm/ADT/StringExtras.h"
39#include "llvm/ADT/StringRef.h"
40#include "llvm/Support/Casting.h"
41#include "llvm/Support/ErrorHandling.h"
42#include "llvm/Support/raw_ostream.h"
43#include <cassert>
44#include <cstring>
45#include <memory>
46#include <optional>
47#include <utility>
48#include <vector>
49
50using namespace clang;
51using namespace ento;
52
53static StringRef StripTrailingDots(StringRef s) { return s.rtrim('.'); }
54
56 Kind k, DisplayHint hint)
57 : str(StripTrailingDots(s)), kind(k), Hint(hint) {}
58
60 : kind(k), Hint(hint) {}
61
63
65
67
69
71
73
75
76void PathPieces::flattenTo(PathPieces &Primary, PathPieces &Current,
77 bool ShouldFlattenMacros) const {
78 for (auto &Piece : *this) {
79 switch (Piece->getKind()) {
81 auto &Call = cast<PathDiagnosticCallPiece>(*Piece);
82 if (auto CallEnter = Call.getCallEnterEvent())
83 Current.push_back(std::move(CallEnter));
84 Call.path.flattenTo(Primary, Primary, ShouldFlattenMacros);
85 if (auto callExit = Call.getCallExitEvent())
86 Current.push_back(std::move(callExit));
87 break;
88 }
90 auto &Macro = cast<PathDiagnosticMacroPiece>(*Piece);
91 if (ShouldFlattenMacros) {
92 Macro.subPieces.flattenTo(Primary, Primary, ShouldFlattenMacros);
93 } else {
94 Current.push_back(Piece);
95 PathPieces NewPath;
96 Macro.subPieces.flattenTo(Primary, NewPath, ShouldFlattenMacros);
97 // FIXME: This probably shouldn't mutate the original path piece.
98 Macro.subPieces = NewPath;
99 }
100 break;
101 }
106 Current.push_back(Piece);
107 break;
108 }
109 }
110}
111
113
115 StringRef CheckerName, const Decl *declWithIssue, StringRef bugtype,
116 StringRef verboseDesc, StringRef shortDesc, StringRef category,
117 PathDiagnosticLocation LocationToUnique, const Decl *DeclToUnique,
118 const Decl *AnalysisEntryPoint,
119 std::unique_ptr<FilesToLineNumsMap> ExecutedLines)
120 : CheckerName(CheckerName), DeclWithIssue(declWithIssue),
121 BugType(StripTrailingDots(bugtype)),
122 VerboseDesc(StripTrailingDots(verboseDesc)),
123 ShortDesc(StripTrailingDots(shortDesc)),
124 Category(StripTrailingDots(category)), UniqueingLoc(LocationToUnique),
125 UniqueingDecl(DeclToUnique), AnalysisEntryPoint(AnalysisEntryPoint),
126 ExecutedLines(std::move(ExecutedLines)), path(pathImpl) {
127 assert(AnalysisEntryPoint);
128}
129
130void PathDiagnosticConsumer::anchor() {}
131
133 // Delete the contents of the FoldingSet if it isn't empty already.
134 for (auto &Diag : Diags)
135 delete &Diag;
136}
137
139 std::unique_ptr<PathDiagnostic> D) {
140 if (!D || D->path.empty())
141 return;
142
143 // We need to flatten the locations (convert Stmt* to locations) because
144 // the referenced statements may be freed by the time the diagnostics
145 // are emitted.
146 D->flattenLocations();
147
148 // If the PathDiagnosticConsumer does not support diagnostics that
149 // cross file boundaries, prune out such diagnostics now.
151 // Verify that the entire path is from the same FileID.
152 FileID FID;
153 const SourceManager &SMgr = D->path.front()->getLocation().getManager();
155 WorkList.push_back(&D->path);
157 llvm::raw_svector_ostream warning(buf);
158 warning << "warning: Path diagnostic report is not generated. Current "
159 << "output format does not support diagnostics that cross file "
160 << "boundaries. Refer to --analyzer-output for valid output "
161 << "formats\n";
162
163 while (!WorkList.empty()) {
164 const PathPieces &path = *WorkList.pop_back_val();
165
166 for (const auto &I : path) {
167 const PathDiagnosticPiece *piece = I.get();
169
170 if (FID.isInvalid()) {
171 FID = SMgr.getFileID(L);
172 } else if (SMgr.getFileID(L) != FID) {
173 llvm::errs() << warning.str();
174 return;
175 }
176
177 // Check the source ranges.
178 ArrayRef<SourceRange> Ranges = piece->getRanges();
179 for (const auto &I : Ranges) {
180 SourceLocation L = SMgr.getExpansionLoc(I.getBegin());
181 if (!L.isFileID() || SMgr.getFileID(L) != FID) {
182 llvm::errs() << warning.str();
183 return;
184 }
185 L = SMgr.getExpansionLoc(I.getEnd());
186 if (!L.isFileID() || SMgr.getFileID(L) != FID) {
187 llvm::errs() << warning.str();
188 return;
189 }
190 }
191
192 if (const auto *call = dyn_cast<PathDiagnosticCallPiece>(piece))
193 WorkList.push_back(&call->path);
194 else if (const auto *macro = dyn_cast<PathDiagnosticMacroPiece>(piece))
195 WorkList.push_back(&macro->subPieces);
196 }
197 }
198
199 if (FID.isInvalid())
200 return; // FIXME: Emit a warning?
201 }
202
203 // Profile the node to see if we already have something matching it
204 llvm::FoldingSetNodeID profile;
205 D->Profile(profile);
206 void *InsertPos = nullptr;
207
208 if (PathDiagnostic *orig = Diags.FindNodeOrInsertPos(profile, InsertPos)) {
209 // Keep the PathDiagnostic with the shorter path.
210 // Note, the enclosing routine is called in deterministic order, so the
211 // results will be consistent between runs (no reason to break ties if the
212 // size is the same).
213 const unsigned orig_size = orig->full_size();
214 const unsigned new_size = D->full_size();
215 if (orig_size <= new_size)
216 return;
217
218 assert(orig != D.get());
219 Diags.RemoveNode(orig);
220 delete orig;
221 }
222
223 Diags.InsertNode(D.release());
224}
225
226static std::optional<bool> comparePath(const PathPieces &X,
227 const PathPieces &Y);
228
229static std::optional<bool>
232 FullSourceLoc XSL = X.getStartLocation().asLocation();
234 if (XSL != YSL)
235 return XSL.isBeforeInTranslationUnitThan(YSL);
236 FullSourceLoc XEL = X.getEndLocation().asLocation();
238 if (XEL != YEL)
239 return XEL.isBeforeInTranslationUnitThan(YEL);
240 return std::nullopt;
241}
242
243static std::optional<bool> compareMacro(const PathDiagnosticMacroPiece &X,
244 const PathDiagnosticMacroPiece &Y) {
245 return comparePath(X.subPieces, Y.subPieces);
246}
247
248static std::optional<bool> compareCall(const PathDiagnosticCallPiece &X,
249 const PathDiagnosticCallPiece &Y) {
250 FullSourceLoc X_CEL = X.callEnter.asLocation();
252 if (X_CEL != Y_CEL)
253 return X_CEL.isBeforeInTranslationUnitThan(Y_CEL);
254 FullSourceLoc X_CEWL = X.callEnterWithin.asLocation();
256 if (X_CEWL != Y_CEWL)
257 return X_CEWL.isBeforeInTranslationUnitThan(Y_CEWL);
258 FullSourceLoc X_CRL = X.callReturn.asLocation();
260 if (X_CRL != Y_CRL)
261 return X_CRL.isBeforeInTranslationUnitThan(Y_CRL);
262 return comparePath(X.path, Y.path);
263}
264
265static std::optional<bool> comparePiece(const PathDiagnosticPiece &X,
266 const PathDiagnosticPiece &Y) {
267 if (X.getKind() != Y.getKind())
268 return X.getKind() < Y.getKind();
269
270 FullSourceLoc XL = X.getLocation().asLocation();
272 if (XL != YL)
273 return XL.isBeforeInTranslationUnitThan(YL);
274
275 if (X.getString() != Y.getString())
276 return X.getString() < Y.getString();
277
278 if (X.getRanges().size() != Y.getRanges().size())
279 return X.getRanges().size() < Y.getRanges().size();
280
281 const SourceManager &SM = XL.getManager();
282
283 for (unsigned i = 0, n = X.getRanges().size(); i < n; ++i) {
284 SourceRange XR = X.getRanges()[i];
285 SourceRange YR = Y.getRanges()[i];
286 if (XR != YR) {
287 if (XR.getBegin() != YR.getBegin())
288 return SM.isBeforeInTranslationUnit(XR.getBegin(), YR.getBegin());
289 return SM.isBeforeInTranslationUnit(XR.getEnd(), YR.getEnd());
290 }
291 }
292
293 switch (X.getKind()) {
295 return compareControlFlow(cast<PathDiagnosticControlFlowPiece>(X),
296 cast<PathDiagnosticControlFlowPiece>(Y));
298 return compareMacro(cast<PathDiagnosticMacroPiece>(X),
299 cast<PathDiagnosticMacroPiece>(Y));
301 return compareCall(cast<PathDiagnosticCallPiece>(X),
302 cast<PathDiagnosticCallPiece>(Y));
306 return std::nullopt;
307 }
308 llvm_unreachable("all cases handled");
309}
310
311static std::optional<bool> comparePath(const PathPieces &X,
312 const PathPieces &Y) {
313 if (X.size() != Y.size())
314 return X.size() < Y.size();
315
316 PathPieces::const_iterator X_I = X.begin(), X_end = X.end();
317 PathPieces::const_iterator Y_I = Y.begin(), Y_end = Y.end();
318
319 for (; X_I != X_end && Y_I != Y_end; ++X_I, ++Y_I)
320 if (std::optional<bool> b = comparePiece(**X_I, **Y_I))
321 return *b;
322
323 return std::nullopt;
324}
325
327 if (XL.isInvalid() && YL.isValid())
328 return true;
329 if (XL.isValid() && YL.isInvalid())
330 return false;
331 std::pair<FileID, unsigned> XOffs = XL.getDecomposedLoc();
332 std::pair<FileID, unsigned> YOffs = YL.getDecomposedLoc();
333 const SourceManager &SM = XL.getManager();
334 std::pair<bool, bool> InSameTU = SM.isInTheSameTranslationUnit(XOffs, YOffs);
335 if (InSameTU.first)
336 return XL.isBeforeInTranslationUnitThan(YL);
338 SM.getFileEntryRefForID(XL.getSpellingLoc().getFileID());
340 SM.getFileEntryRefForID(YL.getSpellingLoc().getFileID());
341 if (!XFE || !YFE)
342 return XFE && !YFE;
343 int NameCmp = XFE->getName().compare(YFE->getName());
344 if (NameCmp != 0)
345 return NameCmp < 0;
346 // Last resort: Compare raw file IDs that are possibly expansions.
347 return XL.getFileID() < YL.getFileID();
348}
349
350static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y) {
351 FullSourceLoc XL = X.getLocation().asLocation();
353 if (XL != YL)
354 return compareCrossTUSourceLocs(XL, YL);
355 FullSourceLoc XUL = X.getUniqueingLoc().asLocation();
357 if (XUL != YUL)
358 return compareCrossTUSourceLocs(XUL, YUL);
359 if (X.getBugType() != Y.getBugType())
360 return X.getBugType() < Y.getBugType();
361 if (X.getCategory() != Y.getCategory())
362 return X.getCategory() < Y.getCategory();
363 if (X.getVerboseDescription() != Y.getVerboseDescription())
364 return X.getVerboseDescription() < Y.getVerboseDescription();
365 if (X.getShortDescription() != Y.getShortDescription())
366 return X.getShortDescription() < Y.getShortDescription();
367 auto CompareDecls = [&XL](const Decl *D1,
368 const Decl *D2) -> std::optional<bool> {
369 if (D1 == D2)
370 return std::nullopt;
371 if (!D1)
372 return true;
373 if (!D2)
374 return false;
375 SourceLocation D1L = D1->getLocation();
376 SourceLocation D2L = D2->getLocation();
377 if (D1L != D2L) {
378 const SourceManager &SM = XL.getManager();
380 FullSourceLoc(D2L, SM));
381 }
382 return std::nullopt;
383 };
384 if (auto Result = CompareDecls(X.getDeclWithIssue(), Y.getDeclWithIssue()))
385 return *Result;
386 if (XUL.isValid()) {
387 if (auto Result = CompareDecls(X.getUniqueingDecl(), Y.getUniqueingDecl()))
388 return *Result;
389 }
390 PathDiagnostic::meta_iterator XI = X.meta_begin(), XE = X.meta_end();
392 if (XE - XI != YE - YI)
393 return (XE - XI) < (YE - YI);
394 for ( ; XI != XE ; ++XI, ++YI) {
395 if (*XI != *YI)
396 return (*XI) < (*YI);
397 }
398 return *comparePath(X.path, Y.path);
399}
400
403 if (flushed)
404 return;
405
406 flushed = true;
407
408 std::vector<const PathDiagnostic *> BatchDiags;
409 for (const auto &D : Diags)
410 BatchDiags.push_back(&D);
411
412 // Sort the diagnostics so that they are always emitted in a deterministic
413 // order.
414 int (*Comp)(const PathDiagnostic *const *, const PathDiagnostic *const *) =
415 [](const PathDiagnostic *const *X, const PathDiagnostic *const *Y) {
416 assert(*X != *Y && "PathDiagnostics not uniqued!");
417 if (compare(**X, **Y))
418 return -1;
419 assert(compare(**Y, **X) && "Not a total order!");
420 return 1;
421 };
422 array_pod_sort(BatchDiags.begin(), BatchDiags.end(), Comp);
423
424 FlushDiagnosticsImpl(BatchDiags, Files);
425
426 // Delete the flushed diagnostics.
427 for (const auto D : BatchDiags)
428 delete D;
429
430 // Clear out the FoldingSet.
431 Diags.clear();
432}
433
435 for (auto It = Set.begin(); It != Set.end();)
436 (It++)->~PDFileEntry();
437}
438
440 StringRef ConsumerName,
441 StringRef FileName) {
442 llvm::FoldingSetNodeID NodeID;
443 NodeID.Add(PD);
444 void *InsertPos;
445 PDFileEntry *Entry = Set.FindNodeOrInsertPos(NodeID, InsertPos);
446 if (!Entry) {
447 Entry = Alloc.Allocate<PDFileEntry>();
448 Entry = new (Entry) PDFileEntry(NodeID);
449 Set.InsertNode(Entry, InsertPos);
450 }
451
452 // Allocate persistent storage for the file name.
453 char *FileName_cstr = (char*) Alloc.Allocate(FileName.size(), 1);
454 memcpy(FileName_cstr, FileName.data(), FileName.size());
455
456 Entry->files.push_back(std::make_pair(ConsumerName,
457 StringRef(FileName_cstr,
458 FileName.size())));
459}
460
463 llvm::FoldingSetNodeID NodeID;
464 NodeID.Add(PD);
465 void *InsertPos;
466 PDFileEntry *Entry = Set.FindNodeOrInsertPos(NodeID, InsertPos);
467 if (!Entry)
468 return nullptr;
469 return &Entry->files;
470}
471
472//===----------------------------------------------------------------------===//
473// PathDiagnosticLocation methods.
474//===----------------------------------------------------------------------===//
475
477 const Stmt *S, LocationOrAnalysisDeclContext LAC, bool UseEndOfStatement) {
478 SourceLocation L = UseEndOfStatement ? S->getEndLoc() : S->getBeginLoc();
479 assert(!LAC.isNull() &&
480 "A valid LocationContext or AnalysisDeclContext should be passed to "
481 "PathDiagnosticLocation upon creation.");
482
483 // S might be a temporary statement that does not have a location in the
484 // source code, so find an enclosing statement and use its location.
485 if (!L.isValid()) {
487 if (LAC.is<const LocationContext*>())
488 ADC = LAC.get<const LocationContext*>()->getAnalysisDeclContext();
489 else
490 ADC = LAC.get<AnalysisDeclContext*>();
491
492 ParentMap &PM = ADC->getParentMap();
493
494 const Stmt *Parent = S;
495 do {
496 Parent = PM.getParent(Parent);
497
498 // In rare cases, we have implicit top-level expressions,
499 // such as arguments for implicit member initializers.
500 // In this case, fall back to the start of the body (even if we were
501 // asked for the statement end location).
502 if (!Parent) {
503 const Stmt *Body = ADC->getBody();
504 if (Body)
505 L = Body->getBeginLoc();
506 else
507 L = ADC->getDecl()->getEndLoc();
508 break;
509 }
510
511 L = UseEndOfStatement ? Parent->getEndLoc() : Parent->getBeginLoc();
512 } while (!L.isValid());
513 }
514
515 // FIXME: Ironically, this assert actually fails in some cases.
516 //assert(L.isValid());
517 return L;
518}
519
522 const LocationContext *CallerCtx,
523 const SourceManager &SM) {
524 const CFGBlock &Block = *SFC->getCallSiteBlock();
525 CFGElement Source = Block[SFC->getIndex()];
526
527 switch (Source.getKind()) {
531 return PathDiagnosticLocation(Source.castAs<CFGStmt>().getStmt(),
532 SM, CallerCtx);
534 const CFGInitializer &Init = Source.castAs<CFGInitializer>();
535 return PathDiagnosticLocation(Init.getInitializer()->getInit(),
536 SM, CallerCtx);
537 }
539 const CFGAutomaticObjDtor &Dtor = Source.castAs<CFGAutomaticObjDtor>();
541 SM, CallerCtx);
542 }
544 const CFGDeleteDtor &Dtor = Source.castAs<CFGDeleteDtor>();
545 return PathDiagnosticLocation(Dtor.getDeleteExpr(), SM, CallerCtx);
546 }
549 const AnalysisDeclContext *CallerInfo = CallerCtx->getAnalysisDeclContext();
550 if (const Stmt *CallerBody = CallerInfo->getBody())
551 return PathDiagnosticLocation::createEnd(CallerBody, SM, CallerCtx);
552 return PathDiagnosticLocation::create(CallerInfo->getDecl(), SM);
553 }
555 const CFGNewAllocator &Alloc = Source.castAs<CFGNewAllocator>();
556 return PathDiagnosticLocation(Alloc.getAllocatorExpr(), SM, CallerCtx);
557 }
559 // Temporary destructors are for temporaries. They die immediately at around
560 // the location of CXXBindTemporaryExpr. If they are lifetime-extended,
561 // they'd be dealt with via an AutomaticObjectDtor instead.
562 const auto &Dtor = Source.castAs<CFGTemporaryDtor>();
563 return PathDiagnosticLocation::createEnd(Dtor.getBindTemporaryExpr(), SM,
564 CallerCtx);
565 }
569 llvm_unreachable("not yet implemented!");
572 llvm_unreachable("CFGElement kind should not be on callsite!");
573 }
574
575 llvm_unreachable("Unknown CFGElement kind");
576}
577
580 const SourceManager &SM) {
581 return PathDiagnosticLocation(D->getBeginLoc(), SM, SingleLocK);
582}
583
586 const SourceManager &SM,
588 assert(S && "Statement cannot be null");
589 return PathDiagnosticLocation(getValidSourceLocation(S, LAC),
590 SM, SingleLocK);
591}
592
595 const SourceManager &SM,
597 if (const auto *CS = dyn_cast<CompoundStmt>(S))
598 return createEndBrace(CS, SM);
599 return PathDiagnosticLocation(getValidSourceLocation(S, LAC, /*End=*/true),
600 SM, SingleLocK);
601}
602
605 const SourceManager &SM) {
606 return PathDiagnosticLocation(BO->getOperatorLoc(), SM, SingleLocK);
607}
608
611 const ConditionalOperator *CO,
612 const SourceManager &SM) {
613 return PathDiagnosticLocation(CO->getColonLoc(), SM, SingleLocK);
614}
615
618 const SourceManager &SM) {
619
620 assert(ME->getMemberLoc().isValid() || ME->getBeginLoc().isValid());
621
622 // In some cases, getMemberLoc isn't valid -- in this case we'll return with
623 // some other related valid SourceLocation.
624 if (ME->getMemberLoc().isValid())
625 return PathDiagnosticLocation(ME->getMemberLoc(), SM, SingleLocK);
626
627 return PathDiagnosticLocation(ME->getBeginLoc(), SM, SingleLocK);
628}
629
632 const SourceManager &SM) {
633 SourceLocation L = CS->getLBracLoc();
634 return PathDiagnosticLocation(L, SM, SingleLocK);
635}
636
639 const SourceManager &SM) {
640 SourceLocation L = CS->getRBracLoc();
641 return PathDiagnosticLocation(L, SM, SingleLocK);
642}
643
646 const SourceManager &SM) {
647 // FIXME: Should handle CXXTryStmt if analyser starts supporting C++.
648 if (const auto *CS = dyn_cast_or_null<CompoundStmt>(LC->getDecl()->getBody()))
649 if (!CS->body_empty()) {
650 SourceLocation Loc = (*CS->body_begin())->getBeginLoc();
651 return PathDiagnosticLocation(Loc, SM, SingleLocK);
652 }
653
654 return PathDiagnosticLocation();
655}
656
659 const SourceManager &SM) {
661 return PathDiagnosticLocation(L, SM, SingleLocK);
662}
663
666 const SourceManager &SMng) {
667 const Stmt* S = nullptr;
668 if (std::optional<BlockEdge> BE = P.getAs<BlockEdge>()) {
669 const CFGBlock *BSrc = BE->getSrc();
670 if (BSrc->getTerminator().isVirtualBaseBranch()) {
671 // TODO: VirtualBaseBranches should also appear for destructors.
672 // In this case we should put the diagnostic at the end of decl.
674 P.getLocationContext()->getDecl(), SMng);
675
676 } else {
677 S = BSrc->getTerminatorCondition();
678 if (!S) {
679 // If the BlockEdge has no terminator condition statement but its
680 // source is the entry of the CFG (e.g. a checker crated the branch at
681 // the beginning of a function), use the function's declaration instead.
682 assert(BSrc == &BSrc->getParent()->getEntry() && "CFGBlock has no "
683 "TerminatorCondition and is not the enrty block of the CFG");
685 P.getLocationContext()->getDecl(), SMng);
686 }
687 }
688 } else if (std::optional<StmtPoint> SP = P.getAs<StmtPoint>()) {
689 S = SP->getStmt();
690 if (P.getAs<PostStmtPurgeDeadSymbols>())
691 return PathDiagnosticLocation::createEnd(S, SMng, P.getLocationContext());
692 } else if (std::optional<PostInitializer> PIP = P.getAs<PostInitializer>()) {
693 return PathDiagnosticLocation(PIP->getInitializer()->getSourceLocation(),
694 SMng);
695 } else if (std::optional<PreImplicitCall> PIC = P.getAs<PreImplicitCall>()) {
696 return PathDiagnosticLocation(PIC->getLocation(), SMng);
697 } else if (std::optional<PostImplicitCall> PIE =
698 P.getAs<PostImplicitCall>()) {
699 return PathDiagnosticLocation(PIE->getLocation(), SMng);
700 } else if (std::optional<CallEnter> CE = P.getAs<CallEnter>()) {
701 return getLocationForCaller(CE->getCalleeContext(),
702 CE->getLocationContext(),
703 SMng);
704 } else if (std::optional<CallExitEnd> CEE = P.getAs<CallExitEnd>()) {
705 return getLocationForCaller(CEE->getCalleeContext(),
706 CEE->getLocationContext(),
707 SMng);
708 } else if (auto CEB = P.getAs<CallExitBegin>()) {
709 if (const ReturnStmt *RS = CEB->getReturnStmt())
711 CEB->getLocationContext());
713 CEB->getLocationContext()->getDecl()->getSourceRange().getEnd(), SMng);
714 } else if (std::optional<BlockEntrance> BE = P.getAs<BlockEntrance>()) {
715 if (std::optional<CFGElement> BlockFront = BE->getFirstElement()) {
716 if (auto StmtElt = BlockFront->getAs<CFGStmt>()) {
717 return PathDiagnosticLocation(StmtElt->getStmt()->getBeginLoc(), SMng);
718 } else if (auto NewAllocElt = BlockFront->getAs<CFGNewAllocator>()) {
720 NewAllocElt->getAllocatorExpr()->getBeginLoc(), SMng);
721 }
722 llvm_unreachable("Unexpected CFG element at front of block");
723 }
724
726 BE->getBlock()->getTerminatorStmt()->getBeginLoc(), SMng);
727 } else if (std::optional<FunctionExitPoint> FE =
728 P.getAs<FunctionExitPoint>()) {
729 return PathDiagnosticLocation(FE->getStmt(), SMng,
730 FE->getLocationContext());
731 } else {
732 llvm_unreachable("Unexpected ProgramPoint");
733 }
734
735 return PathDiagnosticLocation(S, SMng, P.getLocationContext());
736}
737
739 const PathDiagnosticLocation &PDL) {
740 FullSourceLoc L = PDL.asLocation();
741 return PathDiagnosticLocation(L, L.getManager(), SingleLocK);
742}
743
745 PathDiagnosticLocation::genLocation(SourceLocation L,
747 assert(isValid());
748 // Note that we want a 'switch' here so that the compiler can warn us in
749 // case we add more cases.
750 switch (K) {
751 case SingleLocK:
752 case RangeK:
753 break;
754 case StmtK:
755 // Defensive checking.
756 if (!S)
757 break;
758 return FullSourceLoc(getValidSourceLocation(S, LAC),
759 const_cast<SourceManager&>(*SM));
760 case DeclK:
761 // Defensive checking.
762 if (!D)
763 break;
764 return FullSourceLoc(D->getLocation(), const_cast<SourceManager&>(*SM));
765 }
766
767 return FullSourceLoc(L, const_cast<SourceManager&>(*SM));
768}
769
771 PathDiagnosticLocation::genRange(LocationOrAnalysisDeclContext LAC) const {
772 assert(isValid());
773 // Note that we want a 'switch' here so that the compiler can warn us in
774 // case we add more cases.
775 switch (K) {
776 case SingleLocK:
777 return PathDiagnosticRange(SourceRange(Loc,Loc), true);
778 case RangeK:
779 break;
780 case StmtK: {
781 const Stmt *S = asStmt();
782 switch (S->getStmtClass()) {
783 default:
784 break;
785 case Stmt::DeclStmtClass: {
786 const auto *DS = cast<DeclStmt>(S);
787 if (DS->isSingleDecl()) {
788 // Should always be the case, but we'll be defensive.
789 return SourceRange(DS->getBeginLoc(),
790 DS->getSingleDecl()->getLocation());
791 }
792 break;
793 }
794 // FIXME: Provide better range information for different
795 // terminators.
796 case Stmt::IfStmtClass:
797 case Stmt::WhileStmtClass:
798 case Stmt::DoStmtClass:
799 case Stmt::ForStmtClass:
800 case Stmt::ChooseExprClass:
801 case Stmt::IndirectGotoStmtClass:
802 case Stmt::SwitchStmtClass:
803 case Stmt::BinaryConditionalOperatorClass:
804 case Stmt::ConditionalOperatorClass:
805 case Stmt::ObjCForCollectionStmtClass: {
806 SourceLocation L = getValidSourceLocation(S, LAC);
807 return SourceRange(L, L);
808 }
809 }
810 SourceRange R = S->getSourceRange();
811 if (R.isValid())
812 return R;
813 break;
814 }
815 case DeclK:
816 if (const auto *MD = dyn_cast<ObjCMethodDecl>(D))
817 return MD->getSourceRange();
818 if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
819 if (Stmt *Body = FD->getBody())
820 return Body->getSourceRange();
821 }
822 else {
823 SourceLocation L = D->getLocation();
824 return PathDiagnosticRange(SourceRange(L, L), true);
825 }
826 }
827
828 return SourceRange(Loc, Loc);
829}
830
832 if (K == StmtK) {
833 K = RangeK;
834 S = nullptr;
835 D = nullptr;
836 }
837 else if (K == DeclK) {
838 K = SingleLocK;
839 S = nullptr;
840 D = nullptr;
841 }
842}
843
844//===----------------------------------------------------------------------===//
845// Manipulation of PathDiagnosticCallPieces.
846//===----------------------------------------------------------------------===//
847
848std::shared_ptr<PathDiagnosticCallPiece>
850 const SourceManager &SM) {
851 const Decl *caller = CE.getLocationContext()->getDecl();
854 SM);
855 return std::shared_ptr<PathDiagnosticCallPiece>(
856 new PathDiagnosticCallPiece(caller, pos));
857}
858
861 const Decl *caller) {
862 std::shared_ptr<PathDiagnosticCallPiece> C(
863 new PathDiagnosticCallPiece(path, caller));
864 path.clear();
865 auto *R = C.get();
866 path.push_front(std::move(C));
867 return R;
868}
869
871 const SourceManager &SM) {
872 const StackFrameContext *CalleeCtx = CE.getCalleeContext();
873 Callee = CalleeCtx->getDecl();
874
875 callEnterWithin = PathDiagnosticLocation::createBegin(Callee, SM);
876 callEnter = getLocationForCaller(CalleeCtx, CE.getLocationContext(), SM);
877
878 // Autosynthesized property accessors are special because we'd never
879 // pop back up to non-autosynthesized code until we leave them.
880 // This is not generally true for autosynthesized callees, which may call
881 // non-autosynthesized callbacks.
882 // Unless set here, the IsCalleeAnAutosynthesizedPropertyAccessor flag
883 // defaults to false.
884 if (const auto *MD = dyn_cast<ObjCMethodDecl>(Callee))
885 IsCalleeAnAutosynthesizedPropertyAccessor = (
886 MD->isPropertyAccessor() &&
888}
889
890static void describeTemplateParameters(raw_ostream &Out,
891 const ArrayRef<TemplateArgument> TAList,
892 const LangOptions &LO,
893 StringRef Prefix = StringRef(),
894 StringRef Postfix = StringRef());
895
896static void describeTemplateParameter(raw_ostream &Out,
897 const TemplateArgument &TArg,
898 const LangOptions &LO) {
899
902 } else {
903 TArg.print(PrintingPolicy(LO), Out, /*IncludeType*/ true);
904 }
905}
906
907static void describeTemplateParameters(raw_ostream &Out,
908 const ArrayRef<TemplateArgument> TAList,
909 const LangOptions &LO,
910 StringRef Prefix, StringRef Postfix) {
911 if (TAList.empty())
912 return;
913
914 Out << Prefix;
915 for (int I = 0, Last = TAList.size() - 1; I != Last; ++I) {
916 describeTemplateParameter(Out, TAList[I], LO);
917 Out << ", ";
918 }
919 describeTemplateParameter(Out, TAList[TAList.size() - 1], LO);
920 Out << Postfix;
921}
922
923static void describeClass(raw_ostream &Out, const CXXRecordDecl *D,
924 StringRef Prefix = StringRef()) {
925 if (!D->getIdentifier())
926 return;
927 Out << Prefix << '\'' << *D;
928 if (const auto T = dyn_cast<ClassTemplateSpecializationDecl>(D))
929 describeTemplateParameters(Out, T->getTemplateArgs().asArray(),
930 D->getLangOpts(), "<", ">");
931
932 Out << '\'';
933}
934
935static bool describeCodeDecl(raw_ostream &Out, const Decl *D,
936 bool ExtendedDescription,
937 StringRef Prefix = StringRef()) {
938 if (!D)
939 return false;
940
941 if (isa<BlockDecl>(D)) {
942 if (ExtendedDescription)
943 Out << Prefix << "anonymous block";
944 return ExtendedDescription;
945 }
946
947 if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
948 Out << Prefix;
949 if (ExtendedDescription && !MD->isUserProvided()) {
950 if (MD->isExplicitlyDefaulted())
951 Out << "defaulted ";
952 else
953 Out << "implicit ";
954 }
955
956 if (const auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
957 if (CD->isDefaultConstructor())
958 Out << "default ";
959 else if (CD->isCopyConstructor())
960 Out << "copy ";
961 else if (CD->isMoveConstructor())
962 Out << "move ";
963
964 Out << "constructor";
965 describeClass(Out, MD->getParent(), " for ");
966 } else if (isa<CXXDestructorDecl>(MD)) {
967 if (!MD->isUserProvided()) {
968 Out << "destructor";
969 describeClass(Out, MD->getParent(), " for ");
970 } else {
971 // Use ~Foo for explicitly-written destructors.
972 Out << "'" << *MD << "'";
973 }
974 } else if (MD->isCopyAssignmentOperator()) {
975 Out << "copy assignment operator";
976 describeClass(Out, MD->getParent(), " for ");
977 } else if (MD->isMoveAssignmentOperator()) {
978 Out << "move assignment operator";
979 describeClass(Out, MD->getParent(), " for ");
980 } else {
981 if (MD->getParent()->getIdentifier())
982 Out << "'" << *MD->getParent() << "::" << *MD << "'";
983 else
984 Out << "'" << *MD << "'";
985 }
986
987 return true;
988 }
989
990 Out << Prefix << '\'' << cast<NamedDecl>(*D);
991
992 // Adding template parameters.
993 if (const auto FD = dyn_cast<FunctionDecl>(D))
994 if (const TemplateArgumentList *TAList =
995 FD->getTemplateSpecializationArgs())
996 describeTemplateParameters(Out, TAList->asArray(), FD->getLangOpts(), "<",
997 ">");
998
999 Out << '\'';
1000 return true;
1001}
1002
1003std::shared_ptr<PathDiagnosticEventPiece>
1005 // We do not produce call enters and call exits for autosynthesized property
1006 // accessors. We do generally produce them for other functions coming from
1007 // the body farm because they may call callbacks that bring us back into
1008 // visible code.
1009 if (!Callee || IsCalleeAnAutosynthesizedPropertyAccessor)
1010 return nullptr;
1011
1012 SmallString<256> buf;
1013 llvm::raw_svector_ostream Out(buf);
1014
1015 Out << "Calling ";
1016 describeCodeDecl(Out, Callee, /*ExtendedDescription=*/true);
1017
1018 assert(callEnter.asLocation().isValid());
1019 return std::make_shared<PathDiagnosticEventPiece>(callEnter, Out.str());
1020}
1021
1022std::shared_ptr<PathDiagnosticEventPiece>
1024 if (!callEnterWithin.asLocation().isValid())
1025 return nullptr;
1026 if (Callee->isImplicit() || !Callee->hasBody())
1027 return nullptr;
1028 if (const auto *MD = dyn_cast<CXXMethodDecl>(Callee))
1029 if (MD->isDefaulted())
1030 return nullptr;
1031
1032 SmallString<256> buf;
1033 llvm::raw_svector_ostream Out(buf);
1034
1035 Out << "Entered call";
1036 describeCodeDecl(Out, Caller, /*ExtendedDescription=*/false, " from ");
1037
1038 return std::make_shared<PathDiagnosticEventPiece>(callEnterWithin, Out.str());
1039}
1040
1041std::shared_ptr<PathDiagnosticEventPiece>
1043 // We do not produce call enters and call exits for autosynthesized property
1044 // accessors. We do generally produce them for other functions coming from
1045 // the body farm because they may call callbacks that bring us back into
1046 // visible code.
1047 if (NoExit || IsCalleeAnAutosynthesizedPropertyAccessor)
1048 return nullptr;
1049
1050 SmallString<256> buf;
1051 llvm::raw_svector_ostream Out(buf);
1052
1053 if (!CallStackMessage.empty()) {
1054 Out << CallStackMessage;
1055 } else {
1056 bool DidDescribe = describeCodeDecl(Out, Callee,
1057 /*ExtendedDescription=*/false,
1058 "Returning from ");
1059 if (!DidDescribe)
1060 Out << "Returning to caller";
1061 }
1062
1063 assert(callReturn.asLocation().isValid());
1064 return std::make_shared<PathDiagnosticEventPiece>(callReturn, Out.str());
1065}
1066
1067static void compute_path_size(const PathPieces &pieces, unsigned &size) {
1068 for (const auto &I : pieces) {
1069 const PathDiagnosticPiece *piece = I.get();
1070 if (const auto *cp = dyn_cast<PathDiagnosticCallPiece>(piece))
1071 compute_path_size(cp->path, size);
1072 else
1073 ++size;
1074 }
1075}
1076
1078 unsigned size = 0;
1079 compute_path_size(path, size);
1080 return size;
1081}
1082
1083//===----------------------------------------------------------------------===//
1084// FoldingSet profiling methods.
1085//===----------------------------------------------------------------------===//
1086
1087void PathDiagnosticLocation::Profile(llvm::FoldingSetNodeID &ID) const {
1088 ID.Add(Range.getBegin());
1089 ID.Add(Range.getEnd());
1090 ID.Add(static_cast<const SourceLocation &>(Loc));
1091}
1092
1093void PathDiagnosticPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1094 ID.AddInteger((unsigned) getKind());
1095 ID.AddString(str);
1096 // FIXME: Add profiling support for code hints.
1097 ID.AddInteger((unsigned) getDisplayHint());
1098 ArrayRef<SourceRange> Ranges = getRanges();
1099 for (const auto &I : Ranges) {
1100 ID.Add(I.getBegin());
1101 ID.Add(I.getEnd());
1102 }
1103}
1104
1105void PathDiagnosticCallPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1107 for (const auto &I : path)
1108 ID.Add(*I);
1109}
1110
1111void PathDiagnosticSpotPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1113 ID.Add(Pos);
1114}
1115
1116void PathDiagnosticControlFlowPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1118 for (const auto &I : *this)
1119 ID.Add(I);
1120}
1121
1122void PathDiagnosticMacroPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1124 for (const auto &I : subPieces)
1125 ID.Add(*I);
1126}
1127
1128void PathDiagnosticNotePiece::Profile(llvm::FoldingSetNodeID &ID) const {
1130}
1131
1132void PathDiagnosticPopUpPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1134}
1135
1136void PathDiagnostic::Profile(llvm::FoldingSetNodeID &ID) const {
1137 ID.Add(getLocation());
1138 ID.Add(getUniqueingLoc());
1139 ID.AddString(BugType);
1140 ID.AddString(VerboseDesc);
1141 ID.AddString(Category);
1142}
1143
1144void PathDiagnostic::FullProfile(llvm::FoldingSetNodeID &ID) const {
1145 Profile(ID);
1146 for (const auto &I : path)
1147 ID.Add(*I);
1148 for (meta_iterator I = meta_begin(), E = meta_end(); I != E; ++I)
1149 ID.AddString(*I);
1150}
1151
1152LLVM_DUMP_METHOD void PathPieces::dump() const {
1153 unsigned index = 0;
1154 for (PathPieces::const_iterator I = begin(), E = end(); I != E; ++I) {
1155 llvm::errs() << "[" << index++ << "] ";
1156 (*I)->dump();
1157 llvm::errs() << "\n";
1158 }
1159}
1160
1161LLVM_DUMP_METHOD void PathDiagnosticCallPiece::dump() const {
1162 llvm::errs() << "CALL\n--------------\n";
1163
1164 if (const Stmt *SLoc = getLocation().getStmtOrNull())
1165 SLoc->dump();
1166 else if (const auto *ND = dyn_cast_or_null<NamedDecl>(getCallee()))
1167 llvm::errs() << *ND << "\n";
1168 else
1169 getLocation().dump();
1170}
1171
1172LLVM_DUMP_METHOD void PathDiagnosticEventPiece::dump() const {
1173 llvm::errs() << "EVENT\n--------------\n";
1174 llvm::errs() << getString() << "\n";
1175 llvm::errs() << " ---- at ----\n";
1176 getLocation().dump();
1177}
1178
1179LLVM_DUMP_METHOD void PathDiagnosticControlFlowPiece::dump() const {
1180 llvm::errs() << "CONTROL\n--------------\n";
1181 getStartLocation().dump();
1182 llvm::errs() << " ---- to ----\n";
1183 getEndLocation().dump();
1184}
1185
1186LLVM_DUMP_METHOD void PathDiagnosticMacroPiece::dump() const {
1187 llvm::errs() << "MACRO\n--------------\n";
1188 // FIXME: Print which macro is being invoked.
1189}
1190
1191LLVM_DUMP_METHOD void PathDiagnosticNotePiece::dump() const {
1192 llvm::errs() << "NOTE\n--------------\n";
1193 llvm::errs() << getString() << "\n";
1194 llvm::errs() << " ---- at ----\n";
1195 getLocation().dump();
1196}
1197
1198LLVM_DUMP_METHOD void PathDiagnosticPopUpPiece::dump() const {
1199 llvm::errs() << "POP-UP\n--------------\n";
1200 llvm::errs() << getString() << "\n";
1201 llvm::errs() << " ---- at ----\n";
1202 getLocation().dump();
1203}
1204
1205LLVM_DUMP_METHOD void PathDiagnosticLocation::dump() const {
1206 if (!isValid()) {
1207 llvm::errs() << "<INVALID>\n";
1208 return;
1209 }
1210
1211 switch (K) {
1212 case RangeK:
1213 // FIXME: actually print the range.
1214 llvm::errs() << "<range>\n";
1215 break;
1216 case SingleLocK:
1217 asLocation().dump();
1218 llvm::errs() << "\n";
1219 break;
1220 case StmtK:
1221 if (S)
1222 S->dump();
1223 else
1224 llvm::errs() << "<NULL STMT>\n";
1225 break;
1226 case DeclK:
1227 if (const auto *ND = dyn_cast_or_null<NamedDecl>(D))
1228 llvm::errs() << *ND << "\n";
1229 else if (isa<BlockDecl>(D))
1230 // FIXME: Make this nicer.
1231 llvm::errs() << "<block>\n";
1232 else if (D)
1233 llvm::errs() << "<unknown decl>\n";
1234 else
1235 llvm::errs() << "<NULL DECL>\n";
1236 break;
1237 }
1238}
NodeId Parent
Definition: ASTDiff.cpp:191
StringRef P
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
#define SM(sm)
Definition: Cuda.cpp:84
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1156
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::FileManager interface and associated types.
int Category
Definition: Format.cpp:2979
#define X(type, name)
Definition: Value.h:143
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
static std::optional< bool > comparePath(const PathPieces &X, const PathPieces &Y)
static PathDiagnosticLocation getLocationForCaller(const StackFrameContext *SFC, const LocationContext *CallerCtx, const SourceManager &SM)
static void describeClass(raw_ostream &Out, const CXXRecordDecl *D, StringRef Prefix=StringRef())
static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y)
static bool describeCodeDecl(raw_ostream &Out, const Decl *D, bool ExtendedDescription, StringRef Prefix=StringRef())
static std::optional< bool > compareCall(const PathDiagnosticCallPiece &X, const PathDiagnosticCallPiece &Y)
static std::optional< bool > comparePiece(const PathDiagnosticPiece &X, const PathDiagnosticPiece &Y)
static void describeTemplateParameter(raw_ostream &Out, const TemplateArgument &TArg, const LangOptions &LO)
static void compute_path_size(const PathPieces &pieces, unsigned &size)
static std::optional< bool > compareMacro(const PathDiagnosticMacroPiece &X, const PathDiagnosticMacroPiece &Y)
static std::optional< bool > compareControlFlow(const PathDiagnosticControlFlowPiece &X, const PathDiagnosticControlFlowPiece &Y)
static StringRef StripTrailingDots(StringRef s)
static void describeTemplateParameters(raw_ostream &Out, const ArrayRef< TemplateArgument > TAList, const LangOptions &LO, StringRef Prefix=StringRef(), StringRef Postfix=StringRef())
static bool compareCrossTUSourceLocs(FullSourceLoc XL, FullSourceLoc YL)
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
C Language Family Type Representation.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__device__ __2f16 b
__device__ int
__device__ __2f16 float __ockl_bool s
SourceLocation getColonLoc() const
Definition: Expr.h:4169
AnalysisDeclContext contains the context data for the function, method or block under analysis.
const Decl * getDecl() const
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3840
SourceLocation getOperatorLoc() const
Definition: Expr.h:3881
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
Definition: CFG.h:417
const Stmt * getTriggerStmt() const
Definition: CFG.h:427
Represents a single basic block in a source-level CFG.
Definition: CFG.h:604
CFGTerminator getTerminator() const
Definition: CFG.h:1079
CFG * getParent() const
Definition: CFG.h:1107
Stmt * getTerminatorCondition(bool StripParens=true)
Definition: CFG.cpp:6263
Represents C++ object destructor generated from a call to delete.
Definition: CFG.h:442
const CXXDeleteExpr * getDeleteExpr() const
Definition: CFG.h:452
Represents a top-level expression in a basic block.
Definition: CFG.h:55
@ CleanupFunction
Definition: CFG.h:79
@ LifetimeEnds
Definition: CFG.h:63
@ CXXRecordTypedCall
Definition: CFG.h:68
@ AutomaticObjectDtor
Definition: CFG.h:72
@ TemporaryDtor
Definition: CFG.h:76
@ NewAllocator
Definition: CFG.h:62
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type.
Definition: CFG.h:99
Kind getKind() const
Definition: CFG.h:118
Represents C++ base or member initializer from constructor's initialization list.
Definition: CFG.h:227
Represents C++ allocator call.
Definition: CFG.h:247
const CXXNewExpr * getAllocatorExpr() const
Definition: CFG.h:253
const Stmt * getStmt() const
Definition: CFG.h:138
Represents C++ object destructor implicitly generated at the end of full expression for temporary obj...
Definition: CFG.h:510
bool isVirtualBaseBranch() const
Definition: CFG.h:573
CFGBlock & getEntry()
Definition: CFG.h:1322
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents a point when we begin processing an inlined call.
Definition: ProgramPoint.h:628
const StackFrameContext * getCalleeContext() const
Definition: ProgramPoint.h:638
Represents a point when we start the call exit sequence (for inlined call).
Definition: ProgramPoint.h:666
Represents a point when we finish the call exit sequence (for inlined call).
Definition: ProgramPoint.h:686
const StackFrameContext * getCalleeContext() const
Definition: ProgramPoint.h:693
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1606
SourceLocation getLBracLoc() const
Definition: Stmt.h:1738
SourceLocation getRBracLoc() const
Definition: Stmt.h:1739
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4179
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:441
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition: DeclBase.h:1076
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
Definition: DeclBase.cpp:1068
SourceLocation getLocation() const
Definition: DeclBase.h:445
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:437
StringRef getName() const
The name of this FileEntry.
Definition: FileEntry.h:61
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isInvalid() const
A SourceLocation and its associated SourceManager.
FullSourceLoc getExpansionLoc() const
FullSourceLoc getSpellingLoc() const
FileID getFileID() const
std::pair< FileID, unsigned > getDecomposedLoc() const
Decompose the specified location into a raw FileID + Offset pair.
const SourceManager & getManager() const
bool isBeforeInTranslationUnitThan(SourceLocation Loc) const
Determines the order of 2 source locations in the translation unit.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
const Decl * getDecl() const
LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3172
SourceLocation getMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'.
Definition: Expr.h:3361
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:1798
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
Represents a program point just after an implicit call event.
Definition: ProgramPoint.h:597
Represents a point after we ran remove dead bindings AFTER processing the given statement.
Definition: ProgramPoint.h:484
Represents a program point just before an implicit call event.
Definition: ProgramPoint.h:579
const LocationContext * getLocationContext() const
Definition: ProgramPoint.h:175
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3019
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
bool isValid() const
It represents a stack frame of the call stack (based on CallEvent).
const CFGBlock * getCallSiteBlock() const
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
A template argument list.
Definition: DeclTemplate.h:244
Represents a template argument.
Definition: TemplateBase.h:61
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Definition: TemplateBase.h:444
void print(const PrintingPolicy &Policy, raw_ostream &Out, bool IncludeType) const
Print this template argument to the given output stream.
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
void setCallee(const CallEnter &CE, const SourceManager &SM)
std::shared_ptr< PathDiagnosticEventPiece > getCallExitEvent() const
static std::shared_ptr< PathDiagnosticCallPiece > construct(const CallExitEnd &CE, const SourceManager &SM)
std::shared_ptr< PathDiagnosticEventPiece > getCallEnterWithinCallerEvent() const
void Profile(llvm::FoldingSetNodeID &ID) const override
std::shared_ptr< PathDiagnosticEventPiece > getCallEnterEvent() const
PathDiagnosticLocation callEnterWithin
PDFileEntry::ConsumerFiles * getFiles(const PathDiagnostic &PD)
void addDiagnostic(const PathDiagnostic &PD, StringRef ConsumerName, StringRef fileName)
std::vector< std::pair< StringRef, StringRef > > ConsumerFiles
ConsumerFiles files
A vector of <consumer,file> pairs.
virtual void FlushDiagnosticsImpl(std::vector< const PathDiagnostic * > &Diags, FilesMade *filesMade)=0
virtual bool supportsCrossFileDiagnostics() const
Return true if the PathDiagnosticConsumer supports individual PathDiagnostics that span multiple file...
void HandlePathDiagnostic(std::unique_ptr< PathDiagnostic > D)
llvm::FoldingSet< PathDiagnostic > Diags
void FlushDiagnostics(FilesMade *FilesMade)
PathDiagnosticLocation getStartLocation() const
PathDiagnosticLocation getEndLocation() const
void Profile(llvm::FoldingSetNodeID &ID) const override
static PathDiagnosticLocation createMemberLoc(const MemberExpr *ME, const SourceManager &SM)
For member expressions, return the location of the '.
static PathDiagnosticLocation createDeclBegin(const LocationContext *LC, const SourceManager &SM)
Create a location for the beginning of the enclosing declaration body.
void Profile(llvm::FoldingSetNodeID &ID) const
static PathDiagnosticLocation createOperatorLoc(const BinaryOperator *BO, const SourceManager &SM)
Create the location for the operator of the binary expression.
static PathDiagnosticLocation createEndBrace(const CompoundStmt *CS, const SourceManager &SM)
Create a location for the end of the compound statement.
static PathDiagnosticLocation createBeginBrace(const CompoundStmt *CS, const SourceManager &SM)
Create a location for the beginning of the compound statement.
static SourceLocation getValidSourceLocation(const Stmt *S, LocationOrAnalysisDeclContext LAC, bool UseEndOfStatement=false)
Construct a source location that corresponds to either the beginning or the end of the given statemen...
static PathDiagnosticLocation createEnd(const Stmt *S, const SourceManager &SM, const LocationOrAnalysisDeclContext LAC)
Create a location for the end of the statement.
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
static PathDiagnosticLocation create(const Decl *D, const SourceManager &SM)
Create a location corresponding to the given declaration.
static PathDiagnosticLocation createConditionalColonLoc(const ConditionalOperator *CO, const SourceManager &SM)
static PathDiagnosticLocation createDeclEnd(const LocationContext *LC, const SourceManager &SM)
Constructs a location for the end of the enclosing declaration body.
static PathDiagnosticLocation createSingleLocation(const PathDiagnosticLocation &PDL)
Convert the given location into a single kind location.
void Profile(llvm::FoldingSetNodeID &ID) const override
void Profile(llvm::FoldingSetNodeID &ID) const override
ArrayRef< SourceRange > getRanges() const
Return the SourceRanges associated with this PathDiagnosticPiece.
virtual PathDiagnosticLocation getLocation() const =0
virtual void Profile(llvm::FoldingSetNodeID &ID) const
void Profile(llvm::FoldingSetNodeID &ID) const override
void Profile(llvm::FoldingSetNodeID &ID) const override
PathDiagnostic - PathDiagnostic objects represent a single path-sensitive diagnostic.
meta_iterator meta_end() const
void FullProfile(llvm::FoldingSetNodeID &ID) const
Profiles the diagnostic, including its path.
PathDiagnosticLocation getUniqueingLoc() const
Get the location on which the report should be uniqued.
std::deque< std::string >::const_iterator meta_iterator
StringRef getVerboseDescription() const
const Decl * getDeclWithIssue() const
Return the semantic context where an issue occurred.
void Profile(llvm::FoldingSetNodeID &ID) const
Profiles the diagnostic, independent of the path it references.
unsigned full_size()
Return the unrolled size of the path.
StringRef getBugType() const
const Decl * getUniqueingDecl() const
Get the declaration containing the uniqueing location.
StringRef getCategory() const
StringRef getShortDescription() const
meta_iterator meta_begin() const
PathDiagnosticLocation getLocation() const
A Range represents the closed range [from, to].
llvm::PointerUnion< const LocationContext *, AnalysisDeclContext * > LocationOrAnalysisDeclContext
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57