<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111293>111293</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] Asseration failed on `__atomic_test_and_set`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
yijan4845
</td>
</tr>
</table>
<pre>
Compiler Explorer: [https://godbolt.org/z/GzEbhPTza](https://godbolt.org/z/GzEbhPTza)
Attempting to compile below program with Clang Assertion Trunk:
```c
#include <stdbool.h>
bool lock;
int main () {
__atomic_test_and_set (lock, __ATOMIC_ACQUIRE);
}
```
Stack dump:
```
clang: /root/llvm-project/clang/include/clang/AST/Type.h:8782: const T* clang::Type::castAs() const [with T = clang::PointerType]: Assertion `isa<T>(CanonicalType)' failed.
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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 <source>
1. <eof> parser at end of file
2. <source>:3:5: LLVM IR generation of declaration 'main'
3. <source>:3:5: Generating code for declaration 'main'
#0 0x0000000003b99d28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b99d28)
#1 0x0000000003b979ec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b979ec)
#2 0x0000000003ae61f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000752e5a042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000752e5a0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000752e5a042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x0000752e5a0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000752e5a02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000752e5a039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000004116dc3 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4116dc3)
#10 0x0000000004295b8e clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(clang::GlobalDecl, unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4295b8e)
#11 0x00000000043785ce clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43785ce)
#12 0x00000000043cbd74 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#13 0x00000000043bfc0b clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#14 0x00000000043c58ac clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43c58ac)
#15 0x000000000434e8be clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x434e8be)
#16 0x0000000004374b85 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4374b85)
#17 0x0000000003efb405 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3efb405)
#18 0x0000000003f03114 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f03114)
#19 0x0000000003f6b5b4 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f6b5b4)
#20 0x0000000003f7d59c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f7d59c)
#21 0x0000000003fe5f4a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe5f4a)
#22 0x0000000003fe0c65 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe0c65)
#23 0x0000000003fe121b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe121b)
#24 0x0000000003feb593 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#25 0x00000000044f2e26 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#26 0x00000000044e3a08 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44e3a08)
#27 0x000000000661af54 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x661af54)
#28 0x00000000044f0998 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44f0998)
#29 0x00000000047aa2e9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47aa2e9)
#30 0x0000000004728c2e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4728c2e)
#31 0x000000000488fb6e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x488fb6e)
#32 0x0000000000cd801f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcd801f)
#33 0x0000000000ccfd2a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#34 0x0000000004534669 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#35 0x0000000003ae66a4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ae66a4)
#36 0x0000000004534c5f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#37 0x00000000044fa59d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44fa59d)
#38 0x00000000044fb68d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44fb68d)
#39 0x0000000004502fb5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4502fb5)
#40 0x0000000000cd4eef clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcd4eef)
#41 0x0000000000ba49a4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xba49a4)
#42 0x0000752e5a029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#43 0x0000752e5a029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#44 0x0000000000ccf7de _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xccf7de)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWt9v4yoW_mvoC0pk498PfXDTpturubqz0-7sY4QxTnxrgwW4k85fvwKc1Lhpp-n1Xa20o5lRjOHwfR-HwwGDpay3jNJLEF2B6PoC92rHxeVz_SdmYRpGFwUvny9XvO3qhgp4s-8aLqgAQQ5BdLVTqpMgyAFaA7Te8rLgjVpysQVo_ROg9e3Pm2L39eEnBtE1QOnHq6MMeNfAy-3_uVK07VTNtlBxSCwYWNCG_4Cd4FuBW_ijVju4ajDbwlxKKlTNGXwQPXvUHVpjsWf_kuEZBTUjTV9SCIKVVGXBebPcgeDGvtePsOHkEQRXtqRmCra4ZhCgFKAMgmR4AeFmgxVva7JRVKoNZuVGUqXrGQNoBTeb_OGP3-9Wm3z1z3_dfbvRHA92QXI9gTimf68weYRl33avqdhHonmbMUFrwbkCaN00T-2iE_xPSvSjrYHWA-FRSX7_AND64bmjmnqeJinSlghnUsEHgHJ4sA6CXFezvwiWKpeDDrYyiK7MKDxAEFyPW33lNVNUmMbRtbb-MkQg9mqJQbB60LqjdIUZZzXBjamNMoASWOG6oeXScv365Sa_v4GyL9paQQyLfgsF7bhQ2jkmLlarXV8sCW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