[swift-dev] [Compiler] Help IR gen in targetting MSVC

Sangjin Han tinysun.net at gmail.com
Tue Apr 26 15:03:17 CDT 2016


The problem can be solved by modifying that code. Thanks you. I thought
that code will affect only to the CLong type not Int.

But I meet another problem to fix it. I couldn't find the conditional
method to distinct x86_64-*-windows-msvc with x86_64-*-windows-cygnus in
Swift source.

"#if os(Windows)" can not distinct MSVC from Cygwin.

Should I add new condition 'env()' for the environment?

- Han Sangjin


2016-04-26 14:39 GMT+09:00 John McCall <rjmccall at apple.com>:

> > On Apr 25, 2016, at 7:54 PM, Sangjin Han via swift-dev <
> swift-dev at swift.org> wrote:
> > Hi all,
> >
> > I found a bug in my port for MSVC and Cygwin.
> >
> > The C function swift_stdlib_readLine_stdin() is mapped to 'Int' type in
> Swift, but it generates i32 in LLVM if I specify the target as MSVC. If I
> give the target as Cygwin, it generates i64.
> >
> > With the target options, the Cygwin ported swiftc.exe has the same
> output.
> >
> > I know that the one of the differences between MSVC and Cygwin is the
> size of 'long' type. But I don't know even if it is related to this problem.
> >
> > I don't know where to I start with.
>
> The problem is probably the unconditional line
>   public typealias CLong = Int
> in CTypes.swift.  That is generally true for Unix platforms (LP32 / LP64)
> but not MSVC (LLP64).
>
> You will need to conditionalize that line.
>
> John.
>
> >
> > BEGIN OF tt.swift ---
> > import SwiftShims
> >
> >  var linePtr: UnsafeMutablePointer<CChar>? = nil
> >  var readBytes = swift_stdlib_readLine_stdin(&linePtr)
> >  print(readBytes)
> > END OF tt.swift -----
> >
> > C:\temp>swiftc -emit-ir tt.swift -target x86_64-pc-windows-msvc  |
> findstr stdlib
> >   %4 = call i32 @swift_stdlib_readLine_stdin(i8** bitcast (%Sq*
> @_Tv2tt7linePtrGSqGSpVs4Int8__ to i8**))
> > declare i32 @swift_stdlib_readLine_stdin(i8**) #0
> >
> > C:\temp>swiftc -emit-ir tt.swift -target x86_64-unknown-windows-cygnus |
> findstr stdlib
> >   %4 = call i64 @swift_stdlib_readLine_stdin(i8** bitcast (%Sq*
> @_Tv2tt7linePtrGSqGSpVs4Int8__ to i8**))
> > declare i64 @swift_stdlib_readLine_stdin(i8**) #0
> >
> >
> > - Han Sangjin
> >
> > _______________________________________________
> > swift-dev mailing list
> > swift-dev at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160427/b1fdb0de/attachment.html>


More information about the swift-dev mailing list