clang 23.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"
21#include "clang/AST/ParentMap.h"
23#include "clang/AST/Stmt.h"
24#include "clang/AST/Type.h"
26#include "clang/Analysis/CFG.h"
29#include "clang/Basic/LLVM.h"
32#include "llvm/ADT/ArrayRef.h"
33#include "llvm/ADT/FoldingSet.h"
34#include "llvm/ADT/STLExtras.h"
35#include "llvm/ADT/StringExtras.h"
36#include "llvm/ADT/StringRef.h"
37#include "llvm/Support/ErrorHandling.h"
38#include "llvm/Support/raw_ostream.h"
39#include <cassert>
40#include <cstring>
41#include <memory>
42#include <optional>
43#include <utility>
44#include <vector>
45
46using namespace clang;
47using namespace ento;
48
49static StringRef StripTrailingDots(StringRef s) { return s.rtrim('.'); }
50
52 Kind k, DisplayHint hint)
53 : str(StripTrailingDots(s)), kind(k), Hint(hint) {}
54
56 : kind(k), Hint(hint) {}
57
59
61
63
65
67
69
71
72void PathPieces::flattenTo(PathPieces &Primary, PathPieces &Current,
73 bool ShouldFlattenMacros) const {
74 for (auto &Piece : *this) {
75 switch (Piece->getKind()) {
77 auto &Call = cast<PathDiagnosticCallPiece>(*Piece);
78 if (auto CallEnter = Call.getCallEnterEvent())
79 Current.push_back(std::move(CallEnter));
80 Call.path.flattenTo(Primary, Primary, ShouldFlattenMacros);
81 if (auto callExit = Call.getCallExitEvent())
82 Current.push_back(std::move(callExit));
83 break;
84 }
87 if (ShouldFlattenMacros) {
88 Macro.subPieces.flattenTo(Primary, Primary, ShouldFlattenMacros);
89 } else {
90 Current.push_back(Piece);
91 PathPieces NewPath;
92 Macro.subPieces.flattenTo(Primary, NewPath, ShouldFlattenMacros);
93 // FIXME: This probably shouldn't mutate the original path piece.
94 Macro.subPieces = NewPath;
95 }
96 break;
97 }
102 Current.push_back(Piece);
103 break;
104 }
105 }
106}
107
109
111 StringRef CheckerName, const Decl *declWithIssue, StringRef bugtype,
112 StringRef verboseDesc, StringRef shortDesc, StringRef category,
113 PathDiagnosticLocation LocationToUnique, const Decl *DeclToUnique,
114 const Decl *AnalysisEntryPoint,
115 std::unique_ptr<FilesToLineNumsMap> ExecutedLines)
116 : CheckerName(CheckerName), DeclWithIssue(declWithIssue),
117 BugType(StripTrailingDots(bugtype)),
118 VerboseDesc(StripTrailingDots(verboseDesc)),
119 ShortDesc(StripTrailingDots(shortDesc)),
120 Category(StripTrailingDots(category)), UniqueingLoc(LocationToUnique),
121 UniqueingDecl(DeclToUnique), AnalysisEntryPoint(AnalysisEntryPoint),
122 ExecutedLines(std::move(ExecutedLines)), path(pathImpl) {
123 assert(AnalysisEntryPoint);
124}
125
126void PathDiagnosticConsumer::anchor() {}
127
129 // Delete the contents of the FoldingSet if it isn't empty already.
130 for (auto &Diag : Diags)
131 delete &Diag;
132}
133
135 std::unique_ptr<PathDiagnostic> D) {
136 if (!D || D->path.empty())
137 return;
138
139 // We need to flatten the locations (convert Stmt* to locations) because
140 // the referenced statements may be freed by the time the diagnostics
141 // are emitted.
142 D->flattenLocations();
143
144 // If the PathDiagnosticConsumer does not support diagnostics that
145 // cross file boundaries, prune out such diagnostics now.
147 // Verify that the entire path is from the same FileID.
148 FileID FID;
149 const SourceManager &SMgr = D->path.front()->getLocation().getManager();
151 WorkList.push_back(&D->path);
153 llvm::raw_svector_ostream warning(buf);
154 warning << "warning: Path diagnostic report is not generated. Current "
155 << "output format does not support diagnostics that cross file "
156 << "boundaries. Refer to --analyzer-output for valid output "
157 << "formats\n";
158
159 while (!WorkList.empty()) {
160 const PathPieces &path = *WorkList.pop_back_val();
161
162 for (const auto &I : path) {
163 const PathDiagnosticPiece *piece = I.get();
165
166 if (FID.isInvalid()) {
167 FID = SMgr.getFileID(L);
168 } else if (SMgr.getFileID(L) != FID) {
169 llvm::errs() << warning.str();
170 return;
171 }
172
173 // Check the source ranges.
174 ArrayRef<SourceRange> Ranges = piece->getRanges();
175 for (const auto &I : Ranges) {
176 SourceLocation L = SMgr.getExpansionLoc(I.getBegin());
177 if (!L.isFileID() || SMgr.getFileID(L) != FID) {
178 llvm::errs() << warning.str();
179 return;
180 }
181 L = SMgr.getExpansionLoc(I.getEnd());
182 if (!L.isFileID() || SMgr.getFileID(L) != FID) {
183 llvm::errs() << warning.str();
184 return;
185 }
186 }
187
188 if (const auto *call = dyn_cast<PathDiagnosticCallPiece>(piece))
189 WorkList.push_back(&call->path);
190 else if (const auto *macro = dyn_cast<PathDiagnosticMacroPiece>(piece))
191 WorkList.push_back(&macro->subPieces);
192 }
193 }
194
195 if (FID.isInvalid())
196 return; // FIXME: Emit a warning?
197 }
198
199 // Profile the node to see if we already have something matching it
200 llvm::FoldingSetNodeID profile;
201 D->Profile(profile);
202 void *InsertPos = nullptr;
203
204 if (PathDiagnostic *orig = Diags.FindNodeOrInsertPos(profile, InsertPos)) {
205 // Keep the PathDiagnostic with the shorter path.
206 // Note, the enclosing routine is called in deterministic order, so the
207 // results will be consistent between runs (no reason to break ties if the
208 // size is the same).
209 const unsigned orig_size = orig->full_size();
210 const unsigned new_size = D->full_size();
211 if (orig_size <= new_size)
212 return;
213
214 assert(orig != D.get());
215 Diags.RemoveNode(orig);
216 delete orig;
217 }
218
219 Diags.InsertNode(D.release());
220}
221
222static std::optional<bool> comparePath(const PathPieces &X,
223 const PathPieces &Y);
224
225static std::optional<bool>
228 FullSourceLoc XSL = X.getStartLocation().asLocation();
230 if (XSL != YSL)
231 return XSL.isBeforeInTranslationUnitThan(YSL);
232 FullSourceLoc XEL = X.getEndLocation().asLocation();
234 if (XEL != YEL)
235 return XEL.isBeforeInTranslationUnitThan(YEL);
236 return std::nullopt;
237}
238
239static std::optional<bool> compareMacro(const PathDiagnosticMacroPiece &X,
240 const PathDiagnosticMacroPiece &Y) {
241 return comparePath(X.subPieces, Y.subPieces);
242}
243
244static std::optional<bool> compareCall(const PathDiagnosticCallPiece &X,
245 const PathDiagnosticCallPiece &Y) {
246 FullSourceLoc X_CEL = X.callEnter.asLocation();
248 if (X_CEL != Y_CEL)
249 return X_CEL.isBeforeInTranslationUnitThan(Y_CEL);
250 FullSourceLoc X_CEWL = X.callEnterWithin.asLocation();
252 if (X_CEWL != Y_CEWL)
253 return X_CEWL.isBeforeInTranslationUnitThan(Y_CEWL);
254 FullSourceLoc X_CRL = X.callReturn.asLocation();
256 if (X_CRL != Y_CRL)
257 return X_CRL.isBeforeInTranslationUnitThan(Y_CRL);
258 return comparePath(X.path, Y.path);
259}
260
261static std::optional<bool> comparePiece(const PathDiagnosticPiece &X,
262 const PathDiagnosticPiece &Y) {
263 if (X.getKind() != Y.getKind())
264 return X.getKind() < Y.getKind();
265
266 FullSourceLoc XL = X.getLocation().asLocation();
268 if (XL != YL)
269 return XL.isBeforeInTranslationUnitThan(YL);
270
271 if (X.getString() != Y.getString())
272 return X.getString() < Y.getString();
273
274 if (X.getRanges().size() != Y.getRanges().size())
275 return X.getRanges().size() < Y.getRanges().size();
276
277 const SourceManager &SM = XL.getManager();
278
279 for (unsigned i = 0, n = X.getRanges().size(); i < n; ++i) {
280 SourceRange XR = X.getRanges()[i];
281 SourceRange YR = Y.getRanges()[i];
282 if (XR != YR) {
283 if (XR.getBegin() != YR.getBegin())
284 return SM.isBeforeInTranslationUnit(XR.getBegin(), YR.getBegin());
285 return SM.isBeforeInTranslationUnit(XR.getEnd(), YR.getEnd());
286 }
287 }
288
289 switch (X.getKind()) {
302 return std::nullopt;
303 }
304 llvm_unreachable("all cases handled");
305}
306
307static std::optional<bool> comparePath(const PathPieces &X,
308 const PathPieces &Y) {
309 if (X.size() != Y.size())
310 return X.size() < Y.size();
311
312 PathPieces::const_iterator X_I = X.begin(), X_end = X.end();
313 PathPieces::const_iterator Y_I = Y.begin(), Y_end = Y.end();
314
315 for (; X_I != X_end && Y_I != Y_end; ++X_I, ++Y_I)
316 if (std::optional<bool> b = comparePiece(**X_I, **Y_I))
317 return *b;
318
319 return std::nullopt;
320}
321
323 if (XL.isInvalid() && YL.isValid())
324 return true;
325 if (XL.isValid() && YL.isInvalid())
326 return false;
329 const SourceManager &SM = XL.getManager();
330 std::pair<bool, bool> InSameTU = SM.isInTheSameTranslationUnit(XOffs, YOffs);
331 if (InSameTU.first)
332 return XL.isBeforeInTranslationUnitThan(YL);
334 SM.getFileEntryRefForID(XL.getSpellingLoc().getFileID());
336 SM.getFileEntryRefForID(YL.getSpellingLoc().getFileID());
337 if (!XFE || !YFE)
338 return XFE && !YFE;
339 int NameCmp = XFE->getName().compare(YFE->getName());
340 if (NameCmp != 0)
341 return NameCmp < 0;
342 // Last resort: Compare raw file IDs that are possibly expansions.
343 return XL.getFileID() < YL.getFileID();
344}
345
346static bool compare(const PathDiagnostic &X, const PathDiagnostic &Y) {
347 FullSourceLoc XL = X.getLocation().asLocation();
349 if (XL != YL)
350 return compareCrossTUSourceLocs(XL, YL);
351 FullSourceLoc XUL = X.getUniqueingLoc().asLocation();
353 if (XUL != YUL)
354 return compareCrossTUSourceLocs(XUL, YUL);
355 if (X.getBugType() != Y.getBugType())
356 return X.getBugType() < Y.getBugType();
357 if (X.getCategory() != Y.getCategory())
358 return X.getCategory() < Y.getCategory();
359 if (X.getVerboseDescription() != Y.getVerboseDescription())
360 return X.getVerboseDescription() < Y.getVerboseDescription();
361 if (X.getShortDescription() != Y.getShortDescription())
362 return X.getShortDescription() < Y.getShortDescription();
363 auto CompareDecls = [&XL](const Decl *D1,
364 const Decl *D2) -> std::optional<bool> {
365 if (D1 == D2)
366 return std::nullopt;
367 if (!D1)
368 return true;
369 if (!D2)
370 return false;
371 SourceLocation D1L = D1->getLocation();
372 SourceLocation D2L = D2->getLocation();
373 if (D1L != D2L) {
374 const SourceManager &SM = XL.getManager();
376 FullSourceLoc(D2L, SM));
377 }
378 return std::nullopt;
379 };
380 if (auto Result = CompareDecls(X.getDeclWithIssue(), Y.getDeclWithIssue()))
381 return *Result;
382 if (XUL.isValid()) {
383 if (auto Result = CompareDecls(X.getUniqueingDecl(), Y.getUniqueingDecl()))
384 return *Result;
385 }
386 PathDiagnostic::meta_iterator XI = X.meta_begin(), XE = X.meta_end();
388 if (XE - XI != YE - YI)
389 return (XE - XI) < (YE - YI);
390 for ( ; XI != XE ; ++XI, ++YI) {
391 if (*XI != *YI)
392 return (*XI) < (*YI);
393 }
394 return *comparePath(X.path, Y.path);
395}
396
399 if (flushed)
400 return;
401
402 flushed = true;
403
404 std::vector<const PathDiagnostic *> BatchDiags;
405 for (const auto &D : Diags)
406 BatchDiags.push_back(&D);
407
408 // Sort the diagnostics so that they are always emitted in a deterministic
409 // order.
410 int (*Comp)(const PathDiagnostic *const *, const PathDiagnostic *const *) =
411 [](const PathDiagnostic *const *X, const PathDiagnostic *const *Y) {
412 assert(*X != *Y && "PathDiagnostics not uniqued!");
413 if (compare(**X, **Y))
414 return -1;
415 assert(compare(**Y, **X) && "Not a total order!");
416 return 1;
417 };
418 array_pod_sort(BatchDiags.begin(), BatchDiags.end(), Comp);
419
420 FlushDiagnosticsImpl(BatchDiags, Files);
421
422 // Delete the flushed diagnostics.
423 for (const auto D : BatchDiags)
424 delete D;
425
426 // Clear out the FoldingSet.
427 Diags.clear();
428}
429
431 for (auto It = Set.begin(); It != Set.end();)
432 (It++)->~PDFileEntry();
433}
434
436 StringRef ConsumerName,
437 StringRef FileName) {
438 llvm::FoldingSetNodeID NodeID;
439 NodeID.Add(PD);
440 void *InsertPos;
441 PDFileEntry *Entry = Set.FindNodeOrInsertPos(NodeID, InsertPos);
442 if (!Entry) {
443 Entry = Alloc.Allocate<PDFileEntry>();
444 Entry = new (Entry) PDFileEntry(NodeID);
445 Set.InsertNode(Entry, InsertPos);
446 }
447
448 // Allocate persistent storage for the file name.
449 char *FileName_cstr = (char*) Alloc.Allocate(FileName.size(), 1);
450 memcpy(FileName_cstr, FileName.data(), FileName.size());
451
452 Entry->files.push_back(std::make_pair(ConsumerName,
453 StringRef(FileName_cstr,
454 FileName.size())));
455}
456
459 llvm::FoldingSetNodeID NodeID;
460 NodeID.Add(PD);
461 void *InsertPos;
462 PDFileEntry *Entry = Set.FindNodeOrInsertPos(NodeID, InsertPos);
463 if (!Entry)
464 return nullptr;
465 return &Entry->files;
466}
467
468//===----------------------------------------------------------------------===//
469// PathDiagnosticLocation methods.
470//===----------------------------------------------------------------------===//
471
474 bool UseEndOfStatement) {
475 SourceLocation L = UseEndOfStatement ? S->getEndLoc() : S->getBeginLoc();
476 assert(!SFAC.isNull() &&
477 "A valid StackFrame or AnalysisDeclContext should be passed to "
478 "PathDiagnosticLocation upon creation.");
479
480 // S might be a temporary statement that does not have a location in the
481 // source code, so find an enclosing statement and use its location.
482 if (!L.isValid()) {
484 if (auto *SF = dyn_cast<const StackFrame *>(SFAC))
485 ADC = SF->getAnalysisDeclContext();
486 else
487 ADC = cast<AnalysisDeclContext *>(SFAC);
488
489 ParentMap &PM = ADC->getParentMap();
490
491 const Stmt *Parent = S;
492 do {
493 Parent = PM.getParent(Parent);
494
495 // In rare cases, we have implicit top-level expressions,
496 // such as arguments for implicit member initializers.
497 // In this case, fall back to the start of the body (even if we were
498 // asked for the statement end location).
499 if (!Parent) {
500 const Stmt *Body = ADC->getBody();
501 if (Body)
502 L = Body->getBeginLoc();
503 else
504 L = ADC->getDecl()->getEndLoc();
505 break;
506 }
507
508 L = UseEndOfStatement ? Parent->getEndLoc() : Parent->getBeginLoc();
509 } while (!L.isValid());
510 }
511
512 // FIXME: Ironically, this assert actually fails in some cases.
513 //assert(L.isValid());
514 return L;
515}
516
518 const StackFrame *CallerSF,
519 const SourceManager &SM) {
520 const CFGBlock &Block = *SF->getCallSiteBlock();
521 CFGElement Source = Block[SF->getIndex()];
522
523 switch (Source.getKind()) {
527 return PathDiagnosticLocation(Source.castAs<CFGStmt>().getStmt(), SM,
528 CallerSF);
530 const CFGInitializer &Init = Source.castAs<CFGInitializer>();
531 return PathDiagnosticLocation(Init.getInitializer()->getInit(), SM,
532 CallerSF);
533 }
535 const CFGAutomaticObjDtor &Dtor = Source.castAs<CFGAutomaticObjDtor>();
537 CallerSF);
538 }
540 const CFGDeleteDtor &Dtor = Source.castAs<CFGDeleteDtor>();
541 return PathDiagnosticLocation(Dtor.getDeleteExpr(), SM, CallerSF);
542 }
545 const AnalysisDeclContext *CallerInfo = CallerSF->getAnalysisDeclContext();
546 if (const Stmt *CallerBody = CallerInfo->getBody())
547 return PathDiagnosticLocation::createEnd(CallerBody, SM, CallerSF);
548 return PathDiagnosticLocation::create(CallerInfo->getDecl(), SM);
549 }
551 const CFGNewAllocator &Alloc = Source.castAs<CFGNewAllocator>();
552 return PathDiagnosticLocation(Alloc.getAllocatorExpr(), SM, CallerSF);
553 }
555 // Temporary destructors are for temporaries. They die immediately at around
556 // the location of CXXBindTemporaryExpr. If they are lifetime-extended,
557 // they'd be dealt with via an AutomaticObjectDtor instead.
558 const auto &Dtor = Source.castAs<CFGTemporaryDtor>();
559 return PathDiagnosticLocation::createEnd(Dtor.getBindTemporaryExpr(), SM,
560 CallerSF);
561 }
565 llvm_unreachable("not yet implemented!");
569 llvm_unreachable("CFGElement kind should not be on callsite!");
570 }
571
572 llvm_unreachable("Unknown CFGElement kind");
573}
574
575PathDiagnosticLocation
577 const SourceManager &SM) {
578 return PathDiagnosticLocation(D->getBeginLoc(), SM, SingleLocK);
579}
580
584 assert(S && "Statement cannot be null");
585 return PathDiagnosticLocation(getValidSourceLocation(S, SFAC), SM,
586 SingleLocK);
587}
588
592 if (const auto *CS = dyn_cast<CompoundStmt>(S))
593 return createEndBrace(CS, SM);
594 return PathDiagnosticLocation(getValidSourceLocation(S, SFAC, /*End=*/true),
595 SM, SingleLocK);
596}
597
600 const SourceManager &SM) {
601 return PathDiagnosticLocation(BO->getOperatorLoc(), SM, SingleLocK);
602}
603
606 const ConditionalOperator *CO,
607 const SourceManager &SM) {
608 return PathDiagnosticLocation(CO->getColonLoc(), SM, SingleLocK);
609}
610
613 const SourceManager &SM) {
614
615 assert(ME->getMemberLoc().isValid() || ME->getBeginLoc().isValid());
616
617 // In some cases, getMemberLoc isn't valid -- in this case we'll return with
618 // some other related valid SourceLocation.
619 if (ME->getMemberLoc().isValid())
620 return PathDiagnosticLocation(ME->getMemberLoc(), SM, SingleLocK);
621
622 return PathDiagnosticLocation(ME->getBeginLoc(), SM, SingleLocK);
623}
624
627 const SourceManager &SM) {
628 SourceLocation L = CS->getLBracLoc();
629 return PathDiagnosticLocation(L, SM, SingleLocK);
630}
631
634 const SourceManager &SM) {
635 SourceLocation L = CS->getRBracLoc();
636 return PathDiagnosticLocation(L, SM, SingleLocK);
637}
638
641 const SourceManager &SM) {
642 // FIXME: Should handle CXXTryStmt if analyser starts supporting C++.
643 if (const auto *CS = dyn_cast_or_null<CompoundStmt>(SF->getDecl()->getBody()))
644 if (!CS->body_empty()) {
645 SourceLocation Loc = (*CS->body_begin())->getBeginLoc();
646 return PathDiagnosticLocation(Loc, SM, SingleLocK);
647 }
648
649 return PathDiagnosticLocation();
650}
651
654 const SourceManager &SM) {
656 return PathDiagnosticLocation(L, SM, SingleLocK);
657}
658
661 const SourceManager &SMng) {
662 const Stmt* S = nullptr;
663 if (std::optional<BlockEdge> BE = P.getAs<BlockEdge>()) {
664 const CFGBlock *BSrc = BE->getSrc();
665 if (BSrc->getTerminator().isVirtualBaseBranch()) {
666 // TODO: VirtualBaseBranches should also appear for destructors.
667 // In this case we should put the diagnostic at the end of decl.
669 SMng);
670
671 } else {
672 S = BSrc->getTerminatorCondition();
673 if (!S) {
674 // If the BlockEdge has no terminator condition statement but its
675 // source is the entry of the CFG (e.g. a checker crated the branch at
676 // the beginning of a function), use the function's declaration instead.
677 assert(BSrc == &BSrc->getParent()->getEntry() && "CFGBlock has no "
678 "TerminatorCondition and is not the enrty block of the CFG");
680 SMng);
681 }
682 }
683 } else if (std::optional<StmtPoint> SP = P.getAs<StmtPoint>()) {
684 S = SP->getStmt();
687 } else if (std::optional<PostInitializer> PIP = P.getAs<PostInitializer>()) {
688 return PathDiagnosticLocation(PIP->getInitializer()->getSourceLocation(),
689 SMng);
690 } else if (std::optional<PreImplicitCall> PIC = P.getAs<PreImplicitCall>()) {
691 return PathDiagnosticLocation(PIC->getLocation(), SMng);
692 } else if (std::optional<PostImplicitCall> PIE =
693 P.getAs<PostImplicitCall>()) {
694 return PathDiagnosticLocation(PIE->getLocation(), SMng);
695 } else if (std::optional<CallEnter> CE = P.getAs<CallEnter>()) {
696 return getLocationForCaller(CE->getCalleeStackFrame(), CE->getStackFrame(),
697 SMng);
698 } else if (std::optional<CallExitEnd> CEE = P.getAs<CallExitEnd>()) {
699 return getLocationForCaller(CEE->getCalleeStackFrame(),
700 CEE->getStackFrame(), SMng);
701 } else if (auto CEB = P.getAs<CallExitBegin>()) {
702 if (const ReturnStmt *RS = CEB->getReturnStmt())
704 CEB->getStackFrame());
705 return PathDiagnosticLocation(
706 CEB->getStackFrame()->getDecl()->getSourceRange().getEnd(), SMng);
707 } else if (std::optional<BlockEntrance> BE = P.getAs<BlockEntrance>()) {
708 if (std::optional<CFGElement> BlockFront = BE->getFirstElement()) {
709 if (auto StmtElt = BlockFront->getAs<CFGStmt>()) {
710 return PathDiagnosticLocation(StmtElt->getStmt()->getBeginLoc(), SMng);
711 } else if (auto NewAllocElt = BlockFront->getAs<CFGNewAllocator>()) {
712 return PathDiagnosticLocation(
713 NewAllocElt->getAllocatorExpr()->getBeginLoc(), SMng);
714 }
715 llvm_unreachable("Unexpected CFG element at front of block");
716 }
717
718 return PathDiagnosticLocation(
719 BE->getBlock()->getTerminatorStmt()->getBeginLoc(), SMng);
720 } else if (std::optional<FunctionExitPoint> FE =
722 return PathDiagnosticLocation(FE->getStmt(), SMng, FE->getStackFrame());
723 } else {
724 llvm_unreachable("Unexpected ProgramPoint");
725 }
726
727 return PathDiagnosticLocation(S, SMng, P.getStackFrame());
728}
729
731 const PathDiagnosticLocation &PDL) {
732 FullSourceLoc L = PDL.asLocation();
733 return PathDiagnosticLocation(L, L.getManager(), SingleLocK);
734}
735
736FullSourceLoc PathDiagnosticLocation::genLocation(
738 assert(isValid());
739 // Note that we want a 'switch' here so that the compiler can warn us in
740 // case we add more cases.
741 switch (K) {
742 case SingleLocK:
743 case RangeK:
744 break;
745 case StmtK:
746 // Defensive checking.
747 if (!S)
748 break;
749 return FullSourceLoc(getValidSourceLocation(S, SFAC),
750 const_cast<SourceManager &>(*SM));
751 case DeclK:
752 // Defensive checking.
753 if (!D)
754 break;
755 return FullSourceLoc(D->getLocation(), const_cast<SourceManager&>(*SM));
756 }
757
758 return FullSourceLoc(L, const_cast<SourceManager&>(*SM));
759}
760
762PathDiagnosticLocation::genRange(StackFrameOrAnalysisDeclContext SFAC) const {
763 assert(isValid());
764 // Note that we want a 'switch' here so that the compiler can warn us in
765 // case we add more cases.
766 switch (K) {
767 case SingleLocK:
768 return PathDiagnosticRange(SourceRange(Loc,Loc), true);
769 case RangeK:
770 break;
771 case StmtK: {
772 const Stmt *S = asStmt();
773 switch (S->getStmtClass()) {
774 default:
775 break;
776 case Stmt::DeclStmtClass: {
777 const auto *DS = cast<DeclStmt>(S);
778 if (DS->isSingleDecl()) {
779 // Should always be the case, but we'll be defensive.
780 return SourceRange(DS->getBeginLoc(),
781 DS->getSingleDecl()->getLocation());
782 }
783 break;
784 }
785 // FIXME: Provide better range information for different
786 // terminators.
787 case Stmt::IfStmtClass:
788 case Stmt::WhileStmtClass:
789 case Stmt::DoStmtClass:
790 case Stmt::ForStmtClass:
791 case Stmt::ChooseExprClass:
792 case Stmt::IndirectGotoStmtClass:
793 case Stmt::SwitchStmtClass:
794 case Stmt::BinaryConditionalOperatorClass:
795 case Stmt::ConditionalOperatorClass:
796 case Stmt::ObjCForCollectionStmtClass: {
797 SourceLocation L = getValidSourceLocation(S, SFAC);
798 return SourceRange(L, L);
799 }
800 }
801 SourceRange R = S->getSourceRange();
802 if (R.isValid())
803 return R;
804 break;
805 }
806 case DeclK:
807 if (const auto *MD = dyn_cast<ObjCMethodDecl>(D))
808 return MD->getSourceRange();
809 if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
810 if (Stmt *Body = FD->getBody())
811 return Body->getSourceRange();
812 }
813 else {
814 SourceLocation L = D->getLocation();
815 return PathDiagnosticRange(SourceRange(L, L), true);
816 }
817 }
818
819 return SourceRange(Loc, Loc);
820}
821
823 if (K == StmtK) {
824 K = RangeK;
825 S = nullptr;
826 D = nullptr;
827 }
828 else if (K == DeclK) {
829 K = SingleLocK;
830 S = nullptr;
831 D = nullptr;
832 }
833}
834
835//===----------------------------------------------------------------------===//
836// Manipulation of PathDiagnosticCallPieces.
837//===----------------------------------------------------------------------===//
838
839std::shared_ptr<PathDiagnosticCallPiece>
841 const SourceManager &SM) {
842 const Decl *caller = CE.getStackFrame()->getDecl();
845 return std::shared_ptr<PathDiagnosticCallPiece>(
846 new PathDiagnosticCallPiece(caller, pos));
847}
848
851 const Decl *caller) {
852 std::shared_ptr<PathDiagnosticCallPiece> C(
853 new PathDiagnosticCallPiece(path, caller));
854 path.clear();
855 auto *R = C.get();
856 path.push_front(std::move(C));
857 return R;
858}
859
861 const SourceManager &SM) {
862 const StackFrame *CalleeSF = CE.getCalleeStackFrame();
863 Callee = CalleeSF->getDecl();
864
867
868 // Autosynthesized property accessors are special because we'd never
869 // pop back up to non-autosynthesized code until we leave them.
870 // This is not generally true for autosynthesized callees, which may call
871 // non-autosynthesized callbacks.
872 // Unless set here, the IsCalleeAnAutosynthesizedPropertyAccessor flag
873 // defaults to false.
874 if (const auto *MD = dyn_cast<ObjCMethodDecl>(Callee))
875 IsCalleeAnAutosynthesizedPropertyAccessor =
876 (MD->isPropertyAccessor() &&
878}
879
880static void describeTemplateParameters(raw_ostream &Out,
881 const ArrayRef<TemplateArgument> TAList,
882 const LangOptions &LO,
883 StringRef Prefix = StringRef(),
884 StringRef Postfix = StringRef());
885
886static void describeTemplateParameter(raw_ostream &Out,
887 const TemplateArgument &TArg,
888 const LangOptions &LO) {
889
892 } else {
893 TArg.print(PrintingPolicy(LO), Out, /*IncludeType*/ true);
894 }
895}
896
897static void describeTemplateParameters(raw_ostream &Out,
898 const ArrayRef<TemplateArgument> TAList,
899 const LangOptions &LO,
900 StringRef Prefix, StringRef Postfix) {
901 if (TAList.empty())
902 return;
903
904 Out << Prefix;
905 for (int I = 0, Last = TAList.size() - 1; I != Last; ++I) {
906 describeTemplateParameter(Out, TAList[I], LO);
907 Out << ", ";
908 }
909 describeTemplateParameter(Out, TAList[TAList.size() - 1], LO);
910 Out << Postfix;
911}
912
913static void describeClass(raw_ostream &Out, const CXXRecordDecl *D,
914 StringRef Prefix = StringRef()) {
915 if (!D->getIdentifier())
916 return;
917 Out << Prefix << '\'' << *D;
918 if (const auto T = dyn_cast<ClassTemplateSpecializationDecl>(D))
919 describeTemplateParameters(Out, T->getTemplateArgs().asArray(),
920 D->getLangOpts(), "<", ">");
921
922 Out << '\'';
923}
924
925static bool describeCodeDecl(raw_ostream &Out, const Decl *D,
926 bool ExtendedDescription,
927 StringRef Prefix = StringRef()) {
928 if (!D)
929 return false;
930
931 if (isa<BlockDecl>(D)) {
932 if (ExtendedDescription)
933 Out << Prefix << "anonymous block";
934 return ExtendedDescription;
935 }
936
937 if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
938 Out << Prefix;
939 if (ExtendedDescription && !MD->isUserProvided()) {
940 if (MD->isExplicitlyDefaulted())
941 Out << "defaulted ";
942 else
943 Out << "implicit ";
944 }
945
946 if (const auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
947 if (CD->isDefaultConstructor())
948 Out << "default ";
949 else if (CD->isCopyConstructor())
950 Out << "copy ";
951 else if (CD->isMoveConstructor())
952 Out << "move ";
953
954 Out << "constructor";
955 describeClass(Out, MD->getParent(), " for ");
956 } else if (isa<CXXDestructorDecl>(MD)) {
957 if (!MD->isUserProvided()) {
958 Out << "destructor";
959 describeClass(Out, MD->getParent(), " for ");
960 } else {
961 // Use ~Foo for explicitly-written destructors.
962 Out << "'" << *MD << "'";
963 }
964 } else if (MD->isCopyAssignmentOperator()) {
965 Out << "copy assignment operator";
966 describeClass(Out, MD->getParent(), " for ");
967 } else if (MD->isMoveAssignmentOperator()) {
968 Out << "move assignment operator";
969 describeClass(Out, MD->getParent(), " for ");
970 } else {
971 if (MD->getParent()->getIdentifier())
972 Out << "'" << *MD->getParent() << "::" << *MD << "'";
973 else
974 Out << "'" << *MD << "'";
975 }
976
977 return true;
978 }
979
980 Out << Prefix << '\'' << cast<NamedDecl>(*D);
981
982 // Adding template parameters.
983 if (const auto FD = dyn_cast<FunctionDecl>(D))
984 if (const TemplateArgumentList *TAList =
985 FD->getTemplateSpecializationArgs())
986 describeTemplateParameters(Out, TAList->asArray(), FD->getLangOpts(), "<",
987 ">");
988
989 Out << '\'';
990 return true;
991}
992
993std::shared_ptr<PathDiagnosticEventPiece>
995 // We do not produce call enters and call exits for autosynthesized property
996 // accessors. We do generally produce them for other functions coming from
997 // the body farm because they may call callbacks that bring us back into
998 // visible code.
999 if (!Callee || IsCalleeAnAutosynthesizedPropertyAccessor)
1000 return nullptr;
1001
1002 SmallString<256> buf;
1003 llvm::raw_svector_ostream Out(buf);
1004
1005 Out << "Calling ";
1006 describeCodeDecl(Out, Callee, /*ExtendedDescription=*/true);
1007
1008 assert(callEnter.asLocation().isValid());
1009 return std::make_shared<PathDiagnosticEventPiece>(callEnter, Out.str());
1010}
1011
1012std::shared_ptr<PathDiagnosticEventPiece>
1014 if (!callEnterWithin.asLocation().isValid())
1015 return nullptr;
1016 if (Callee->isImplicit() || !Callee->hasBody())
1017 return nullptr;
1018 if (const auto *MD = dyn_cast<CXXMethodDecl>(Callee))
1019 if (MD->isDefaulted())
1020 return nullptr;
1021
1022 SmallString<256> buf;
1023 llvm::raw_svector_ostream Out(buf);
1024
1025 Out << "Entered call";
1026 describeCodeDecl(Out, Caller, /*ExtendedDescription=*/false, " from ");
1027
1028 return std::make_shared<PathDiagnosticEventPiece>(callEnterWithin, Out.str());
1029}
1030
1031std::shared_ptr<PathDiagnosticEventPiece>
1033 // We do not produce call enters and call exits for autosynthesized property
1034 // accessors. We do generally produce them for other functions coming from
1035 // the body farm because they may call callbacks that bring us back into
1036 // visible code.
1037 if (NoExit || IsCalleeAnAutosynthesizedPropertyAccessor)
1038 return nullptr;
1039
1040 SmallString<256> buf;
1041 llvm::raw_svector_ostream Out(buf);
1042
1043 if (!CallStackMessage.empty()) {
1044 Out << CallStackMessage;
1045 } else {
1046 bool DidDescribe = describeCodeDecl(Out, Callee,
1047 /*ExtendedDescription=*/false,
1048 "Returning from ");
1049 if (!DidDescribe)
1050 Out << "Returning to caller";
1051 }
1052
1053 assert(callReturn.asLocation().isValid());
1054 return std::make_shared<PathDiagnosticEventPiece>(callReturn, Out.str());
1055}
1056
1057static void compute_path_size(const PathPieces &pieces, unsigned &size) {
1058 for (const auto &I : pieces) {
1059 const PathDiagnosticPiece *piece = I.get();
1060 if (const auto *cp = dyn_cast<PathDiagnosticCallPiece>(piece))
1061 compute_path_size(cp->path, size);
1062 else
1063 ++size;
1064 }
1065}
1066
1068 unsigned size = 0;
1069 compute_path_size(path, size);
1070 return size;
1071}
1072
1075 const LangOptions &LangOpts) const {
1077 FullSourceLoc FullLoc(
1078 SrcMgr.getExpansionLoc(UPDLoc.isValid() ? UPDLoc.asLocation()
1079 : getLocation().asLocation()),
1080 SrcMgr);
1081
1082 return clang::getIssueHash(FullLoc, getCheckerName(), getBugType(),
1083 getDeclWithIssue(), LangOpts);
1084}
1085
1086//===----------------------------------------------------------------------===//
1087// FoldingSet profiling methods.
1088//===----------------------------------------------------------------------===//
1089
1090void PathDiagnosticLocation::Profile(llvm::FoldingSetNodeID &ID) const {
1091 ID.Add(Range.getBegin());
1092 ID.Add(Range.getEnd());
1093 ID.Add(static_cast<const SourceLocation &>(Loc));
1094}
1095
1096void PathDiagnosticPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1097 ID.AddInteger((unsigned) getKind());
1098 ID.AddString(str);
1099 // FIXME: Add profiling support for code hints.
1100 ID.AddInteger((unsigned) getDisplayHint());
1102 for (const auto &I : Ranges) {
1103 ID.Add(I.getBegin());
1104 ID.Add(I.getEnd());
1105 }
1106}
1107
1108void PathDiagnosticCallPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1110 for (const auto &I : path)
1111 ID.Add(*I);
1112}
1113
1114void PathDiagnosticSpotPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1116 ID.Add(Pos);
1117}
1118
1119void PathDiagnosticControlFlowPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1121 for (const auto &I : *this)
1122 ID.Add(I);
1123}
1124
1125void PathDiagnosticMacroPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1127 for (const auto &I : subPieces)
1128 ID.Add(*I);
1129}
1130
1131void PathDiagnosticNotePiece::Profile(llvm::FoldingSetNodeID &ID) const {
1133}
1134
1135void PathDiagnosticPopUpPiece::Profile(llvm::FoldingSetNodeID &ID) const {
1137}
1138
1139void PathDiagnostic::Profile(llvm::FoldingSetNodeID &ID) const {
1140 ID.Add(getLocation());
1141 ID.Add(getUniqueingLoc());
1142 ID.AddString(BugType);
1143 ID.AddString(VerboseDesc);
1144 ID.AddString(Category);
1145}
1146
1147void PathDiagnostic::FullProfile(llvm::FoldingSetNodeID &ID) const {
1148 Profile(ID);
1149 for (const auto &I : path)
1150 ID.Add(*I);
1151 for (meta_iterator I = meta_begin(), E = meta_end(); I != E; ++I)
1152 ID.AddString(*I);
1153}
1154
1155LLVM_DUMP_METHOD void PathPieces::dump() const {
1156 unsigned index = 0;
1157 for (const PathDiagnosticPieceRef &Piece : *this) {
1158 llvm::errs() << "[" << index++ << "] ";
1159 Piece->dump();
1160 llvm::errs() << "\n";
1161 }
1162}
1163
1164LLVM_DUMP_METHOD void PathDiagnosticCallPiece::dump() const {
1165 llvm::errs() << "CALL\n--------------\n";
1166
1167 if (const Stmt *SLoc = getLocation().getStmtOrNull())
1168 SLoc->dump();
1169 else if (const auto *ND = dyn_cast_or_null<NamedDecl>(getCallee()))
1170 llvm::errs() << *ND << "\n";
1171 else
1172 getLocation().dump();
1173}
1174
1175LLVM_DUMP_METHOD void PathDiagnosticEventPiece::dump() const {
1176 llvm::errs() << "EVENT\n--------------\n";
1177 llvm::errs() << getString() << "\n";
1178 llvm::errs() << " ---- at ----\n";
1179 getLocation().dump();
1180}
1181
1182LLVM_DUMP_METHOD void PathDiagnosticControlFlowPiece::dump() const {
1183 llvm::errs() << "CONTROL\n--------------\n";
1184 getStartLocation().dump();
1185 llvm::errs() << " ---- to ----\n";
1186 getEndLocation().dump();
1187}
1188
1189LLVM_DUMP_METHOD void PathDiagnosticMacroPiece::dump() const {
1190 llvm::errs() << "MACRO\n--------------\n";
1191 // FIXME: Print which macro is being invoked.
1192}
1193
1194LLVM_DUMP_METHOD void PathDiagnosticNotePiece::dump() const {
1195 llvm::errs() << "NOTE\n--------------\n";
1196 llvm::errs() << getString() << "\n";
1197 llvm::errs() << " ---- at ----\n";
1198 getLocation().dump();
1199}
1200
1201LLVM_DUMP_METHOD void PathDiagnosticPopUpPiece::dump() const {
1202 llvm::errs() << "POP-UP\n--------------\n";
1203 llvm::errs() << getString() << "\n";
1204 llvm::errs() << " ---- at ----\n";
1205 getLocation().dump();
1206}
1207
1208LLVM_DUMP_METHOD void PathDiagnosticLocation::dump() const {
1209 if (!isValid()) {
1210 llvm::errs() << "<INVALID>\n";
1211 return;
1212 }
1213
1214 switch (K) {
1215 case RangeK:
1216 // FIXME: actually print the range.
1217 llvm::errs() << "<range>\n";
1218 break;
1219 case SingleLocK:
1220 asLocation().dump();
1221 llvm::errs() << "\n";
1222 break;
1223 case StmtK:
1224 if (S)
1225 S->dump();
1226 else
1227 llvm::errs() << "<NULL STMT>\n";
1228 break;
1229 case DeclK:
1230 if (const auto *ND = dyn_cast_or_null<NamedDecl>(D))
1231 llvm::errs() << *ND << "\n";
1232 else if (isa<BlockDecl>(D))
1233 // FIXME: Make this nicer.
1234 llvm::errs() << "<block>\n";
1235 else if (D)
1236 llvm::errs() << "<unknown decl>\n";
1237 else
1238 llvm::errs() << "<NULL DECL>\n";
1239 break;
1240 }
1241}
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
static Decl::Kind getKind(const Decl *D)
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.
Result
Implement __builtin_bit_cast and related operations.
#define X(type, name)
Definition Value.h:97
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.
#define SM(sm)
static std::optional< bool > comparePath(const PathPieces &X, const PathPieces &Y)
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 PathDiagnosticLocation getLocationForCaller(const StackFrame *SF, const StackFrame *CallerSF, const SourceManager &SM)
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__ __2f16 float __ockl_bool s
SourceLocation getColonLoc() const
Definition Expr.h:4384
AnalysisDeclContext contains the context data for the function, method or block under analysis.
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4041
SourceLocation getOperatorLoc() const
Definition Expr.h:4083
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
Definition CFG.h:445
const Stmt * getTriggerStmt() const
Definition CFG.h:455
Represents a single basic block in a source-level CFG.
Definition CFG.h:632
CFGTerminator getTerminator() const
Definition CFG.h:1112
const Stmt * getTerminatorCondition(bool StripParens=true) const
Definition CFG.cpp:6515
CFG * getParent() const
Definition CFG.h:1136
Represents C++ object destructor generated from a call to delete.
Definition CFG.h:470
const CXXDeleteExpr * getDeleteExpr() const
Definition CFG.h:480
Represents a top-level expression in a basic block.
Definition CFG.h:55
@ CleanupFunction
Definition CFG.h:80
@ CXXRecordTypedCall
Definition CFG.h:69
@ FullExprCleanup
Definition CFG.h:65
@ AutomaticObjectDtor
Definition CFG.h:73
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type.
Definition CFG.h:100
Represents C++ base or member initializer from constructor's initialization list.
Definition CFG.h:229
Represents C++ allocator call.
Definition CFG.h:249
const Stmt * getStmt() const
Definition CFG.h:140
Represents C++ object destructor implicitly generated at the end of full expression for temporary obj...
Definition CFG.h:538
bool isVirtualBaseBranch() const
Definition CFG.h:601
CFGBlock & getEntry()
Definition CFG.h:1364
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a point when we begin processing an inlined call.
const StackFrame * getCalleeStackFrame() const
Represents a point when we start the call exit sequence (for inlined call).
Represents a point when we finish the call exit sequence (for inlined call).
const StackFrame * getCalleeStackFrame() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1750
SourceLocation getLBracLoc() const
Definition Stmt.h:1867
SourceLocation getRBracLoc() const
Definition Stmt.h:1868
ConditionalOperator - The ?
Definition Expr.h:4394
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:443
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:1100
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
SourceLocation getLocation() const
Definition DeclBase.h:447
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
FileIDAndOffset 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...
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3367
SourceLocation getMemberLoc() const
getMemberLoc - Return the location of the "member", in X->F, it is the location of 'F'.
Definition Expr.h:3556
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.cpp:1799
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
Stmt * getParent(Stmt *) const
Represents a program point just after an implicit call event.
Represents a point after we ran remove dead bindings AFTER processing the given statement.
Represents a program point just before an implicit call event.
const StackFrame * getStackFrame() const
std::optional< T > getAs() const
Convert to the specified ProgramPoint type, returning std::nullopt if this ProgramPoint is not of the...
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3170
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
It represents a stack frame of the call stack.
unsigned getIndex() const
LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const
const Decl * getDecl() const
const CFGBlock * getCallSiteBlock() const
Stmt - This represents one statement.
Definition Stmt.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:367
StmtClass getStmtClass() const
Definition Stmt.h:1503
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
A template argument list.
Represents a template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
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.
ArgKind getKind() const
Return the kind of stored template argument.
PathDiagnosticLocation getLocation() const override
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)
ConsumerFiles files
A vector of <consumer,file> pairs.
std::vector< std::pair< StringRef, StringRef > > ConsumerFiles
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 StackFrame *SF, const SourceManager &SM)
Create a location for the beginning of the enclosing declaration body.
static SourceLocation getValidSourceLocation(const Stmt *S, StackFrameOrAnalysisDeclContext SFAC, bool UseEndOfStatement=false)
Construct a source location that corresponds to either the beginning or the end of the given statemen...
static PathDiagnosticLocation createDeclEnd(const StackFrame *SF, const SourceManager &SM)
Constructs a location for the end of the enclosing declaration body.
void Profile(llvm::FoldingSetNodeID &ID) const
static PathDiagnosticLocation createEnd(const Stmt *S, const SourceManager &SM, const StackFrameOrAnalysisDeclContext SFAC)
Create a location for the end of the statement.
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 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 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
DisplayHint getDisplayHint() const
getDisplayHint - Return a hint indicating where the diagnostic should be displayed by the PathDiagnos...
void Profile(llvm::FoldingSetNodeID &ID) const override
void Profile(llvm::FoldingSetNodeID &ID) const override
PathDiagnosticLocation getLocation() const override
PathDiagnostic - PathDiagnostic objects represent a single path-sensitive diagnostic.
StringRef getCheckerName() const
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.
const Decl * getUniqueingDecl() const
Get the declaration containing the uniqueing location.
StringRef getCategory() const
StringRef getShortDescription() const
meta_iterator meta_begin() const
SmallString< 32 > getIssueHash(const SourceManager &SrcMgr, const LangOptions &LangOpts) const
Get a hash that identifies the issue.
PathDiagnosticLocation getLocation() const
Public enums and private classes that are part of the SourceManager implementation.
static const FunctionDecl * getCallee(const CXXConstructExpr &D)
llvm::PointerUnion< const StackFrame *, AnalysisDeclContext * > StackFrameOrAnalysisDeclContext
std::shared_ptr< PathDiagnosticPiece > PathDiagnosticPieceRef
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
Definition FileEntry.h:208
std::pair< FileID, unsigned > FileIDAndOffset
llvm::SmallString< 32 > getIssueHash(const FullSourceLoc &IssueLoc, llvm::StringRef CheckerName, llvm::StringRef WarningMessage, const Decl *IssueDecl, const LangOptions &LangOpts)
Returns an opaque identifier for a diagnostic.
U cast(CodeGen::Address addr)
Definition Address.h:327
Describes how types, statements, expressions, and declarations should be printed.