Skip to content

Commit ec2d5bc

Browse files
authored
[ClangImporter] Don't pass API notes options when compiling bitcode. (#10425)
Avoids a bogus "argument unused" warning, since bitcode compilation doesn't bother to set up much of a Clang AST context. (-embed-bitcode compiles in two steps: source -> bitcode, then bitcode -> object file. This is about the second step.) Patch by Bob Wilson, who's currently on vacation but wanted this to get in sooner rather than later. rdar://problem/31372950
1 parent b34218b commit ec2d5bc

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,23 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
620620
"-Xclang", "-fmodule-format=obj",
621621
});
622622
}
623+
624+
// Enable API notes alongside headers/in frameworks.
625+
invocationArgStrs.push_back("-fapinotes-modules");
626+
627+
// Add API notes paths.
628+
for (const auto &searchPath : searchPathOpts.ImportSearchPaths) {
629+
invocationArgStrs.push_back("-iapinotes-modules");
630+
invocationArgStrs.push_back(searchPath);
631+
}
632+
invocationArgStrs.push_back("-iapinotes-modules");
633+
invocationArgStrs.push_back(searchPathOpts.RuntimeLibraryImportPath);
634+
635+
// Map the Swift major version into the API notes version for Swift. This
636+
// has the effect of allowing API notes to effect changes only on Swift
637+
// major versions, not minor versions.
638+
invocationArgStrs.push_back("-fapinotes-swift-version=" +
639+
llvm::itostr(languageVersion[0]));
623640
}
624641

625642
static void
@@ -691,23 +708,6 @@ addCommonInvocationArguments(std::vector<std::string> &invocationArgStrs,
691708
for (auto extraArg : importerOpts.ExtraArgs) {
692709
invocationArgStrs.push_back(extraArg);
693710
}
694-
695-
// Enable API notes alongside headers/in frameworks.
696-
invocationArgStrs.push_back("-fapinotes-modules");
697-
698-
// Add API notes paths.
699-
for (const auto &searchPath : searchPathOpts.ImportSearchPaths) {
700-
invocationArgStrs.push_back("-iapinotes-modules");
701-
invocationArgStrs.push_back(searchPath);
702-
}
703-
invocationArgStrs.push_back("-iapinotes-modules");
704-
invocationArgStrs.push_back(searchPathOpts.RuntimeLibraryImportPath);
705-
706-
// Map the Swift major version into the API notes version for Swift. This
707-
// has the effect of allowing API notes to effect changes only on Swift
708-
// major versions, not minor versions.
709-
invocationArgStrs.push_back("-fapinotes-swift-version=" +
710-
llvm::itostr(ctx.LangOpts.EffectiveLanguageVersion[0]));
711711
}
712712

713713
bool ClangImporter::canReadPCH(StringRef PCHFilename) {

test/Frontend/embed-bitcode.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
2323
; CHECK-IMPORTER: clang
2424
; CHECK-IMPORTER: -fembed-bitcode
2525
; CHECK-IMPORTER: -target
26+
; CHECK-IMPORTER-NOT: argument unused
2627

2728
define i32 @f0() nounwind ssp {
2829
ret i32 0

0 commit comments

Comments
 (0)