================ @@ -80,13 +78,47 @@ void ExceptionEscapeCheck::check(const MatchFinder::MatchResult &Result) { if (!MatchedDecl) return; - if (Tracer.analyze(MatchedDecl).getBehaviour() == - utils::ExceptionAnalyzer::State::Throwing) - // FIXME: We should provide more information about the exact location where - // the exception is thrown, maybe the full path the exception escapes - diag(MatchedDecl->getLocation(), "an exception may be thrown in function " - "%0 which should not throw exceptions") - << MatchedDecl; + const utils::ExceptionAnalyzer::ExceptionInfo Info = + Tracer.analyze(MatchedDecl); + + if (Info.getBehaviour() != utils::ExceptionAnalyzer::State::Throwing) { + return; + } + + diag(MatchedDecl->getLocation(), "an exception may be thrown in function " + "%0 which should not throw exceptions") + << MatchedDecl; + + const utils::ExceptionAnalyzer::ExceptionInfo::ThrowInfo ThrowInfo = + Info.getExceptions().begin()->getSecond(); + + if (ThrowInfo.Loc.isInvalid()) { + return; + } + + const utils::ExceptionAnalyzer::CallStack &Stack = ThrowInfo.Stack; + diag(ThrowInfo.Loc, + "frame #0: unhandled exception may be thrown in function %0 here", + DiagnosticIDs::Note) + << Stack.back().first; + + size_t FrameNo = 1; + for (auto CurrIt = ++Stack.rbegin(), PrevIt = Stack.rbegin(); + CurrIt != Stack.rend(); ++CurrIt, ++PrevIt) { + const FunctionDecl *CurrFunction = CurrIt->first; + const FunctionDecl *PrevFunction = PrevIt->first; + const SourceLocation PrevLocation = PrevIt->second; + if (PrevLocation.isValid()) { + diag(PrevLocation, "frame #%0: function %1 calls function %2 here", ---------------- HerrCai0907 wrote:
```suggestion diag(PrevLocation, "frame #%0: function '%1' calls function '%2' here", ``` https://github.com/llvm/llvm-project/pull/134375 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits