From ca773106a63517668e36a2ddd5031584e4e5e5ac Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Tue, 9 Apr 2024 17:52:14 -0700 Subject: [PATCH 01/15] [lldb] Use `endianness` enum class in LLVM namespace (cherry picked from commit c07f420b130d71ded8d937eb6a4a364fded6fab6) --- .../Plugins/LanguageRuntime/Swift/SwiftMetadataCache.cpp | 2 +- .../Plugins/LanguageRuntime/Swift/SwiftMetadataCache.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) 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; } From 9ba352472b33e8ee234f503220a79b7e7bf0c783 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Wed, 17 Apr 2024 20:00:13 -0700 Subject: [PATCH 02/15] [lldb] Update `DWARFASTParser` references to use new `plugin::dwarf` namespace (cherry picked from commit 78598ae8913159e12a4d92d60db555191114e50c) --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h | 1 + lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h | 9 +++++++-- .../Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) 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.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/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 Date: Wed, 17 Apr 2024 20:01:16 -0700 Subject: [PATCH 03/15] [lldb] Remove unused methods that were removed from superclass (cherry picked from commit 3ec9866ff796f83e1f9c66eb5482b2863d23c11c) --- .../TypeSystem/Swift/TypeSystemSwift.cpp | 7 ------- .../Plugins/TypeSystem/Swift/TypeSystemSwift.h | 17 ----------------- 2 files changed, 24 deletions(-) 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. From 2113178dbe7148f1a428d8ddc7883fa8f4f74f94 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Tue, 16 Apr 2024 20:02:13 -0700 Subject: [PATCH 04/15] [lldb] Fix up `StreamFile.h` references `StreamFile.h` moved from `lldb/Core` to `lldb/Host`. Update Swift references. (cherry picked from commit a1f9c2fd69821fc82adb3070f60df611c5cc1587) --- lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp | 2 +- lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp | 2 +- lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index 960abac9efeec..9c91e0af91e0d 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" diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp index 7b80d9a552bc3..5c9ba255f9d2c 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" From acebc2d15378d65a9b9abad57b13fc1e82b41284 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Tue, 16 Apr 2024 20:04:42 -0700 Subject: [PATCH 05/15] [lldb] Remove duplicate case statement for `eManglingSchemeSwift` `eManglingSchemeSwift` is not guarded by `LLDB_ENABLE_SWIFT`, so a case was added upstream. Remove the now duplicated case statement. (cherry picked from commit fb74e310a01224f021a19a59d00beff31f185d8c) --- lldb/source/Symbol/Symtab.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp index f54912eba6cd7..15c9819bfcaa6 100644 --- a/lldb/source/Symbol/Symtab.cpp +++ b/lldb/source/Symbol/Symtab.cpp @@ -275,10 +275,6 @@ static bool lldb_skip_name(llvm::StringRef mangled, case Mangled::eManglingSchemeSwift: return false; -#ifdef LLDB_ENABLE_SWIFT - case Mangled::eManglingSchemeSwift: - // This is handled separately. -#endif // LLDB_ENABLE_SWIFT // Don't try and demangle things we can't categorize. case Mangled::eManglingSchemeNone: return true; From a84622bc4fbd506a91283829b6b2798816ee3aee Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Tue, 16 Apr 2024 20:07:05 -0700 Subject: [PATCH 06/15] [lldb] Rename `SmallString::startswith` to `starts_with` (cherry picked from commit 1ca2c5f9c0c1ace1e0cd83df205681799bbb5fd4) --- lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index 9c91e0af91e0d..257a9e6b508b0 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -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 From bc8464f4312532ed8d5ae9b99cea7dd6c1b99e59 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Tue, 16 Apr 2024 20:09:24 -0700 Subject: [PATCH 07/15] [lldb] Update `CodeGenOpt::Level` to new `CodeGenOptLevel` enum class (cherry picked from commit 180103f714f9bf56e4709e0506a179b8761684d1) --- lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index 257a9e6b508b0..e7f2831bb07e0 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -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( From df177d6c1f9a5ec86e5aeb8f9bd6a3760f6140f0 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Tue, 16 Apr 2024 20:16:05 -0700 Subject: [PATCH 08/15] [lldb] Convert `ConstString` to `std::string` when appending (cherry picked from commit 7df11fffaf30d4ba5b55283a5beb84203ba72d32) --- lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index e7f2831bb07e0..90066bbd76482 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -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) { From 110ba1091ec244f994174f896bc85364297b6acf Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Tue, 16 Apr 2024 20:34:22 -0700 Subject: [PATCH 09/15] [lldb] Remove old reference to `m_swift_ast_context_triple` Seems there's a `SetTriple` on the context itself now. (cherry picked from commit 2c67baf82079c819ea152df086f98c10f764adb6) --- lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp index 5c9ba255f9d2c..f05e0712ee4bb 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp @@ -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() { From 0a1c90337e484d71612bd742346c92697e166723 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 3 Aug 2023 09:51:58 -0700 Subject: [PATCH 10/15] Re-expose GTest for now LLVM hid GTest from folks that aren't building as part of LLVM, or that aren't installing GTest. While this is the right thing to do and is totally sensible, it doesn't work with Swift, which does neither. Re-expose GTest for now. This should get cleaned up once Swift builds things reasonably. (cherry picked from commit ade5638923f1506496a390308a5725bdcbe23697) --- third-party/unittest/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 "") From 141bce57d81f6cbd66060cdcf22e31da0b116277 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Sun, 28 Apr 2024 18:55:09 -0700 Subject: [PATCH 11/15] [Support] Do not use `llvm::size` in `getLoopPreheader` There's no reason to require random access on downstream clients here. (cherry picked from commit 355f86e7741422bff73fb568013456a4cbf5e76b) --- llvm/include/llvm/Support/GenericLoopInfoImpl.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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. From a907f1bdeceefafa77f0f4d1f9b3445a2c6621ec Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Thu, 22 Feb 2024 11:45:12 +0000 Subject: [PATCH 12/15] [Triple] Add "swift" as a vendor. We want this so we can uniquely identify our fully-static Linux target using a triple (since we wish to make decisions about it in the compiler driver that wouldn't be appropriate for an "unknown" triple). rdar://123436421 (cherry picked from commit 18ba85603c12ae8f3bc1aa035456aa929f64afef) --- llvm/include/llvm/TargetParser/Triple.h | 3 ++- llvm/lib/TargetParser/Triple.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) 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/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); } From 8aeffcdc56d07c38a1e3572df214eecbf9a7a511 Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Tue, 8 Aug 2023 20:21:36 +0100 Subject: [PATCH 13/15] [cxx-interop] Workaround a Swift compiler bug ``` :0: error: calling a private constructor of class 'clang::StmtIterator' swift/llvm-project/clang/include/clang/AST/StmtIterator.h:137:3: note: declared private here StmtIterator(const StmtIteratorBase &RHS) ^ ``` rdar://113514872 (cherry picked from commit f7b421ff1fe19c0453f072dcfcddda7d0a77df5a) --- clang/include/clang/AST/StmtIterator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); }; From e4e5036acead9eb5d125523ead59575a99a54d1c Mon Sep 17 00:00:00 2001 From: Jon Roelofs Date: Fri, 25 Aug 2023 11:23:00 -0700 Subject: [PATCH 14/15] Revert "Cleanup unwind table emission code a bit." This reverts commit 648ce3d358560c0f60340fcf28ad2563d213eca2. rdar://113994760 https://github.com/llvm/llvm-project/issues/64826 (cherry picked from commit 1c7f71cb6df44baee430f0b5180ce7cd9915c512) --- llvm/include/llvm/CodeGen/MachineFunction.h | 17 +++- llvm/lib/CodeGen/AsmPrinter/AIXException.cpp | 11 ++- llvm/lib/CodeGen/AsmPrinter/ARMException.cpp | 3 +- .../CodeGen/AsmPrinter/DwarfCFIException.cpp | 13 ++- llvm/lib/CodeGen/AsmPrinter/DwarfException.h | 26 ++++-- llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp | 14 +-- llvm/lib/CodeGen/AsmPrinter/WasmException.cpp | 10 +++ llvm/lib/CodeGen/AsmPrinter/WasmException.h | 1 + llvm/lib/CodeGen/AsmPrinter/WinException.cpp | 8 ++ llvm/lib/CodeGen/MachineFunction.cpp | 88 ++++++++++++++++--- .../X86/gcc_except_table_bb_sections.ll | 11 ++- ...able_bb_sections_ehpad_groups_with_cold.ll | 9 +- llvm/test/CodeGen/XCore/exception.ll | 5 +- 13 files changed, 171 insertions(+), 45 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index 9f8e846cac45b..ea7e82ddb1f72 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -1200,6 +1200,10 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { /// Find or create an LandingPadInfo for the specified MachineBasicBlock. LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad); + /// Remap landing pad labels and remove any deleted landing pads. + void tidyLandingPads(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/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/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 From ac0c2a4ee96bb74d46d9aae16be3a3c63ae334b8 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Wed, 29 May 2024 21:27:49 -0700 Subject: [PATCH 15/15] Revert "[Driver] Mark -arch as TargetSpecific (#74365)" Temporarily reverts commit 4e0275a2c8f7f94cc1aacf4803fc827fad8f56d4 to unblock swift's rebranch build, which currently passes `-arch` unconditionally. (cherry picked from commit 201e84df3142beb2f618bc0d6f0e3479a3ea57ad) --- clang/include/clang/Driver/Options.td | 2 +- clang/test/Driver/arc-exceptions.m | 4 ++-- clang/test/Driver/arm-arch-darwin.c | 8 ++------ clang/test/Frontend/darwin-eabi.c | 6 +++--- 4 files changed, 8 insertions(+), 12 deletions(-) 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__