| Issue |
172208
|
| Summary |
[Clang] crashes with casting between _Atomic _Complex types
|
| Labels |
c11,
clang:codegen,
crash-on-valid
|
| Assignees |
AmrDeveloper
|
| Reporter |
AmrDeveloper
|
Clang trunk crashes on the following snippet (https://godbolt.org/z/9EPTMYvYW)
```
void explicit_cast_atomic_complex_to_atomic_complex() {
_Atomic _Complex float a = 2.0f;
_Atomic _Complex int b = (_Atomic _Complex int)a;
}
```
Crashlog
```
clang: /root/llvm-project/llvm/tools/clang/include/clang/AST/TypeBase.h:9163: const T* clang::Type::castAs() const [with T = clang::ComplexType]: 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 -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 <source>
1. <eof> parser at end of file
2. <source>:1:6: LLVM IR generation of declaration 'explicit_cast_atomic_complex_to_atomic_complex'
3. <source>:1:6: Generating code for declaration 'explicit_cast_atomic_complex_to_atomic_complex'
#0 0x00000000042bc068 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42bc068)
#1 0x00000000042b9494 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42b9494)
#2 0x00000000041fe278 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x000079a277a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000079a277a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x000079a277a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x000079a277a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000079a277a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x000079a277a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000004661f73 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4661f73)
#10 0x0000000004661fdc (anonymous namespace)::ComplexExprEmitter::EmitComplexToComplexCast(std::pair<llvm::Value*, llvm::Value*>, clang::QualType, clang::QualType, clang::SourceLocation) (.isra.0) CGExprComplex.cpp:0:0
#11 0x000000000466bfb4 (anonymous namespace)::ComplexExprEmitter::EmitCast(clang::CastKind, clang::Expr*, clang::QualType) CGExprComplex.cpp:0:0
#12 0x00000000046698f4 (anonymous namespace)::ComplexExprEmitter::Visit(clang::Expr*) CGExprComplex.cpp:0:0
#13 0x000000000466cda8 clang::CodeGen::CodeGenFunction::EmitComplexExpr(clang::Expr const*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x466cda8)
#14 0x0000000004b5b7df clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b5b7df)
#15 0x0000000004b69b50 clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b69b50)
#16 0x0000000004b6a1e6 clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (.part.0) CGDecl.cpp:0:0
#17 0x0000000004b6a8b7 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b6a8b7)
#18 0x00000000047abffc clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47abffc)
#19 0x00000000047c2e0d clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47c2e0d)
#20 0x00000000047ba371 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47ba371)
#21 0x00000000047c296b clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47c296b)
#22 0x000000000482a56e clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x482a56e)
#23 0x000000000483b964 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x483b964)
#24 0x00000000048a9770 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48a9770)
#25 0x00000000048a4414 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48a4414)
#26 0x00000000048a4bf3 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48a4bf3)
#27 0x00000000048afce3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#28 0x0000000004c0f099 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#29 0x0000000004bffbc4 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4bffbc4)
#30 0x00000000069bc8a4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x69bc8a4)
#31 0x0000000004c0c4a8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c0c4a8)
#32 0x0000000004f01b45 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f01b45)
#33 0x0000000004e81dbe clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4e81dbe)
#34 0x0000000004ffbbfd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ffbbfd)
#35 0x0000000000dcf4cc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdcf4cc)
#36 0x0000000000dc5f2a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#37 0x0000000000dc60ad int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#38 0x0000000004c7f0d9 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
#39 0x00000000041fe714 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x41fe714)
#40 0x0000000004c7f6ef 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
#41 0x0000000004c3fee2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c3fee2)
#42 0x0000000004c40e8e 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+0x4c40e8e)
#43 0x0000000004c482c5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c482c5)
#44 0x0000000000dcb8d1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdcb8d1)
#45 0x0000000000c77584 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc77584)
#46 0x000079a277a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#47 0x000079a277a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#48 0x0000000000dc59c5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdc59c5)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
The reason is that in the CG Complex emitter, we try to cast `Atomic(Complex(T))` the type directly to `Complex(T)`, which is not possible
https://github.com/llvm/llvm-project/blob/1a1c5df7f9ec8681d35f4fe343aa5d9a76f671ea/clang/lib/CodeGen/CGExprComplex.cpp#L513-L520
I will open a PR soon with the fix
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs