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

[AVR] clang++ crashes when building a simple function #56423

Closed
benshi001 opened this issue Jul 7, 2022 · 2 comments
Closed

[AVR] clang++ crashes when building a simple function #56423

benshi001 opened this issue Jul 7, 2022 · 2 comments
Assignees
Labels
backend:AVR crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@benshi001
Copy link
Member

benshi001 commented Jul 7, 2022

For the following C++ code,

long map(long x, long in_min, long in_max, long out_min, long out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Build it with clang++ a.cpp --target=avr -mmcu=atmega328 -S -O3 -Wall, then the following error rises

# After AVR pseudo instruction expansion pass
# Machine code for function _Z3maplllll: NoPHIs, TracksLiveness, NoVRegs, TiedOpsRewritten, TracksDebugUserValues
Frame Objects:
  fi#-2: size=2, align=1, fixed, at location [SP+4]
  fi#-1: size=2, align=1, fixed, at location [SP+2]
  fi#0: size=1, align=1, at location [SP-1]
  fi#1: size=1, align=1, at location [SP-2]
  fi#2: size=1, align=1, at location [SP-3]
  fi#3: size=1, align=1, at location [SP-4]
  fi#4: size=1, align=1, at location [SP-5]
  fi#5: size=1, align=1, at location [SP-6]
  fi#6: size=1, align=1, at location [SP-7]
  fi#7: size=1, align=1, at location [SP-8]
  fi#8: size=1, align=1, at location [SP-9]
  fi#9: size=1, align=1, at location [SP-10]
Function Live Ins: $r23r22, $r25r24, $r19r18, $r21r20, $r15r14, $r17r16, $r11r10, $r13r12

bb.0.entry:
  liveins: $r11r10, $r13r12, $r15r14, $r17r16, $r19r18, $r21r20, $r23r22, $r25r24, $r6, $r7, $r8, $r9, $r14, $r15, $r16, $r17, $r28, $r29
  frame-setup PUSHRr killed $r6, implicit-def $sp, implicit $sp
  frame-setup PUSHRr killed $r7, implicit-def $sp, implicit $sp
  frame-setup PUSHRr killed $r8, implicit-def $sp, implicit $sp
  frame-setup PUSHRr killed $r9, implicit-def $sp, implicit $sp
  frame-setup PUSHRr killed $r14, implicit-def $sp, implicit $sp
  frame-setup PUSHRr killed $r15, implicit-def $sp, implicit $sp
  frame-setup PUSHRr killed $r16, implicit-def $sp, implicit $sp
  frame-setup PUSHRr killed $r17, implicit-def $sp, implicit $sp
  frame-setup PUSHRr killed $r28, implicit-def $sp, implicit $sp
  frame-setup PUSHRr killed $r29, implicit-def $sp, implicit $sp
  $r28 = frame-setup INRdA 61
  $r29 = frame-setup INRdA 62
  $r9r8 = MOVWRdRr $r21r20
  $r7r6 = MOVWRdRr $r19r18
  $r21r20 = MOVWRdRr $r25r24
  $r19r18 = MOVWRdRr $r23r22
  early-clobber $r22 = LDDRdPtrQ $r29r28, 13 :: (load (s16) from %fixed-stack.1, align 1)
  early-clobber $r23 = LDDRdPtrQ $r29r28, 14 :: (load (s16) from %fixed-stack.1, align 1)
  early-clobber $r24 = LDDRdPtrQ $r29r28, 15 :: (load (s16) from %fixed-stack.1 + 2, align 1)
  early-clobber $r25 = LDDRdPtrQ $r29r28, 16 :: (load (s16) from %fixed-stack.1 + 2, align 1)
  $r22 = SUBRdRr killed $r22(tied-def 0), $r10, implicit-def $sreg
  $r23 = SBCRdRr killed $r23(tied-def 0), $r11, implicit-def $sreg, implicit killed $sreg
  $r24 = SBCRdRr killed $r24(tied-def 0), $r12, implicit-def $sreg, implicit $sreg
  $r25 = SBCRdRr killed $r25(tied-def 0), $r13, implicit-def dead $sreg, implicit killed $sreg
  $r18 = SUBRdRr killed $r18(tied-def 0), $r6, implicit-def $sreg
  $r19 = SBCRdRr killed $r19(tied-def 0), $r7, implicit-def $sreg, implicit killed $sreg
  $r20 = SBCRdRr killed $r20(tied-def 0), $r8, implicit-def $sreg, implicit $sreg
  $r21 = SBCRdRr killed $r21(tied-def 0), $r9, implicit-def dead $sreg, implicit killed $sreg
  CALLk &__mulsi3, <regmask $r2 $r3 $r4 $r5 $r6 $r7 $r8 $r9 $r10 $r11 $r12 $r13 $r14 $r15 $r16 $r17 $r28 $r29 $r3r2 $r5r4 $r7r6 $r9r8 $r10r9 $r11r10 $r12r11 $r13r12 $r14r13 $r15r14 $r16r15 $r17r16 $r29r28>, implicit $sp, implicit $r23r22, implicit $r25r24, implicit $r19r18, implicit $r21r20, implicit-def $sp, implicit-def $r23r22, implicit-def $r25r24
  $r14 = SUBRdRr killed $r14(tied-def 0), killed $r6, implicit-def $sreg
  $r15 = SBCRdRr killed $r15(tied-def 0), killed $r7, implicit-def $sreg, implicit killed $sreg
  $r16 = SBCRdRr killed $r16(tied-def 0), killed $r8, implicit-def $sreg, implicit $sreg
  $r17 = SBCRdRr killed $r17(tied-def 0), killed $r9, implicit-def dead $sreg, implicit killed $sreg
  $r19r18 = MOVWRdRr killed $r15r14
  $r21r20 = MOVWRdRr killed $r17r16
  CALLk &__divmodsi4, <regmask $r2 $r3 $r4 $r5 $r6 $r7 $r8 $r9 $r10 $r11 $r12 $r13 $r14 $r15 $r16 $r17 $r28 $r29 $r3r2 $r5r4 $r7r6 $r9r8 $r10r9 $r11r10 $r12r11 $r13r12 $r14r13 $r15r14 $r16r15 $r17r16 $r29r28>, implicit $sp, implicit $r23r22, implicit $r25r24, implicit $r19r18, implicit $r21r20, implicit-def $sp, implicit-def $r19r18, implicit-def $r21r20
  $r18 = ADDRdRr killed $r18(tied-def 0), killed $r10, implicit-def $sreg
  $r19 = ADCRdRr killed $r19(tied-def 0), killed $r11, implicit-def $sreg, implicit killed $sreg
  $r20 = ADCRdRr killed $r20(tied-def 0), killed $r12, implicit-def $sreg, implicit $sreg
  $r21 = ADCRdRr killed $r21(tied-def 0), killed $r13, implicit-def dead $sreg, implicit killed $sreg
  $r23r22 = MOVWRdRr killed $r19r18
  $r25r24 = MOVWRdRr killed $r21r20
  $r29 = POPRd implicit-def $sp, implicit $sp
  $r28 = POPRd implicit-def $sp, implicit $sp
  $r17 = POPRd implicit-def $sp, implicit $sp
  $r16 = POPRd implicit-def $sp, implicit $sp
  $r15 = POPRd implicit-def $sp, implicit $sp
  $r14 = POPRd implicit-def $sp, implicit $sp
  $r9 = POPRd implicit-def $sp, implicit $sp
  $r8 = POPRd implicit-def $sp, implicit $sp
  $r7 = POPRd implicit-def $sp, implicit $sp
  $r6 = POPRd implicit-def $sp, implicit $sp
  RET implicit $r23r22, implicit $r25r24

# End machine code for function _Z3maplllll.

*** Bad machine code: Using an undefined physical register ***
- function:    _Z3maplllll
- basic block: %bb.0 entry (0x555b3e7035e8)
- instruction: $r14 = SUBRdRr killed $r14(tied-def 0), killed $r6, implicit-def $sreg
- operand 1:   killed $r14(tied-def 0)

*** Bad machine code: Using an undefined physical register ***
- function:    _Z3maplllll
- basic block: %bb.0 entry (0x555b3e7035e8)
- instruction: $r15 = SBCRdRr killed $r15(tied-def 0), killed $r7, implicit-def $sreg, implicit killed $sreg
- operand 1:   killed $r15(tied-def 0)

*** Bad machine code: Using an undefined physical register ***
- function:    _Z3maplllll
- basic block: %bb.0 entry (0x555b3e7035e8)
- instruction: $r16 = SBCRdRr killed $r16(tied-def 0), killed $r8, implicit-def $sreg, implicit $sreg
- operand 1:   killed $r16(tied-def 0)

*** Bad machine code: Using an undefined physical register ***
- function:    _Z3maplllll
- basic block: %bb.0 entry (0x555b3e7035e8)
- instruction: $r17 = SBCRdRr killed $r17(tied-def 0), killed $r9, implicit-def dead $sreg, implicit killed $sreg
- operand 1:   killed $r17(tied-def 0)
fatal error: error in backend: Found 4 machine code errors.
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: /home/benshi/work/llvm-project/debug/bin/clang++ --target=avr -mmcu=atmega328 -O3 /tmp/a.cpp -c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '/tmp/a.cpp'.
4.      Running pass 'Verify generated machine code' on function '@_Z3maplllll'

 #0 0x0000555b318af1f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/benshi/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:22
 #1 0x0000555b318af2b3 PrintStackTraceSignalHandler(void*) /home/benshi/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
 #2 0x0000555b318ace1a llvm::sys::RunSignalHandlers() /home/benshi/work/llvm-project/llvm/lib/Support/Signals.cpp:103:20
 #3 0x0000555b318aea05 llvm::sys::CleanupOnSignal(unsigned long) /home/benshi/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:361:31
 #4 0x0000555b317cf904 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /home/benshi/work/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:76:5
 #5 0x0000555b317d00b6 llvm::CrashRecoveryContext::HandleExit(int) /home/benshi/work/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:442:3
 #6 0x0000555b318a7ed7 llvm::sys::Process::Exit(int, bool) /home/benshi/work/llvm-project/llvm/lib/Support/Process.cpp:99:3
 #7 0x0000555b2fa1a36a ensureStackAddressSpace() /home/benshi/work/llvm-project/clang/tools/driver/cc1_main.cpp:132:39
 #8 0x0000555b317d84ae llvm::report_fatal_error(llvm::Twine const&, bool) /home/benshi/work/llvm-project/llvm/lib/Support/ErrorHandling.cpp:104:36
 #9 0x0000555b3066f329 (anonymous namespace)::MachineVerifierPass::runOnMachineFunction(llvm::MachineFunction&) /home/benshi/work/llvm-project/llvm/lib/CodeGen/MachineVerifier.cpp:311:14
#10 0x0000555b305eb6ad llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/benshi/work/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:73:33
#11 0x0000555b30dbb5c6 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/benshi/work/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1430:20
#12 0x0000555b30dbb967 llvm::FPPassManager::runOnModule(llvm::Module&) /home/benshi/work/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1476:13
#13 0x0000555b30dbbdf9 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/benshi/work/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1545:20
#14 0x0000555b30db6bea llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/benshi/work/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:535:13
#15 0x0000555b30dbc719 llvm::legacy::PassManager::run(llvm::Module&) /home/benshi/work/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1673:1
#16 0x0000555b31e01fa6 (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) /home/benshi/work/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1012:51
#17 0x0000555b31e021ae (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) /home/benshi/work/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1037:17
#18 0x0000555b31e03228 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) /home/benshi/work/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1193:25
#19 0x0000555b332bcae9 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/benshi/work/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:379:24
#20 0x0000555b3516f9d2 clang::ParseAST(clang::Sema&, bool, bool) /home/benshi/work/llvm-project/clang/lib/Parse/ParseAST.cpp:182:14
#21 0x0000555b32910017 clang::ASTFrontendAction::ExecuteAction() /home/benshi/work/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1143:11
#22 0x0000555b332b9018 clang::CodeGenAction::ExecuteAction() /home/benshi/work/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1143:5
#23 0x0000555b3290f8d6 clang::FrontendAction::Execute() /home/benshi/work/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1040:38
#24 0x0000555b32840a2d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/benshi/work/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1033:42
#25 0x0000555b32abc7d5 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/benshi/work/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:266:38
#26 0x0000555b2fa1ac41 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/benshi/work/llvm-project/clang/tools/driver/cc1_main.cpp:248:40
#27 0x0000555b2fa0b2a2 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) /home/benshi/work/llvm-project/clang/tools/driver/driver.cpp:317:20
#28 0x0000555b326fe739 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'()::operator()() const /home/benshi/work/llvm-project/clang/lib/Driver/Job.cpp:407:32
#29 0x0000555b326fed68 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) /home/benshi/work/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:40
#30 0x0000555b302fba3e llvm::function_ref<void ()>::operator()() const /home/benshi/work/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:62
#31 0x0000555b317d0050 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /home/benshi/work/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:426:10
#32 0x0000555b326fe957 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const /home/benshi/work/llvm-project/clang/lib/Driver/Job.cpp:407:7
#33 0x0000555b3269dc30 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /home/benshi/work/llvm-project/clang/lib/Driver/Compilation.cpp:200:22
#34 0x0000555b3269dfbe clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const /home/benshi/work/llvm-project/clang/lib/Driver/Compilation.cpp:254:62
#35 0x0000555b326af4f1 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) /home/benshi/work/llvm-project/clang/lib/Driver/Driver.cpp:1738:28
#36 0x0000555b2fa0c7ab clang_main(int, char**) /home/benshi/work/llvm-project/clang/tools/driver/driver.cpp:513:39
#37 0x0000555b2fa09add main /home/benshi/work/llvm-project/debug/tools/clang/tools/driver/clang-driver.cpp:11:63
#38 0x00007f117e516083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3
#39 0x0000555b2fa099fe _start (/home/benshi/work/llvm-project/debug/bin/clang+++0x2c729fe)
clang-15: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 15.0.0 (git@github.com:llvm/llvm-project.git ac77649951db17f1126bde08d580ec101f0759bc)
Target: avr
Thread model: posix
InstalledDir: /home/benshi/work/llvm-project/debug/bin
clang-15: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-15: note: diagnostic msg: /tmp/a-bc41fc.cpp
clang-15: note: diagnostic msg: /tmp/a-bc41fc.sh
clang-15: note: diagnostic msg:

********************
@benshi001 benshi001 self-assigned this Jul 7, 2022
@benshi001 benshi001 changed the title [AVR] clang crashes when building a simple function [AVR] clang++ crashes when building a simple function Jul 7, 2022
@benshi001 benshi001 added the crash Prefer [crash-on-valid] or [crash-on-invalid] label Jul 25, 2022
@benshi001 benshi001 assigned benshi001 and unassigned benshi001 Jan 20, 2023
@benshi001 benshi001 self-assigned this Feb 24, 2023
@benshi001
Copy link
Member Author

fixed by https://reviews.llvm.org/D144720

@KOLANICH
Copy link
Contributor

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AVR crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

2 participants