diff --git a/clang/include/clang/AST/StmtIterator.h b/clang/include/clang/AST/StmtIterator.h index e98408c51a505..9adb3f21492d0 100644 --- a/clang/include/clang/AST/StmtIterator.h +++ b/clang/include/clang/AST/StmtIterator.h @@ -133,10 +133,10 @@ struct StmtIterator : public StmtIteratorImpl { StmtIterator(const VariableArrayType *t) : StmtIteratorImpl(t) {} -private: StmtIterator(const StmtIteratorBase &RHS) : StmtIteratorImpl(RHS) {} +private: inline friend StmtIterator cast_away_const(const ConstStmtIterator &RHS); }; diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index ad42564f9de37..92591eaf7cdf7 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1065,7 +1065,7 @@ def all__load : Flag<["-"], "all_load">; def allowable__client : Separate<["-"], "allowable_client">; def ansi : Flag<["-", "--"], "ansi">, Group; def arch__errors__fatal : Flag<["-"], "arch_errors_fatal">; -def arch : Separate<["-"], "arch">, Flags<[NoXarchOption,TargetSpecific]>; +def arch : Separate<["-"], "arch">, Flags<[NoXarchOption]>; def arch__only : Separate<["-"], "arch_only">; def autocomplete : Joined<["--"], "autocomplete=">; def bind__at__load : Flag<["-"], "bind_at_load">; diff --git a/clang/test/Driver/arc-exceptions.m b/clang/test/Driver/arc-exceptions.m index c1dd02d59988c..4501ccd073823 100644 --- a/clang/test/Driver/arc-exceptions.m +++ b/clang/test/Driver/arc-exceptions.m @@ -1,5 +1,5 @@ -// RUN: %clang -### -x objective-c --target=x86_64-apple-macos10.6 -fobjc-arc -fsyntax-only %s 2> %t.log +// RUN: %clang -### -x objective-c -arch x86_64 -fobjc-arc -fsyntax-only %s 2> %t.log // RUN: grep objective-c %t.log // RUN: not grep "fobjc-arc-exceptions" %t.log -// RUN: %clang -### -x objective-c++ --target=x86_64-apple-macos10.6 -fobjc-arc -fsyntax-only %s 2> %t.log +// RUN: %clang -### -x objective-c++ -arch x86_64 -fobjc-arc -fsyntax-only %s 2> %t.log // RUN: grep "fobjc-arc-exceptions" %t.log diff --git a/clang/test/Driver/arm-arch-darwin.c b/clang/test/Driver/arm-arch-darwin.c index f6d3f88a3f8d1..55089619d1e71 100644 --- a/clang/test/Driver/arm-arch-darwin.c +++ b/clang/test/Driver/arm-arch-darwin.c @@ -1,10 +1,6 @@ // On Darwin, arch should override CPU for triple purposes // RUN: %clang -target armv7m-apple-darwin -arch armv7m -mcpu=cortex-m4 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V7M-DARWIN %s // CHECK-V7M-DARWIN: "-cc1"{{.*}} "-triple" "thumbv7m-{{.*}} "-target-cpu" "cortex-m4" +// RUN: %clang -target armv7m -arch armv7m -mcpu=cortex-m4 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V7M-OVERRIDDEN %s +// CHECK-V7M-OVERRIDDEN: "-cc1"{{.*}} "-triple" "thumbv7em-{{.*}} "-target-cpu" "cortex-m4" -/// -arch is unsupported for non-Darwin targets. -// RUN: not %clang --target=armv7m -arch armv7m -mcpu=cortex-m4 -### -c %s 2>&1 | FileCheck -check-prefix=ERR %s -// ERR: unsupported option '-arch' for target 'armv7m' - -// RUN: not %clang --target=aarch64-linux-gnu -arch arm64 -### -c %s 2>&1 | FileCheck -check-prefix=ERR2 %s -// ERR2: unsupported option '-arch' for target 'aarch64-linux-gnu' diff --git a/clang/test/Frontend/darwin-eabi.c b/clang/test/Frontend/darwin-eabi.c index 9d62632891cbe..27471e6cfb0e6 100644 --- a/clang/test/Frontend/darwin-eabi.c +++ b/clang/test/Frontend/darwin-eabi.c @@ -1,6 +1,6 @@ -// RUN: %clang --target=armv6m-apple-darwin -dM -E %s | FileCheck %s -// RUN: %clang --target=armv7m-apple-darwin -dM -E %s | FileCheck %s -// RUN: %clang --target=armv7em-apple-darwin -dM -E %s | FileCheck %s +// RUN: %clang -arch armv6m -dM -E %s | FileCheck %s +// RUN: %clang -arch armv7m -dM -E %s | FileCheck %s +// RUN: %clang -arch armv7em -dM -E %s | FileCheck %s // RUN: %clang_cc1 -triple thumbv7m-apple-unknown-macho -dM -E %s | FileCheck %s // CHECK-NOT: __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp b/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp index a12ed0c76a3a3..7ae8bbd8ef73a 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp @@ -18,11 +18,11 @@ #include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" -#include "lldb/Core/StreamFile.h" #include "lldb/Core/ValueObject.h" #include "lldb/DataFormatters/TypeSummary.h" #include "lldb/DataFormatters/ValueObjectPrinter.h" #include "lldb/Host/HostInfo.h" +#include "lldb/Host/StreamFile.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Symbol/ObjectFile.h" diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.cpp b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.cpp index 44e8a40b77a25..aa87358ceeb87 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.cpp +++ b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.cpp @@ -177,7 +177,7 @@ SwiftMetadataCache::generateHashTableBlob( } // Make sure that no bucket is at offset 0. - llvm::support::endian::write(blobStream, 0, llvm::support::little); + llvm::support::endian::write(blobStream, 0, llvm::endianness::little); uint32_t table_control_offset = table_generator.Emit(blobStream, m_info); return {{std::move(table_control_offset), std::move(hash_table_blob)}}; } diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.h b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.h index 2d094f27d70bb..ea07296b0b261 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.h +++ b/lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.h @@ -67,7 +67,7 @@ class TypeRefInfo { offset_type key_len = key.size(); // Write the key length so we don't have to traverse it later. llvm::support::endian::write(out, key_len, - llvm::support::little); + llvm::endianness::little); // Since the data type is always a constant size there's no need to write // it. offset_type data_len = sizeof(data_type); @@ -80,7 +80,7 @@ class TypeRefInfo { void EmitData(llvm::raw_ostream &out, key_type_ref key, data_type_ref data, unsigned len) { - llvm::support::endian::write(out, data, llvm::support::little); + llvm::support::endian::write(out, data, llvm::endianness::little); } // Decoder functions. @@ -92,7 +92,7 @@ class TypeRefInfo { static std::pair ReadKeyDataLength(const unsigned char *&data) { offset_type key_len = - llvm::support::endian::readNext(data); offset_type data_len = sizeof(data_type); return std::make_pair(key_len, data_len); @@ -105,7 +105,7 @@ class TypeRefInfo { static data_type ReadData(internal_key_type key, const uint8_t *data, unsigned length) { data_type result = - llvm::support::endian::readNext(data); return result; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 55d19192ccb78..05a612faba57c 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -41,6 +41,7 @@ #include "UniqueDWARFASTType.h" class DWARFASTParserClang; +class DWARFASTParserSwift; namespace llvm { class DWARFDebugAbbrev; diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index 960abac9efeec..90066bbd76482 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -96,11 +96,11 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/Progress.h" #include "lldb/Core/Section.h" -#include "lldb/Core/StreamFile.h" #include "lldb/Expression/DiagnosticManager.h" #include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" +#include "lldb/Host/StreamFile.h" #include "lldb/Host/XML.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/ObjectFile.h" @@ -1600,7 +1600,7 @@ void SwiftASTContext::AddExtraClangArgs(const std::vector &source, continue; } // Drop -Werror; it would only cause trouble in the debugger. - if (clang_argument.startswith("-Werror")) + if (clang_argument.starts_with("-Werror")) continue; // Drop `--`. This might be coming from the user-provided setting @@ -5242,7 +5242,7 @@ swift::irgen::IRGenModule &SwiftASTContext::GetIRGenModule() { const llvm::Target *llvm_target = llvm::TargetRegistry::lookupTarget(llvm_triple.str(), error_str); - llvm::CodeGenOpt::Level optimization_level = llvm::CodeGenOpt::Level::None; + llvm::CodeGenOptLevel optimization_level = llvm::CodeGenOptLevel::None; // Create a target machine. llvm::TargetMachine *target_machine = llvm_target->createTargetMachine( @@ -9221,7 +9221,7 @@ bool SwiftASTContext::GetCompileUnitImportsImpl( } std::string category = "Importing Swift module dependencies for "; - category += compile_unit->GetPrimaryFile().GetFilename(); + category += compile_unit->GetPrimaryFile().GetFilename().GetString(); Progress progress(category, "", cu_imports.size()); size_t completion = 0; for (const SourceModule &module : cu_imports) { diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h index fd7507ffe1033..5e808f9c39c9a 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h @@ -77,11 +77,16 @@ namespace llvm { class LLVMContext; } -class DWARFASTParser; class SwiftEnumDescriptor; namespace lldb_private { +namespace plugin { +namespace dwarf { +class DWARFASTParser; +} // namespace dwarf +} // namespace plugin + struct SourceModule; class SwiftASTContext; class ClangExternalASTSourceCallbacks; @@ -549,7 +554,7 @@ class SwiftASTContext : public TypeSystemSwift { bool IsFixedSize(CompilerType compiler_type); - DWARFASTParser *GetDWARFParser() override; + plugin::dwarf::DWARFASTParser *GetDWARFParser() override; // CompilerDecl functions ConstString DeclGetName(void *opaque_decl) override { diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp index e01111675ba6c..a564d5d64c78a 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp @@ -71,13 +71,6 @@ void TypeSystemSwift::Terminate() { /// \} -void TypeSystemSwift::DumpValue( - lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, Stream &s, - lldb::Format format, const DataExtractor &data, lldb::offset_t data_offset, - size_t data_byte_size, uint32_t bitfield_bit_size, - uint32_t bitfield_bit_offset, bool show_types, bool show_summary, - bool verbose, uint32_t depth) {} - void TypeSystemSwift::Dump(llvm::raw_ostream &output) { // TODO: What to dump? } diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h index b541aea38c9e4..5a75a6e985263 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h @@ -187,13 +187,6 @@ class TypeSystemSwift : public TypeSystem { /// For example, int is converted to Int32. virtual CompilerType ConvertClangTypeToSwiftType(CompilerType clang_type) = 0; - void DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, - Stream &s, lldb::Format format, const DataExtractor &data, - lldb::offset_t data_offset, size_t data_byte_size, - uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, - bool show_types, bool show_summary, bool verbose, - uint32_t depth) override; - /// \see lldb_private::TypeSystem::Dump void Dump(llvm::raw_ostream &output) override; @@ -231,10 +224,6 @@ class TypeSystemSwift : public TypeSystem { return {}; } bool IsScalarType(lldb::opaque_compiler_type_t type) override; - bool IsCStringType(lldb::opaque_compiler_type_t type, - uint32_t &length) override { - return false; - } bool IsVectorType(lldb::opaque_compiler_type_t type, CompilerType *element_type, uint64_t *size) override { return false; @@ -323,12 +312,6 @@ class TypeSystemSwift : public TypeSystem { CompilerType GetNonReferenceType(lldb::opaque_compiler_type_t type) override { return {}; } - - // TODO: This method appear unused. Should they be removed? - void DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, - Stream &s, const DataExtractor &data, - lldb::offset_t data_offset, size_t data_byte_size) override { - } /// \} protected: /// Used in the logs. diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp index 7b80d9a552bc3..f05e0712ee4bb 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp @@ -24,7 +24,7 @@ #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/Core/Debugger.h" #include "lldb/Core/DumpDataExtractor.h" -#include "lldb/Core/StreamFile.h" +#include "lldb/Host/StreamFile.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/TypeList.h" #include "lldb/Symbol/TypeMap.h" @@ -1980,8 +1980,6 @@ void TypeSystemSwiftTypeRef::SetTriple(const llvm::Triple triple) { // This function appears to be only called via Module::SetArchitecture(ArchSpec). if (auto *swift_ast_context = GetSwiftASTContextOrNull(nullptr)) swift_ast_context->SetTriple(triple); - else - m_swift_ast_context_triple = triple; } void TypeSystemSwiftTypeRef::ClearModuleDependentCaches() { diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h index 450630d4be09b..0f75946c14556 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h @@ -109,7 +109,7 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift { Status IsCompatible() override; void DiagnoseWarnings(Process &process, Module &module) const override; - DWARFASTParser *GetDWARFParser() override; + plugin::dwarf::DWARFASTParser *GetDWARFParser() override; // CompilerDecl functions ConstString DeclGetName(void *opaque_decl) override { return ConstString(""); @@ -496,7 +496,7 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift { mutable std::unique_ptr m_dwarf_importer_for_clang_types_up; mutable std::unique_ptr m_name_importer_up; - std::unique_ptr m_dwarf_ast_parser_up; + std::unique_ptr m_dwarf_ast_parser_up; /// The APINotesManager responsible for each Clang module. llvm::DenseMap *LPMap = nullptr, + bool TidyIfNoBeginLabels = true); + /// Return a reference to the landing pad info for the current function. const std::vector &getLandingPads() const { return LandingPads; @@ -1215,11 +1219,22 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { /// entry. MCSymbol *addLandingPad(MachineBasicBlock *LandingPad); + /// Provide the catch typeinfo for a landing pad. + void addCatchTypeInfo(MachineBasicBlock *LandingPad, + ArrayRef TyInfo); + + /// Provide the filter typeinfo for a landing pad. + void addFilterTypeInfo(MachineBasicBlock *LandingPad, + ArrayRef TyInfo); + + /// Add a cleanup action for a landing pad. + void addCleanup(MachineBasicBlock *LandingPad); + /// Return the type id for the specified typeinfo. This is function wide. unsigned getTypeIDFor(const GlobalValue *TI); /// Return the id of the filter encoded by TyIds. This is function wide. - int getFilterIDFor(ArrayRef TyIds); + int getFilterIDFor(std::vector &TyIds); /// Map the landing pad's EH symbol to the call site indexes. void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef Sites); diff --git a/llvm/include/llvm/Support/GenericLoopInfoImpl.h b/llvm/include/llvm/Support/GenericLoopInfoImpl.h index 1e0d0ee446fc4..c9c7354937545 100644 --- a/llvm/include/llvm/Support/GenericLoopInfoImpl.h +++ b/llvm/include/llvm/Support/GenericLoopInfoImpl.h @@ -208,7 +208,10 @@ BlockT *LoopBase::getLoopPreheader() const { return nullptr; // Make sure there is only one exit out of the preheader. - if (llvm::size(llvm::children(Out)) != 1) + typedef GraphTraits BlockTraits; + typename BlockTraits::ChildIteratorType SI = BlockTraits::child_begin(Out); + ++SI; + if (SI != BlockTraits::child_end(Out)) return nullptr; // Multiple exits from the block, must not be a preheader. // The predecessor has exactly one successor, so it is a preheader. diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h index b3bb354b38ff5..c8af7fe791cf8 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -194,7 +194,8 @@ class Triple { Mesa, SUSE, OpenEmbedded, - LastVendorType = OpenEmbedded + Swift, + LastVendorType = Swift }; enum OSType { UnknownOS, diff --git a/llvm/lib/CodeGen/AsmPrinter/AIXException.cpp b/llvm/lib/CodeGen/AsmPrinter/AIXException.cpp index 82b5ccdc70ea1..6943c95845945 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AIXException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AIXException.cpp @@ -21,7 +21,16 @@ namespace llvm { -AIXException::AIXException(AsmPrinter *A) : EHStreamer(A) {} +AIXException::AIXException(AsmPrinter *A) : DwarfCFIExceptionBase(A) {} + +// This overrides 'DwarfCFIExceptionBase::markFunctionEnd', to avoid the call to +// tidyLandingPads. This is necessary, because the +// 'PPCAIXAsmPrinter::emitFunctionBodyEnd' function already checked whether we +// need ehinfo, and emitted a traceback table with the bits set to indicate that +// we will be emitting it, if so. Thus, if we remove it now -- so late in the +// process -- we'll end up having emitted a reference to __ehinfo.N symbol, but +// not emitting a definition for said symbol. +void AIXException::markFunctionEnd() {} void AIXException::emitExceptionInfoTable(const MCSymbol *LSDA, const MCSymbol *PerSym) { diff --git a/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp b/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp index de6ebcf0c3419..aa56442881d46 100644 --- a/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp @@ -19,7 +19,7 @@ #include "llvm/MC/MCStreamer.h" using namespace llvm; -ARMException::ARMException(AsmPrinter *A) : EHStreamer(A) {} +ARMException::ARMException(AsmPrinter *A) : DwarfCFIExceptionBase(A) {} ARMException::~ARMException() = default; @@ -51,6 +51,7 @@ void ARMException::beginFunction(const MachineFunction *MF) { void ARMException::markFunctionEnd() { if (shouldEmitCFI) Asm->OutStreamer->emitCFIEndProc(); + DwarfCFIExceptionBase::markFunctionEnd(); } /// endFunction - Gather and emit post-function exception information. diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp index 10c844ddb14a1..81ed6798b8ade 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp @@ -23,7 +23,18 @@ #include "llvm/Target/TargetOptions.h" using namespace llvm; -DwarfCFIException::DwarfCFIException(AsmPrinter *A) : EHStreamer(A) {} +DwarfCFIExceptionBase::DwarfCFIExceptionBase(AsmPrinter *A) : EHStreamer(A) {} + +void DwarfCFIExceptionBase::markFunctionEnd() { + // Map all labels and get rid of any dead landing pads. + if (!Asm->MF->getLandingPads().empty()) { + MachineFunction *NonConstMF = const_cast(Asm->MF); + NonConstMF->tidyLandingPads(); + } +} + +DwarfCFIException::DwarfCFIException(AsmPrinter *A) + : DwarfCFIExceptionBase(A) {} DwarfCFIException::~DwarfCFIException() = default; diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfException.h b/llvm/lib/CodeGen/AsmPrinter/DwarfException.h index c2c11c7bc14d1..9b09edc5e75f6 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfException.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfException.h @@ -21,7 +21,19 @@ namespace llvm { class MachineFunction; class ARMTargetStreamer; -class LLVM_LIBRARY_VISIBILITY DwarfCFIException : public EHStreamer { +class LLVM_LIBRARY_VISIBILITY DwarfCFIExceptionBase : public EHStreamer { +protected: + DwarfCFIExceptionBase(AsmPrinter *A); + + /// Per-function flag to indicate if frame CFI info should be emitted. + bool shouldEmitCFI = false; + /// Per-module flag to indicate if .cfi_section has beeen emitted. + bool hasEmittedCFISections = false; + + void markFunctionEnd() override; +}; + +class LLVM_LIBRARY_VISIBILITY DwarfCFIException : public DwarfCFIExceptionBase { /// Per-function flag to indicate if .cfi_personality should be emitted. bool shouldEmitPersonality = false; @@ -63,13 +75,7 @@ class LLVM_LIBRARY_VISIBILITY DwarfCFIException : public EHStreamer { void endBasicBlockSection(const MachineBasicBlock &MBB) override; }; -class LLVM_LIBRARY_VISIBILITY ARMException : public EHStreamer { - /// Per-function flag to indicate if frame CFI info should be emitted. - bool shouldEmitCFI = false; - - /// Per-module flag to indicate if .cfi_section has beeen emitted. - bool hasEmittedCFISections = false; - +class LLVM_LIBRARY_VISIBILITY ARMException : public DwarfCFIExceptionBase { void emitTypeInfos(unsigned TTypeEncoding, MCSymbol *TTBaseLabel) override; ARMTargetStreamer &getTargetStreamer(); @@ -93,7 +99,7 @@ class LLVM_LIBRARY_VISIBILITY ARMException : public EHStreamer { void markFunctionEnd() override; }; -class LLVM_LIBRARY_VISIBILITY AIXException : public EHStreamer { +class LLVM_LIBRARY_VISIBILITY AIXException : public DwarfCFIExceptionBase { /// This is AIX's compat unwind section, which unwinder would use /// to find the location of LSDA area and personality rountine. void emitExceptionInfoTable(const MCSymbol *LSDA, const MCSymbol *PerSym); @@ -101,6 +107,8 @@ class LLVM_LIBRARY_VISIBILITY AIXException : public EHStreamer { public: AIXException(AsmPrinter *A); + void markFunctionEnd() override; + void endModule() override {} void beginFunction(const MachineFunction *MF) override {} void endFunction(const MachineFunction *MF) override; diff --git a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp index 32239535e4d02..9ef9a1e06067e 100644 --- a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp @@ -194,12 +194,6 @@ void EHStreamer::computePadMap( const LandingPadInfo *LandingPad = LandingPads[i]; for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) { MCSymbol *BeginLabel = LandingPad->BeginLabels[j]; - MCSymbol *EndLabel = LandingPad->BeginLabels[j]; - // If we have deleted the code for a given invoke after registering it in - // the LandingPad label list, the associated symbols will not have been - // emitted. In that case, ignore this callsite entry. - if (!BeginLabel->isDefined() || !EndLabel->isDefined()) - continue; assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!"); PadRange P = { i, j }; PadMap[BeginLabel] = P; @@ -388,14 +382,8 @@ MCSymbol *EHStreamer::emitExceptionTable() { SmallVector LandingPads; LandingPads.reserve(PadInfos.size()); - for (const LandingPadInfo &LPI : PadInfos) { - // If a landing-pad has an associated label, but the label wasn't ever - // emitted, then skip it. (This can occur if the landingpad's MBB was - // deleted). - if (LPI.LandingPadLabel && !LPI.LandingPadLabel->isDefined()) - continue; + for (const LandingPadInfo &LPI : PadInfos) LandingPads.push_back(&LPI); - } // Order landing pads lexicographically by type id. llvm::sort(LandingPads, [](const LandingPadInfo *L, const LandingPadInfo *R) { diff --git a/llvm/lib/CodeGen/AsmPrinter/WasmException.cpp b/llvm/lib/CodeGen/AsmPrinter/WasmException.cpp index bf65e525dde14..a514ff161ceea 100644 --- a/llvm/lib/CodeGen/AsmPrinter/WasmException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/WasmException.cpp @@ -42,6 +42,16 @@ void WasmException::endModule() { } } +void WasmException::markFunctionEnd() { + // Get rid of any dead landing pads. + if (!Asm->MF->getLandingPads().empty()) { + auto *NonConstMF = const_cast(Asm->MF); + // Wasm does not set BeginLabel and EndLabel information for landing pads, + // so we should set the second argument false. + NonConstMF->tidyLandingPads(nullptr, /* TidyIfNoBeginLabels */ false); + } +} + void WasmException::endFunction(const MachineFunction *MF) { bool ShouldEmitExceptionTable = false; for (const LandingPadInfo &Info : MF->getLandingPads()) { diff --git a/llvm/lib/CodeGen/AsmPrinter/WasmException.h b/llvm/lib/CodeGen/AsmPrinter/WasmException.h index 86cc37dfde079..419b569d123ca 100644 --- a/llvm/lib/CodeGen/AsmPrinter/WasmException.h +++ b/llvm/lib/CodeGen/AsmPrinter/WasmException.h @@ -28,6 +28,7 @@ class LLVM_LIBRARY_VISIBILITY WasmException : public EHStreamer { void endModule() override; void beginFunction(const MachineFunction *MF) override {} + void markFunctionEnd() override; void endFunction(const MachineFunction *MF) override; protected: diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp index 6d6432b61f2d7..97e51949808aa 100644 --- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp @@ -130,6 +130,14 @@ void WinException::endFunction(const MachineFunction *MF) { if (F.hasPersonalityFn()) Per = classifyEHPersonality(F.getPersonalityFn()->stripPointerCasts()); + // Get rid of any dead landing pads if we're not using funclets. In funclet + // schemes, the landing pad is not actually reachable. It only exists so + // that we can emit the right table data. + if (!isFuncletEHPersonality(Per)) { + MachineFunction *NonConstMF = const_cast(MF); + NonConstMF->tidyLandingPads(); + } + endFuncletImpl(); // endFunclet will emit the necessary .xdata tables for table-based SEH. diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index 8366ad2859069..96aa7075109a5 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -799,31 +799,32 @@ MCSymbol *MachineFunction::addLandingPad(MachineBasicBlock *LandingPad) { if (LPI->isCleanup() && LPI->getNumClauses() != 0) LP.TypeIds.push_back(0); + if (LPI->isCleanup()) + addCleanup(LandingPad); + // FIXME: New EH - Add the clauses in reverse order. This isn't 100% // correct, but we need to do it this way because of how the DWARF EH // emitter processes the clauses. for (unsigned I = LPI->getNumClauses(); I != 0; --I) { Value *Val = LPI->getClause(I - 1); if (LPI->isCatch(I - 1)) { - LP.TypeIds.push_back( - getTypeIDFor(dyn_cast(Val->stripPointerCasts()))); + addCatchTypeInfo(LandingPad, + dyn_cast(Val->stripPointerCasts())); } else { // Add filters in a list. auto *CVal = cast(Val); - SmallVector FilterList; + SmallVector FilterList; for (const Use &U : CVal->operands()) - FilterList.push_back( - getTypeIDFor(cast(U->stripPointerCasts()))); + FilterList.push_back(cast(U->stripPointerCasts())); - LP.TypeIds.push_back(getFilterIDFor(FilterList)); + addFilterTypeInfo(LandingPad, FilterList); } } } else if (const auto *CPI = dyn_cast(FirstI)) { for (unsigned I = CPI->arg_size(); I != 0; --I) { - auto *TypeInfo = - dyn_cast(CPI->getArgOperand(I - 1)->stripPointerCasts()); - LP.TypeIds.push_back(getTypeIDFor(TypeInfo)); + Value *TypeInfo = CPI->getArgOperand(I - 1)->stripPointerCasts(); + addCatchTypeInfo(LandingPad, dyn_cast(TypeInfo)); } } else { @@ -833,6 +834,73 @@ MCSymbol *MachineFunction::addLandingPad(MachineBasicBlock *LandingPad) { return LandingPadLabel; } +void MachineFunction::addCatchTypeInfo(MachineBasicBlock *LandingPad, + ArrayRef TyInfo) { + LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); + for (const GlobalValue *GV : llvm::reverse(TyInfo)) + LP.TypeIds.push_back(getTypeIDFor(GV)); +} + +void MachineFunction::addFilterTypeInfo(MachineBasicBlock *LandingPad, + ArrayRef TyInfo) { + LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); + std::vector IdsInFilter(TyInfo.size()); + for (unsigned I = 0, E = TyInfo.size(); I != E; ++I) + IdsInFilter[I] = getTypeIDFor(TyInfo[I]); + LP.TypeIds.push_back(getFilterIDFor(IdsInFilter)); +} + +void MachineFunction::tidyLandingPads(DenseMap *LPMap, + bool TidyIfNoBeginLabels) { + for (unsigned i = 0; i != LandingPads.size(); ) { + LandingPadInfo &LandingPad = LandingPads[i]; + if (LandingPad.LandingPadLabel && + !LandingPad.LandingPadLabel->isDefined() && + (!LPMap || (*LPMap)[LandingPad.LandingPadLabel] == 0)) + LandingPad.LandingPadLabel = nullptr; + + // Special case: we *should* emit LPs with null LP MBB. This indicates + // "nounwind" case. + if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) { + LandingPads.erase(LandingPads.begin() + i); + continue; + } + + if (TidyIfNoBeginLabels) { + for (unsigned j = 0, e = LandingPads[i].BeginLabels.size(); j != e; ++j) { + MCSymbol *BeginLabel = LandingPad.BeginLabels[j]; + MCSymbol *EndLabel = LandingPad.EndLabels[j]; + if ((BeginLabel->isDefined() || (LPMap && (*LPMap)[BeginLabel] != 0)) && + (EndLabel->isDefined() || (LPMap && (*LPMap)[EndLabel] != 0))) + continue; + + LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j); + LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j); + --j; + --e; + } + + // Remove landing pads with no try-ranges. + if (LandingPads[i].BeginLabels.empty()) { + LandingPads.erase(LandingPads.begin() + i); + continue; + } + } + + // If there is no landing pad, ensure that the list of typeids is empty. + // If the only typeid is a cleanup, this is the same as having no typeids. + if (!LandingPad.LandingPadBlock || + (LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0])) + LandingPad.TypeIds.clear(); + ++i; + } +} + +void MachineFunction::addCleanup(MachineBasicBlock *LandingPad) { + LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad); + LP.TypeIds.push_back(0); +} + void MachineFunction::setCallSiteLandingPad(MCSymbol *Sym, ArrayRef Sites) { LPadToCallSiteMap[Sym].append(Sites.begin(), Sites.end()); @@ -846,7 +914,7 @@ unsigned MachineFunction::getTypeIDFor(const GlobalValue *TI) { return TypeInfos.size(); } -int MachineFunction::getFilterIDFor(ArrayRef TyIds) { +int MachineFunction::getFilterIDFor(std::vector &TyIds) { // If the new filter coincides with the tail of an existing filter, then // re-use the existing filter. Folding filters more than this requires // re-ordering filters and/or their elements - probably not worth it. diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp index 4fc1ff5aaa051..f8ae37b8c27b1 100644 --- a/llvm/lib/TargetParser/Triple.cpp +++ b/llvm/lib/TargetParser/Triple.cpp @@ -253,6 +253,7 @@ StringRef Triple::getVendorTypeName(VendorType Kind) { case PC: return "pc"; case SCEI: return "scei"; case SUSE: return "suse"; + case Swift: return "swift"; } llvm_unreachable("Invalid VendorType!"); @@ -634,6 +635,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) { .Case("amd", Triple::AMD) .Case("mesa", Triple::Mesa) .Case("suse", Triple::SUSE) + .Case("swift", Triple::Swift) .Case("oe", Triple::OpenEmbedded) .Default(Triple::UnknownVendor); } diff --git a/llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll b/llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll index d14bb8e03443d..accef082fdadc 100644 --- a/llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll +++ b/llvm/test/CodeGen/X86/gcc_except_table_bb_sections.ll @@ -148,7 +148,7 @@ declare i32 @__gxx_personality_v0(...) ; CHECK-NEXT: .uleb128 .Ltmp0-.Lfunc_begin0 # >> Call Site 1 << ; CHECK-NEXT: .uleb128 .Ltmp1-.Ltmp0 # Call between .Ltmp0 and .Ltmp1 ; CHECK-NEXT: .uleb128 .Ltmp2-main.__part.2 # jumps to .Ltmp2 -; CHECK-NEXT: .byte 3 # On action: 2 +; CHECK-NEXT: .byte 5 # On action: 3 ; CHECK-NEXT: .p2align 2 ; CHECK-NEXT: .Lexception1: @@ -207,9 +207,12 @@ declare i32 @__gxx_personality_v0(...) ; CHECK-NEXT: .byte 0 # >> Action Record 1 << ; CHECK-NEXT: # Cleanup ; CHECK-NEXT: .byte 0 # No further actions -; CHECK-NEXT: .byte 1 # >> Action Record 2 << -; CHECK-NEXT: # Catch TypeInfo 1 -; CHECK-NEXT: .byte 125 # Continue to action 1 +; CHECK-NEXT: .byte 0 # >> Action Record 2 << +; CHECK-NEXT: # Cleanup +; CHECK-NEXT: .byte 125 # Continue to action 1 +; CHECK-NEXT: .byte 1 # >> Action Record 3 << +; CHECK-NEXT: # Catch TypeInfo 1 +; CHECK-NEXT: .byte 125 # Continue to action 2 ; CHECK-NEXT: .p2align 2 ; CHECK-NEXT: # >> Catch TypeInfos << diff --git a/llvm/test/CodeGen/X86/gcc_except_table_bb_sections_ehpad_groups_with_cold.ll b/llvm/test/CodeGen/X86/gcc_except_table_bb_sections_ehpad_groups_with_cold.ll index 82dafecbf3c29..065acc536afa7 100644 --- a/llvm/test/CodeGen/X86/gcc_except_table_bb_sections_ehpad_groups_with_cold.ll +++ b/llvm/test/CodeGen/X86/gcc_except_table_bb_sections_ehpad_groups_with_cold.ll @@ -66,7 +66,7 @@ declare i32 @__gxx_personality_v0(...) ; CHECK-NEXT: .uleb128 .Ltmp0-.Lfunc_begin0 # >> Call Site 1 << ; CHECK-NEXT: .uleb128 .Ltmp1-.Ltmp0 # Call between .Ltmp0 and .Ltmp1 ; CHECK-NEXT: .uleb128 .Ltmp2-main.cold # jumps to .Ltmp2 -; CHECK-NEXT: .byte 3 # On action: 2 +; CHECK-NEXT: .byte 5 # On action: 3 ; CHECK-NEXT: .p2align 2 ; CHECK-NEXT: .Lexception1: ; CHECK-NEXT: .byte 0 # @LPStart Encoding = absptr @@ -85,9 +85,12 @@ declare i32 @__gxx_personality_v0(...) ; CHECK-NEXT: .byte 0 # >> Action Record 1 << ; CHECK-NEXT: # Cleanup ; CHECK-NEXT: .byte 0 # No further actions -; CHECK-NEXT: .byte 1 # >> Action Record 2 << -; CHECK-NEXT: # Catch TypeInfo 1 +; CHECK-NEXT: .byte 0 # >> Action Record 2 << +; CHECK-NEXT: # Cleanup ; CHECK-NEXT: .byte 125 # Continue to action 1 +; CHECK-NEXT: .byte 1 # >> Action Record 3 << +; CHECK-NEXT: # Catch TypeInfo 1 +; CHECK-NEXT: .byte 125 # Continue to action 2 ; CHECK-NEXT: .p2align 2 ; CHECK-NEXT: # >> Catch TypeInfos << ; CHECK-NEXT: .long _ZTIi # TypeInfo 1 diff --git a/llvm/test/CodeGen/XCore/exception.ll b/llvm/test/CodeGen/XCore/exception.ll index 725c17eca6a9d..2869f594ff262 100644 --- a/llvm/test/CodeGen/XCore/exception.ll +++ b/llvm/test/CodeGen/XCore/exception.ll @@ -112,7 +112,7 @@ Exit: ; CHECK: .uleb128 [[PRE_G]]-[[START]] ; CHECK: .uleb128 [[POST_G]]-[[PRE_G]] ; CHECK: .uleb128 [[LANDING]]-[[START]] -; CHECK: .byte 5 +; CHECK: .byte 7 ; CHECK: .uleb128 [[POST_G]]-[[START]] ; CHECK: .uleb128 [[END]]-[[POST_G]] ; CHECK: .byte 0 @@ -120,10 +120,11 @@ Exit: ; CHECK: [[CST_END]]: ; CHECK: .byte 0 ; CHECK: .byte 0 +; CHECK: .byte 0 +; CHECK: .byte 125 ; CHECK: .byte 1 ; CHECK: .byte 125 ; CHECK: .byte 2 -; CHECK: .byte 125 ; CHECK: .p2align 2 ; CHECK: .long _ZTIi ; CHECK: .long _ZTId diff --git a/third-party/unittest/CMakeLists.txt b/third-party/unittest/CMakeLists.txt index bf6ef54555144..d78cb4228edf8 100644 --- a/third-party/unittest/CMakeLists.txt +++ b/third-party/unittest/CMakeLists.txt @@ -42,7 +42,11 @@ endif() # by unittests if these are built. set(BUILDTREE_ONLY BUILDTREE_ONLY) -set(EXCLUDE_FROM_ALL ON) +# TODO: Swift does not build as part of the LLVM unified build, so it can't find +# GTest when LLVM doesn't export it. Swift should be built in the unified +# build, but we're not there yet. Put this back once Swift gets cleaned up +# a bit. rdar://113340971 +# set(EXCLUDE_FROM_ALL ON) if (LLVM_INSTALL_GTEST) set(EXCLUDE_FROM_ALL OFF) set(BUILDTREE_ONLY "")