diff --git a/clang/lib/Interpreter/IncrementalAction.cpp b/clang/lib/Interpreter/IncrementalAction.cpp index 3d489fce54bc6..d22031c8fa893 100644 --- a/clang/lib/Interpreter/IncrementalAction.cpp +++ b/clang/lib/Interpreter/IncrementalAction.cpp @@ -135,6 +135,11 @@ bool InProcessPrintingASTConsumer::HandleTopLevelDecl(DeclGroupRef DGR) { if (DGR.isNull()) return true; + CompilerInstance *CI = Interp.getCompilerInstance(); + DiagnosticsEngine &Diags = CI->getDiagnostics(); + if (Diags.hasErrorOccurred()) + return true; + for (Decl *D : DGR) if (auto *TLSD = llvm::dyn_cast(D)) if (TLSD && TLSD->isSemiMissing()) { diff --git a/clang/test/Interpreter/pretty-print.c b/clang/test/Interpreter/pretty-print.c index 9a7bf752238ab..b8058a762897e 100644 --- a/clang/test/Interpreter/pretty-print.c +++ b/clang/test/Interpreter/pretty-print.c @@ -20,6 +20,9 @@ const char* c_null_str = 0; c_null_str "Hello, world" // CHECK-NEXT: ({{(const )?}}char[13]) "Hello, world" +printf("Hello World\n"); +// expected-error {{call to undeclared library function 'printf' with type 'int (const char *, ...)' }} + int x = 42; x // CHECK-NEXT: (int) 42