Skip to content

Conversation

Vipul-Cariappa
Copy link
Contributor

Fixes the following crash in clang-repl

clang-repl> try { throw 1; } catch { 0; }
In file included from <<< inputs >>>:1:
input_line_1:1:23: error: expected '('
    1 | try { throw 1; } catch { 0; }
      |                       ^
      |                       (
clang-repl: /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1757: void clang::DeclContext::addHiddenDecl(clang::Decl*): Assertion `D->getLexicalDeclContext() == this && "Decl inserted into wrong lexical context"' failed.
 #0 0x000059b28459e6da llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:804:22
 #1 0x000059b28459eaed PrintStackTraceSignalHandler(void*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:880:1
 #2 0x000059b28459bf7f llvm::sys::RunSignalHandlers() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Signals.cpp:105:20
 #3 0x000059b28459df8e SignalHandler(int, siginfo_t*, void*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:418:13
 #4 0x000077cdf444ea50 (/usr/lib/libc.so.6+0x42a50)
 #5 0x000077cdf44aee3b pthread_kill (/usr/lib/libc.so.6+0xa2e3b)
 #6 0x000077cdf444e928 raise (/usr/lib/libc.so.6+0x42928)
 #7 0x000077cdf443156c abort (/usr/lib/libc.so.6+0x2556c)
 #8 0x000077cdf44314d2 __assert_perror_fail (/usr/lib/libc.so.6+0x254d2)
 #9 0x000077cdf4444c56 (/usr/lib/libc.so.6+0x38c56)
#10 0x000059b28495bfc4 clang::DeclContext::addHiddenDecl(clang::Decl*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1759:3
#11 0x000059b28495c0f5 clang::DeclContext::addDecl(clang::Decl*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1785:37
#12 0x000059b28773cc2a clang::Sema::ActOnStartTopLevelStmtDecl(clang::Scope*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Sema/SemaDecl.cpp:20302:18
#13 0x000059b286f1efdf clang::Parser::ParseTopLevelStmtDecl() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/ParseDecl.cpp:6024:62
#14 0x000059b286ef18ee clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/Parser.cpp:1065:35
#15 0x000059b286ef0702 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/Parser.cpp:758:36
#16 0x000059b28562dff2 clang::IncrementalParser::ParseOrWrapTopLevelDecl() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/IncrementalParser.cpp:66:36
#17 0x000059b28562e5b7 clang::IncrementalParser::Parse(llvm::StringRef) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/IncrementalParser.cpp:132:8
#18 0x000059b28561832b clang::Interpreter::Parse(llvm::StringRef) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/Interpreter.cpp:570:8
#19 0x000059b285618cbd clang::Interpreter::ParseAndExecute(llvm::StringRef, clang::Value*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/Interpreter.cpp:649:8
#20 0x000059b2836f9343 main /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/tools/clang-repl/ClangRepl.cpp:255:59
#21 0x000077cdf443388e (/usr/lib/libc.so.6+0x2788e)
#22 0x000077cdf443394a __libc_start_main (/usr/lib/libc.so.6+0x2794a)
#23 0x000059b2836f7965 _start (./bin/clang-repl+0x73b8965)
fish: Job 1, './bin/clang-repl' terminated by signal SIGABRT (Abort)

With this change:

clang-repl> try { throw 1; } catch { 0; }
In file included from <<< inputs >>>:1:
input_line_1:1:23: error: expected '('
    1 | try { throw 1; } catch { 0; }
      |                       ^
      |                       (
error: Parsing failed.
clang-repl> 1;
clang-repl> %quit

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 13, 2025

@llvm/pr-subscribers-clang

Author: Vipul Cariappa (Vipul-Cariappa)

Changes

Fixes the following crash in clang-repl

clang-repl&gt; try { throw 1; } catch { 0; }
In file included from &lt;&lt;&lt; inputs &gt;&gt;&gt;:1:
input_line_1:1:23: error: expected '('
    1 | try { throw 1; } catch { 0; }
      |                       ^
      |                       (
clang-repl: /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1757: void clang::DeclContext::addHiddenDecl(clang::Decl*): Assertion `D-&gt;getLexicalDeclContext() == this &amp;&amp; "Decl inserted into wrong lexical context"' failed.
 #<!-- -->0 0x000059b28459e6da llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:804:22
 #<!-- -->1 0x000059b28459eaed PrintStackTraceSignalHandler(void*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:880:1
 #<!-- -->2 0x000059b28459bf7f llvm::sys::RunSignalHandlers() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Signals.cpp:105:20
 #<!-- -->3 0x000059b28459df8e SignalHandler(int, siginfo_t*, void*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:418:13
 #<!-- -->4 0x000077cdf444ea50 (/usr/lib/libc.so.6+0x42a50)
 #<!-- -->5 0x000077cdf44aee3b pthread_kill (/usr/lib/libc.so.6+0xa2e3b)
 #<!-- -->6 0x000077cdf444e928 raise (/usr/lib/libc.so.6+0x42928)
 #<!-- -->7 0x000077cdf443156c abort (/usr/lib/libc.so.6+0x2556c)
 #<!-- -->8 0x000077cdf44314d2 __assert_perror_fail (/usr/lib/libc.so.6+0x254d2)
 #<!-- -->9 0x000077cdf4444c56 (/usr/lib/libc.so.6+0x38c56)
#<!-- -->10 0x000059b28495bfc4 clang::DeclContext::addHiddenDecl(clang::Decl*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1759:3
#<!-- -->11 0x000059b28495c0f5 clang::DeclContext::addDecl(clang::Decl*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1785:37
#<!-- -->12 0x000059b28773cc2a clang::Sema::ActOnStartTopLevelStmtDecl(clang::Scope*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Sema/SemaDecl.cpp:20302:18
#<!-- -->13 0x000059b286f1efdf clang::Parser::ParseTopLevelStmtDecl() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/ParseDecl.cpp:6024:62
#<!-- -->14 0x000059b286ef18ee clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/Parser.cpp:1065:35
#<!-- -->15 0x000059b286ef0702 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&lt;clang::DeclGroupRef&gt;&amp;, clang::Sema::ModuleImportState&amp;) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/Parser.cpp:758:36
#<!-- -->16 0x000059b28562dff2 clang::IncrementalParser::ParseOrWrapTopLevelDecl() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/IncrementalParser.cpp:66:36
#<!-- -->17 0x000059b28562e5b7 clang::IncrementalParser::Parse(llvm::StringRef) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/IncrementalParser.cpp:132:8
#<!-- -->18 0x000059b28561832b clang::Interpreter::Parse(llvm::StringRef) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/Interpreter.cpp:570:8
#<!-- -->19 0x000059b285618cbd clang::Interpreter::ParseAndExecute(llvm::StringRef, clang::Value*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/Interpreter.cpp:649:8
#<!-- -->20 0x000059b2836f9343 main /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/tools/clang-repl/ClangRepl.cpp:255:59
#<!-- -->21 0x000077cdf443388e (/usr/lib/libc.so.6+0x2788e)
#<!-- -->22 0x000077cdf443394a __libc_start_main (/usr/lib/libc.so.6+0x2794a)
#<!-- -->23 0x000059b2836f7965 _start (./bin/clang-repl+0x73b8965)
fish: Job 1, './bin/clang-repl' terminated by signal SIGABRT (Abort)

With this change:

clang-repl&gt; try { throw 1; } catch { 0; }
In file included from &lt;&lt;&lt; inputs &gt;&gt;&gt;:1:
input_line_1:1:23: error: expected '('
    1 | try { throw 1; } catch { 0; }
      |                       ^
      |                       (
error: Parsing failed.
clang-repl&gt; 1;
clang-repl&gt; %quit

Full diff: https://github.com/llvm/llvm-project/pull/127087.diff

2 Files Affected:

  • (modified) clang/lib/Parse/ParseDecl.cpp (+1-1)
  • (modified) clang/unittests/Interpreter/InterpreterTest.cpp (+7)
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 75b5e11f8327c..7ae136af47391 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -6024,7 +6024,7 @@ Parser::DeclGroupPtrTy Parser::ParseTopLevelStmtDecl() {
   TopLevelStmtDecl *TLSD = Actions.ActOnStartTopLevelStmtDecl(getCurScope());
   StmtResult R = ParseStatementOrDeclaration(Stmts, SubStmtCtx);
   if (!R.isUsable())
-    return nullptr;
+    R = Actions.ActOnNullStmt(Tok.getLocation());
 
   Actions.ActOnFinishTopLevelStmtDecl(TLSD, R.get());
 
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index 30b051e747f92..578f1d4c0eac6 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -107,6 +107,13 @@ TEST_F(InterpreterTest, Errors) {
 
   auto RecoverErr = Interp->Parse("int var1 = 42;");
   EXPECT_TRUE(!!RecoverErr);
+
+  Err = Interp->Parse("try { throw 1; } catch { 0; }").takeError();
+  EXPECT_THAT(DiagnosticOutput, HasSubstr("error: expected '('"));
+  EXPECT_EQ("Parsing failed.", llvm::toString(std::move(Err)));
+
+  RecoverErr = Interp->Parse("var1 = 424;");
+  EXPECT_TRUE(!!RecoverErr);
 }
 
 // Here we test whether the user can mix declarations and statements. The

@Vipul-Cariappa
Copy link
Contributor Author

cc @vgvassilev

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm! Thank you, @Vipul-Cariappa!

@vgvassilev vgvassilev merged commit 4ac68ba into llvm:main Feb 14, 2025
11 checks passed
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
…127087)

Fixes the following crash in clang-repl

```c++
clang-repl> try { throw 1; } catch { 0; }
In file included from <<< inputs >>>:1:
input_line_1:1:23: error: expected '('
    1 | try { throw 1; } catch { 0; }
      |                       ^
      |                       (
clang-repl: /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1757: void clang::DeclContext::addHiddenDecl(clang::Decl*): Assertion `D->getLexicalDeclContext() == this && "Decl inserted into wrong lexical context"' failed.
 #0 0x000059b28459e6da llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:804:22
 #1 0x000059b28459eaed PrintStackTraceSignalHandler(void*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:880:1
 llvm#2 0x000059b28459bf7f llvm::sys::RunSignalHandlers() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Signals.cpp:105:20
 llvm#3 0x000059b28459df8e SignalHandler(int, siginfo_t*, void*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:418:13
 llvm#4 0x000077cdf444ea50 (/usr/lib/libc.so.6+0x42a50)
 llvm#5 0x000077cdf44aee3b pthread_kill (/usr/lib/libc.so.6+0xa2e3b)
 llvm#6 0x000077cdf444e928 raise (/usr/lib/libc.so.6+0x42928)
 llvm#7 0x000077cdf443156c abort (/usr/lib/libc.so.6+0x2556c)
 llvm#8 0x000077cdf44314d2 __assert_perror_fail (/usr/lib/libc.so.6+0x254d2)
 llvm#9 0x000077cdf4444c56 (/usr/lib/libc.so.6+0x38c56)
llvm#10 0x000059b28495bfc4 clang::DeclContext::addHiddenDecl(clang::Decl*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1759:3
llvm#11 0x000059b28495c0f5 clang::DeclContext::addDecl(clang::Decl*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1785:37
llvm#12 0x000059b28773cc2a clang::Sema::ActOnStartTopLevelStmtDecl(clang::Scope*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Sema/SemaDecl.cpp:20302:18
llvm#13 0x000059b286f1efdf clang::Parser::ParseTopLevelStmtDecl() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/ParseDecl.cpp:6024:62
llvm#14 0x000059b286ef18ee clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/Parser.cpp:1065:35
llvm#15 0x000059b286ef0702 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/Parser.cpp:758:36
llvm#16 0x000059b28562dff2 clang::IncrementalParser::ParseOrWrapTopLevelDecl() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/IncrementalParser.cpp:66:36
llvm#17 0x000059b28562e5b7 clang::IncrementalParser::Parse(llvm::StringRef) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/IncrementalParser.cpp:132:8
llvm#18 0x000059b28561832b clang::Interpreter::Parse(llvm::StringRef) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/Interpreter.cpp:570:8
llvm#19 0x000059b285618cbd clang::Interpreter::ParseAndExecute(llvm::StringRef, clang::Value*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/Interpreter.cpp:649:8
llvm#20 0x000059b2836f9343 main /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/tools/clang-repl/ClangRepl.cpp:255:59
llvm#21 0x000077cdf443388e (/usr/lib/libc.so.6+0x2788e)
llvm#22 0x000077cdf443394a __libc_start_main (/usr/lib/libc.so.6+0x2794a)
llvm#23 0x000059b2836f7965 _start (./bin/clang-repl+0x73b8965)
fish: Job 1, './bin/clang-repl' terminated by signal SIGABRT (Abort)
```

With this change:
```c++
clang-repl> try { throw 1; } catch { 0; }
In file included from <<< inputs >>>:1:
input_line_1:1:23: error: expected '('
    1 | try { throw 1; } catch { 0; }
      |                       ^
      |                       (
error: Parsing failed.
clang-repl> 1;
clang-repl> %quit
```
@anutosh491
Copy link
Member

anutosh491 commented Feb 18, 2025

There are quite some observations made by @kr-2003 and me here.

  1. We realize even without this fix, stuff worked perfectly on our Macos ARM devices. So looks like a Ubuntu issue anyways

image

  1. Obviously the try-catch block works when wrapped inside a class/function (not a top level decl)

  2. If we build clang-repl with different configs, it works even on ubuntu

i) -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -DLLVM_USE_SPLIT_DWARF=ON -DLLVM_USE_LINKER=lld

With this

(base) abhinav@jarvis-2223:~/Desktop/Coding/llvm-project/build/bin$ ./clang-repl --version
LLVM (http://llvm.org/):
  LLVM version 20.1.0-rc1
  Optimized build.
(base) abhinav@jarvis-2223:~/Desktop/Coding/llvm-project/build/bin$ ./clang-repl
clang-repl> #include <iostream>
clang-repl> try { throw 1; } catch { std::cout << "Caught Exception" << std::endl; }
In file included from <<< inputs >>>:1:
input_line_2:1:23: error: expected '('
    1 | try { throw 1; } catch { std::cout << "Caught Exception" << std::endl; }
      |                       ^
      |                       (
error: Parsing failed.
clang-repl>

ii) With the following it fails.

-DLLVM_ENABLE_PROJECTS=clang                        \
        -DLLVM_TARGETS_TO_BUILD="host;NVPTX"                \
        -DCMAKE_BUILD_TYPE=Release                          \
        -DLLVM_ENABLE_ASSERTIONS=ON                         \
        -DCLANG_ENABLE_STATIC_ANALYZER=OFF                  \
        -DCLANG_ENABLE_ARCMT=OFF                            \
        -DCLANG_ENABLE_FORMAT=OFF                           \
        -DCLANG_ENABLE_BOOTSTRAP=OFF                        \
        -DLLVM_ENABLE_ZSTD=OFF                              \
        -DLLVM_ENABLE_TERMINFO=OFF                          \
        -DLLVM_ENABLE_LIBXML2=OFF                           \
        

Abhinav, could you also past the diff between how using two different configs affects the build ?
Maybe that might point us to the root cause behind all of this.

@kr-2003
Copy link
Contributor

kr-2003 commented Feb 18, 2025

There are quite some observations made by @kr-2003 and me here.

  1. We realize even without this fix, stuff worked perfectly on our Macos ARM devices. So looks like a Ubuntu issue anyways

image

  1. Obviously the try-catch block works when wrapped inside a class/function (not a top level decl)
  2. If we build clang-repl with different configs, it works even on ubuntu

i) -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -DLLVM_USE_SPLIT_DWARF=ON -DLLVM_USE_LINKER=lld

With this

(base) abhinav@jarvis-2223:~/Desktop/Coding/llvm-project/build/bin$ ./clang-repl --version
LLVM (http://llvm.org/):
  LLVM version 20.1.0-rc1
  Optimized build.
(base) abhinav@jarvis-2223:~/Desktop/Coding/llvm-project/build/bin$ ./clang-repl
clang-repl> #include <iostream>
clang-repl> try { throw 1; } catch { std::cout << "Caught Exception" << std::endl; }
In file included from <<< inputs >>>:1:
input_line_2:1:23: error: expected '('
    1 | try { throw 1; } catch { std::cout << "Caught Exception" << std::endl; }
      |                       ^
      |                       (
error: Parsing failed.
clang-repl>

ii) With the following it fails.

-DLLVM_ENABLE_PROJECTS=clang                        \
        -DLLVM_TARGETS_TO_BUILD="host;NVPTX"                \
        -DCMAKE_BUILD_TYPE=Release                          \
        -DLLVM_ENABLE_ASSERTIONS=ON                         \
        -DCLANG_ENABLE_STATIC_ANALYZER=OFF                  \
        -DCLANG_ENABLE_ARCMT=OFF                            \
        -DCLANG_ENABLE_FORMAT=OFF                           \
        -DCLANG_ENABLE_BOOTSTRAP=OFF                        \
        -DLLVM_ENABLE_ZSTD=OFF                              \
        -DLLVM_ENABLE_TERMINFO=OFF                          \
        -DLLVM_ENABLE_LIBXML2=OFF                           \
        

Abhinav, could you also past the diff between how using two different configs affects the build ? Maybe that might point us to the root cause behind all of this.

Sure, this is diff of two CMakeCache.txt files when built with different flags.

2c2
< # For build in directory: /home/abhinav/Desktop/Coding/llvm-project/build
---
> # For build in directory: /home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/build
76a77,79
> //Build clang-format VS plugin
> BUILD_CLANG_FORMAT_VS_PLUGIN:BOOL=OFF
> 
89,91d91
< //Host clang executable. Saves building if cross-compiling.
< CLANG:STRING=
< 
128c128,134
< CLANG_ENABLE_ARCMT:BOOL=ON
---
> CLANG_ENABLE_ARCMT:BOOL=OFF
> 
> //No help, variable specified on the command line.
> CLANG_ENABLE_BOOTSTRAP:UNINITIALIZED=OFF
> 
> //No help, variable specified on the command line.
> CLANG_ENABLE_FORMAT:UNINITIALIZED=OFF
134c140
< CLANG_ENABLE_LIBXML2:BOOL=ON
---
> CLANG_ENABLE_LIBXML2:BOOL=OFF
140c146
< CLANG_ENABLE_STATIC_ANALYZER:BOOL=ON
---
> CLANG_ENABLE_STATIC_ANALYZER:BOOL=OFF
144c150
< CLANG_EXECUTABLE_VERSION:STRING=20
---
> CLANG_EXECUTABLE_VERSION:STRING=19
158,163d163
< //Install the scan-build tool
< CLANG_INSTALL_SCANBUILD:BOOL=ON
< 
< //Install the scan-view tool
< CLANG_INSTALL_SCANVIEW:BOOL=ON
< 
169c169
< CLANG_PGO_TRAINING_DATA:PATH=/home/abhinav/Desktop/Coding/llvm-project/clang/utils/perf-training
---
> CLANG_PGO_TRAINING_DATA:PATH=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/clang/utils/perf-training
212c212
< //Whether to build arcmt-test as part of CLANG
---
> //Whether to build ARCMT_TEST as part of CLANG
215c215
< //Whether to build clang-check as part of CLANG
---
> //Whether to build CLANG_CHECK as part of CLANG
221c221
< //Whether to build clang-extdef-mapping as part of CLANG
---
> //Whether to build CLANG_EXTDEF_MAPPING as part of CLANG
226a227,229
> //Whether to build clang-format-vs as part of CLANG
> CLANG_TOOL_CLANG_FORMAT_VS_BUILD:BOOL=ON
> 
250a254,256
> //Whether to build clang-rename as part of CLANG
> CLANG_TOOL_CLANG_RENAME_BUILD:BOOL=ON
> 
260,263c266
< //Whether to build clang-sycl-linker as part of CLANG
< CLANG_TOOL_CLANG_SYCL_LINKER_BUILD:BOOL=ON
< 
< //Whether to build c-arcmt-test as part of CLANG
---
> //Whether to build C_ARCMT_TEST as part of CLANG
290c293
< //Whether to build scan-build as part of CLANG
---
> //Whether to build SCAN_BUILD as part of CLANG
293c296
< //Whether to build scan-build-py as part of CLANG
---
> //Whether to build SCAN_BUILD_PY as part of CLANG
296c299
< //Whether to build scan-view as part of CLANG
---
> //Whether to build SCAN_VIEW as part of CLANG
339c342
< CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
---
> CMAKE_BUILD_TYPE:STRING=Debug
433c436
< CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=/home/abhinav/Desktop/Coding/llvm-project/build/CMakeFiles/pkgRedirects
---
> CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/build/CMakeFiles/pkgRedirects
534c537
< CMAKE_PROJECT_VERSION:STATIC=20.1.0
---
> CMAKE_PROJECT_VERSION:STATIC=19.1.7
537c540
< CMAKE_PROJECT_VERSION_MAJOR:STATIC=20
---
> CMAKE_PROJECT_VERSION_MAJOR:STATIC=19
543c546
< CMAKE_PROJECT_VERSION_PATCH:STATIC=0
---
> CMAKE_PROJECT_VERSION_PATCH:STATIC=7
702c705
< LIBCLANG_LIBRARY_VERSION:STRING=20
---
> LIBCLANG_LIBRARY_VERSION:STRING=19
707,715d709
< //Path to a file.
< LIBXML2_INCLUDE_DIR:PATH=/usr/include/libxml2
< 
< //Path to a library.
< LIBXML2_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libxml2.so
< 
< //Path to a program.
< LIBXML2_XMLLINT_EXECUTABLE:FILEPATH=/home/abhinav/miniconda3/bin/xmllint
< 
732,734d725
< //Host llvm-as executable. Saves building if cross-compiling.
< LLVM_AS:STRING=
< 
736c727
< LLVM_BINARY_DIR:STATIC=/home/abhinav/Desktop/Coding/llvm-project/build
---
> LLVM_BINARY_DIR:STATIC=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/build
772,773d762
< LLVM_BUILD_LLVM_DYLIB_VIS:BOOL=FALSE
< 
780,782d768
< //Build the telemetry library. This does not enable telemetry.
< LLVM_BUILD_TELEMETRY:BOOL=ON
< 
814c800
< LLVM_ENABLE_ASSERTIONS:BOOL=OFF
---
> LLVM_ENABLE_ASSERTIONS:BOOL=ON
836,839d821
< //Enhance Debugify's line number coverage tracking; enabling this
< // is ABI-breaking. Can be DISABLED, or COVERAGE.
< LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING:STRING=DISABLED
< 
885c867
< LLVM_ENABLE_LIBXML2:STRING=ON
---
> LLVM_ENABLE_LIBXML2:STRING=OFF
947a930,932
> //No help, variable specified on the command line.
> LLVM_ENABLE_TERMINFO:UNINITIALIZED=OFF
> 
969c954
< LLVM_ENABLE_ZSTD:STRING=ON
---
> LLVM_ENABLE_ZSTD:STRING=OFF
992c977
< LLVM_EXTERNAL_CLANG_SOURCE_DIR:PATH=/home/abhinav/Desktop/Coding/llvm-project/llvm/../clang
---
> LLVM_EXTERNAL_CLANG_SOURCE_DIR:PATH=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/llvm/../clang
1154,1156d1138
< //Host llvm-link executable. Saves building if cross-compiling.
< LLVM_LINK:STRING=
< 
1206c1188
< LLVM_SOURCE_DIR:STATIC=/home/abhinav/Desktop/Coding/llvm-project/llvm
---
> LLVM_SOURCE_DIR:STATIC=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/llvm
1218c1200
< LLVM_TARGETS_TO_BUILD:STRING=all
---
> LLVM_TARGETS_TO_BUILD:STRING=host;NVPTX
1233c1215
< LLVM_THINLTO_CACHE_PATH:STRING=/home/abhinav/Desktop/Coding/llvm-project/build/lto.cache
---
> LLVM_THINLTO_CACHE_PATH:STRING=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/build/lto.cache
1237c1219
< LLVM_THIRD_PARTY_DIR:STRING=/home/abhinav/Desktop/Coding/llvm-project/llvm/../third-party
---
> LLVM_THIRD_PARTY_DIR:STRING=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/llvm/../third-party
1323,1325d1304
< //Whether to build llvm-cgdata as part of LLVM
< LLVM_TOOL_LLVM_CGDATA_BUILD:BOOL=ON
< 
1332,1334d1310
< //Whether to build llvm-ctxprof-util as part of LLVM
< LLVM_TOOL_LLVM_CTXPROF_UTIL_BUILD:BOOL=ON
< 
1600,1602d1575
< //No help, variable specified on the command line.
< LLVM_USE_LINKER:UNINITIALIZED=lld
< 
1619c1592
< LLVM_USE_SPLIT_DWARF:BOOL=ON
---
> LLVM_USE_SPLIT_DWARF:BOOL=OFF
1656,1658d1628
< //Host opt executable. Saves building if cross-compiling.
< OPT:STRING=
< 
1701c1671
< benchmark_BINARY_DIR:STATIC=/home/abhinav/Desktop/Coding/llvm-project/build/third-party/benchmark
---
> benchmark_BINARY_DIR:STATIC=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/build/third-party/benchmark
1707,1719c1677
< benchmark_SOURCE_DIR:STATIC=/home/abhinav/Desktop/Coding/llvm-project/third-party/benchmark
< 
< clang_exe:STRING=$<TARGET_FILE:clang>
< 
< clang_target:STRING=clang
< 
< llvm_as_exe:STRING=$<TARGET_FILE:llvm-as>
< 
< llvm_as_target:STRING=llvm-as
< 
< llvm_link_exe:STRING=$<TARGET_FILE:llvm-link>
< 
< llvm_link_target:STRING=llvm-link
---
> benchmark_SOURCE_DIR:STATIC=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/third-party/benchmark
1729,1744d1686
< opt_exe:STRING=$<TARGET_FILE:opt>
< 
< opt_target:STRING=opt
< 
< //Path to a library.
< pkgcfg_lib_PC_LIBXML_xml2:FILEPATH=/usr/lib/x86_64-linux-gnu/libxml2.so
< 
< //Path to a file.
< zstd_INCLUDE_DIR:PATH=zstd_INCLUDE_DIR-NOTFOUND
< 
< //Path to a library.
< zstd_LIBRARY:FILEPATH=zstd_LIBRARY-NOTFOUND
< 
< //Path to a library.
< zstd_STATIC_LIBRARY:FILEPATH=zstd_STATIC_LIBRARY-NOTFOUND
< 
1788a1731,1732
> //ADVANCED property for variable: CLANG_TOOL_CLANG_FORMAT_VS_BUILD
> CLANG_TOOL_CLANG_FORMAT_VS_BUILD-ADVANCED:INTERNAL=1
1804a1749,1750
> //ADVANCED property for variable: CLANG_TOOL_CLANG_RENAME_BUILD
> CLANG_TOOL_CLANG_RENAME_BUILD-ADVANCED:INTERNAL=1
1811,1812d1756
< //ADVANCED property for variable: CLANG_TOOL_CLANG_SYCL_LINKER_BUILD
< CLANG_TOOL_CLANG_SYCL_LINKER_BUILD-ADVANCED:INTERNAL=1
1853c1797
< CMAKE_CACHEFILE_DIR:INTERNAL=/home/abhinav/Desktop/Coding/llvm-project/build
---
> CMAKE_CACHEFILE_DIR:INTERNAL=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/build
1934c1878
< CMAKE_HOME_DIRECTORY:INTERNAL=/home/abhinav/Desktop/Coding/llvm-project/llvm
---
> CMAKE_HOME_DIRECTORY:INTERNAL=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/llvm
1986c1930
< CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=610
---
> CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=483
2073,2074d2016
< //Test CXX_SUPPORTS_CUSTOM_LINKER
< CXX_SUPPORTS_CUSTOM_LINKER:INTERNAL=1
2101,2102d2042
< //Details about finding LibXml2
< FIND_PACKAGE_MESSAGE_DETAILS_LibXml2:INTERNAL=[/usr/lib/x86_64-linux-gnu/libxml2.so][/usr/include/libxml2][v2.9.10()]
2166a2107,2110
> //Have symbol dladdr
> HAVE_DLADDR:INTERNAL=1
> //Have include dlfcn.h
> HAVE_DLFCN_H:INTERNAL=1
2168a2113,2118
> //Have include errno.h
> HAVE_ERRNO_H:INTERNAL=1
> //Have include fcntl.h
> HAVE_FCNTL_H:INTERNAL=1
> //Have include fenv.h
> HAVE_FENV_H:INTERNAL=1
2174a2125,2126
> //Have symbol getrlimit
> HAVE_GETRLIMIT:INTERNAL=1
2189,2190d2140
< //Have symbol xmlReadMemory
< HAVE_LIBXML2:INTERNAL=1
2194a2145,2146
> //Have include link.h
> HAVE_LINK_H:INTERNAL=1
2196a2149,2150
> //Have include mach/mach.h
> HAVE_MACH_MACH_H:INTERNAL=
2202a2157,2158
> //Have include malloc/malloc.h
> HAVE_MALLOC_MALLOC_H:INTERNAL=
2213,2214c2169,2170
< //Have symbol pthread_get_name_np
< HAVE_PTHREAD_GET_NAME_NP:INTERNAL=
---
> //Have include pthread.h
> HAVE_PTHREAD_H:INTERNAL=1
2221,2222d2176
< //Have symbol pthread_set_name_np
< HAVE_PTHREAD_SET_NAME_NP:INTERNAL=
2228a2183,2184
> //Have symbol setrlimit
> HAVE_SETRLIMIT:INTERNAL=1
2230a2187,2188
> //Have include signal.h
> HAVE_SIGNAL_H:INTERNAL=1
2238a2197,2216
> //Have include sysexits.h
> HAVE_SYSEXITS_H:INTERNAL=1
> //Have include sys/ioctl.h
> HAVE_SYS_IOCTL_H:INTERNAL=1
> //Have include sys/mman.h
> HAVE_SYS_MMAN_H:INTERNAL=1
> //Have include sys/param.h
> HAVE_SYS_PARAM_H:INTERNAL=1
> //Have include sys/resource.h
> HAVE_SYS_RESOURCE_H:INTERNAL=1
> //Have include sys/stat.h
> HAVE_SYS_STAT_H:INTERNAL=1
> //Have include sys/time.h
> HAVE_SYS_TIME_H:INTERNAL=1
> //Have include sys/types.h
> HAVE_SYS_TYPES_H:INTERNAL=1
> //Have include termios.h
> HAVE_TERMIOS_H:INTERNAL=1
> //Have include unistd.h
> HAVE_UNISTD_H:INTERNAL=1
2251,2258d2228
< //ADVANCED property for variable: LIBXML2_INCLUDE_DIR
< LIBXML2_INCLUDE_DIR-ADVANCED:INTERNAL=1
< //ADVANCED property for variable: LIBXML2_LIBRARY
< LIBXML2_LIBRARY-ADVANCED:INTERNAL=1
< //ADVANCED property for variable: LIBXML2_XMLLINT_EXECUTABLE
< LIBXML2_XMLLINT_EXECUTABLE-ADVANCED:INTERNAL=1
< //Test LINKER_SUPPORTS_GDB_INDEX
< LINKER_SUPPORTS_GDB_INDEX:INTERNAL=1
2263,2264d2232
< //ADVANCED property for variable: LLVM_BUILD_LLVM_DYLIB_VIS
< LLVM_BUILD_LLVM_DYLIB_VIS-ADVANCED:INTERNAL=1
2266,2267d2233
< //STRINGS property for variable: LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING
< LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING-STRINGS:INTERNAL=DISABLED;COVERAGE
2317,2318d2282
< //ADVANCED property for variable: LLVM_TOOL_LLVM_CGDATA_BUILD
< LLVM_TOOL_LLVM_CGDATA_BUILD-ADVANCED:INTERNAL=1
2323,2324d2286
< //ADVANCED property for variable: LLVM_TOOL_LLVM_CTXPROF_UTIL_BUILD
< LLVM_TOOL_LLVM_CTXPROF_UTIL_BUILD-ADVANCED:INTERNAL=1
2518,2552d2479
< PC_LIBXML_CFLAGS:INTERNAL=-I/usr/include/libxml2
< PC_LIBXML_CFLAGS_I:INTERNAL=
< PC_LIBXML_CFLAGS_OTHER:INTERNAL=
< PC_LIBXML_FOUND:INTERNAL=1
< PC_LIBXML_INCLUDEDIR:INTERNAL=/usr/include
< PC_LIBXML_INCLUDE_DIRS:INTERNAL=/usr/include/libxml2
< PC_LIBXML_LDFLAGS:INTERNAL=-L/usr/lib/x86_64-linux-gnu;-lxml2
< PC_LIBXML_LDFLAGS_OTHER:INTERNAL=
< PC_LIBXML_LIBDIR:INTERNAL=/usr/lib/x86_64-linux-gnu
< PC_LIBXML_LIBRARIES:INTERNAL=xml2
< PC_LIBXML_LIBRARY_DIRS:INTERNAL=/usr/lib/x86_64-linux-gnu
< PC_LIBXML_LIBS:INTERNAL=
< PC_LIBXML_LIBS_L:INTERNAL=
< PC_LIBXML_LIBS_OTHER:INTERNAL=
< PC_LIBXML_LIBS_PATHS:INTERNAL=
< PC_LIBXML_MODULE_NAME:INTERNAL=libxml-2.0
< PC_LIBXML_PREFIX:INTERNAL=/usr
< PC_LIBXML_STATIC_CFLAGS:INTERNAL=-I/usr/include/libxml2
< PC_LIBXML_STATIC_CFLAGS_I:INTERNAL=
< PC_LIBXML_STATIC_CFLAGS_OTHER:INTERNAL=
< PC_LIBXML_STATIC_INCLUDE_DIRS:INTERNAL=/usr/include/libxml2
< PC_LIBXML_STATIC_LDFLAGS:INTERNAL=-L/usr/lib/x86_64-linux-gnu;-lxml2;-licui18n;-licuuc;-licudata;-lz;-llzma;-lm
< PC_LIBXML_STATIC_LDFLAGS_OTHER:INTERNAL=
< PC_LIBXML_STATIC_LIBDIR:INTERNAL=
< PC_LIBXML_STATIC_LIBRARIES:INTERNAL=xml2;icui18n;icuuc;icudata;z;lzma;m
< PC_LIBXML_STATIC_LIBRARY_DIRS:INTERNAL=/usr/lib/x86_64-linux-gnu
< PC_LIBXML_STATIC_LIBS:INTERNAL=
< PC_LIBXML_STATIC_LIBS_L:INTERNAL=
< PC_LIBXML_STATIC_LIBS_OTHER:INTERNAL=
< PC_LIBXML_STATIC_LIBS_PATHS:INTERNAL=
< PC_LIBXML_VERSION:INTERNAL=2.9.10
< PC_LIBXML_libxml-2.0_INCLUDEDIR:INTERNAL=
< PC_LIBXML_libxml-2.0_LIBDIR:INTERNAL=
< PC_LIBXML_libxml-2.0_PREFIX:INTERNAL=
< PC_LIBXML_libxml-2.0_VERSION:INTERNAL=
2592d2518
< __pkg_config_arguments_PC_LIBXML:INTERNAL=QUIET;libxml-2.0
2594d2519
< __pkg_config_checked_PC_LIBXML:INTERNAL=1
2601,2609d2525
< //ADVANCED property for variable: pkgcfg_lib_PC_LIBXML_xml2
< pkgcfg_lib_PC_LIBXML_xml2-ADVANCED:INTERNAL=1
< prefix_result:INTERNAL=/usr/lib/x86_64-linux-gnu
< //ADVANCED property for variable: zstd_INCLUDE_DIR
< zstd_INCLUDE_DIR-ADVANCED:INTERNAL=1
< //ADVANCED property for variable: zstd_LIBRARY
< zstd_LIBRARY-ADVANCED:INTERNAL=1
< //ADVANCED property for variable: zstd_STATIC_LIBRARY
< zstd_STATIC_LIBRARY-ADVANCED:INTERNAL=1

@Vipul-Cariappa
Copy link
Contributor Author

My theory with limited testing: The crash is caused by assertion failure at https://github.com/llvm/llvm-project/blob/eb7c947272952d40d3235d89652a10da52cb2b4d/clang/lib/AST/DeclBase.cpp#L1757C1-L1758C54. So if we disable assertions it does not crash, and crashes otherwise.
Maybe you can confirm this.
There is a flaw in the logic of recovering from syntax/semantic errors.

@kr-2003
Copy link
Contributor

kr-2003 commented Feb 18, 2025

My theory with limited testing: The crash is caused by assertion failure at https://github.com/llvm/llvm-project/blob/eb7c947272952d40d3235d89652a10da52cb2b4d/clang/lib/AST/DeclBase.cpp#L1757C1-L1758C54. So if we disable assertions it does not crash, and crashes otherwise. Maybe you can confirm this. There is a flaw in the logic of recovering from syntax/semantic errors.

Even without removing those assertions, the malformed try-catch block gave parsing error successfully if we build it with the following flags.
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -DLLVM_USE_SPLIT_DWARF=ON -DLLVM_USE_LINKER=lld

@anutosh491
Copy link
Member

Hmmm confused !

So does it really come down to the flag responsible for enabling assertions.
LLVM_ENABLE_ASSERTIONS=ON

@kr-2003
Copy link
Contributor

kr-2003 commented Feb 19, 2025

Hmmm confused !

So does it really come down to the flag responsible for enabling assertions.
LLVM_ENABLE_ASSERTIONS=ON

Seems like it. This is the only flag that explains this behaviour.

@anutosh491
Copy link
Member

Maybe @vgvassilev might know more about this behaviour and if it is expected.

For some context you can read the discussion from here #127087 (comment)

sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
…127087)

Fixes the following crash in clang-repl

```c++
clang-repl> try { throw 1; } catch { 0; }
In file included from <<< inputs >>>:1:
input_line_1:1:23: error: expected '('
    1 | try { throw 1; } catch { 0; }
      |                       ^
      |                       (
clang-repl: /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1757: void clang::DeclContext::addHiddenDecl(clang::Decl*): Assertion `D->getLexicalDeclContext() == this && "Decl inserted into wrong lexical context"' failed.
 #0 0x000059b28459e6da llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:804:22
 llvm#1 0x000059b28459eaed PrintStackTraceSignalHandler(void*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:880:1
 llvm#2 0x000059b28459bf7f llvm::sys::RunSignalHandlers() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Signals.cpp:105:20
 llvm#3 0x000059b28459df8e SignalHandler(int, siginfo_t*, void*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/llvm/lib/Support/Unix/Signals.inc:418:13
 llvm#4 0x000077cdf444ea50 (/usr/lib/libc.so.6+0x42a50)
 llvm#5 0x000077cdf44aee3b pthread_kill (/usr/lib/libc.so.6+0xa2e3b)
 llvm#6 0x000077cdf444e928 raise (/usr/lib/libc.so.6+0x42928)
 llvm#7 0x000077cdf443156c abort (/usr/lib/libc.so.6+0x2556c)
 llvm#8 0x000077cdf44314d2 __assert_perror_fail (/usr/lib/libc.so.6+0x254d2)
 llvm#9 0x000077cdf4444c56 (/usr/lib/libc.so.6+0x38c56)
llvm#10 0x000059b28495bfc4 clang::DeclContext::addHiddenDecl(clang::Decl*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1759:3
llvm#11 0x000059b28495c0f5 clang::DeclContext::addDecl(clang::Decl*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/AST/DeclBase.cpp:1785:37
llvm#12 0x000059b28773cc2a clang::Sema::ActOnStartTopLevelStmtDecl(clang::Scope*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Sema/SemaDecl.cpp:20302:18
llvm#13 0x000059b286f1efdf clang::Parser::ParseTopLevelStmtDecl() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/ParseDecl.cpp:6024:62
llvm#14 0x000059b286ef18ee clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/Parser.cpp:1065:35
llvm#15 0x000059b286ef0702 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Parse/Parser.cpp:758:36
llvm#16 0x000059b28562dff2 clang::IncrementalParser::ParseOrWrapTopLevelDecl() /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/IncrementalParser.cpp:66:36
llvm#17 0x000059b28562e5b7 clang::IncrementalParser::Parse(llvm::StringRef) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/IncrementalParser.cpp:132:8
llvm#18 0x000059b28561832b clang::Interpreter::Parse(llvm::StringRef) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/Interpreter.cpp:570:8
llvm#19 0x000059b285618cbd clang::Interpreter::ParseAndExecute(llvm::StringRef, clang::Value*) /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/lib/Interpreter/Interpreter.cpp:649:8
llvm#20 0x000059b2836f9343 main /home/vipul-cariappa/Documents/Workspace/cpp-py/llvms/llvm-project-a/clang/tools/clang-repl/ClangRepl.cpp:255:59
llvm#21 0x000077cdf443388e (/usr/lib/libc.so.6+0x2788e)
llvm#22 0x000077cdf443394a __libc_start_main (/usr/lib/libc.so.6+0x2794a)
llvm#23 0x000059b2836f7965 _start (./bin/clang-repl+0x73b8965)
fish: Job 1, './bin/clang-repl' terminated by signal SIGABRT (Abort)
```

With this change:
```c++
clang-repl> try { throw 1; } catch { 0; }
In file included from <<< inputs >>>:1:
input_line_1:1:23: error: expected '('
    1 | try { throw 1; } catch { 0; }
      |                       ^
      |                       (
error: Parsing failed.
clang-repl> 1;
clang-repl> %quit
```
@Vipul-Cariappa Vipul-Cariappa deleted the dev/clangREPL-ErrRecovery branch March 26, 2025 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants