Skip to content

Instantly share code, notes, and snippets.

@hyp
Last active July 25, 2023 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyp/1fab108ec4d447428909dafacd135f90 to your computer and use it in GitHub Desktop.
Save hyp/1fab108ec4d447428909dafacd135f90 to your computer and use it in GitHub Desktop.
interopMissingMOduleRefMiscompile
// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: cp %t/Inputs/header.h %t/Inputs2/header.h
// RUN: %target-swift-frontend %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop -disable-availability-checking -emit-module -module-name SwiftMod -o %t
// RUN: %target-swift-frontend %t/test2.swift -I %t/Inputs2 -enable-experimental-cxx-interop -disable-availability-checking -emit-ir -I %t -Xcc -fmodule-map-file=%t/Inputs2/module.modulemap
//--- Inputs/module.modulemap
module CxxModule {
header "header.h"
header "header2.h"
requires cplusplus
}
//--- Inputs2/module.modulemap
module CxxModule {
header "header.h"
requires cplusplus
}
//--- test2.swift
import SwiftMod
public func p () {
let m = UsePrivateStruct()
m.test()
// This gets miscompiled as it thinks `UsePrivateStruct` is an empty struct
// Emitted LLVM IR is completely WRONG:
//define swiftcc void @"$s5test21pyyF"() #0 {
//entry:
// call swiftcc void @"$s8SwiftMod16UsePrivateStructVACycfC"()
// call swiftcc void @"$s8SwiftMod16UsePrivateStructV4testyyF"()
// ret void
//}
}
//--- Inputs/header2.h
struct CxxStructTwo {
public:
int x;
int y;
};
//--- Inputs/header.h
class CxxStruct {
public:
int x; int y;
void method() const;
};
//--- test.swift
import CxxModule
public struct UsePrivateStruct {
var p = CxxStructTwo()
public init() {
p.x = 2
p.y = 3
}
public func test() {
print(p)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment