-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Extend and clean the ccall test suite. #14215
Conversation
Also, as part of #14204 I learned that I should use the C type aliases. Should I convert the ccall test suite to use these types? I've currently kept it at how it was implemented before, except where the types differ (i.e. use |
no, there's no need to convert. this looks like a good improvement. the previous tests were usually enough to cause failures for the x86_64 ABI, but I'm not surprised they were insufficient to catch other problems. perhaps you already know this (as advice for #14194), but part of the original value of this file is that you can introspect how clang lowers it as a way of matching the EABI spec to the llvm attributes: |
@vtjnash OK thanks for the clarification, much appreciated! |
Char is not wchar_t on windows. |
So apparently this trips up the Win32 ABI (unsure about the Win64 one, it just seems to have halted). I guess those ABI's will need fixing before this can be merged? There's also some compilation warnings in |
The win64 freeze is probably not your fault, I would restart it but there's a conflict so this needs a rebase. |
Yep, good catch. It looks like we have a couple mistakes in our ABI. We had copied our ABI from LDC, and they fixed this over the summer: ldc-developers/ldc#856
|
Bump. Does this help improve testing, given the recent arm and aarch64 abi implementations? |
Yeah sorry for not updating this, but I haven't found the time to fix the Windows ABI. Without that, I guess this can't get merged. Maybe somebody else could look at this? Concerning the ARM ABI, it greatly helped me verify the the implementation and find corner cases, and it should pass this test suite without any issue. Though there are still some untested code paths (I should probably look at coverage statistics some day), this PR greatly improves testing coverage. |
For the failing test, the llvm ir generated by clang is ; ModuleID = 'test.c'
target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
target triple = "i386-pc-windows-msvc18.0.0"
%struct.struct10 = type { i8, i8, i8, i8 }
; Function Attrs: nounwind
define i32 @test_10(%struct.struct10* byval nocapture align 4 %a) #0 {
%1 = getelementptr inbounds %struct.struct10, %struct.struct10* %a, i32 0, i32 0
%2 = bitcast %struct.struct10* %a to i32*
%3 = load i32, i32* %2, align 4
%4 = trunc i32 %3 to i16
%5 = trunc i32 %3 to i8
%6 = add i8 %5, 1
store i8 %6, i8* %1, align 4, !tbaa !1
%7 = getelementptr inbounds %struct.struct10, %struct.struct10* %a, i32 0, i32 1
%8 = lshr i16 %4, 8
%9 = trunc i16 %8 to i8
%10 = add i8 %9, -2
store i8 %10, i8* %7, align 1, !tbaa !5
%11 = getelementptr inbounds %struct.struct10, %struct.struct10* %a, i32 0, i32 2
%12 = lshr i32 %3, 16
%13 = trunc i32 %12 to i8
%14 = add i8 %13, 3
store i8 %14, i8* %11, align 2, !tbaa !6
%15 = getelementptr inbounds %struct.struct10, %struct.struct10* %a, i32 0, i32 3
%16 = lshr i32 %3, 24
%17 = trunc i32 %16 to i8
%18 = add i8 %17, -4
store i8 %18, i8* %15, align 1, !tbaa !7
%19 = bitcast %struct.struct10* %a to i32*
%20 = load i32, i32* %19, align 4
ret i32 %20
}
attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.ident = !{!0}
!0 = !{!"clang version 3.7.1 (tags/RELEASE_371/final)"}
!1 = !{!2, !3, i64 0}
!2 = !{!"", !3, i64 0, !3, i64 1, !3, i64 2, !3, i64 3}
!3 = !{!"omnipotent char", !4, i64 0}
!4 = !{!"Simple C/C++ TBAA"}
!5 = !{!2, !3, i64 1}
!6 = !{!2, !3, i64 2}
!7 = !{!2, !3, i64 3} And it appears to be passing the argument by reference but not using sret whereas the logic in |
From the clang output and the ldc code, it seems that the win32 abi use sret for structs that are 1, 2, 4, 8 bytes in size and use pass by reference for all structs. |
Subsumed by #14906 |
@yuyichao OK, thanks for looking into this. |
The current
ccall
test suite doesn't match/test all functionality inlibccalltest
. This PR removes some unused functionality fromlibccalltest
, but mainly extendslibccalltest
andtest/ccall
to align the different structs and test methods.As part of a small clean-up, I've also scoped most tests in a
let...end
block, and added a factor-like parameter to the struct test methods to catch cases where the ABI allocates too much memory for a certain parameter (it helped me discover issues with the ARM ABI from #14194).I've only tested these changes on x86_64, so it's possible that it triggers some issues on other platforms...
cc @vtjnash
[edit by tkelman: fixes https://github.com//issues/13242]