diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-05 01:25:28 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-05 01:25:28 +0000 |
commit | 21ff9c99d3df1e4a13e6820fc2aa7a8cc6673198 (patch) | |
tree | 9b53871f7316413ea895e459cb459ca1a8f7ed67 /lib | |
parent | 797b6327571f9d7b1c45404a56ddcbf9b9298ae8 (diff) |
When parsing a function body, add it to the crash stack, giving us something
like:
Stack dump:
0. t.c:5:10: in compound statement ('{}')
1. t.c:3:12: in compound statement ('{}')
2. t.c:3:12: parsing function body 'foo'
3. clang t.c
Abort
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66118 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Parse/MinimalAction.cpp | 15 | ||||
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 5 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 9 |
4 files changed, 33 insertions, 0 deletions
diff --git a/lib/Parse/MinimalAction.cpp b/lib/Parse/MinimalAction.cpp index 9cd5b979ca..5238a89957 100644 --- a/lib/Parse/MinimalAction.cpp +++ b/lib/Parse/MinimalAction.cpp @@ -16,8 +16,23 @@ #include "clang/Parse/Scope.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/RecyclingAllocator.h" +#include "llvm/Support/raw_ostream.h" using namespace clang; +void PrettyStackTraceDecl::print(llvm::raw_ostream &OS) const { + if (Loc.isValid()) { + Loc.print(OS, SM); + OS << ": "; + } + OS << Message; + + std::string Name = Actions.getDeclName(TheDecl); + if (!Name.empty()) + OS << " '" << Name << '\''; + + OS << '\n'; +} + /// TypeNameInfo - A link exists here for each scope that an identifier is /// defined. namespace { diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 1ecbe8bd84..cb9bdc7cfb 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -1288,6 +1288,10 @@ Parser::DeclTy *Parser::ParseFunctionStatementBody(DeclTy *Decl) { assert(Tok.is(tok::l_brace)); SourceLocation LBraceLoc = Tok.getLocation(); + PrettyStackTraceDecl CrashInfo(Decl, LBraceLoc, Actions, + PP.getSourceManager(), + "parsing function body"); + // Do not enter a scope for the brace, as the arguments are in the same scope // (the function body) as the body itself. Instead, just read the statement // list and put it into a CompoundStmt for safe keeping. diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 31a8c3889d..de9b4cd013 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -290,6 +290,11 @@ public: //===--------------------------------------------------------------------===// // Symbol table / Decl tracking callbacks: SemaDecl.cpp. // + + /// getDeclName - Return a pretty name for the specified decl if possible, or + /// an empty string if not. This is used for pretty crash reporting. + virtual std::string getDeclName(DeclTy *D); + virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, Scope *S, const CXXScopeSpec *SS); virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup){ diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e1b27c64a4..97002ef02f 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -30,6 +30,15 @@ #include <functional> using namespace clang; +/// getDeclName - Return a pretty name for the specified decl if possible, or +/// an empty string if not. This is used for pretty crash reporting. +std::string Sema::getDeclName(DeclTy *d) { + Decl *D = static_cast<Decl *>(d); + if (NamedDecl *DN = dyn_cast_or_null<NamedDecl>(D)) + return DN->getQualifiedNameAsString(); + return ""; +} + /// \brief If the identifier refers to a type name within this scope, /// return the declaration of that type. /// |