Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/swift/ClangImporter/SwiftAbstractBasicReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class DataStreamBasicReader
return uint32_t(asImpl().readUInt64());
}

clang::UnsignedOrNone readUnsignedOrNone() {
return clang::UnsignedOrNone::fromInternalRepresentation(
unsigned(asImpl().readUInt64()));
}

clang::Selector readSelector() {
uint64_t numArgsPlusOne = asImpl().readUInt64();

Expand Down
4 changes: 4 additions & 0 deletions include/swift/ClangImporter/SwiftAbstractBasicWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class DataStreamBasicWriter
asImpl().writeUInt64(uint64_t(value));
}

void writeUnsignedOrNone(clang::UnsignedOrNone value) {
asImpl().writeUInt64(uint64_t(value.toInternalRepresentation()));
}

void writeSelector(clang::Selector selector) {
if (selector.isNull()) {
asImpl().writeUInt64(0);
Expand Down
5 changes: 1 addition & 4 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,6 @@ Type IntrinsicTypeDecoder::decodeImmediate() {
case IITDescriptor::Metadata:
case IITDescriptor::ExtendArgument:
case IITDescriptor::TruncArgument:
case IITDescriptor::HalfVecArgument:
case IITDescriptor::VarArg:
case IITDescriptor::Token:
case IITDescriptor::VecOfAnyPtrsToElt:
Expand All @@ -2506,9 +2505,7 @@ Type IntrinsicTypeDecoder::decodeImmediate() {
case IITDescriptor::Subdivide4Argument:
case IITDescriptor::PPCQuad:
case IITDescriptor::AArch64Svcount:
case IITDescriptor::OneThirdVecArgument:
case IITDescriptor::OneFifthVecArgument:
case IITDescriptor::OneSeventhVecArgument:
case IITDescriptor::OneNthEltsVecArgument:
// These types cannot be expressed in swift yet.
return Type();

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ClangTypeConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ getClangBuiltinTypeFromKind(const clang::ASTContext &context,
#define SVE_TYPE(Name, Id, SingletonId) \
case clang::BuiltinType::Id: \
return context.SingletonId;
#include "clang/Basic/AArch64SVEACLETypes.def"
#include "clang/Basic/AArch64ACLETypes.def"
#define PPC_VECTOR_TYPE(Name, Id, Size) \
case clang::BuiltinType::Id: \
return context.Id##Ty;
Expand Down
1 change: 1 addition & 0 deletions lib/Basic/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
return "none";
case llvm::Triple::UEFI:
case llvm::Triple::LiteOS:
case llvm::Triple::Managarm:
llvm_unreachable("unsupported OS");
}
llvm_unreachable("unsupported OS");
Expand Down
12 changes: 6 additions & 6 deletions lib/Basic/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ void printTripleInfo(const CompilerInvocation &invocation,
out << " \"arch\": \"" << swift::getMajorArchitectureName(triple)
<< "\",\n";

clang::DiagnosticsEngine DE{new clang::DiagnosticIDs(),
new clang::DiagnosticOptions(),
clang::DiagnosticOptions diagOpts;
clang::DiagnosticsEngine DE{new clang::DiagnosticIDs(), diagOpts,
new clang::IgnoringDiagConsumer()};
std::shared_ptr<clang::TargetOptions> TO =
std::make_shared<clang::TargetOptions>();
TO->Triple = triple.str();
clang::TargetInfo *TI = clang::TargetInfo::CreateTargetInfo(DE, TO);

clang::TargetOptions targetOpts;
targetOpts.Triple = triple.str();
clang::TargetInfo *TI = clang::TargetInfo::CreateTargetInfo(DE, targetOpts);
out << " \"pointerWidthInBits\": "
<< TI->getPointerWidth(clang::LangAS::Default) << ",\n";
out << " \"pointerWidthInBytes\": "
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ OmissionTypeName importer::getClangTypeNameForOmission(clang::ASTContext &ctx,

// ARM SVE builtin types that don't have Swift equivalents.
#define SVE_TYPE(Name, Id, ...) case clang::BuiltinType::Id:
#include "clang/Basic/AArch64SVEACLETypes.def"
#include "clang/Basic/AArch64ACLETypes.def"
return OmissionTypeName();

// PPC MMA builtin types that don't have Swift equivalents.
Expand Down
15 changes: 6 additions & 9 deletions lib/ClangImporter/ClangDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ namespace {

public:
ClangDiagRenderer(const clang::LangOptions &langOpts,
clang::DiagnosticOptions *diagOpts,
decltype(callback) fn)
: DiagnosticNoteRenderer(langOpts, diagOpts),
callback(fn) {}
clang::DiagnosticOptions &diagOpts, decltype(callback) fn)
: DiagnosticNoteRenderer(langOpts, diagOpts), callback(fn) {}

private:
/// Is this a diagnostic that doesn't do the user any good to show if it
Expand Down Expand Up @@ -107,10 +105,9 @@ namespace {

ClangDiagnosticConsumer::ClangDiagnosticConsumer(
ClangImporter::Implementation &impl,
clang::DiagnosticOptions &clangDiagOptions,
bool dumpToStderr)
: TextDiagnosticPrinter(llvm::errs(), &clangDiagOptions),
ImporterImpl(impl), DumpToStderr(dumpToStderr) {}
clang::DiagnosticOptions &clangDiagOptions, bool dumpToStderr)
: TextDiagnosticPrinter(llvm::errs(), clangDiagOptions), ImporterImpl(impl),
DumpToStderr(dumpToStderr) {}

void ClangDiagnosticConsumer::HandleDiagnostic(
clang::DiagnosticsEngine::Level clangDiagLevel,
Expand Down Expand Up @@ -179,7 +176,7 @@ void ClangDiagnosticConsumer::HandleDiagnostic(
assert(clangDiag.hasSourceManager());
auto clangCI = ImporterImpl.getClangInstance();
ClangDiagRenderer renderer(clangCI->getLangOpts(),
&clangCI->getDiagnosticOpts(), emitDiag);
clangCI->getDiagnosticOpts(), emitDiag);
clang::FullSourceLoc clangDiagLoc(clangDiag.getLocation(),
clangDiag.getSourceManager());
renderer.emitDiagnostic(clangDiagLoc, clangDiagLevel, message,
Expand Down
89 changes: 46 additions & 43 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "swift/AST/ConcreteDeclRef.h"
#include "swift/AST/DiagnosticEngine.h"
#include "swift/AST/DiagnosticsClangImporter.h"
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/Evaluator.h"
#include "swift/AST/IRGenOptions.h"
Expand Down Expand Up @@ -328,7 +329,7 @@ class BridgingPPTracker : public clang::PPCallbacks {
return;
SmallVector<clang::SourceLocation, 4> IdLocs;
for (auto &P : Path)
IdLocs.push_back(P.second);
IdLocs.push_back(P.getLoc());
handleImport(ImportLoc, IdLocs, Imported);
}

Expand Down Expand Up @@ -966,10 +967,8 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
// FIXME: The following attempts to do an initial ReadAST invocation to verify
// the PCH, without causing trouble for the existing CompilerInstance.
// Look into combining creating the ASTReader along with verification + update
// if necessary, so that we can create and use one ASTReader in the common case
// when there is no need for update.
clang::CompilerInstance CI(Impl.Instance->getPCHContainerOperations(),
&Impl.Instance->getModuleCache());
// if necessary, so that we can create and use one ASTReader in the common
// case when there is no need for update.
auto invocation =
std::make_shared<clang::CompilerInvocation>(*Impl.Invocation);
invocation->getPreprocessorOpts().DisablePCHOrModuleValidation =
Expand All @@ -984,10 +983,13 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
// will try to free it.
invocation->getPreprocessorOpts().RemappedFileBuffers.clear();

CI.setInvocation(std::move(invocation));
clang::DiagnosticOptions diagOpts;
clang::CompilerInstance CI(std::move(invocation),
Impl.Instance->getPCHContainerOperations(),
&Impl.Instance->getModuleCache());
CI.setTarget(&Impl.Instance->getTarget());
CI.setDiagnostics(&*clang::CompilerInstance::createDiagnostics(
Impl.Instance->getVirtualFileSystem(), new clang::DiagnosticOptions()));
Impl.Instance->getVirtualFileSystem(), diagOpts));

// Note: Reusing the file manager is safe; this is a component that's already
// reused when building PCM files for the module cache.
Expand Down Expand Up @@ -1139,13 +1141,11 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
//
// The long-term client for Clang diagnostics is set up afterwards, after the
// clang::CompilerInstance is created.
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> tempDiagOpts{
new clang::DiagnosticOptions};
auto *tempDiagClient =
new ClangDiagnosticConsumer(Impl, *tempDiagOpts,
ctx.ClangImporterOpts.DumpClangDiagnostics);
clang::DiagnosticOptions tempDiagOpts;
auto *tempDiagClient = new ClangDiagnosticConsumer(
Impl, tempDiagOpts, ctx.ClangImporterOpts.DumpClangDiagnostics);
auto clangDiags = clang::CompilerInstance::createDiagnostics(
*VFS, tempDiagOpts.get(), tempDiagClient,
*VFS, tempDiagOpts, tempDiagClient,
/*owned*/ true);

// If using direct cc1 module build, use extra args to setup ClangImporter.
Expand Down Expand Up @@ -1265,10 +1265,10 @@ std::unique_ptr<clang::CompilerInvocation> ClangImporter::createClangInvocation(
// option here is either generated by dependency scanner or just round tripped
// from `getClangCC1Arguments` so we don't expect it to fail. Use a simple
// printing diagnostics consumer for debugging any unexpected error.
auto diagOpts = llvm::makeIntrusiveRefCnt<clang::DiagnosticOptions>();
clang::DiagnosticOptions diagOpts;
clang::DiagnosticsEngine clangDiags(
new clang::DiagnosticIDs(), diagOpts,
new clang::TextDiagnosticPrinter(llvm::errs(), diagOpts.get()));
new clang::TextDiagnosticPrinter(llvm::errs(), diagOpts));

// Finally, use the CC1 command-line and the diagnostic engine
// to instantiate our Invocation.
Expand Down Expand Up @@ -1364,12 +1364,10 @@ ClangImporter::create(ASTContext &ctx,
std::make_unique<clang::ObjectFilePCHContainerWriter>());
PCHContainerOperations->registerReader(
std::make_unique<clang::ObjectFilePCHContainerReader>());
importer->Impl.Instance.reset(
new clang::CompilerInstance(std::move(PCHContainerOperations)));
importer->Impl.Instance.reset(new clang::CompilerInstance(
importer->Impl.Invocation, std::move(PCHContainerOperations)));
}
auto &instance = *importer->Impl.Instance;
instance.setInvocation(importer->Impl.Invocation);

if (tracker)
instance.addDependencyCollector(tracker->getClangCollector());

Expand Down Expand Up @@ -1414,7 +1412,7 @@ ClangImporter::create(ASTContext &ctx,
if (!swiftTargetClangInvocation)
return nullptr;
auto targetInfo = clang::TargetInfo::CreateTargetInfo(
clangDiags, swiftTargetClangInvocation->TargetOpts);
clangDiags, swiftTargetClangInvocation->getTargetOpts());
// Ensure the target info has configured target-specific defines
std::string defineBuffer;
llvm::raw_string_ostream predefines(defineBuffer);
Expand All @@ -1426,7 +1424,7 @@ ClangImporter::create(ASTContext &ctx,
} else {
// Just use the existing Invocation's directly
importer->Impl.setSwiftTargetInfo(clang::TargetInfo::CreateTargetInfo(
clangDiags, importer->Impl.Invocation->TargetOpts));
clangDiags, importer->Impl.Invocation->getTargetOpts()));
importer->Impl.setSwiftCodeGenOptions(
new clang::CodeGenOptions(importer->Impl.Invocation->getCodeGenOpts()));
}
Expand All @@ -1445,9 +1443,8 @@ ClangImporter::create(ASTContext &ctx,
// things here.

// Create the target instance.
instance.setTarget(
clang::TargetInfo::CreateTargetInfo(clangDiags,
instance.getInvocation().TargetOpts));
instance.setTarget(clang::TargetInfo::CreateTargetInfo(
clangDiags, instance.getInvocation().getTargetOpts()));
if (!instance.hasTarget())
return nullptr;

Expand Down Expand Up @@ -1900,9 +1897,8 @@ std::string ClangImporter::getBridgingHeaderContents(
clang::FileManager &fileManager = Impl.Instance->getFileManager();

clang::CompilerInstance rewriteInstance(
Impl.Instance->getPCHContainerOperations(),
&Impl.Instance->getModuleCache());
rewriteInstance.setInvocation(invocation);
std::move(invocation), Impl.Instance->getPCHContainerOperations(),
&Impl.Instance->getModuleCache());
rewriteInstance.createDiagnostics(fileManager.getVirtualFileSystem(),
new clang::IgnoringDiagConsumer);
rewriteInstance.setFileManager(&fileManager);
Expand Down Expand Up @@ -2006,9 +2002,8 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() {
clang::FileManager &fileManager = Impl.Instance->getFileManager();

auto clonedInstance = std::make_unique<clang::CompilerInstance>(
Impl.Instance->getPCHContainerOperations(),
&Impl.Instance->getModuleCache());
clonedInstance->setInvocation(std::move(invocation));
std::move(invocation), Impl.Instance->getPCHContainerOperations(),
&Impl.Instance->getModuleCache());
clonedInstance->createDiagnostics(fileManager.getVirtualFileSystem(),
&Impl.Instance->getDiagnosticClient(),
/*ShouldOwnClient=*/false);
Expand Down Expand Up @@ -2297,17 +2292,15 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
auto realModuleName = SwiftContext.getRealModuleName(path.front().Item).str();

// Convert the Swift import path over to a Clang import path.
SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>, 4>
clangPath;
SmallVector<clang::IdentifierLoc, 4> clangPath;
bool isTopModuleComponent = true;
for (auto component : path) {
StringRef item = isTopModuleComponent? realModuleName:
component.Item.str();
isTopModuleComponent = false;

clangPath.emplace_back(
getClangPreprocessor().getIdentifierInfo(item),
exportSourceLoc(component.Loc));
clangPath.emplace_back(exportSourceLoc(component.Loc),
getClangPreprocessor().getIdentifierInfo(item));
}

auto &diagEngine = Instance->getDiagnostics();
Expand All @@ -2317,14 +2310,13 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
auto loadModule = [&](clang::ModuleIdPath path,
clang::Module::NameVisibilityKind visibility)
-> clang::ModuleLoadResult {
auto importRAII =
diagClient.handleImport(clangPath.front().first, diagEngine,
importLoc);
auto importRAII = diagClient.handleImport(
clangPath.front().getIdentifierInfo(), diagEngine, importLoc);

std::string preservedIndexStorePathOption;
auto &clangFEOpts = Instance->getFrontendOpts();
if (!clangFEOpts.IndexStorePath.empty()) {
StringRef moduleName = path[0].first->getName();
StringRef moduleName = path[0].getIdentifierInfo()->getName();
// Ignore the SwiftShims module for the index data.
if (moduleName == SwiftContext.SwiftShimsModuleName.str()) {
preservedIndexStorePathOption = clangFEOpts.IndexStorePath;
Expand Down Expand Up @@ -4162,8 +4154,8 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const {
});

clang::CompilerInvocation instance;
clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(),
new clang::DiagnosticOptions(),
clang::DiagnosticOptions diagOpts;
clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(), diagOpts,
new clang::IgnoringDiagConsumer());
bool success = clang::CompilerInvocation::CreateFromArgs(instance, clangArgs,
clangDiags);
Expand Down Expand Up @@ -4216,8 +4208,19 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const {
if (!Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper.empty()) {
// Remap all the paths if requested.
llvm::PrefixMapper Mapper;
clang::tooling::dependencies::DepscanPrefixMapping::configurePrefixMapper(
Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper, Mapper);
SmallVector<llvm::MappedPrefix> Prefixes;
if (auto E = llvm::MappedPrefix::transformJoined(
Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper, Prefixes)) {
// Take permanent ownership of this string. In general the diagnostic
// might outlive this function.
auto errorMessage =
Impl.SwiftContext.AllocateCopy(llvm::toString(std::move(E)));
Impl.SwiftContext.Diags.diagnose(SourceLoc(), diag::error_prefix_mapping,
errorMessage);
}
Mapper.addRange(Prefixes);
Mapper.sort();

clang::tooling::dependencies::DepscanPrefixMapping::remapInvocationPaths(
instance, Mapper);
instance.getFrontendOpts().PathPrefixMappings.clear();
Expand Down
3 changes: 2 additions & 1 deletion lib/ClangImporter/ClangIncludePaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ ClangImporter::createClangDriver(

auto diagVFS = vfs ? vfs : llvm::vfs::getRealFileSystem();

clang::DiagnosticOptions diagOpts;
auto *silentDiagConsumer = new clang::DiagnosticConsumer();
auto clangDiags = clang::CompilerInstance::createDiagnostics(
*diagVFS, new clang::DiagnosticOptions(), silentDiagConsumer);
*diagVFS, diagOpts, silentDiagConsumer);
clang::driver::Driver clangDriver(ClangImporterOpts.clangPath,
LangOpts.Target.str(), *clangDiags,
"clang LLVM compiler", vfs);
Expand Down
4 changes: 2 additions & 2 deletions lib/ClangImporter/ClangModuleDependencyScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ void ClangImporter::getBridgingHeaderOptions(
// Round-trip clang args to canonicalize and clear the options that swift
// compiler doesn't need.
clang::CompilerInvocation depsInvocation;
clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(),
new clang::DiagnosticOptions(),
clang::DiagnosticOptions diagOpts;
clang::DiagnosticsEngine clangDiags(new clang::DiagnosticIDs(), diagOpts,
new clang::IgnoringDiagConsumer());

llvm::SmallVector<const char *> clangArgs;
Expand Down
8 changes: 4 additions & 4 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4219,14 +4219,14 @@ namespace {
for (auto param : attr->params()) {
// FIXME: Swift assumes no escaping to globals. We should diagnose
// this.
if (param == clang::LifetimeCaptureByAttr::GLOBAL ||
param == clang::LifetimeCaptureByAttr::UNKNOWN ||
param == clang::LifetimeCaptureByAttr::INVALID)
if (param == clang::LifetimeCaptureByAttr::Global ||
param == clang::LifetimeCaptureByAttr::Unknown ||
param == clang::LifetimeCaptureByAttr::Invalid)
continue;

paramHasAnnotation[idx] = true;
if (isa<clang::CXXMethodDecl>(decl) &&
param == clang::LifetimeCaptureByAttr::THIS) {
param == clang::LifetimeCaptureByAttr::This) {
auto [it, inserted] = inheritedArgDependences.try_emplace(
result->getSelfIndex(), SmallBitVector(dependencyVecSize));
it->second[idx] = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ static ValueDecl *importMacro(ClangImporter::Implementation &impl,
clang::LookupResult R(S, {{tok.getIdentifierInfo()}, {}},
clang::Sema::LookupAnyName);
if (S.LookupName(R, S.TUScope))
if (R.getResultKind() == clang::LookupResult::LookupResultKind::Found)
if (R.getResultKind() == clang::LookupResultKind::Found)
if (const auto *VD = dyn_cast<clang::ValueDecl>(R.getFoundDecl()))
return importDeclAlias(impl, DC, VD, name);
}
Expand Down
Loading