<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63789>63789</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang/LLVM Parse Bug
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
frobnitzem
</td>
</tr>
</table>
<pre>
While compiling a large header-based library, I ran into a segfault that appears to be coming from the clang C++ source parser. For this particular package, the `grid_generator.cc` file is the only one of its cc source files that displays the error. All its other sources compile fine with llvm. I originally used a few system-specific modified llvm-15 versions, but have since reproduced the error with basic llvm-12 and llvm-14. gcc-7.5 does not have the error. Apple-clang 14 on my macbook also does not have the error.
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: clang++ -Iinc -Iinc/mpi -Iinc/dealii -Iinc/boost-1.70.0/include -std=c++14 -o tmp.o -c grid_generator.cc
1. grid_generator.cc:6106:3: current parser token 'template'
2. grid_generator.cc:36:1 <Spelling=inc/dealii/deal.II/base/config.h:73:32>: parsing namespace 'dealii'
3. grid_generator.cc:42:1: parsing namespace 'dealii::double free or corruption (out)
build.sh: line 7: 3328785 Aborted (core dumped) clang++ -Iinc -Iinc/mpi -Iinc/dealii -Iinc/boost-1.70.0/include -std=c++14 -o tmp.o -c grid_generator.cc
```
A reproducer for the bug is here (in the `build.sh` script):
https://github.com/frobnitzem/llvm-parse-bug1
Changing the text of the source file slightly around the indicated error token does not resolve the issue,
but sometimes causes the error message to blame a file location thousands of lines away (e.g. 3059,2023, etc.).
Other versions of clang have more verbose output. In particular, Cray clang version 15.0.0 (324a8e7de6a18594c06a0ee5d8c0eda2109c6ac6) shows:
```
...
# define BOOST_HAS_TRIVIAL_ASSIGN(T) (__has_trivial_assign(T) && !is_volatile<T>::value && is_assignable<T&, const T&>::value)
^
inc/boost-1.70.0/include/boost/signals2/detail/auto_buffer.hpp:157:51: note: in instantiation of template class 'boost::has_trivial_assign<boost::variant<boost::shared_ptr<void>, boost::signals2::detail::foreign_void_shared_ptr>>' requested here
typedef typename boost::mpl::if_c< boost::has_trivial_assign<T>::value
^
inc/boost-1.70.0/include/boost/signals2/detail/slot_call_iterator.hpp:65:27: note: in instantiation of template class 'boost::signals2::detail::auto_buffer<boost::variant<boost::shared_ptr<void>, boost::signals2::detail::foreign_void_shared_ptr>, boost::signals2::detail::store_n_objects<10>>' requested here
tracked_ptrs_type tracked_ptrs;
^
Didn't find this decl on its identifier's chain!
UNREACHABLE executed at /home/jenkins/clang/lib/Sema/IdentifierResolver.cpp:82!
PLEASE submit a bug report to Cray and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: clang++ -Iinc -Iinc/mpi -Iinc/dealii -Iinc/boost-1.70.0/include -std=c++14 -o tmp.o -c grid_generator.cc
1. grid_generator.cc:6106:3: current parser token 'template'
2. grid_generator.cc:36:1 <Spelling=inc/dealii/deal.II/base/config.h:394:32>: parsing namespace 'dealii'
3. grid_generator.cc:42:1: parsing namespace 'dealii::GridGenerator'
4. grid_generator.cc:5898:3: parsing function body 'dealii::GridGenerator::hyper_shell<3>'
#0 0x00000000038ef25f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x00000000038ec9c3 llvm::sys::CleanupOnSignal(unsigned long) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x38ec9c3)
#2 0x0000000003828387 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f0bb27f78bf (/lib64/libpthread.so.0+0x168bf)
#4 0x00007f0bb14dbcba raise (/lib64/libc.so.6+0x4acba)
#5 0x00007f0bb14dd354 abort (/lib64/libc.so.6+0x4c354)
#6 0x0000000003836719 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x3836719)
#7 0x0000000005a62466 clang::IdentifierResolver::IdDeclInfo::RemoveDecl(clang::NamedDecl*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5a62466)
#8 0x0000000005a629ab clang::IdentifierResolver::RemoveDecl(clang::NamedDecl*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5a629ab)
#9 0x0000000005c35e56 clang::Sema::ActOnPopScope(clang::SourceLocation, clang::Scope*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5c35e56)
#10 0x000000000594c824 clang::Parser::ExitScope() (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x594c824)
#11 0x0000000005a26e1c clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5a26e1c)
#12 0x0000000005956326 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5956326)
#13 0x0000000005a38223 clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5a38223)
#14 0x0000000005a4526d clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5a4526d)
#15 0x0000000005a4550c clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5a4550c)
#16 0x0000000005987ba4 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5987ba4)
#17 0x000000000595898b clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x595898b)
#18 0x000000000599ba16 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x599ba16)
#19 0x000000000599eae8 clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x599eae8)
#20 0x0000000005987d99 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5987d99)
#21 0x000000000595898b clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x595898b)
#22 0x000000000599ba16 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x599ba16)
#23 0x000000000599eae8 clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x599eae8)
#24 0x0000000005987d99 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5987d99)
#25 0x000000000595898b clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x595898b)
#26 0x000000000595991d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x595991d)
#27 0x0000000005949941 clang::ParseAST(clang::Sema&, bool, bool) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x5949941)
#28 0x00000000044cdd98 clang::FrontendAction::Execute() (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x44cdd98)
#29 0x000000000444a635 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x444a635)
#30 0x000000000459807a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x459807a)
#31 0x0000000000e1eaa9 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0xe1eaa9)
#32 0x0000000000e1989b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#33 0x00000000042787d4 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#34 0x00000000038284f3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x38284f3)
#35 0x000000000427a9e5 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x427a9e5)
#36 0x000000000423c24e clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x423c24e)
#37 0x000000000423d4ac clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x423d4ac)
#38 0x000000000424c99b clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0x424c99b)
#39 0x0000000000e1badd clang_main(int, char**) (/opt/cray/pe/cce/15.0.0/cce-clang/x86_64/bin/clang-15+0xe1badd)
#40 0x00007f0bb14c629c __libc_start_main (/lib64/libc.so.6+0x3529c)
#41 0x0000000000e16b49 _start /home/abuild/rpmbuild/BUILD/glibc-2.31/csu/../sysdeps/x86_64/start.S:120:0
clang-15: error: clang frontend command failed with exit code 134 (use -v to see invocation)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW19z4yj2_TTkhYpLQn8sPeTBceKZTGUnXe3s7KMLoWubbSS0gNLxfvpfAbIjnMQ9v9l4uqamU92JLInLPedeDlcCU635pgW4Qtk1ym4uaG-2Ul2tlaxabv4LzUUl693Vv7ZcAGay6bjg7QZTLKjaAN4CrUFdVlRDjQWvFFU7ROb4DivaYt4aiSnWsFnTXhhsttRg2nVAlcZG4sqZt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