Skip to content

Commit c75d198

Browse files
authored
Merge pull request #38326 from etcwilde/ewilde/swift-rebranch
[Swift Rebranch] Cherry-picking swift changes from next branch
2 parents a3ebc9a + 727115b commit c75d198

21 files changed

+54
-46
lines changed

include/swift/AST/TBDGenRequests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class TBDGenDescriptor final {
7070
const TBDGenOptions &getOptions() const { return Opts; }
7171
TBDGenOptions &getOptions() { return Opts; }
7272

73-
const llvm::DataLayout &getDataLayout() const;
73+
const StringRef getDataLayoutString() const;
7474
const llvm::Triple &getTarget() const;
7575

7676
bool operator==(const TBDGenDescriptor &other) const;

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ ClangImporter::create(ASTContext &ctx,
11701170
//
11711171
// FIXME: We shouldn't need to do this, the target should be immutable once
11721172
// created. This complexity should be lifted elsewhere.
1173-
instance.getTarget().adjust(instance.getLangOpts());
1173+
instance.getTarget().adjust(clangDiags, instance.getLangOpts());
11741174

11751175
if (importerOpts.Mode == ClangImporterOptions::Modes::EmbedBitcode)
11761176
return importer;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,14 +1167,14 @@ makeBitFieldAccessors(ClangImporter::Implementation &Impl,
11671167

11681168
auto cGetterSelfExpr = new (Ctx) clang::DeclRefExpr(Ctx, cGetterSelf, false,
11691169
recordType,
1170-
clang::VK_RValue,
1170+
clang::VK_PRValue,
11711171
clang::SourceLocation());
11721172
auto cGetterExpr = clang::MemberExpr::CreateImplicit(Ctx,
11731173
cGetterSelfExpr,
11741174
/*isarrow=*/ false,
11751175
fieldDecl,
11761176
fieldType,
1177-
clang::VK_RValue,
1177+
clang::VK_PRValue,
11781178
clang::OK_BitField);
11791179

11801180

@@ -1211,7 +1211,7 @@ makeBitFieldAccessors(ClangImporter::Implementation &Impl,
12111211

12121212
auto cSetterSelfExpr = new (Ctx) clang::DeclRefExpr(Ctx, cSetterSelf, false,
12131213
recordPointerType,
1214-
clang::VK_RValue,
1214+
clang::VK_PRValue,
12151215
clang::SourceLocation());
12161216

12171217
auto cSetterMemberExpr = clang::MemberExpr::CreateImplicit(Ctx,
@@ -1224,15 +1224,15 @@ makeBitFieldAccessors(ClangImporter::Implementation &Impl,
12241224

12251225
auto cSetterValueExpr = new (Ctx) clang::DeclRefExpr(Ctx, cSetterValue, false,
12261226
fieldType,
1227-
clang::VK_RValue,
1227+
clang::VK_PRValue,
12281228
clang::SourceLocation());
12291229

12301230
auto cSetterExpr = clang::BinaryOperator::Create(Ctx,
12311231
cSetterMemberExpr,
12321232
cSetterValueExpr,
12331233
clang::BO_Assign,
12341234
fieldType,
1235-
clang::VK_RValue,
1235+
clang::VK_PRValue,
12361236
clang::OK_Ordinary,
12371237
clang::SourceLocation(),
12381238
clang::FPOptionsOverride());

lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3539,7 +3539,7 @@ void Driver::printHelp(bool ShowHidden) const {
35393539
if (!ShowHidden)
35403540
ExcludedFlagsBitmask |= HelpHidden;
35413541

3542-
getOpts().PrintHelp(llvm::outs(), Name.c_str(), "Swift compiler",
3542+
getOpts().printHelp(llvm::outs(), Name.c_str(), "Swift compiler",
35433543
IncludedFlagsBitmask, ExcludedFlagsBitmask,
35443544
/*ShowAllAliases*/false);
35453545

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ int swift::performFrontend(ArrayRef<const char *> Args,
21082108
Invocation.getFrontendOptions().PrintHelpHidden ? 0 :
21092109
llvm::opt::HelpHidden;
21102110
std::unique_ptr<llvm::opt::OptTable> Options(createSwiftOptTable());
2111-
Options->PrintHelp(llvm::outs(), displayName(MainExecutablePath).c_str(),
2111+
Options->printHelp(llvm::outs(), displayName(MainExecutablePath).c_str(),
21122112
"Swift frontend", IncludedFlagsBitmask,
21132113
ExcludedFlagsBitmask, /*ShowAllAliases*/false);
21142114
return finishDiagProcessing(0, /*verifierEnabled*/ false);

lib/IRGen/IRGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ static void embedBitcode(llvm::Module *M, const IRGenOptions &Opts)
824824

825825
// Save llvm.compiler.used and remove it.
826826
SmallVector<llvm::Constant*, 2> UsedArray;
827-
SmallSet<llvm::GlobalValue*, 4> UsedGlobals;
827+
SmallVector<llvm::GlobalValue*, 4> UsedGlobals;
828828
auto *UsedElementType =
829829
llvm::Type::getInt8Ty(M->getContext())->getPointerTo(0);
830830
llvm::GlobalVariable *Used =
@@ -1533,7 +1533,7 @@ bool swift::performLLVM(const IRGenOptions &Opts, ASTContext &Ctx,
15331533

15341534
auto *Clang = static_cast<ClangImporter *>(Ctx.getClangModuleLoader());
15351535
// Use clang's datalayout.
1536-
Module->setDataLayout(Clang->getTargetInfo().getDataLayout());
1536+
Module->setDataLayout(Clang->getTargetInfo().getDataLayoutString());
15371537

15381538
embedBitcode(Module, Opts);
15391539
if (::performLLVM(Opts, Ctx.Diags, nullptr, nullptr, Module,

lib/IRGen/IRGenModule.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,18 @@ static void sanityCheckStdlib(IRGenModule &IGM) {
192192

193193
IRGenModule::IRGenModule(IRGenerator &irgen,
194194
std::unique_ptr<llvm::TargetMachine> &&target,
195-
SourceFile *SF,
196-
StringRef ModuleName, StringRef OutputFilename,
195+
SourceFile *SF, StringRef ModuleName,
196+
StringRef OutputFilename,
197197
StringRef MainInputFilenameForDebugInfo,
198198
StringRef PrivateDiscriminator)
199-
: LLVMContext(new llvm::LLVMContext()),
200-
IRGen(irgen), Context(irgen.SIL.getASTContext()),
199+
: LLVMContext(new llvm::LLVMContext()), IRGen(irgen),
200+
Context(irgen.SIL.getASTContext()),
201201
// The LLVMContext (and the IGM itself) will get deleted by the IGMDeleter
202202
// as long as the IGM is registered with the IRGenerator.
203-
ClangCodeGen(createClangCodeGenerator(Context, *LLVMContext,
204-
irgen.Opts,
203+
ClangCodeGen(createClangCodeGenerator(Context, *LLVMContext, irgen.Opts,
205204
ModuleName, PrivateDiscriminator)),
206205
Module(*ClangCodeGen->GetModule()),
207-
DataLayout(irgen.getClangDataLayout()),
206+
DataLayout(irgen.getClangDataLayoutString()),
208207
Triple(irgen.getEffectiveClangTriple()), TargetMachine(std::move(target)),
209208
silConv(irgen.SIL), OutputFilename(OutputFilename),
210209
MainInputFilenameForDebugInfo(MainInputFilenameForDebugInfo),
@@ -1750,12 +1749,12 @@ llvm::Triple IRGenerator::getEffectiveClangTriple() {
17501749
return llvm::Triple(CI->getTargetInfo().getTargetOpts().Triple);
17511750
}
17521751

1753-
const llvm::DataLayout &IRGenerator::getClangDataLayout() {
1752+
const llvm::StringRef IRGenerator::getClangDataLayoutString() {
17541753
return static_cast<ClangImporter *>(
17551754
SIL.getASTContext().getClangModuleLoader())
17561755
->getTargetInfo()
1757-
.getDataLayout();
1758-
}
1756+
.getDataLayoutString();
1757+
}
17591758

17601759
TypeExpansionContext IRGenModule::getMaximalTypeExpansionContext() const {
17611760
return TypeExpansionContext::maximal(getSwiftModule(),

lib/IRGen/IRGenModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ class IRGenerator {
519519
/// Return the effective triple used by clang.
520520
llvm::Triple getEffectiveClangTriple();
521521

522-
const llvm::DataLayout &getClangDataLayout();
522+
const llvm::StringRef getClangDataLayoutString();
523523
};
524524

525525
class ConstantReference {

lib/Serialization/Serialization.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ using llvm::BCBlockRAII;
7878

7979
ASTContext &SerializerBase::getASTContext() const { return M->getASTContext(); }
8080

81+
static StringRef withNullAsEmptyStringRef(const char *data) {
82+
return StringRef(data ? data : "");
83+
}
84+
8185
/// Used for static_assert.
8286
static constexpr bool declIDFitsIn32Bits() {
8387
using Int32Info = std::numeric_limits<uint32_t>;
@@ -5567,7 +5571,7 @@ void swift::serializeToBuffers(
55675571
std::unique_ptr<llvm::MemoryBuffer> *moduleSourceInfoBuffer,
55685572
const SILModule *M) {
55695573

5570-
assert(!StringRef::withNullAsEmpty(options.OutputPath).empty());
5574+
assert(!withNullAsEmptyStringRef(options.OutputPath).empty());
55715575
{
55725576
FrontendStatsTracer tracer(getContext(DC).Stats,
55735577
"Serialization, swiftmodule, to buffer");
@@ -5588,7 +5592,7 @@ void swift::serializeToBuffers(
55885592
std::move(buf), options.OutputPath);
55895593
}
55905594

5591-
if (!StringRef::withNullAsEmpty(options.DocOutputPath).empty()) {
5595+
if (!withNullAsEmptyStringRef(options.DocOutputPath).empty()) {
55925596
FrontendStatsTracer tracer(getContext(DC).Stats,
55935597
"Serialization, swiftdoc, to buffer");
55945598
llvm::SmallString<1024> buf;
@@ -5605,7 +5609,7 @@ void swift::serializeToBuffers(
56055609
std::move(buf), options.DocOutputPath);
56065610
}
56075611

5608-
if (!StringRef::withNullAsEmpty(options.SourceInfoOutputPath).empty()) {
5612+
if (!withNullAsEmptyStringRef(options.SourceInfoOutputPath).empty()) {
56095613
FrontendStatsTracer tracer(getContext(DC).Stats,
56105614
"Serialization, swiftsourceinfo, to buffer");
56115615
llvm::SmallString<1024> buf;
@@ -5627,12 +5631,12 @@ void swift::serialize(ModuleOrSourceFile DC,
56275631
const SerializationOptions &options,
56285632
const SILModule *M,
56295633
const fine_grained_dependencies::SourceFileDepGraph *DG) {
5630-
assert(!StringRef::withNullAsEmpty(options.OutputPath).empty());
5634+
assert(!withNullAsEmptyStringRef(options.OutputPath).empty());
56315635

56325636
if (StringRef(options.OutputPath) == "-") {
56335637
// Special-case writing to stdout.
56345638
Serializer::writeToStream(llvm::outs(), DC, M, options, DG);
5635-
assert(StringRef::withNullAsEmpty(options.DocOutputPath).empty());
5639+
assert(withNullAsEmptyStringRef(options.DocOutputPath).empty());
56365640
return;
56375641
}
56385642

@@ -5647,7 +5651,7 @@ void swift::serialize(ModuleOrSourceFile DC,
56475651
if (hadError)
56485652
return;
56495653

5650-
if (!StringRef::withNullAsEmpty(options.DocOutputPath).empty()) {
5654+
if (!withNullAsEmptyStringRef(options.DocOutputPath).empty()) {
56515655
(void)withOutputFile(getContext(DC).Diags,
56525656
options.DocOutputPath,
56535657
[&](raw_ostream &out) {
@@ -5658,7 +5662,7 @@ void swift::serialize(ModuleOrSourceFile DC,
56585662
});
56595663
}
56605664

5661-
if (!StringRef::withNullAsEmpty(options.SourceInfoOutputPath).empty()) {
5665+
if (!withNullAsEmptyStringRef(options.SourceInfoOutputPath).empty()) {
56625666
(void)withOutputFile(getContext(DC).Diags,
56635667
options.SourceInfoOutputPath,
56645668
[&](raw_ostream &out) {

lib/Serialization/SerializeSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,8 +1565,8 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
15651565
Ty = cast<IntegerLiteralInst>(&SI)->getType();
15661566
break;
15671567
case SILInstructionKind::FloatLiteralInst:
1568-
cast<IntegerLiteralInst>(&SI)->getValue().toString(Str, 16,
1569-
/*signed*/ true);
1568+
cast<FloatLiteralInst>(&SI)->getBits().toString(Str, 16,
1569+
/*signed*/ true);
15701570
Ty = cast<FloatLiteralInst>(&SI)->getType();
15711571
break;
15721572
}

lib/TBDGen/TBDGen.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static bool isGlobalOrStaticVar(VarDecl *VD) {
6868

6969
TBDGenVisitor::TBDGenVisitor(const TBDGenDescriptor &desc,
7070
APIRecorder &recorder)
71-
: TBDGenVisitor(desc.getTarget(), desc.getDataLayout(),
71+
: TBDGenVisitor(desc.getTarget(), desc.getDataLayoutString(),
7272
desc.getParentModule(), desc.getOptions(), recorder) {}
7373

7474
void TBDGenVisitor::addSymbolInternal(StringRef name, SymbolKind kind,
@@ -390,7 +390,9 @@ void TBDGenVisitor::addSymbol(StringRef name, SymbolSource source,
390390
if (kind == SymbolKind::ObjectiveCClass) {
391391
mangled = name;
392392
} else {
393-
llvm::Mangler::getNameWithPrefix(mangled, name, DataLayout);
393+
if (!DataLayout)
394+
DataLayout = llvm::DataLayout(DataLayoutDescription);
395+
llvm::Mangler::getNameWithPrefix(mangled, name, *DataLayout);
394396
}
395397

396398
addSymbolInternal(mangled, kind, source);

lib/TBDGen/TBDGenRequests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ ModuleDecl *TBDGenDescriptor::getParentModule() const {
4848
return Input.get<FileUnit *>()->getParentModule();
4949
}
5050

51-
const llvm::DataLayout &TBDGenDescriptor::getDataLayout() const {
51+
const StringRef TBDGenDescriptor::getDataLayoutString() const {
5252
auto &ctx = getParentModule()->getASTContext();
5353
auto *clang = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
54-
return clang->getTargetInfo().getDataLayout();
54+
return llvm::StringRef(clang->getTargetInfo().getDataLayoutString());
5555
}
5656

5757
const llvm::Triple &TBDGenDescriptor::getTarget() const {

lib/TBDGen/TBDGenVisitor.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
9292
llvm::StringSet<> DuplicateSymbolChecker;
9393
#endif
9494

95-
const llvm::DataLayout &DataLayout;
95+
Optional<llvm::DataLayout> DataLayout = None;
96+
const StringRef DataLayoutDescription;
97+
9698
UniversalLinkageInfo UniversalLinkInfo;
9799
ModuleDecl *SwiftModule;
98100
const TBDGenOptions &Opts;
@@ -167,10 +169,10 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
167169
const AutoDiffConfig &config);
168170

169171
public:
170-
TBDGenVisitor(const llvm::Triple &target, const llvm::DataLayout &dataLayout,
172+
TBDGenVisitor(const llvm::Triple &target, const StringRef dataLayoutString,
171173
ModuleDecl *swiftModule, const TBDGenOptions &opts,
172174
APIRecorder &recorder)
173-
: DataLayout(dataLayout),
175+
: DataLayoutDescription(dataLayoutString),
174176
UniversalLinkInfo(target, opts.HasMultipleIGMs, /*forcePublic*/ false),
175177
SwiftModule(swiftModule), Opts(opts), recorder(recorder),
176178
previousInstallNameMap(parsePreviousModuleInstallNameMap()) {}

tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,6 @@ void TestOptions::printHelp(bool ShowHidden) const {
446446

447447
TestOptTable Table;
448448

449-
Table.PrintHelp(llvm::outs(), "sourcekitd-test [options] <inputs>",
449+
Table.printHelp(llvm::outs(), "sourcekitd-test [options] <inputs>",
450450
"SourceKit Testing Tool", ShowHidden);
451451
}

tools/driver/autolink_extract_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class AutolinkExtractInvocation {
8282
if (ParsedArgs.getLastArg(OPT_help)) {
8383
std::string ExecutableName =
8484
llvm::sys::path::stem(MainExecutablePath).str();
85-
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
85+
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
8686
"Swift Autolink Extract", options::AutolinkExtractOption,
8787
0, /*ShowAllAliases*/false);
8888
return 1;

tools/driver/modulewrap_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ModuleWrapInvocation {
9696
if (ParsedArgs.getLastArg(OPT_help)) {
9797
std::string ExecutableName =
9898
llvm::sys::path::stem(MainExecutablePath).str();
99-
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
99+
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
100100
"Swift Module Wrapper", options::ModuleWrapOption, 0,
101101
/*ShowAllAliases*/false);
102102
return 1;

tools/driver/swift_api_digester_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2655,7 +2655,7 @@ class SwiftAPIDigesterInvocation {
26552655
void printHelp() {
26562656
std::string ExecutableName =
26572657
llvm::sys::path::stem(MainExecutablePath).str();
2658-
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(), "Swift API Digester",
2658+
Table->printHelp(llvm::outs(), ExecutableName.c_str(), "Swift API Digester",
26592659
/*IncludedFlagsBitmask*/ SwiftAPIDigesterOption,
26602660
/*ExcludedFlagsBitmask*/ 0,
26612661
/*ShowAllAliases*/ false);

tools/driver/swift_api_extract_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class SwiftAPIExtractInvocation {
6565
if (ParsedArgs.getLastArg(OPT_help)) {
6666
std::string ExecutableName =
6767
llvm::sys::path::stem(MainExecutablePath).str();
68-
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
68+
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
6969
"Swift API Extract", options::SwiftAPIExtractOption, 0,
7070
/*ShowAllAliases*/ false);
7171
return 1;

tools/driver/swift_indent_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class SwiftIndentInvocation {
149149
if (ParsedArgs.getLastArg(OPT_help)) {
150150
std::string ExecutableName =
151151
llvm::sys::path::stem(MainExecutablePath).str();
152-
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
152+
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
153153
"Swift Format Tool", options::SwiftIndentOption, 0,
154154
/*ShowAllAliases*/false);
155155
return 1;

tools/driver/swift_symbolgraph_extract_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args,
6262
if (ParsedArgs.getLastArg(OPT_help) || Args.empty()) {
6363
std::string ExecutableName =
6464
llvm::sys::path::stem(MainExecutablePath).str();
65-
Table->PrintHelp(llvm::outs(), ExecutableName.c_str(),
65+
Table->printHelp(llvm::outs(), ExecutableName.c_str(),
6666
"Swift Symbol Graph Extractor",
6767
SwiftSymbolGraphExtractOption, 0,
6868
/*ShowAllAliases*/ false);

tools/swift-syntax-parser-test/swift-syntax-parser-test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
#include "swift/Basic/LLVM.h"
1919
#include "swift/Basic/LLVMInitialize.h"
2020
#include "llvm/Support/CommandLine.h"
21+
#include "llvm/Support/Format.h"
2122
#include "llvm/Support/MemoryBuffer.h"
22-
#include "llvm/Support/Timer.h"
2323
#include "llvm/Support/SourceMgr.h"
24+
#include "llvm/Support/Timer.h"
2425

2526
using namespace swift;
2627
using namespace llvm;

0 commit comments

Comments
 (0)