@@ -52,11 +52,6 @@ class SourceManager;
5252
5353namespace ento {
5454
55- class ExplodedNode ;
56- class SymExpr ;
57-
58- using SymbolRef = const SymExpr *;
59-
6055// ===----------------------------------------------------------------------===//
6156// High-level interface for handlers of path-sensitive diagnostics.
6257// ===----------------------------------------------------------------------===//
@@ -276,18 +271,21 @@ class PathDiagnosticLocation {
276271 static PathDiagnosticLocation createDeclEnd (const LocationContext *LC,
277272 const SourceManager &SM);
278273
279- // / Create a location corresponding to the given valid ExplodedNode .
274+ // / Create a location corresponding to the given valid ProgramPoint .
280275 static PathDiagnosticLocation create (const ProgramPoint &P,
281276 const SourceManager &SMng);
282277
283- // / Create a location corresponding to the next valid ExplodedNode as end
284- // / of path location.
285- static PathDiagnosticLocation createEndOfPath (const ExplodedNode* N);
286-
287278 // / Convert the given location into a single kind location.
288279 static PathDiagnosticLocation createSingleLocation (
289280 const PathDiagnosticLocation &PDL);
290281
282+ // / Construct a source location that corresponds to either the beginning
283+ // / or the end of the given statement, or a nearby valid source location
284+ // / if the statement does not have a valid source location of its own.
285+ static SourceLocation
286+ getValidSourceLocation (const Stmt *S, LocationOrAnalysisDeclContext LAC,
287+ bool UseEndOfStatement = false );
288+
291289 bool operator ==(const PathDiagnosticLocation &X) const {
292290 return K == X.K && Loc == X.Loc && Range == X.Range ;
293291 }
@@ -332,13 +330,6 @@ class PathDiagnosticLocation {
332330 void Profile (llvm::FoldingSetNodeID &ID) const ;
333331
334332 void dump () const ;
335-
336- // / Given an exploded node, retrieve the statement that should be used
337- // / for the diagnostic location.
338- static const Stmt *getStmt (const ExplodedNode *N);
339-
340- // / Retrieve the statement corresponding to the successor node.
341- static const Stmt *getNextStmt (const ExplodedNode *N);
342333};
343334
344335class PathDiagnosticLocationPair {
@@ -502,65 +493,13 @@ class PathDiagnosticSpotPiece : public PathDiagnosticPiece {
502493 }
503494};
504495
505- // / Interface for classes constructing Stack hints.
506- // /
507- // / If a PathDiagnosticEvent occurs in a different frame than the final
508- // / diagnostic the hints can be used to summarize the effect of the call.
509- class StackHintGenerator {
510- public:
511- virtual ~StackHintGenerator () = 0 ;
512-
513- // / Construct the Diagnostic message for the given ExplodedNode.
514- virtual std::string getMessage (const ExplodedNode *N) = 0;
515- };
516-
517- // / Constructs a Stack hint for the given symbol.
518- // /
519- // / The class knows how to construct the stack hint message based on
520- // / traversing the CallExpr associated with the call and checking if the given
521- // / symbol is returned or is one of the arguments.
522- // / The hint can be customized by redefining 'getMessageForX()' methods.
523- class StackHintGeneratorForSymbol : public StackHintGenerator {
524- private:
525- SymbolRef Sym;
526- std::string Msg;
527-
528- public:
529- StackHintGeneratorForSymbol (SymbolRef S, StringRef M) : Sym(S), Msg(M) {}
530- ~StackHintGeneratorForSymbol () override = default ;
531-
532- // / Search the call expression for the symbol Sym and dispatch the
533- // / 'getMessageForX()' methods to construct a specific message.
534- std::string getMessage (const ExplodedNode *N) override ;
535-
536- // / Produces the message of the following form:
537- // / 'Msg via Nth parameter'
538- virtual std::string getMessageForArg (const Expr *ArgE, unsigned ArgIndex);
539-
540- virtual std::string getMessageForReturn (const CallExpr *CallExpr) {
541- return Msg;
542- }
543-
544- virtual std::string getMessageForSymbolNotFound () {
545- return Msg;
546- }
547- };
548-
549496class PathDiagnosticEventPiece : public PathDiagnosticSpotPiece {
550497 Optional<bool > IsPrunable;
551498
552- // / If the event occurs in a different frame than the final diagnostic,
553- // / supply a message that will be used to construct an extra hint on the
554- // / returns from all the calls on the stack from this event to the final
555- // / diagnostic.
556- std::unique_ptr<StackHintGenerator> CallStackHint;
557-
558499public:
559500 PathDiagnosticEventPiece (const PathDiagnosticLocation &pos,
560- StringRef s, bool addPosRange = true ,
561- StackHintGenerator *stackHint = nullptr )
562- : PathDiagnosticSpotPiece(pos, s, Event, addPosRange),
563- CallStackHint (stackHint) {}
501+ StringRef s, bool addPosRange = true )
502+ : PathDiagnosticSpotPiece(pos, s, Event, addPosRange) {}
564503 ~PathDiagnosticEventPiece () override ;
565504
566505 // / Mark the diagnostic piece as being potentially prunable. This
@@ -577,16 +516,6 @@ class PathDiagnosticEventPiece : public PathDiagnosticSpotPiece {
577516 return IsPrunable.hasValue () ? IsPrunable.getValue () : false ;
578517 }
579518
580- bool hasCallStackHint () { return (bool )CallStackHint; }
581-
582- // / Produce the hint for the given node. The node contains
583- // / information about the call for which the diagnostic can be generated.
584- std::string getCallStackMessage (const ExplodedNode *N) {
585- if (CallStackHint)
586- return CallStackHint->getMessage (N);
587- return {};
588- }
589-
590519 void dump () const override ;
591520
592521 static bool classof (const PathDiagnosticPiece *P) {
@@ -863,11 +792,6 @@ class PathDiagnostic : public llvm::FoldingSetNode {
863792 VerboseDesc += S;
864793 }
865794
866- // / If the last piece of the report point to the header file, resets
867- // / the location of the report to be the last location in the main source
868- // / file.
869- void resetDiagnosticLocationToMainFile ();
870-
871795 StringRef getVerboseDescription () const { return VerboseDesc; }
872796
873797 StringRef getShortDescription () const {
@@ -878,11 +802,6 @@ class PathDiagnostic : public llvm::FoldingSetNode {
878802 StringRef getBugType () const { return BugType; }
879803 StringRef getCategory () const { return Category; }
880804
881- // / Return the semantic context where an issue occurred. If the
882- // / issue occurs along a path, this represents the "central" area
883- // / where the bug manifests.
884- const Decl *getDeclWithIssue () const { return DeclWithIssue; }
885-
886805 using meta_iterator = std::deque<std::string>::const_iterator;
887806
888807 meta_iterator meta_begin () const { return OtherDesc.begin (); }
@@ -897,10 +816,23 @@ class PathDiagnostic : public llvm::FoldingSetNode {
897816 return *ExecutedLines;
898817 }
899818
819+ // / Return the semantic context where an issue occurred. If the
820+ // / issue occurs along a path, this represents the "central" area
821+ // / where the bug manifests.
822+ const Decl *getDeclWithIssue () const { return DeclWithIssue; }
823+
824+ void setDeclWithIssue (const Decl *D) {
825+ DeclWithIssue = D;
826+ }
827+
900828 PathDiagnosticLocation getLocation () const {
901829 return Loc;
902830 }
903831
832+ void setLocation (PathDiagnosticLocation NewLoc) {
833+ Loc = NewLoc;
834+ }
835+
904836 // / Get the location on which the report should be uniqued.
905837 PathDiagnosticLocation getUniqueingLoc () const {
906838 return UniqueingLoc;
0 commit comments