Skip to content

Commit 3b702bf

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents dbeb676 + 71eedb1 commit 3b702bf

File tree

20 files changed

+103
-63
lines changed

20 files changed

+103
-63
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,10 @@ namespace swift {
670670
/// Options for controlling the behavior of the Clang importer.
671671
class ClangImporterOptions final {
672672
public:
673+
/// The path to the Clang compiler executable.
674+
/// Used to detect the default include paths.
675+
std::string clangPath = "clang";
676+
673677
/// The module cache path which the Clang importer should use.
674678
std::string ModuleCachePath;
675679

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ ClangImporter::getClangArguments(ASTContext &ctx) {
964964
std::vector<std::string> invocationArgStrs;
965965
// Clang expects this to be like an actual command line. So we need to pass in
966966
// "clang" for argv[0]
967-
invocationArgStrs.push_back("clang");
967+
invocationArgStrs.push_back(ctx.ClangImporterOpts.clangPath);
968968
switch (ctx.ClangImporterOpts.Mode) {
969969
case ClangImporterOptions::Modes::Normal:
970970
case ClangImporterOptions::Modes::PrecompiledModule:

lib/ClangImporter/ImportType.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,7 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
19181918
// Import the parameter type into Swift.
19191919
Type swiftParamTy;
19201920
bool isParamTypeImplicitlyUnwrapped = false;
1921+
bool isInOut = false;
19211922

19221923
auto referenceType = dyn_cast<clang::ReferenceType>(paramTy);
19231924
if (referenceType &&
@@ -1937,6 +1938,10 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
19371938
swiftParamTy =
19381939
findGenericTypeInGenericDecls(templateParamType, genericParams);
19391940
} else {
1941+
if (auto refType = dyn_cast<clang::ReferenceType>(paramTy)) {
1942+
paramTy = refType->getPointeeType();
1943+
isInOut = true;
1944+
}
19401945
auto importedType = importType(paramTy, importKind, allowNSUIntegerAsInt,
19411946
Bridgeability::Full, OptionalityOfParam);
19421947
if (!importedType)
@@ -1968,7 +1973,8 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
19681973
param, AccessLevel::Private, SourceLoc(), SourceLoc(), name,
19691974
importSourceLoc(param->getLocation()), bodyName,
19701975
ImportedHeaderUnit);
1971-
paramInfo->setSpecifier(ParamSpecifier::Default);
1976+
paramInfo->setSpecifier(isInOut ? ParamSpecifier::InOut
1977+
: ParamSpecifier::Default);
19721978
paramInfo->setInterfaceType(swiftParamTy);
19731979
recordImplicitUnwrapForDecl(paramInfo, isParamTypeImplicitlyUnwrapped);
19741980
recordUnsafeConcurrencyForDecl(

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
264264
inputArgs.AddLastArg(arguments, options::OPT_swift_version);
265265
inputArgs.AddLastArg(arguments, options::OPT_enforce_exclusivity_EQ);
266266
inputArgs.AddLastArg(arguments, options::OPT_stats_output_dir);
267+
inputArgs.AddLastArg(arguments, options::OPT_tools_directory);
267268
inputArgs.AddLastArg(arguments, options::OPT_trace_stats_events);
268269
inputArgs.AddLastArg(arguments, options::OPT_profile_stats_events);
269270
inputArgs.AddLastArg(arguments, options::OPT_profile_stats_entities);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
6868
Path, FrontendOpts.UseSharedResourceFolder, LibPath);
6969
setRuntimeResourcePath(LibPath.str());
7070

71+
llvm::SmallString<128> clangPath(Path);
72+
llvm::sys::path::remove_filename(clangPath);
73+
llvm::sys::path::append(clangPath, "clang");
74+
ClangImporterOpts.clangPath = std::string(clangPath);
75+
7176
llvm::SmallString<128> DiagnosticDocsPath(Path);
7277
llvm::sys::path::remove_filename(DiagnosticDocsPath); // Remove /swift
7378
llvm::sys::path::remove_filename(DiagnosticDocsPath); // Remove /bin
@@ -990,6 +995,18 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
990995
StringRef workingDirectory) {
991996
using namespace options;
992997

998+
if (const Arg *a = Args.getLastArg(OPT_tools_directory)) {
999+
// If a custom tools directory is specified, try to find Clang there.
1000+
// This is useful when the Swift executable is located in a different
1001+
// directory than the Clang/LLVM executables, for example, when building
1002+
// the Swift project itself.
1003+
llvm::SmallString<128> clangPath(a->getValue());
1004+
llvm::sys::path::append(clangPath, "clang");
1005+
if (llvm::sys::fs::exists(clangPath)) {
1006+
Opts.clangPath = std::string(clangPath);
1007+
}
1008+
}
1009+
9931010
if (const Arg *A = Args.getLastArg(OPT_module_cache_path)) {
9941011
Opts.ModuleCachePath = A->getValue();
9951012
}

lib/SIL/IR/Bridging.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ TypeConverter::getBridgedParam(SILFunctionTypeRepresentation rep,
4242
AbstractionPattern pattern,
4343
AnyFunctionType::Param param,
4444
Bridgeability bridging) {
45-
assert(!param.getParameterFlags().isInOut() &&
46-
!param.getParameterFlags().isVariadic());
45+
assert(!param.getParameterFlags().isVariadic());
4746

4847
auto bridged = getLoweredBridgedType(pattern, param.getPlainType(), bridging,
4948
rep, TypeConverter::ForArgument);

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ function(_compile_swift_files
407407
compute_library_subdir(library_subdir
408408
"${library_subdir_sdk}" "${SWIFTFILE_ARCHITECTURE}")
409409

410+
if(NOT "${SWIFT_NATIVE_CLANG_TOOLS_PATH}" STREQUAL "")
411+
list(APPEND swift_flags "-tools-directory" "${SWIFT_NATIVE_CLANG_TOOLS_PATH}")
412+
endif()
413+
410414
# If we have a custom module cache path, use it.
411415
if (SWIFT_MODULE_CACHE_PATH)
412416
list(APPEND swift_flags "-module-cache-path" "${SWIFT_MODULE_CACHE_PATH}")

test/Interop/Cxx/reference/reference-irgen.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,31 @@ public func getConstCxxRvalueRef() -> UnsafePointer<CInt> {
3232

3333
public func setCxxRef() {
3434
var val: CInt = 21
35-
withUnsafeMutablePointer(to: &val) {
36-
setStaticIntRef($0)
37-
}
35+
setStaticIntRef(&val)
3836
}
3937

4038
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main9setCxxRefyyF"()
4139
// CHECK: call void @{{_Z15setStaticIntRefRi|"\?setStaticIntRef@@YAXAEAH@Z"}}(i32* {{nonnull %val|%2}})
4240

4341
public func setCxxConstRef() {
4442
var val: CInt = 21
45-
withUnsafePointer(to: &val) {
46-
setConstStaticIntRef($0)
47-
}
43+
setConstStaticIntRef(&val)
4844
}
4945

5046
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main14setCxxConstRefyyF"()
5147
// CHECK: call void @{{_Z20setConstStaticIntRefRKi|"\?setConstStaticIntRef@@YAXAEBH@Z"}}(i32* {{nonnull %val|%2}})
5248

5349
public func setCxxRvalueRef() {
5450
var val: CInt = 21
55-
withUnsafeMutablePointer(to: &val) {
56-
setStaticIntRvalueRef($0)
57-
}
51+
setStaticIntRvalueRef(&val)
5852
}
5953

6054
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main15setCxxRvalueRefyyF"()
6155
// CHECK: call void @{{_Z21setStaticIntRvalueRefOi|"\?setStaticIntRvalueRef@@YAX\$\$QEAH@Z"}}(i32* {{nonnull %val|%2}})
6256

6357
public func setCxxConstRvalueRef() {
6458
var val: CInt = 21
65-
withUnsafePointer(to: &val) {
66-
setConstStaticIntRvalueRef($0)
67-
}
59+
setConstStaticIntRvalueRef(&val)
6860
}
6961

7062
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main20setCxxConstRvalueRefyyF"()

test/Interop/Cxx/reference/reference-module-interface.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// CHECK: func getConstStaticIntRef() -> UnsafePointer<Int32>
77
// CHECK: func getConstStaticIntRvalueRef() -> UnsafePointer<Int32>
88
// CHECK: func setStaticInt(_: Int32)
9-
// CHECK: func setStaticIntRef(_: UnsafeMutablePointer<Int32>)
10-
// CHECK: func setStaticIntRvalueRef(_: UnsafeMutablePointer<Int32>)
11-
// CHECK: func setConstStaticIntRef(_: UnsafePointer<Int32>)
12-
// CHECK: func setConstStaticIntRvalueRef(_: UnsafePointer<Int32>)
9+
// CHECK: func setStaticIntRef(_: inout Int32)
10+
// CHECK: func setStaticIntRvalueRef(_: inout Int32)
11+
// CHECK: func setConstStaticIntRef(_: inout Int32)
12+
// CHECK: func setConstStaticIntRvalueRef(_: inout Int32)
1313
// CHECK: func getFuncRef() -> @convention(c) () -> Int32
1414
// CHECK: func getFuncRvalueRef() -> @convention(c) () -> Int32
1515

test/Interop/Cxx/reference/reference-silgen.swift

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,48 +36,36 @@ func getConstCxxRvalueRef() -> UnsafePointer<CInt> {
3636

3737
func setCxxRef() {
3838
var val: CInt = 21
39-
withUnsafeMutablePointer(to: &val) {
40-
setStaticIntRef($0)
41-
}
39+
setStaticIntRef(&val)
4240
}
4341

44-
// CHECK: // closure #1 in setCxxRef()
45-
// CHECK: sil private @$s4main9setCxxRefyyFySpys5Int32VGXEfU_ : $@convention(thin) (UnsafeMutablePointer<Int32>) -> ()
46-
// CHECK: [[REF:%.*]] = function_ref @{{_Z15setStaticIntRefRi|\?setStaticIntRef@@YAXAEAH@Z}} : $@convention(c) (UnsafeMutablePointer<Int32>) -> ()
47-
// CHECK: apply [[REF]](%0) : $@convention(c) (UnsafeMutablePointer<Int32>) -> ()
42+
// CHECK: sil hidden @$s4main9setCxxRefyyF : $@convention(thin) () -> ()
43+
// CHECK: [[REF:%.*]] = function_ref @{{_Z15setStaticIntRefRi|\?setStaticIntRef@@YAXAEAH@Z}} : $@convention(c) (@inout Int32) -> ()
44+
// CHECK: apply [[REF]](%{{[0-9]+}}) : $@convention(c) (@inout Int32) -> ()
4845

4946
func setCxxConstRef() {
5047
var val: CInt = 21
51-
withUnsafePointer(to: &val) {
52-
setConstStaticIntRef($0)
53-
}
48+
setConstStaticIntRef(&val)
5449
}
5550

56-
// CHECK: // closure #1 in setCxxConstRef()
57-
// CHECK: sil private @$s4main14setCxxConstRefyyFySPys5Int32VGXEfU_ : $@convention(thin) (UnsafePointer<Int32>) -> ()
58-
// CHECK: [[REF:%.*]] = function_ref @{{_Z20setConstStaticIntRefRKi|\?setConstStaticIntRef@@YAXAEBH@Z}} : $@convention(c) (UnsafePointer<Int32>) -> ()
59-
// CHECK: apply [[REF]](%0) : $@convention(c) (UnsafePointer<Int32>) -> ()
51+
// CHECK: sil hidden @$s4main14setCxxConstRefyyF : $@convention(thin) () -> ()
52+
// CHECK: [[REF:%.*]] = function_ref @{{_Z20setConstStaticIntRefRKi|\?setConstStaticIntRef@@YAXAEBH@Z}} : $@convention(c) (@inout Int32) -> ()
53+
// CHECK: apply [[REF]](%{{[0-9]+}}) : $@convention(c) (@inout Int32) -> ()
6054

6155
func setCxxRvalueRef() {
6256
var val: CInt = 21
63-
withUnsafeMutablePointer(to: &val) {
64-
setStaticIntRvalueRef($0)
65-
}
57+
setStaticIntRvalueRef(&val)
6658
}
6759

68-
// CHECK: // closure #1 in setCxxRvalueRef()
69-
// CHECK: sil private @$s4main15setCxxRvalueRefyyFySpys5Int32VGXEfU_ : $@convention(thin) (UnsafeMutablePointer<Int32>) -> ()
70-
// CHECK: [[REF:%.*]] = function_ref @{{_Z21setStaticIntRvalueRefOi|\?setStaticIntRvalueRef@@YAX\$\$QEAH@Z}} : $@convention(c) (UnsafeMutablePointer<Int32>) -> ()
71-
// CHECK: apply [[REF]](%0) : $@convention(c) (UnsafeMutablePointer<Int32>) -> ()
60+
// CHECK: sil hidden @$s4main15setCxxRvalueRefyyF : $@convention(thin) () -> ()
61+
// CHECK: [[REF:%.*]] = function_ref @{{_Z21setStaticIntRvalueRefOi|\?setStaticIntRvalueRef@@YAX\$\$QEAH@Z}} : $@convention(c) (@inout Int32) -> ()
62+
// CHECK: apply [[REF]](%{{[0-9]+}}) : $@convention(c) (@inout Int32) -> ()
7263

7364
func setCxxConstRvalueRef() {
7465
var val: CInt = 21
75-
withUnsafePointer(to: &val) {
76-
setConstStaticIntRvalueRef($0)
77-
}
66+
setConstStaticIntRvalueRef(&val)
7867
}
7968

80-
// CHECK: // closure #1 in setCxxConstRvalueRef()
81-
// CHECK: sil private @$s4main20setCxxConstRvalueRefyyFySPys5Int32VGXEfU_ : $@convention(thin) (UnsafePointer<Int32>) -> ()
82-
// CHECK: [[REF:%.*]] = function_ref @{{_Z26setConstStaticIntRvalueRefOKi|\?setConstStaticIntRvalueRef@@YAX\$\$QEBH@Z}} : $@convention(c) (UnsafePointer<Int32>) -> ()
83-
// CHECK: apply [[REF]](%0) : $@convention(c) (UnsafePointer<Int32>) -> ()
69+
// CHECK: sil hidden @$s4main20setCxxConstRvalueRefyyF : $@convention(thin) () -> ()
70+
// CHECK: [[REF:%.*]] = function_ref @{{_Z26setConstStaticIntRvalueRefOKi|\?setConstStaticIntRvalueRef@@YAX\$\$QEBH@Z}} : $@convention(c) (@inout Int32) -> ()
71+
// CHECK: apply [[REF]](%{{[0-9]+}}) : $@convention(c) (@inout Int32) -> ()

0 commit comments

Comments
 (0)