Skip to content

[FMV] The compiler crashes in the absence of default target version. #84015

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

Closed
labrinea opened this issue Mar 5, 2024 · 3 comments
Closed

[FMV] The compiler crashes in the absence of default target version. #84015

labrinea opened this issue Mar 5, 2024 · 3 comments
Assignees
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. crash-on-invalid

Comments

@labrinea
Copy link
Collaborator

labrinea commented Mar 5, 2024

I believe we should be diagnosing the lack of default definition instead of crashing.
I can only reproduce this if a declaration if followed by a definition as below:

fmv.c

int __attribute__((target_version("sm4"))) def(void);
int __attribute__((target_version("sha1"))) def(void) { return 1; }

$ clang --target=aarch64-linux-gnu --rtlib=compiler-rt fmv.c -S -o -

llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:2796: void clang::CodeGen::CodeGenFunction::EmitAArch64MultiVersionResolver(llvm::Function*, llvm::ArrayRef<clang::CodeGen::CodeGenFunction::MultiVersionResolverOption>): Assertion `Options.back().Conditions.Features.size() == 0 && "Default case must be last"' 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: ./bin/clang --target=aarch64-linux-gnu --rtlib=compiler-rt ../llvm-project/fmv.c -S -o -
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
 #0 0x00005644724ee8df llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./bin/clang+0x81cb8df)
 #1 0x00005644724ec41c llvm::sys::CleanupOnSignal(unsigned long) (./bin/clang+0x81c941c)
 #2 0x0000564472425dc8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f8dfd333420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f8dfcdd000b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f8dfcdaf859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f8dfcdaf729 get_sysdep_segment_value /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f8dfcdaf729 _nl_load_domain /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f8dfcdc0fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x0000564472950e53 clang::CodeGen::CodeGenFunction::EmitAArch64MultiVersionResolver(llvm::Function*, llvm::ArrayRef<clang::CodeGen::CodeGenFunction::MultiVersionResolverOption>) (./bin/clang+0x862de53)
#10 0x000056447285f3c7 clang::CodeGen::CodeGenModule::emitMultiVersionFunctions() (./bin/clang+0x853c3c7)
#11 0x0000564472861d01 clang::CodeGen::CodeGenModule::Release() (./bin/clang+0x853ed01)
#12 0x0000564472d9c352 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#13 0x0000564472d9bb85 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (./bin/clang+0x8a78b85)
#14 0x0000564474eff8d9 clang::ParseAST(clang::Sema&, bool, bool) (./bin/clang+0xabdc8d9)
#15 0x0000564472d9b418 clang::CodeGenAction::ExecuteAction() (./bin/clang+0x8a78418)
#16 0x00005644732bafa9 clang::FrontendAction::Execute() (./bin/clang+0x8f97fa9)
#17 0x0000564473234c2e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (./bin/clang+0x8f11c2e)
#18 0x00005644733b2796 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (./bin/clang+0x908f796)
#19 0x000056446f6ab256 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (./bin/clang+0x5388256)
@labrinea labrinea self-assigned this Mar 5, 2024
@labrinea labrinea added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer crash-on-invalid and removed new issue labels Mar 5, 2024
@labrinea
Copy link
Collaborator Author

labrinea commented Mar 8, 2024

The patch in #84405 seems to fix this ticket. After applying the patch the behavior is that without a default declaration we generate a normal function definition disregarding the target version attribute. This might not be the desired behavior (perhaps we would like to diagnose the absense of default declaration), but it is an improvement compared to crashing.

@labrinea
Copy link
Collaborator Author

This is fixed by #85923. Closing.

@EugeneZelenko EugeneZelenko added clang:codegen IR generation bugs: mangling, exceptions, etc. and removed clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer labels Mar 20, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 20, 2024

@llvm/issue-subscribers-clang-codegen

Author: Alexandros Lamprineas (labrinea)

I believe we should be diagnosing the lack of default definition instead of crashing. I can only reproduce this if a declaration if followed by a definition as below:

fmv.c

int __attribute__((target_version("sm4"))) def(void);
int __attribute__((target_version("sha1"))) def(void) { return 1; }

$ clang --target=aarch64-linux-gnu --rtlib=compiler-rt fmv.c -S -o -

llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:2796: void clang::CodeGen::CodeGenFunction::EmitAArch64MultiVersionResolver(llvm::Function*, llvm::ArrayRef&lt;clang::CodeGen::CodeGenFunction::MultiVersionResolverOption&gt;): Assertion `Options.back().Conditions.Features.size() == 0 &amp;&amp; "Default case must be last"' 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: ./bin/clang --target=aarch64-linux-gnu --rtlib=compiler-rt ../llvm-project/fmv.c -S -o -
1.	&lt;eof&gt; parser at end of file
2.	Per-file LLVM IR generation
 #<!-- -->0 0x00005644724ee8df llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (./bin/clang+0x81cb8df)
 #<!-- -->1 0x00005644724ec41c llvm::sys::CleanupOnSignal(unsigned long) (./bin/clang+0x81c941c)
 #<!-- -->2 0x0000564472425dc8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #<!-- -->3 0x00007f8dfd333420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #<!-- -->4 0x00007f8dfcdd000b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #<!-- -->5 0x00007f8dfcdaf859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7
 #<!-- -->6 0x00007f8dfcdaf729 get_sysdep_segment_value /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:509:8
 #<!-- -->7 0x00007f8dfcdaf729 _nl_load_domain /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:970:34
 #<!-- -->8 0x00007f8dfcdc0fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #<!-- -->9 0x0000564472950e53 clang::CodeGen::CodeGenFunction::EmitAArch64MultiVersionResolver(llvm::Function*, llvm::ArrayRef&lt;clang::CodeGen::CodeGenFunction::MultiVersionResolverOption&gt;) (./bin/clang+0x862de53)
#<!-- -->10 0x000056447285f3c7 clang::CodeGen::CodeGenModule::emitMultiVersionFunctions() (./bin/clang+0x853c3c7)
#<!-- -->11 0x0000564472861d01 clang::CodeGen::CodeGenModule::Release() (./bin/clang+0x853ed01)
#<!-- -->12 0x0000564472d9c352 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&amp;) ModuleBuilder.cpp:0:0
#<!-- -->13 0x0000564472d9bb85 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) (./bin/clang+0x8a78b85)
#<!-- -->14 0x0000564474eff8d9 clang::ParseAST(clang::Sema&amp;, bool, bool) (./bin/clang+0xabdc8d9)
#<!-- -->15 0x0000564472d9b418 clang::CodeGenAction::ExecuteAction() (./bin/clang+0x8a78418)
#<!-- -->16 0x00005644732bafa9 clang::FrontendAction::Execute() (./bin/clang+0x8f97fa9)
#<!-- -->17 0x0000564473234c2e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (./bin/clang+0x8f11c2e)
#<!-- -->18 0x00005644733b2796 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (./bin/clang+0x908f796)
#<!-- -->19 0x000056446f6ab256 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (./bin/clang+0x5388256)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. crash-on-invalid
Projects
None yet
Development

No branches or pull requests

5 participants