Skip to content

Commit cec6da6

Browse files
committed
[cxxmodules] Print stacktrace before aborting on a missing exception.
We will probably see an increasing amount of these failures with C++ modules as we now deserialize all declarations instead of just the PCH ones. To safe us a lot of debugging time on where to push the needed transaction, let's directly print the stack trace here in the rare case that we crash here.
1 parent 2ebbb74 commit cec6da6

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

interpreter/cling/lib/Interpreter/DeclCollector.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "clang/Lex/MacroInfo.h"
2121
#include "clang/Lex/Preprocessor.h"
2222
#include "clang/Lex/Token.h"
23+
#include "llvm/Support/Signals.h"
2324

2425
using namespace clang;
2526

@@ -57,6 +58,15 @@ namespace {
5758
return true;
5859
return false;
5960
}
61+
62+
/// \brief Asserts that the given transaction is not null, otherwise prints a
63+
/// stack trace to stderr and aborts execution.
64+
static void assertHasTransaction(const cling::Transaction* T) {
65+
if (!T) {
66+
llvm::sys::PrintStackTrace(llvm::errs());
67+
llvm_unreachable("Missing transaction during deserialization!");
68+
}
69+
}
6070
}
6171

6272
namespace cling {
@@ -67,7 +77,7 @@ namespace cling {
6777

6878
void MacroDirective(const clang::Token& MacroNameTok,
6979
const clang::MacroDirective* MD) {
70-
assert(m_Parent->m_CurTransaction && "Missing transction");
80+
assertHasTransaction(m_Parent->m_CurTransaction);
7181
Transaction::MacroDirectiveInfo MDE(MacroNameTok.getIdentifierInfo(), MD);
7282
m_Parent->m_CurTransaction->append(MDE);
7383
}
@@ -101,7 +111,7 @@ namespace cling {
101111

102112
bool DeclCollector::comesFromASTReader(DeclGroupRef DGR) const {
103113
assert(!DGR.isNull() && "DeclGroupRef is Null!");
104-
assert(m_CurTransaction && "No current transaction when deserializing");
114+
assertHasTransaction(m_CurTransaction);
105115
if (m_CurTransaction->getCompilationOpts().CodeGenerationForModule)
106116
return true;
107117

@@ -183,7 +193,7 @@ namespace cling {
183193
if (DGR.isNull())
184194
return true;
185195

186-
assert(m_CurTransaction && "Missing transction");
196+
assertHasTransaction(m_CurTransaction);
187197
Transaction::DelayCallInfo DCI(DGR, Transaction::kCCIHandleTopLevelDecl);
188198
m_CurTransaction->append(DCI);
189199
if (!m_Consumer
@@ -222,7 +232,7 @@ namespace cling {
222232
}
223233

224234
void DeclCollector::HandleInterestingDecl(DeclGroupRef DGR) {
225-
assert(m_CurTransaction && "Missing transction");
235+
assertHasTransaction(m_CurTransaction);
226236
Transaction::DelayCallInfo DCI(DGR, Transaction::kCCIHandleInterestingDecl);
227237
m_CurTransaction->append(DCI);
228238
if (m_Consumer
@@ -231,7 +241,7 @@ namespace cling {
231241
}
232242

233243
void DeclCollector::HandleTagDeclDefinition(TagDecl* TD) {
234-
assert(m_CurTransaction && "Missing transction");
244+
assertHasTransaction(m_CurTransaction);
235245
Transaction::DelayCallInfo DCI(DeclGroupRef(TD),
236246
Transaction::kCCIHandleTagDeclDefinition);
237247
m_CurTransaction->append(DCI);
@@ -242,7 +252,7 @@ namespace cling {
242252
}
243253

244254
void DeclCollector::HandleInvalidTagDeclDefinition(clang::TagDecl *TD){
245-
assert(m_CurTransaction && "Missing transction");
255+
assertHasTransaction(m_CurTransaction);
246256
Transaction::DelayCallInfo DCI(DeclGroupRef(TD),
247257
Transaction::kCCIHandleTagDeclDefinition);
248258
m_CurTransaction->append(DCI);
@@ -254,7 +264,7 @@ namespace cling {
254264
}
255265

256266
void DeclCollector::HandleVTable(CXXRecordDecl* RD) {
257-
assert(m_CurTransaction && "Missing transction");
267+
assertHasTransaction(m_CurTransaction);
258268
Transaction::DelayCallInfo DCI(DeclGroupRef(RD),
259269
Transaction::kCCIHandleVTable);
260270
m_CurTransaction->append(DCI);
@@ -272,7 +282,7 @@ namespace cling {
272282
}
273283

274284
void DeclCollector::CompleteTentativeDefinition(VarDecl* VD) {
275-
assert(m_CurTransaction && "Missing transction");
285+
assertHasTransaction(m_CurTransaction);
276286
// C has tentative definitions which we might need to deal with when running
277287
// in C mode.
278288
Transaction::DelayCallInfo DCI(DeclGroupRef(VD),
@@ -290,7 +300,7 @@ namespace cling {
290300
}
291301

292302
void DeclCollector::HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {
293-
assert(m_CurTransaction && "Missing transction");
303+
assertHasTransaction(m_CurTransaction);
294304
Transaction::DelayCallInfo DCI(DeclGroupRef(D),
295305
Transaction::kCCIHandleCXXImplicitFunctionInstantiation);
296306
m_CurTransaction->append(DCI);
@@ -301,7 +311,7 @@ namespace cling {
301311
}
302312

303313
void DeclCollector::HandleCXXStaticMemberVarInstantiation(VarDecl *D) {
304-
assert(m_CurTransaction && "Missing transction");
314+
assertHasTransaction(m_CurTransaction);
305315
Transaction::DelayCallInfo DCI(DeclGroupRef(D),
306316
Transaction::kCCIHandleCXXStaticMemberVarInstantiation);
307317
m_CurTransaction->append(DCI);

0 commit comments

Comments
 (0)