Skip to content

Commit 7546af7

Browse files
committed
Report executePrintValue errors with DiagnosticsEngine.
1 parent 624e4cc commit 7546af7

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

lib/Interpreter/ValuePrinter.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "clang/AST/DeclCXX.h"
2424
#include "clang/AST/Expr.h"
2525
#include "clang/AST/Type.h"
26+
#include "clang/Sema/SemaDiagnostic.h"
2627
#include "clang/Frontend/CompilerInstance.h"
2728

2829
#include "llvm/Support/Format.h"
@@ -144,22 +145,6 @@ struct AccessCtrlRAII_t {
144145

145146
};
146147

147-
#ifndef NDEBUG
148-
/// Is typenam parsable?
149-
bool canParseTypeName(cling::Interpreter& Interp, llvm::StringRef typenam) {
150-
151-
AccessCtrlRAII_t AccessCtrlRAII(Interp);
152-
153-
cling::Interpreter::CompilationResult Res
154-
= Interp.declare("namespace { void* cling_printValue_Failure_Typename_check"
155-
" = (void*)" + typenam.str() + "nullptr; }");
156-
if (Res != cling::Interpreter::kSuccess)
157-
cling::errs() << "ERROR in cling::canParseTypeName(): "
158-
"this typename cannot be spelled.\n";
159-
return Res == cling::Interpreter::kSuccess;
160-
}
161-
#endif
162-
163148
static std::string printDeclType(const clang::QualType& QT,
164149
const clang::NamedDecl* D) {
165150
if (!QT.hasQualifiers())
@@ -609,14 +594,13 @@ static std::string callPrintValue(const Value& V, const void* Val) {
609594
if (printValueV.isValid() && printValueV.getPtr())
610595
return *(std::string *) printValueV.getPtr();
611596

612-
// That didn't work. We probably diagnosed the issue as part of evaluate().
613-
cling::errs() <<"ERROR in cling's callPrintValue(): cannot pass value!\n";
614-
615-
// Check that the issue comes from an unparsable type name: lambdas, unnamed
616-
// namespaces, types declared inside functions etc. Assert on everything
617-
// else.
618-
assert(!canParseTypeName(*Interp, getTypeString(V))
619-
&& "printValue failed on a valid type name.");
597+
// Probably diagnosed the issue as part of evaluate(), but make sure to
598+
// mark the Sema with an error if not.
599+
clang::DiagnosticsEngine& Diag = Interp->getDiagnostics();
600+
const unsigned ID = Diag.getCustomDiagID(
601+
clang::DiagnosticsEngine::Level::Error,
602+
"Could not execute cling::printValue with '%0'");
603+
Diag.Report(Interp->getSourceLocation(), ID) << getTypeString(V);
620604

621605
return "ERROR in cling's callPrintValue(): missing value string.";
622606
}

test/Prompt/ValuePrinter/Regression.C

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ auto bla=[](double *x, double *par, int blub){return x[0]*blub;} // CHECK: ((lam
9090
#include <functional>
9191
using namespace std::placeholders;
9292
auto fn_moo = std::bind (bla, _1,_2,10) // CHECK: ERROR in cling's callPrintValue(): missing value string.
93+
// expected-error {{Could not execute cling::printValue with '{{.*}}'}}
9394
// expected-error {{use of undeclared identifier 'lambda'}}
9495
// expected-error {{expected expression}}
9596
// expected-error {{type name requires a specifier or qualifier}}

0 commit comments

Comments
 (0)