Author: Jason Molenda
Date: 2024-05-21T18:04:38-07:00
New Revision: dfdf1c5fe45a82b9c578306f3d7627fd251d63f8

URL: 
https://github.com/llvm/llvm-project/commit/dfdf1c5fe45a82b9c578306f3d7627fd251d63f8
DIFF: 
https://github.com/llvm/llvm-project/commit/dfdf1c5fe45a82b9c578306f3d7627fd251d63f8.diff

LOG: Revert "[clang-repl] Extend the C support. (#89804)"

This reverts commit 253c28fa829cee0104c2fc59ed1a958980b5138c.

This commit is causing failures on the lldb CI bots, e.g.
https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/as-lldb-cmake/4307/

On my local macOS desktop build,
```
bin/lldb-dotest -p TestImportBuiltinFileID.py
Assertion failed: (D->getLexicalDeclContext() == this && "Decl inserted into 
wrong lexical context"), function addHiddenDecl, file DeclBase.cpp, line 1692.

6  libsystem_c.dylib        0x0000000185f0b8d0 abort + 128
7  libsystem_c.dylib        0x0000000185f0abc8 err + 0
8  liblldb.19.0.0git.dylib  0x00000001311e5800 
clang::DeclContext::addHiddenDecl(clang::Decl*) + 120
9  liblldb.19.0.0git.dylib  0x00000001311e5978 
clang::DeclContext::addDecl(clang::Decl*) + 32
10 liblldb.19.0.0git.dylib  0x000000012f617b48 
clang::Sema::ActOnStartTopLevelStmtDecl(clang::Scope*) + 64
11 liblldb.19.0.0git.dylib  0x000000012eaf76c8 
clang::Parser::ParseTopLevelStmtDecl() + 208
12 liblldb.19.0.0git.dylib  0x000000012ec051fc 
clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, 
clang::ParsedAttributes&, clang::ParsingDeclSpec*) + 3412
13 liblldb.19.0.0git.dylib  0x000000012ec03274 
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, 
clang::Sema::ModuleImportState&) + 2020
14 liblldb.19.0.0git.dylib  0x000000012eaca860 clang::ParseAST(clang::Sema&, 
bool, bool) + 604
15 liblldb.19.0.0git.dylib  0x000000012e8554c0 
clang::ASTFrontendAction::ExecuteAction() + 308
16 liblldb.19.0.0git.dylib  0x000000012e854c78 clang::FrontendAction::Execute() 
+ 124
17 liblldb.19.0.0git.dylib  0x000000012e76dcfc 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 984
18 liblldb.19.0.0git.dylib  0x000000012e784500 
compileModuleImpl(clang::CompilerInstance&, clang::SourceLocation, 
llvm::StringRef, clang::FrontendInputFile, llvm::StringRef, llvm::StringRef, 
llvm::function_ref<void (clang::CompilerInstance&)>, llvm::function_ref<void 
(clang::CompilerInstance&)>)::$_1::operator()() const + 52
```
Reverting until Vassil has a chance to look int oit.

Added: 
    

Modified: 
    clang/lib/Interpreter/IncrementalParser.cpp
    clang/lib/Sema/SemaDecl.cpp

Removed: 
    clang/test/Interpreter/execute.c


################################################################################
diff  --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 5bc8385d874a1..ef90fe9e6f545 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -387,7 +387,8 @@ std::unique_ptr<llvm::Module> 
IncrementalParser::GenModule() {
 
 void IncrementalParser::CleanUpPTU(PartialTranslationUnit &PTU) {
   TranslationUnitDecl *MostRecentTU = PTU.TUPart;
-  if (StoredDeclsMap *Map = MostRecentTU->getPrimaryContext()->getLookupPtr()) 
{
+  TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl();
+  if (StoredDeclsMap *Map = FirstTU->getPrimaryContext()->getLookupPtr()) {
     for (auto &&[Key, List] : *Map) {
       DeclContextLookupResult R = List.getLookupResult();
       std::vector<NamedDecl *> NamedDeclsToRemove;
@@ -406,16 +407,6 @@ void IncrementalParser::CleanUpPTU(PartialTranslationUnit 
&PTU) {
       }
     }
   }
-
-  // FIXME: We should de-allocate MostRecentTU
-  for (Decl *D : MostRecentTU->decls()) {
-    auto *ND = dyn_cast<NamedDecl>(D);
-    if (!ND)
-      continue;
-    // Check if we need to clean up the IdResolver chain.
-    if (ND->getDeclName().getFETokenInfo())
-      getCI()->getSema().IdResolver.RemoveDecl(ND);
-  }
 }
 
 llvm::StringRef IncrementalParser::GetMangledName(GlobalDecl GD) const {

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6e60ec761b253..8049ddfed872c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2282,13 +2282,9 @@ void Sema::ActOnPopScope(SourceLocation Loc, Scope *S) {
     if (LabelDecl *LD = dyn_cast<LabelDecl>(D))
       CheckPoppedLabel(LD, *this, addDiag);
 
-    // Partial translation units that are created in incremental processing 
must
-    // not clean up the IdResolver because PTUs should take into account the
-    // declarations that came from previous PTUs.
-    if (!PP.isIncrementalProcessingEnabled())
-      IdResolver.RemoveDecl(D);
-
-    // Warn on it if we are shadowing a declaration.
+    // Remove this name from our lexical scope, and warn on it if we haven't
+    // already.
+    IdResolver.RemoveDecl(D);
     auto ShadowI = ShadowingDecls.find(D);
     if (ShadowI != ShadowingDecls.end()) {
       if (const auto *FD = dyn_cast<FieldDecl>(ShadowI->second)) {

diff  --git a/clang/test/Interpreter/execute.c 
b/clang/test/Interpreter/execute.c
deleted file mode 100644
index 44a3a32c93011..0000000000000
--- a/clang/test/Interpreter/execute.c
+++ /dev/null
@@ -1,21 +0,0 @@
-// REQUIRES: host-supports-jit
-// UNSUPPORTED: system-aix
-
-// RUN: cat %s | clang-repl -Xcc -xc -Xcc -Xclang -Xcc -verify | FileCheck %s
-// RUN: cat %s | clang-repl -Xcc -xc -Xcc -O2 -Xcc -Xclang -Xcc -verify| 
FileCheck %s
-int printf(const char *, ...);
-int i = 42; err // expected-error{{use of undeclared identifier}}
-int i = 42;
-struct S { float f; struct S *m;} s = {1.0, 0};
-// FIXME: Making foo inline fails to emit the function.
-int foo() { return 42; }
-void run() {                                                    \
-  printf("i = %d\n", i);                                        \
-  printf("S[f=%f, m=0x%llx]\n", s.f, (unsigned long long)s.m);  \
-  int r3 = foo();                                               \
-}
-run();
-// CHECK: i = 42
-// CHECK-NEXT: S[f=1.000000, m=0x0]
-
-%quit


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to