<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58424>58424</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang crashes when compiling certain files
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
HarukaMa
</td>
</tr>
</table>
<pre>
"Certain files" as I was getting the crash when compiling Transmission (a BitTorrent client), which source code I'm not familiar with. I currently have no clue if this is caused by my compiled clang / llvm or it's a clang bug. System compiler (version below) doesn't have this issue, and I've not tested it with other versions of the compiler.
Using self-compiled Xcode toolchain on macOS 10.15.
clang version: `clang version 15.0.2 (https://github.com/llvm/llvm-project 4bd3f3759259548e159aeba5c76efb9a0864e6fa)`
Compiler used when compiling the toolchain: `Apple clang version 12.0.0 (clang-1200.0.32.29)`
Full cmake command line:
```
CC=gcc CXX=g++ cmake ../llvm -GNinja -DLLVM_TARGETS_TO_BUILD="all" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=1 -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_ENABLE_PROJECTS="bolt;clang;clang-tools-extra;compiler-rt;cross-project-tests;libclc;lld;lldb;mlir;openmp;polly;pstl" -DLLVM_CREATE_XCODE_TOOLCHAIN=1 -DLLVM_BUILD_LLVM_DYLIB=1 -DLLVM_ENABLE_EH=1 -DLLVM_ENABLE_FFI=1 -DLLVM_OPTIMIZED_TABLEGEN=1 -DLLDB_CODESIGN_IDENTITY="Mac Developer: Local" -DLIBCXX_ENABLE_SHARED=1 -DLIBCXX_INCLUDE_BENCHMARKS=0 -DLLVM_INCLUDE_TESTS=0 -DLLVM_BUILD_BENCHMARKS=0 -DLLVM_INCLUDE_BENCHMARKS=0 -DLLVM_BUILD_EXAMPLES=0 -DLLVM_INCLUDE_EXAMPLES=0
```
Stack trace:
```
Stack dump:
0. Program arguments: /usr/local/bin/clang -cc1 -emit-obj -debug-info-kind=standalone -O2 -std=gnu++17 handshake-b4b2c9.reduced.cpp
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'handshake-b4b2c9.reduced.cpp'.
4. Running pass 'Live Variable Analysis' on function '@_Z1wv'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 clang 0x0000000102634a27 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1 clang 0x0000000102633714 llvm::sys::RunSignalHandlers() + 260
2 clang 0x0000000102635070 SignalHandler(int) + 272
3 libsystem_platform.dylib 0x00007fff6859a5fd _sigtramp + 29
4 libsystem_platform.dylib 0x00007ffeefb03f38 _sigtramp + 18446744071685183832
5 clang 0x00000001018aecbf llvm::LiveVariables::runOnInstr(llvm::MachineInstr&, llvm::SmallVectorImpl<unsigned int>&) + 655
6 clang 0x00000001018af1bb llvm::LiveVariables::runOnBlock(llvm::MachineBasicBlock*, unsigned int) + 683
7 clang 0x00000001018af8e0 llvm::LiveVariables::runOnMachineFunction(llvm::MachineFunction&) + 1072
8 clang 0x0000000101936d14 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 596
9 clang 0x0000000101d5fcf7 llvm::FPPassManager::runOnFunction(llvm::Function&) + 1095
10 clang 0x0000000101d66543 llvm::FPPassManager::runOnModule(llvm::Module&) + 67
11 clang 0x0000000101d603b9 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 905
12 clang 0x000000010299f975 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>) + 5349
13 clang 0x0000000102d33e40 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 2032
14 clang 0x00000001043dc91e clang::ParseAST(clang::Sema&, bool, bool) + 798
15 clang 0x000000010310767a clang::FrontendAction::Execute() + 90
16 clang 0x000000010306dae6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 838
17 clang 0x000000010318b808 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 680
18 clang 0x00000001001020e8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 1944
19 clang 0x00000001000ffcc7 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) + 295
20 clang 0x00000001000ff4ae clang_main(int, char**) + 12526
21 libdyld.dylib 0x00007fff683a1cc9 start + 1
```
Reduced failing source file:
```cpp
namespace std {
enum aa : char;
inline namespace {
template <class a> struct b {
typedef a *c;
};
template <class a> struct B {
typedef typename b<a>::c c;
};
template <class a> using d = typename B<a>::c;
template <class a> a *addressof(a &);
template <class e> struct f {
using g = decltype(e());
static e h(e i, g ab) { return i + (ab - i); }
};
template <class ac, class e, class ad = f<ac>> ac l(ac i, e ab) {
return ad::h(i, ab);
}
template <class j, class k> struct D {
j ae;
k af;
template <class q, class ag> D(q i, ag ab) : ae(i), af(ab) {}
};
template <class j, class k> D<j, k> ah(j i, k ab) { return D<j, k>(i, ab); }
template <class e, class ai = decltype(e())> D<ai, ai> aj(e i, e ab) {
return ah(i, ab);
}
template <class ak, class al, class am> D<ak, am> an(ak i, al ab, am ao) {
while (i != ab) {
*ao = *++i;
++ao;
}
return D<ak, am>(i, ao);
}
template <class ak, class al, class am> void ap(ak i, al ab, am ao) {
auto aq = aj(i, ab);
auto ar = an(aq.ae, aq.af, ao);
unsigned char *m = l(ao, ar.af);
ah(i, m);
}
template <class as, class at> void au(as i, as ab, at ao) { ap(i, ab, ao); }
template <class a> struct av {
using c = a *;
};
template <class a> class aw {
public:
typename av<a>::c operator->();
};
template <class ax> auto ay(ax &i) { return i.ay(); }
template <class ax> auto az(ax i) { return i.az(); }
} // namespace
inline namespace ba {
template <class as, class bb, class at> void bc(as i, bb ab, at ao) {
au(i, i + ab, ao);
}
template <class a, int bb> struct u {
a bd[bb];
int az() { return bb; }
a *ay() { return bd; }
};
template <class a, int bb> void operator==(u<a, bb>, u<a, bb>);
template <class a> struct be {
a bf;
};
template <class a> struct bg : be<a> {
using bh = a;
bh &bi() { return this->bf; }
};
template <class a> class bj : bg<a> {
public:
using bh = a;
d<bh> operator->() { return addressof(this->bi()); }
};
} // namespace ba
} // namespace std
void bk(void *);
using bl = std::u<char, 20>;
using bm = std::u<std::aa, 0>;
class bn {
public:
struct bo {
bm bp;
bl bq;
};
std::bj<bo> br();
};
class bs {
public:
void bt(void *);
};
auto constexpr bu{8};
enum bv { bw, bx };
struct {
std::aw<bn> by;
} bz;
bool ca(unsigned char *i) {
unsigned char *cb = i += bu;
std::u<std::aa, 20> cc;
int n = az(cc);
std::bc(reinterpret_cast<char *>(0), n, cb);
return true;
}
bl cd;
void ce() {
std::bj o = bz.by->br();
o->bq == cd;
}
bs *cf;
void t() {
auto cg = std::u<unsigned char, 8>{};
unsigned char *p = ay(cg), *v = ay(cg);
ca(p);
cf->bt(v);
}
void x() {
if (auto cg = std::u<unsigned char, 8>{}; ca(ay(cg))) {
unsigned char *r = ay(cg);
bk(r);
}
}
void s() { ce(); }
bool y;
bv z;
void w() {
while (y)
switch (z) {
case bw:
t();
x();
break;
case bx:
s();
}
}
```
Compiler command:
```
/usr/local/bin/clang -cc1 -emit-obj -debug-info-kind=standalone -O2 -std=gnu++17 handshake-b4b2c9.reduced.cpp
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFWllz4roS_jXkRQXlDTAPeWDLJPckk1TCnJo5L5Qsy-DE2B7ZDmF-_emW5A0chrl1q24qhW0t3V9_6kUyeIl_uO5Z1pyLnIYxCcKIZ_BMaEbuyB4-NzzPw3hD8i0nTNBsS_ZbHhOW7NIwwo6VoHG2C7MsTGLSs1xKZmG-SoTgcU5YFMKlZ0161hwmhmxLsqQQDGQlPid3PWu8I3GSk4DuQBwVZB_m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