1 //===--- PathDiagnostic.h - Path-Specific Diagnostic Handling ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the PathDiagnostic-related interfaces.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_PATHDIAGNOSTIC_H
15 #define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_PATHDIAGNOSTIC_H
17 #include "clang/Analysis/ProgramPoint.h"
18 #include "clang/Basic/SourceLocation.h"
19 #include "llvm/ADT/FoldingSet.h"
20 #include "llvm/ADT/IntrusiveRefCntPtr.h"
21 #include "llvm/ADT/Optional.h"
22 #include "llvm/ADT/PointerUnion.h"
30 class ConditionalOperator;
31 class AnalysisDeclContext;
35 class LocationContext;
47 typedef const SymExpr* SymbolRef;
49 //===----------------------------------------------------------------------===//
50 // High-level interface for handlers of path-sensitive diagnostics.
51 //===----------------------------------------------------------------------===//
55 class PathDiagnosticConsumer {
57 class PDFileEntry : public llvm::FoldingSetNode {
59 PDFileEntry(llvm::FoldingSetNodeID &NodeID) : NodeID(NodeID) {}
61 typedef std::vector<std::pair<StringRef, StringRef> > ConsumerFiles;
63 /// \brief A vector of <consumer,file> pairs.
66 /// \brief A precomputed hash tag used for uniquing PDFileEntry objects.
67 const llvm::FoldingSetNodeID NodeID;
69 /// \brief Used for profiling in the FoldingSet.
70 void Profile(llvm::FoldingSetNodeID &ID) { ID = NodeID; }
74 llvm::BumpPtrAllocator Alloc;
75 llvm::FoldingSet<PDFileEntry> Set;
80 bool empty() const { return Set.empty(); }
82 void addDiagnostic(const PathDiagnostic &PD,
83 StringRef ConsumerName,
86 PDFileEntry::ConsumerFiles *getFiles(const PathDiagnostic &PD);
90 virtual void anchor();
92 PathDiagnosticConsumer() : flushed(false) {}
93 virtual ~PathDiagnosticConsumer();
95 void FlushDiagnostics(FilesMade *FilesMade);
97 virtual void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
98 FilesMade *filesMade) = 0;
100 virtual StringRef getName() const = 0;
102 void HandlePathDiagnostic(std::unique_ptr<PathDiagnostic> D);
104 enum PathGenerationScheme { None, Minimal, Extensive, AlternateExtensive };
105 virtual PathGenerationScheme getGenerationScheme() const { return Minimal; }
106 virtual bool supportsLogicalOpControlFlow() const { return false; }
108 /// Return true if the PathDiagnosticConsumer supports individual
109 /// PathDiagnostics that span multiple files.
110 virtual bool supportsCrossFileDiagnostics() const { return false; }
114 llvm::FoldingSet<PathDiagnostic> Diags;
117 //===----------------------------------------------------------------------===//
118 // Path-sensitive diagnostics.
119 //===----------------------------------------------------------------------===//
121 class PathDiagnosticRange : public SourceRange {
125 PathDiagnosticRange(const SourceRange &R, bool isP = false)
126 : SourceRange(R), isPoint(isP) {}
128 PathDiagnosticRange() : isPoint(false) {}
131 typedef llvm::PointerUnion<const LocationContext*, AnalysisDeclContext*>
132 LocationOrAnalysisDeclContext;
134 class PathDiagnosticLocation {
136 enum Kind { RangeK, SingleLocK, StmtK, DeclK } K;
139 const SourceManager *SM;
141 PathDiagnosticRange Range;
143 PathDiagnosticLocation(SourceLocation L, const SourceManager &sm,
145 : K(kind), S(nullptr), D(nullptr), SM(&sm),
146 Loc(genLocation(L)), Range(genRange()) {
149 FullSourceLoc genLocation(
150 SourceLocation L = SourceLocation(),
151 LocationOrAnalysisDeclContext LAC = (AnalysisDeclContext *)nullptr) const;
153 PathDiagnosticRange genRange(
154 LocationOrAnalysisDeclContext LAC = (AnalysisDeclContext *)nullptr) const;
157 /// Create an invalid location.
158 PathDiagnosticLocation()
159 : K(SingleLocK), S(nullptr), D(nullptr), SM(nullptr) {}
161 /// Create a location corresponding to the given statement.
162 PathDiagnosticLocation(const Stmt *s,
163 const SourceManager &sm,
164 LocationOrAnalysisDeclContext lac)
165 : K(s->getLocStart().isValid() ? StmtK : SingleLocK),
166 S(K == StmtK ? s : nullptr),
168 Loc(genLocation(SourceLocation(), lac)),
169 Range(genRange(lac)) {
170 assert(K == SingleLocK || S);
171 assert(K == SingleLocK || Loc.isValid());
172 assert(K == SingleLocK || Range.isValid());
175 /// Create a location corresponding to the given declaration.
176 PathDiagnosticLocation(const Decl *d, const SourceManager &sm)
177 : K(DeclK), S(nullptr), D(d), SM(&sm),
178 Loc(genLocation()), Range(genRange()) {
180 assert(Loc.isValid());
181 assert(Range.isValid());
184 /// Create a location at an explicit offset in the source.
186 /// This should only be used if there are no more appropriate constructors.
187 PathDiagnosticLocation(SourceLocation loc, const SourceManager &sm)
188 : K(SingleLocK), S(nullptr), D(nullptr), SM(&sm), Loc(loc, sm),
190 assert(Loc.isValid());
191 assert(Range.isValid());
194 /// Create a location corresponding to the given declaration.
195 static PathDiagnosticLocation create(const Decl *D,
196 const SourceManager &SM) {
197 return PathDiagnosticLocation(D, SM);
200 /// Create a location for the beginning of the declaration.
201 static PathDiagnosticLocation createBegin(const Decl *D,
202 const SourceManager &SM);
204 /// Create a location for the beginning of the statement.
205 static PathDiagnosticLocation createBegin(const Stmt *S,
206 const SourceManager &SM,
207 const LocationOrAnalysisDeclContext LAC);
209 /// Create a location for the end of the statement.
211 /// If the statement is a CompoundStatement, the location will point to the
212 /// closing brace instead of following it.
213 static PathDiagnosticLocation createEnd(const Stmt *S,
214 const SourceManager &SM,
215 const LocationOrAnalysisDeclContext LAC);
217 /// Create the location for the operator of the binary expression.
218 /// Assumes the statement has a valid location.
219 static PathDiagnosticLocation createOperatorLoc(const BinaryOperator *BO,
220 const SourceManager &SM);
221 static PathDiagnosticLocation createConditionalColonLoc(
222 const ConditionalOperator *CO,
223 const SourceManager &SM);
225 /// For member expressions, return the location of the '.' or '->'.
226 /// Assumes the statement has a valid location.
227 static PathDiagnosticLocation createMemberLoc(const MemberExpr *ME,
228 const SourceManager &SM);
230 /// Create a location for the beginning of the compound statement.
231 /// Assumes the statement has a valid location.
232 static PathDiagnosticLocation createBeginBrace(const CompoundStmt *CS,
233 const SourceManager &SM);
235 /// Create a location for the end of the compound statement.
236 /// Assumes the statement has a valid location.
237 static PathDiagnosticLocation createEndBrace(const CompoundStmt *CS,
238 const SourceManager &SM);
240 /// Create a location for the beginning of the enclosing declaration body.
241 /// Defaults to the beginning of the first statement in the declaration body.
242 static PathDiagnosticLocation createDeclBegin(const LocationContext *LC,
243 const SourceManager &SM);
245 /// Constructs a location for the end of the enclosing declaration body.
246 /// Defaults to the end of brace.
247 static PathDiagnosticLocation createDeclEnd(const LocationContext *LC,
248 const SourceManager &SM);
250 /// Create a location corresponding to the given valid ExplodedNode.
251 static PathDiagnosticLocation create(const ProgramPoint& P,
252 const SourceManager &SMng);
254 /// Create a location corresponding to the next valid ExplodedNode as end
255 /// of path location.
256 static PathDiagnosticLocation createEndOfPath(const ExplodedNode* N,
257 const SourceManager &SM);
259 /// Convert the given location into a single kind location.
260 static PathDiagnosticLocation createSingleLocation(
261 const PathDiagnosticLocation &PDL);
263 bool operator==(const PathDiagnosticLocation &X) const {
264 return K == X.K && Loc == X.Loc && Range == X.Range;
267 bool operator!=(const PathDiagnosticLocation &X) const {
268 return !(*this == X);
271 bool isValid() const {
272 return SM != nullptr;
275 FullSourceLoc asLocation() const {
279 PathDiagnosticRange asRange() const {
283 const Stmt *asStmt() const { assert(isValid()); return S; }
284 const Decl *asDecl() const { assert(isValid()); return D; }
286 bool hasRange() const { return K == StmtK || K == RangeK || K == DeclK; }
289 *this = PathDiagnosticLocation();
294 const SourceManager& getManager() const { assert(isValid()); return *SM; }
296 void Profile(llvm::FoldingSetNodeID &ID) const;
300 /// \brief Given an exploded node, retrieve the statement that should be used
301 /// for the diagnostic location.
302 static const Stmt *getStmt(const ExplodedNode *N);
304 /// \brief Retrieve the statement corresponding to the successor node.
305 static const Stmt *getNextStmt(const ExplodedNode *N);
308 class PathDiagnosticLocationPair {
310 PathDiagnosticLocation Start, End;
312 PathDiagnosticLocationPair(const PathDiagnosticLocation &start,
313 const PathDiagnosticLocation &end)
314 : Start(start), End(end) {}
316 const PathDiagnosticLocation &getStart() const { return Start; }
317 const PathDiagnosticLocation &getEnd() const { return End; }
319 void setStart(const PathDiagnosticLocation &L) { Start = L; }
320 void setEnd(const PathDiagnosticLocation &L) { End = L; }
327 void Profile(llvm::FoldingSetNodeID &ID) const {
333 //===----------------------------------------------------------------------===//
334 // Path "pieces" for path-sensitive diagnostics.
335 //===----------------------------------------------------------------------===//
337 class PathDiagnosticPiece : public RefCountedBaseVPTR {
339 enum Kind { ControlFlow, Event, Macro, Call };
340 enum DisplayHint { Above, Below };
343 const std::string str;
345 const DisplayHint Hint;
347 /// \brief In the containing bug report, this piece is the last piece from
348 /// the main source file.
349 bool LastInMainSourceFile;
351 /// A constant string that can be used to tag the PathDiagnosticPiece,
352 /// typically with the identification of the creator. The actual pointer
353 /// value is meant to be an identifier; the string itself is useful for
357 std::vector<SourceRange> ranges;
359 PathDiagnosticPiece() = delete;
360 PathDiagnosticPiece(const PathDiagnosticPiece &P) = delete;
361 void operator=(const PathDiagnosticPiece &P) = delete;
364 PathDiagnosticPiece(StringRef s, Kind k, DisplayHint hint = Below);
366 PathDiagnosticPiece(Kind k, DisplayHint hint = Below);
369 ~PathDiagnosticPiece() override;
371 StringRef getString() const { return str; }
373 /// Tag this PathDiagnosticPiece with the given C-string.
374 void setTag(const char *tag) { Tag = tag; }
376 /// Return the opaque tag (if any) on the PathDiagnosticPiece.
377 const void *getTag() const { return Tag.data(); }
379 /// Return the string representation of the tag. This is useful
381 StringRef getTagStr() const { return Tag; }
383 /// getDisplayHint - Return a hint indicating where the diagnostic should
384 /// be displayed by the PathDiagnosticConsumer.
385 DisplayHint getDisplayHint() const { return Hint; }
387 virtual PathDiagnosticLocation getLocation() const = 0;
388 virtual void flattenLocations() = 0;
390 Kind getKind() const { return kind; }
392 void addRange(SourceRange R) {
398 void addRange(SourceLocation B, SourceLocation E) {
399 if (!B.isValid() || !E.isValid())
401 ranges.push_back(SourceRange(B,E));
404 /// Return the SourceRanges associated with this PathDiagnosticPiece.
405 ArrayRef<SourceRange> getRanges() const { return ranges; }
407 virtual void Profile(llvm::FoldingSetNodeID &ID) const;
409 void setAsLastInMainSourceFile() {
410 LastInMainSourceFile = true;
413 bool isLastInMainSourceFile() const {
414 return LastInMainSourceFile;
417 virtual void dump() const = 0;
421 class PathPieces : public std::list<IntrusiveRefCntPtr<PathDiagnosticPiece> > {
422 void flattenTo(PathPieces &Primary, PathPieces &Current,
423 bool ShouldFlattenMacros) const;
427 PathPieces flatten(bool ShouldFlattenMacros) const {
429 flattenTo(Result, Result, ShouldFlattenMacros);
436 class PathDiagnosticSpotPiece : public PathDiagnosticPiece {
438 PathDiagnosticLocation Pos;
440 PathDiagnosticSpotPiece(const PathDiagnosticLocation &pos,
442 PathDiagnosticPiece::Kind k,
443 bool addPosRange = true)
444 : PathDiagnosticPiece(s, k), Pos(pos) {
445 assert(Pos.isValid() && Pos.asLocation().isValid() &&
446 "PathDiagnosticSpotPiece's must have a valid location.");
447 if (addPosRange && Pos.hasRange()) addRange(Pos.asRange());
450 PathDiagnosticLocation getLocation() const override { return Pos; }
451 void flattenLocations() override { Pos.flatten(); }
453 void Profile(llvm::FoldingSetNodeID &ID) const override;
455 static bool classof(const PathDiagnosticPiece *P) {
456 return P->getKind() == Event || P->getKind() == Macro;
460 /// \brief Interface for classes constructing Stack hints.
462 /// If a PathDiagnosticEvent occurs in a different frame than the final
463 /// diagnostic the hints can be used to summarize the effect of the call.
464 class StackHintGenerator {
466 virtual ~StackHintGenerator() = 0;
468 /// \brief Construct the Diagnostic message for the given ExplodedNode.
469 virtual std::string getMessage(const ExplodedNode *N) = 0;
472 /// \brief Constructs a Stack hint for the given symbol.
474 /// The class knows how to construct the stack hint message based on
475 /// traversing the CallExpr associated with the call and checking if the given
476 /// symbol is returned or is one of the arguments.
477 /// The hint can be customized by redefining 'getMessageForX()' methods.
478 class StackHintGeneratorForSymbol : public StackHintGenerator {
484 StackHintGeneratorForSymbol(SymbolRef S, StringRef M) : Sym(S), Msg(M) {}
485 ~StackHintGeneratorForSymbol() override {}
487 /// \brief Search the call expression for the symbol Sym and dispatch the
488 /// 'getMessageForX()' methods to construct a specific message.
489 std::string getMessage(const ExplodedNode *N) override;
491 /// Produces the message of the following form:
492 /// 'Msg via Nth parameter'
493 virtual std::string getMessageForArg(const Expr *ArgE, unsigned ArgIndex);
494 virtual std::string getMessageForReturn(const CallExpr *CallExpr) {
497 virtual std::string getMessageForSymbolNotFound() {
502 class PathDiagnosticEventPiece : public PathDiagnosticSpotPiece {
503 Optional<bool> IsPrunable;
505 /// If the event occurs in a different frame than the final diagnostic,
506 /// supply a message that will be used to construct an extra hint on the
507 /// returns from all the calls on the stack from this event to the final
509 std::unique_ptr<StackHintGenerator> CallStackHint;
512 PathDiagnosticEventPiece(const PathDiagnosticLocation &pos,
513 StringRef s, bool addPosRange = true,
514 StackHintGenerator *stackHint = nullptr)
515 : PathDiagnosticSpotPiece(pos, s, Event, addPosRange),
516 CallStackHint(stackHint) {}
518 ~PathDiagnosticEventPiece() override;
520 /// Mark the diagnostic piece as being potentially prunable. This
521 /// flag may have been previously set, at which point it will not
522 /// be reset unless one specifies to do so.
523 void setPrunable(bool isPrunable, bool override = false) {
524 if (IsPrunable.hasValue() && !override)
526 IsPrunable = isPrunable;
529 /// Return true if the diagnostic piece is prunable.
530 bool isPrunable() const {
531 return IsPrunable.hasValue() ? IsPrunable.getValue() : false;
534 bool hasCallStackHint() { return (bool)CallStackHint; }
536 /// Produce the hint for the given node. The node contains
537 /// information about the call for which the diagnostic can be generated.
538 std::string getCallStackMessage(const ExplodedNode *N) {
540 return CallStackHint->getMessage(N);
544 void dump() const override;
546 static inline bool classof(const PathDiagnosticPiece *P) {
547 return P->getKind() == Event;
551 class PathDiagnosticCallPiece : public PathDiagnosticPiece {
552 PathDiagnosticCallPiece(const Decl *callerD,
553 const PathDiagnosticLocation &callReturnPos)
554 : PathDiagnosticPiece(Call), Caller(callerD), Callee(nullptr),
555 NoExit(false), callReturn(callReturnPos) {}
557 PathDiagnosticCallPiece(PathPieces &oldPath, const Decl *caller)
558 : PathDiagnosticPiece(Call), Caller(caller), Callee(nullptr),
559 NoExit(true), path(oldPath) {}
564 // Flag signifying that this diagnostic has only call enter and no matching
568 // The custom string, which should appear after the call Return Diagnostic.
569 // TODO: Should we allow multiple diagnostics?
570 std::string CallStackMessage;
573 PathDiagnosticLocation callEnter;
574 PathDiagnosticLocation callEnterWithin;
575 PathDiagnosticLocation callReturn;
578 ~PathDiagnosticCallPiece() override;
580 const Decl *getCaller() const { return Caller; }
582 const Decl *getCallee() const { return Callee; }
583 void setCallee(const CallEnter &CE, const SourceManager &SM);
585 bool hasCallStackMessage() { return !CallStackMessage.empty(); }
586 void setCallStackMessage(StringRef st) {
587 CallStackMessage = st;
590 PathDiagnosticLocation getLocation() const override {
594 IntrusiveRefCntPtr<PathDiagnosticEventPiece> getCallEnterEvent() const;
595 IntrusiveRefCntPtr<PathDiagnosticEventPiece>
596 getCallEnterWithinCallerEvent() const;
597 IntrusiveRefCntPtr<PathDiagnosticEventPiece> getCallExitEvent() const;
599 void flattenLocations() override {
601 callReturn.flatten();
602 for (PathPieces::iterator I = path.begin(),
603 E = path.end(); I != E; ++I) (*I)->flattenLocations();
606 static PathDiagnosticCallPiece *construct(const ExplodedNode *N,
607 const CallExitEnd &CE,
608 const SourceManager &SM);
610 static PathDiagnosticCallPiece *construct(PathPieces &pieces,
613 void dump() const override;
615 void Profile(llvm::FoldingSetNodeID &ID) const override;
617 static inline bool classof(const PathDiagnosticPiece *P) {
618 return P->getKind() == Call;
622 class PathDiagnosticControlFlowPiece : public PathDiagnosticPiece {
623 std::vector<PathDiagnosticLocationPair> LPairs;
625 PathDiagnosticControlFlowPiece(const PathDiagnosticLocation &startPos,
626 const PathDiagnosticLocation &endPos,
628 : PathDiagnosticPiece(s, ControlFlow) {
629 LPairs.push_back(PathDiagnosticLocationPair(startPos, endPos));
632 PathDiagnosticControlFlowPiece(const PathDiagnosticLocation &startPos,
633 const PathDiagnosticLocation &endPos)
634 : PathDiagnosticPiece(ControlFlow) {
635 LPairs.push_back(PathDiagnosticLocationPair(startPos, endPos));
638 ~PathDiagnosticControlFlowPiece() override;
640 PathDiagnosticLocation getStartLocation() const {
641 assert(!LPairs.empty() &&
642 "PathDiagnosticControlFlowPiece needs at least one location.");
643 return LPairs[0].getStart();
646 PathDiagnosticLocation getEndLocation() const {
647 assert(!LPairs.empty() &&
648 "PathDiagnosticControlFlowPiece needs at least one location.");
649 return LPairs[0].getEnd();
652 void setStartLocation(const PathDiagnosticLocation &L) {
653 LPairs[0].setStart(L);
656 void setEndLocation(const PathDiagnosticLocation &L) {
660 void push_back(const PathDiagnosticLocationPair &X) { LPairs.push_back(X); }
662 PathDiagnosticLocation getLocation() const override {
663 return getStartLocation();
666 typedef std::vector<PathDiagnosticLocationPair>::iterator iterator;
667 iterator begin() { return LPairs.begin(); }
668 iterator end() { return LPairs.end(); }
670 void flattenLocations() override {
671 for (iterator I=begin(), E=end(); I!=E; ++I) I->flatten();
674 typedef std::vector<PathDiagnosticLocationPair>::const_iterator
676 const_iterator begin() const { return LPairs.begin(); }
677 const_iterator end() const { return LPairs.end(); }
679 static inline bool classof(const PathDiagnosticPiece *P) {
680 return P->getKind() == ControlFlow;
683 void dump() const override;
685 void Profile(llvm::FoldingSetNodeID &ID) const override;
688 class PathDiagnosticMacroPiece : public PathDiagnosticSpotPiece {
690 PathDiagnosticMacroPiece(const PathDiagnosticLocation &pos)
691 : PathDiagnosticSpotPiece(pos, "", Macro) {}
693 ~PathDiagnosticMacroPiece() override;
695 PathPieces subPieces;
697 bool containsEvent() const;
699 void flattenLocations() override {
700 PathDiagnosticSpotPiece::flattenLocations();
701 for (PathPieces::iterator I = subPieces.begin(),
702 E = subPieces.end(); I != E; ++I) (*I)->flattenLocations();
705 static inline bool classof(const PathDiagnosticPiece *P) {
706 return P->getKind() == Macro;
709 void dump() const override;
711 void Profile(llvm::FoldingSetNodeID &ID) const override;
714 /// PathDiagnostic - PathDiagnostic objects represent a single path-sensitive
715 /// diagnostic. It represents an ordered-collection of PathDiagnosticPieces,
716 /// each which represent the pieces of the path.
717 class PathDiagnostic : public llvm::FoldingSetNode {
718 std::string CheckName;
719 const Decl *DeclWithIssue;
721 std::string VerboseDesc;
722 std::string ShortDesc;
723 std::string Category;
724 std::deque<std::string> OtherDesc;
726 /// \brief Loc The location of the path diagnostic report.
727 PathDiagnosticLocation Loc;
730 SmallVector<PathPieces *, 3> pathStack;
732 /// \brief Important bug uniqueing location.
733 /// The location info is useful to differentiate between bugs.
734 PathDiagnosticLocation UniqueingLoc;
735 const Decl *UniqueingDecl;
737 PathDiagnostic() = delete;
739 PathDiagnostic(StringRef CheckName, const Decl *DeclWithIssue,
740 StringRef bugtype, StringRef verboseDesc, StringRef shortDesc,
741 StringRef category, PathDiagnosticLocation LocationToUnique,
742 const Decl *DeclToUnique);
746 const PathPieces &path;
748 /// Return the path currently used by builders for constructing the
750 PathPieces &getActivePath() {
751 if (pathStack.empty())
753 return *pathStack.back();
756 /// Return a mutable version of 'path'.
757 PathPieces &getMutablePieces() {
761 /// Return the unrolled size of the path.
762 unsigned full_size();
764 void pushActivePath(PathPieces *p) { pathStack.push_back(p); }
765 void popActivePath() { if (!pathStack.empty()) pathStack.pop_back(); }
767 bool isWithinCall() const { return !pathStack.empty(); }
769 void setEndOfPath(std::unique_ptr<PathDiagnosticPiece> EndPiece) {
770 assert(!Loc.isValid() && "End location already set!");
771 Loc = EndPiece->getLocation();
772 assert(Loc.isValid() && "Invalid location for end-of-path piece");
773 getActivePath().push_back(EndPiece.release());
776 void appendToDesc(StringRef S) {
777 if (!ShortDesc.empty())
779 VerboseDesc.append(S);
785 Loc = PathDiagnosticLocation();
788 /// \brief If the last piece of the report point to the header file, resets
789 /// the location of the report to be the last location in the main source
791 void resetDiagnosticLocationToMainFile();
793 StringRef getVerboseDescription() const { return VerboseDesc; }
794 StringRef getShortDescription() const {
795 return ShortDesc.empty() ? VerboseDesc : ShortDesc;
797 StringRef getCheckName() const { return CheckName; }
798 StringRef getBugType() const { return BugType; }
799 StringRef getCategory() const { return Category; }
801 /// Return the semantic context where an issue occurred. If the
802 /// issue occurs along a path, this represents the "central" area
803 /// where the bug manifests.
804 const Decl *getDeclWithIssue() const { return DeclWithIssue; }
806 typedef std::deque<std::string>::const_iterator meta_iterator;
807 meta_iterator meta_begin() const { return OtherDesc.begin(); }
808 meta_iterator meta_end() const { return OtherDesc.end(); }
809 void addMeta(StringRef s) { OtherDesc.push_back(s); }
811 PathDiagnosticLocation getLocation() const {
812 assert(Loc.isValid() && "No report location set yet!");
816 /// \brief Get the location on which the report should be uniqued.
817 PathDiagnosticLocation getUniqueingLoc() const {
821 /// \brief Get the declaration containing the uniqueing location.
822 const Decl *getUniqueingDecl() const {
823 return UniqueingDecl;
826 void flattenLocations() {
828 for (PathPieces::iterator I = pathImpl.begin(), E = pathImpl.end();
829 I != E; ++I) (*I)->flattenLocations();
832 /// Profiles the diagnostic, independent of the path it references.
834 /// This can be used to merge diagnostics that refer to the same issue
835 /// along different paths.
836 void Profile(llvm::FoldingSetNodeID &ID) const;
838 /// Profiles the diagnostic, including its path.
840 /// Two diagnostics with the same issue along different paths will generate
841 /// different profiles.
842 void FullProfile(llvm::FoldingSetNodeID &ID) const;
845 } // end GR namespace
847 } //end clang namespace