Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang assertion trunk crash on va_arg (aarch64) #59034

Closed
int6 opened this issue Nov 16, 2022 · 6 comments
Closed

Clang assertion trunk crash on va_arg (aarch64) #59034

int6 opened this issue Nov 16, 2022 · 6 comments
Labels
clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@int6
Copy link
Contributor

int6 commented Nov 16, 2022

https://godbolt.org/z/Mq95K9hMa

main.c

typedef __builtin_va_list va_list;
#define va_start(ap, param) __builtin_va_start(ap, param)
#define va_end(ap)          __builtin_va_end(ap)
#define va_arg(ap, type)    __builtin_va_arg(ap, type)

struct T {};

struct T A(int x, ...)
{
    va_list args;
    va_start(args, x);

    struct T val = va_arg(args, struct T);

    va_end(args);

    return val;
}
clang: /root/llvm-project/clang/include/clang/CodeGen/CGFunctionInfo.h:349: llvm::Type* clang::CodeGen::ABIArgInfo::getCoerceToType() const: Assertion `canHaveCoerceToType() && "Invalid kind!"' 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 -S --gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics -target aarch64-linux-gnu <source>
1.	<eof> parser at end of file
2.	<source>:8:10: LLVM IR generation of declaration 'A'
3.	<source>:8:10: Generating code for declaration 'A'
 #0 0x000055d38026d764 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055d38026b4fc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f7c4fc)
 #2 0x000055d3801a6e48 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007faa6dc83420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007faa6d75000b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007faa6d72f859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007faa6d72f729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007faa6d740fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000055d38088613f (anonymous namespace)::AArch64ABIInfo::EmitAAPCSVAArg(clang::CodeGen::Address, clang::QualType, clang::CodeGen::CodeGenFunction&) const TargetInfo.cpp:0:0
 #9 0x000055d380886425 (anonymous namespace)::AArch64ABIInfo::EmitVAArg(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType) const TargetInfo.cpp:0:0
#10 0x000055d380a9450f (anonymous namespace)::AggExprEmitter::Visit(clang::Expr*) CGExprAgg.cpp:0:0
#11 0x000055d380a96103 clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47a7103)
#12 0x000055d380a3cb4c clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x474db4c)
#13 0x000055d380a473f9 clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47583f9)
#14 0x000055d380a488d2 clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (.part.0) CGDecl.cpp:0:0
#15 0x000055d380a48b90 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4759b90)
#16 0x000055d3806df4f7 clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43f04f7)
#17 0x000055d3806f34c7 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44044c7)
#18 0x000055d3806ec83c clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43fd83c)
#19 0x000055d3806f2dc4 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4403dc4)
#20 0x000055d380751d9e clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4462d9e)
#21 0x000055d3807642d4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44752d4)
#22 0x000055d3807c2e69 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44d3e69)
#23 0x000055d3807be0d5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44cf0d5)
#24 0x000055d3807be773 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44cf773)
#25 0x000055d3807c74d2 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#26 0x000055d3815a3c59 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#27 0x000055d381595a40 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52a6a40)
#28 0x000055d38286ba14 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x657ca14)
#29 0x000055d3815a0c28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52b1c28)
#30 0x000055d380e319d9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b429d9)
#31 0x000055d380db84ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ac94ce)
#32 0x000055d380f170c3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c280c3)
#33 0x000055d37d76aae4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x147bae4)
#34 0x000055d37d766907 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#35 0x000055d380c22549 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
#36 0x000055d3801a75ea llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3eb85ea)
#37 0x000055d380c22d9f clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#38 0x000055d380bec0f9 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48fd0f9)
#39 0x000055d380becb7d 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+0x48fdb7d)
#40 0x000055d380bf661c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x490761c)
#41 0x000055d37d7690f2 clang_main(int, char**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x147a0f2)
#42 0x00007faa6d731083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#43 0x000055d37d76223e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x147323e)
clang-16: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
@EugeneZelenko EugeneZelenko added clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Nov 16, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 16, 2022

@llvm/issue-subscribers-clang-codegen

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 17, 2022

@llvm/issue-subscribers-backend-aarch64

@DavidSpickett
Copy link
Collaborator

Any relation to #58794 ? There is a fix posted for that one.

@int6
Copy link
Contributor Author

int6 commented Nov 18, 2022

Seems crash here in line 6005

Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr, QualType Ty,
CodeGenFunction &CGF) const {
ABIArgInfo AI = classifyArgumentType(Ty, /*IsVariadic=*/true,
CGF.CurFnInfo->getCallingConvention());
bool IsIndirect = AI.isIndirect();
llvm::Type *BaseTy = CGF.ConvertType(Ty);
if (IsIndirect)
BaseTy = llvm::PointerType::getUnqual(BaseTy);
else if (AI.getCoerceToType())
BaseTy = AI.getCoerceToType();

AI.getCoerceToType has assert that AI's kind is one of Direct, Extend, Indirect, but when the vaarg is an empty record type, AI's kind actually is Ignore

getCoerceToType

llvm::Type *getCoerceToType() const {
assert(canHaveCoerceToType() && "Invalid kind!");
return TypeData;
}

canHaveCoerceToType

bool canHaveCoerceToType() const {
return isDirect() || isExtend() || isCoerceAndExpand();
}

@yronglin
Copy link
Contributor

I try to fix it in https://reviews.llvm.org/D138511

yronglin added a commit that referenced this issue Dec 20, 2022
…y record type in variadic arg

Fix AArch64ABIInfo::EmitAAPCSVAArg crash with empty record type in variadic arg

Open issue: #59034

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D138511
@yronglin
Copy link
Contributor

Fix by ebe530e

CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this issue Dec 25, 2022
…y record type in variadic arg

Fix AArch64ABIInfo::EmitAAPCSVAArg crash with empty record type in variadic arg

Open issue: llvm/llvm-project#59034

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D138511
veselypeta pushed a commit to veselypeta/cherillvm that referenced this issue Jun 10, 2024
…y record type in variadic arg

Fix AArch64ABIInfo::EmitAAPCSVAArg crash with empty record type in variadic arg

Open issue: llvm/llvm-project#59034

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D138511
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

6 participants