Skip to content

Commit a0a89cb

Browse files
committed
Report ValueExtractionSynthesizer errors with DiagnosticsEngine.
1 parent da71bd1 commit a0a89cb

File tree

4 files changed

+51
-24
lines changed

4 files changed

+51
-24
lines changed

lib/Interpreter/ValueExtractionSynthesizer.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ namespace {
205205
}
206206

207207
Expr* ValueExtractionSynthesizer::SynthesizeSVRInit(Expr* E) {
208-
if (!m_gClingVD && !FindAndCacheRuntimeDecls())
208+
if (!m_gClingVD && !FindAndCacheRuntimeDecls(E))
209209
return nullptr;
210210

211211
// Build a reference to gCling
@@ -408,54 +408,54 @@ namespace {
408408
return Call.get();
409409
}
410410

411-
static bool VSError(const char* err) {
412-
cling::errs() << "ValueExtractionSynthesizer error: " << err << ".\n";
411+
static bool VSError(clang::Sema* Sema, clang::Expr* E, llvm::StringRef Err) {
412+
DiagnosticsEngine& Diags = Sema->getDiagnostics();
413+
Diags.Report(E->getLocStart(),
414+
Diags.getCustomDiagID(
415+
clang::DiagnosticsEngine::Level::Error,
416+
"ValueExtractionSynthesizer could not find: '%0'."))
417+
<< Err;
413418
return false;
414419
}
415420

416-
bool ValueExtractionSynthesizer::FindAndCacheRuntimeDecls() {
421+
bool ValueExtractionSynthesizer::FindAndCacheRuntimeDecls(clang::Expr* E) {
417422
assert(!m_gClingVD && "Called multiple times!?");
418423
DeclContext* NSD = m_Context->getTranslationUnitDecl();
419424
clang::VarDecl* clingVD = nullptr;
420425
if (m_Sema->getLangOpts().CPlusPlus) {
421426
if (!(NSD = utils::Lookup::Namespace(m_Sema, "cling")))
422-
return VSError("cling namespace not defined");
427+
return VSError(m_Sema, E, "cling namespace");
423428
if (!(NSD = utils::Lookup::Namespace(m_Sema, "runtime", NSD)))
424-
return VSError("cling::runtime namespace not defined");
425-
if (!(clingVD = cast<VarDecl>(utils::Lookup::Named(m_Sema, "gCling",
426-
NSD))))
427-
return VSError("cling::runtime::gCling not defined");
428-
if (!NSD)
429-
return VSError("cling::runtime namespace not defined");
430-
429+
return VSError(m_Sema, E, "cling::runtime namespace");
430+
if (!(clingVD = dyn_cast_or_null<VarDecl>(
431+
utils::Lookup::Named(m_Sema, "gCling", NSD))))
432+
return VSError(m_Sema, E, "cling::runtime::gCling");
431433
if (!(NSD = utils::Lookup::Namespace(m_Sema, "internal", NSD)))
432-
return VSError("cling::runtime::internal namespace not defined");
434+
return VSError(m_Sema, E, "cling::runtime::internal namespace");
433435
}
434436
LookupResult R(*m_Sema, &m_Context->Idents.get("setValueNoAlloc"),
435437
SourceLocation(), Sema::LookupOrdinaryName,
436438
Sema::ForRedeclaration);
437439

438440
m_Sema->LookupQualifiedName(R, NSD);
439441
if (R.empty())
440-
return VSError("Cannot find cling::runtime::internal::setValueNoAlloc");
442+
return VSError(m_Sema, E, "cling::runtime::internal::setValueNoAlloc");
441443

442444
const bool ADL = false;
443445
CXXScopeSpec CSS;
444446
m_UnresolvedNoAlloc = m_Sema->BuildDeclarationNameExpr(CSS, R, ADL).get();
445447
if (!m_UnresolvedNoAlloc)
446-
return VSError("Could not build cling::runtime::internal"
447-
"::setValueNoAlloc");
448+
return VSError(m_Sema, E, "cling::runtime::internal::setValueNoAlloc");
448449

449450
R.clear();
450451
R.setLookupName(&m_Context->Idents.get("setValueWithAlloc"));
451452
m_Sema->LookupQualifiedName(R, NSD);
452453
if (R.empty())
453-
return VSError("Cannot find cling::runtime::internal::setValueWithAlloc");
454+
return VSError(m_Sema, E, "cling::runtime::internal::setValueWithAlloc");
454455

455456
m_UnresolvedWithAlloc = m_Sema->BuildDeclarationNameExpr(CSS, R, ADL).get();
456457
if (!m_UnresolvedWithAlloc)
457-
return VSError("Could not build cling::runtime::internal"
458-
"::setValueWithAlloc");
458+
return VSError(m_Sema, E, "cling::runtime::internal::setValueWithAlloc");
459459

460460
R.clear();
461461
R.setLookupName(&m_Context->Idents.get("copyArray"));
@@ -467,11 +467,11 @@ namespace {
467467
// Once the import of template functions becomes supported by clang,
468468
// this check can be de-activated.
469469
if (!m_isChildInterpreter && R.empty())
470-
return VSError("Cannot find cling::runtime::internal::copyArray");
470+
return VSError(m_Sema, E, "cling::runtime::internal::copyArray");
471471

472472
m_UnresolvedCopyArray = m_Sema->BuildDeclarationNameExpr(CSS, R, ADL).get();
473473
if (!m_UnresolvedCopyArray)
474-
return VSError("Could not build cling::runtime::internal::copyArray");
474+
return VSError(m_Sema, E, "cling::runtime::internal::copyArray");
475475

476476
m_gClingVD = clingVD;
477477
return true;

lib/Interpreter/ValueExtractionSynthesizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace cling {
9090

9191
// Find and cache cling::runtime::gCling, setValueNoAlloc,
9292
// setValueWithAlloc on first request.
93-
bool FindAndCacheRuntimeDecls();
93+
bool FindAndCacheRuntimeDecls(clang::Expr*);
9494
};
9595

9696
} // namespace cling

test/Driver/C.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
int printf(const char*,...);
1717
printf("CHECK 123 %p\n", gCling); // CHECK: CHECK 123
1818

19-
// expected-no-diagnostics
19+
12 // expected-error {{ValueExtractionSynthesizer could not find: 'cling::runtime::internal::setValueNoAlloc'.}}
20+
21+
32 // expected-error {{ValueExtractionSynthesizer could not find: 'cling::runtime::internal::setValueNoAlloc'.}}
22+
2023
.q

test/ErrorRecovery/ABI.C

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,35 @@
77
//------------------------------------------------------------------------------
88

99
// RUN: %cling -C -E -P %s | %cling -nostdinc++ -Xclang -verify 2>&1 | FileCheck %s
10-
// RUN: %cling -C -E -P -DCLING_NO_BUILTIN %s | %cling -nostdinc++ -nobuiltininc -Xclang -verify 2>&1 | FileCheck %s
10+
// RUN: %cling -C -E -P -DCLING_VALEXTRACT_ERR %s | %cling -nostdinc++ -nobuiltininc -Xclang -verify 2>&1 | FileCheck %s
11+
// RUN: %cling -C -E -P -DCLING_VALEXTRACT_ERR2 %s | %cling -nostdinc++ -nobuiltininc -Xclang -verify 2>&1 | FileCheck %s
12+
// RUN: %cling -C -E -P -DCLING_VALEXTRACT_ERR3 %s | %cling -nostdinc++ -nobuiltininc -Xclang -verify 2>&1 | FileCheck %s
1113

1214
// expected-error@input_line_1:1 {{'new' file not found}}
1315

1416
// CHECK: Warning in cling::IncrementalParser::CheckABICompatibility():
1517
// CHECK-NEXT: Possible C++ standard library mismatch, compiled with {{.*$}}
1618

19+
20+
#if defined(CLING_VALEXTRACT_ERR) || defined(CLING_VALEXTRACT_ERR2) || \
21+
defined(CLING_VALEXTRACT_ERR3)
22+
23+
struct Trigger {} Tr;
24+
25+
#ifdef CLING_VALEXTRACT_ERR
26+
Tr // expected-error@2 {{ValueExtractionSynthesizer could not find: 'cling namespace'.}}
27+
#endif
28+
29+
#ifdef CLING_VALEXTRACT_ERR2
30+
namespace cling {}
31+
Tr // expected-error@2 {{ValueExtractionSynthesizer could not find: 'cling::runtime namespace'.}}
32+
#endif
33+
34+
#ifdef CLING_VALEXTRACT_ERR3
35+
namespace cling { namespace runtime {} }
36+
Tr // expected-error@2 {{ValueExtractionSynthesizer could not find: 'cling::runtime::gCling'.}}
37+
#endif
38+
39+
#endif
40+
1741
.q

0 commit comments

Comments
 (0)