|
23 | 23 | #include "clang/AST/DeclCXX.h" |
24 | 24 | #include "clang/AST/Expr.h" |
25 | 25 | #include "clang/AST/Type.h" |
| 26 | +#include "clang/Sema/SemaDiagnostic.h" |
26 | 27 | #include "clang/Frontend/CompilerInstance.h" |
27 | 28 |
|
28 | 29 | #include "llvm/Support/Format.h" |
@@ -144,22 +145,6 @@ struct AccessCtrlRAII_t { |
144 | 145 |
|
145 | 146 | }; |
146 | 147 |
|
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 | | - |
163 | 148 | static std::string printDeclType(const clang::QualType& QT, |
164 | 149 | const clang::NamedDecl* D) { |
165 | 150 | if (!QT.hasQualifiers()) |
@@ -609,14 +594,13 @@ static std::string callPrintValue(const Value& V, const void* Val) { |
609 | 594 | if (printValueV.isValid() && printValueV.getPtr()) |
610 | 595 | return *(std::string *) printValueV.getPtr(); |
611 | 596 |
|
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); |
620 | 604 |
|
621 | 605 | return "ERROR in cling's callPrintValue(): missing value string."; |
622 | 606 | } |
|
0 commit comments