From 5ff27fe1ff03d5aeaf8567c97618170f0cef8f58 Mon Sep 17 00:00:00 2001 From: Purva-Chaudhari Date: Sun, 29 May 2022 04:55:10 +0000 Subject: [PATCH] [clang-repl] Recover the lookup tables of the primary context. Before this patch, there was re-declaration error if error was encountered in the same line. The recovery support acted only if this type of error was encountered in the first line of the program and not in subsequent lines. For example: ``` clang-repl> int i=9; clang-repl> int j=9; err; input_line_3:1:5: error: redefinition of 'j' int j = 9; ``` Differential revision: https://reviews.llvm.org/D123674 --- clang/lib/Interpreter/IncrementalParser.cpp | 2 +- clang/test/Interpreter/execute.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Interpreter/IncrementalParser.cpp b/clang/lib/Interpreter/IncrementalParser.cpp index 0f1ef32..87687ea 100644 --- a/clang/lib/Interpreter/IncrementalParser.cpp +++ b/clang/lib/Interpreter/IncrementalParser.cpp @@ -188,7 +188,7 @@ IncrementalParser::ParseOrWrapTopLevelDecl() { S.TUScope->setEntity(PreviousTU); // Clean up the lookup table - if (StoredDeclsMap *Map = PreviousTU->getLookupPtr()) { + if (StoredDeclsMap *Map = PreviousTU->getPrimaryContext()->getLookupPtr()) { for (auto I = Map->begin(); I != Map->end(); ++I) { StoredDeclsList &List = I->second; DeclContextLookupResult R = List.getLookupResult(); diff --git a/clang/test/Interpreter/execute.cpp b/clang/test/Interpreter/execute.cpp index 298046c..5f3fe3e 100644 --- a/clang/test/Interpreter/execute.cpp +++ b/clang/test/Interpreter/execute.cpp @@ -1,3 +1,4 @@ +// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;" // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \ // RUN: 'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s // REQUIRES: host-supports-jit -- 2.7.4