avr-llvm / llvm

[MERGED UPSTREAM] AVR backend for the LLVM compiler library
220 stars 21 forks source link

Assertion failure: Call result #4 has unhandled type i16 at CallingConvLower.cpp:167 #175

Closed shepmaster closed 8 years ago

shepmaster commented 8 years ago
Call result #4 has unhandled type i16
UNREACHABLE executed at avr-rust/src/llvm/lib/CodeGen/CallingConvLower.cpp:167!

Running llc -march=avr -mcpu=atmega328p -filetype=obj bugpoint-reduced-simplified.ll on:

; ModuleID = 'bugpoint-reduced-simplified.bc'
target datalayout = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8-i64:8:8-f32:8:8-f64:8:8-n8"
target triple = "avr-atmel-none"

; Function Attrs: inlinehint nounwind uwtable
define void @_ZN3ops13i64.RemAssign10rem_assign20h23f1175739be271cXrkE(i64* noalias nocapture dereferenceable(8), i64) unnamed_addr #0 {
entry-block:
  %2 = srem i64 0, %1
  store i64 %2, i64* %0, align 1
  ret void
}

attributes #0 = { inlinehint nounwind uwtable }
dylanmckay commented 8 years ago

Reduced testcase:

define void @foo(i64*, i64) {
  %remainder = srem i64 0, %1
  store i64 %remainder, i64* %0, align 1
  ret void
}

Added to test/CodeGen/AVR/calling-conv-assertion.ll in 5d82a2734281af8484d6c76fd32e2891c7ac3fc6.

shepmaster commented 8 years ago

Ok, so the error message means that the result of a function call (specifically index 4) of type i16 could not be fit within the calling convention. There are actually 8 values to be returned of type i16, and only 4 register pairs available: R25R24, R23R22, R21R20, R19R18.

shepmaster commented 8 years ago

Slightly smaller:

define i64 @foo(i64) {
  %remainder = srem i64 0, %0
  ret i64 %remainder
}
shepmaster commented 8 years ago

An interesting thing is that the version that returns a void has this issue. Since it's deliberately storing into a pointer, I wouldn't expect there to be any issue here...

shepmaster commented 8 years ago

Tracking more debugging, it appears to be happening because of the sdivrem call specifically, as it would return i64, i64, which corresponds to the 8xi16 spots.

dylanmckay commented 8 years ago

Could you check what the calling convention is? C, AVR_BUILTIN, etc.

shepmaster commented 8 years ago

The calling convention is 0, which should be C. At this line, it's using the RetCC_AVR set.

shepmaster commented 8 years ago

Fixed in #194