Skip to content

Commit 4b79360

Browse files
Merge pull request swiftlang#10511 from aschwaighofer/fix_clang_importer_invocation_args
We also need to pass a min-vers string to the ClangImporter when running under the embed-bitcode mode
2 parents 71c2c1e + 318be46 commit 4b79360

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -563,24 +563,6 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
563563
}
564564
}
565565

566-
if (triple.isOSDarwin()) {
567-
std::string minVersionBuf;
568-
llvm::raw_string_ostream minVersionOpt{minVersionBuf};
569-
minVersionOpt << getMinVersionOptNameForDarwinTriple(triple);
570-
571-
unsigned major, minor, micro;
572-
if (triple.isiOS()) {
573-
triple.getiOSVersion(major, minor, micro);
574-
} else if (triple.isWatchOS()) {
575-
triple.getWatchOSVersion(major, minor, micro);
576-
} else {
577-
assert(triple.isMacOSX());
578-
triple.getMacOSXVersion(major, minor, micro);
579-
}
580-
minVersionOpt << clang::VersionTuple(major, minor, micro);
581-
invocationArgStrs.push_back(std::move(minVersionOpt.str()));
582-
}
583-
584566
if (searchPathOpts.SDKPath.empty()) {
585567
invocationArgStrs.push_back("-Xclang");
586568
invocationArgStrs.push_back("-nostdsysteminc");
@@ -665,6 +647,24 @@ addCommonInvocationArguments(std::vector<std::string> &invocationArgStrs,
665647
invocationArgStrs.push_back("-target");
666648
invocationArgStrs.push_back(triple.str());
667649

650+
if (triple.isOSDarwin()) {
651+
std::string minVersionBuf;
652+
llvm::raw_string_ostream minVersionOpt{minVersionBuf};
653+
minVersionOpt << getMinVersionOptNameForDarwinTriple(triple);
654+
655+
unsigned major, minor, micro;
656+
if (triple.isiOS()) {
657+
triple.getiOSVersion(major, minor, micro);
658+
} else if (triple.isWatchOS()) {
659+
triple.getWatchOSVersion(major, minor, micro);
660+
} else {
661+
assert(triple.isMacOSX());
662+
triple.getMacOSXVersion(major, minor, micro);
663+
}
664+
minVersionOpt << clang::VersionTuple(major, minor, micro);
665+
invocationArgStrs.push_back(std::move(minVersionOpt.str()));
666+
}
667+
668668
invocationArgStrs.push_back(ImporterImpl::moduleImportBufferName);
669669

670670
if (ctx.LangOpts.EnableAppExtensionRestrictions) {

test/Frontend/embed-bitcode-tvos.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; REQUIRES: CODEGENERATOR=AArch64
2+
; RUN: llvm-as %s -o %t.bc
3+
; RUN: %swift -target arm64-apple-tvos9 -c -module-name someModule -embed-bitcode -disable-llvm-optzns -o %t2.o %t.bc -dump-clang-diagnostics 2> %t.diags.txt
4+
; RUN: llvm-objdump -macho -private-headers %t2.o | %FileCheck %s
5+
; RUN: %FileCheck -check-prefix CHECK-IMPORTER %s < %t.diags.txt
6+
7+
target triple = "arm64-apple-tvos9.0"
8+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
9+
10+
; CHECK: LC_VERSION_MIN_TVOS
11+
12+
; CHECK-IMPORTER: clang
13+
; CHECK-IMPORTER: -fembed-bitcode
14+
; CHECK-IMPORTER: -target
15+
; CHECK-IMPORTER: -mtvos-version-min=9
16+
; CHECK-IMPORTER-NOT: argument unused
17+
18+
define i32 @f0() nounwind ssp {
19+
ret i32 0
20+
}

0 commit comments

Comments
 (0)