diff --git a/include/swift/ABI/ObjectFile.h b/include/swift/ABI/ObjectFile.h index 2158215c4862f..fddf9c7e064e2 100644 --- a/include/swift/ABI/ObjectFile.h +++ b/include/swift/ABI/ObjectFile.h @@ -83,7 +83,7 @@ class SwiftObjectFileFormatELF : public SwiftObjectFileFormat { } }; -/// Responsible for providing the COFF reflection section identifiers +/// Responsible for providing the COFF reflection section identifiers. class SwiftObjectFileFormatCOFF : public SwiftObjectFileFormat { public: llvm::StringRef getSectionName(ReflectionSectionKind section) override { @@ -101,5 +101,28 @@ class SwiftObjectFileFormatCOFF : public SwiftObjectFileFormat { return sectionName.starts_with(".sw5"); } }; + +/// Responsible for providing the WebAssembly reflection section identifiers. +/// WebAssembly binaries store all reflection metadata in the DATA +/// section. There are symbols for each reflection section kind in the "name" +/// section that point to the corresponding offset inside DATA. +class SwiftObjectFileFormatWasm : public SwiftObjectFileFormat { +public: + llvm::StringRef getSectionName(ReflectionSectionKind section) override { + switch (section) { +#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \ + case KIND: \ + return ELF; +#include "llvm/BinaryFormat/Swift.def" +#undef HANDLE_SWIFT_SECTION + } + llvm_unreachable("Section not found."); + } + + bool sectionContainsReflectionData(llvm::StringRef sectionName) override { + return sectionName.starts_with("swift5_"); + } +}; + } // namespace swift #endif // SWIFT_ABI_OBJECTFILE_H diff --git a/include/swift/AST/Attr.h b/include/swift/AST/Attr.h index 3d010447b27f3..2aeb34da2b65c 100644 --- a/include/swift/AST/Attr.h +++ b/include/swift/AST/Attr.h @@ -1098,7 +1098,7 @@ class ObjCAttr final : public DeclAttribute, unsigned length = 2; if (auto name = getName()) length += name->getNumSelectorPieces(); - return {getTrailingObjects(), length}; + return getTrailingObjects(length); } /// Retrieve the trailing location information. @@ -1107,7 +1107,7 @@ class ObjCAttr final : public DeclAttribute, unsigned length = 2; if (auto name = getName()) length += name->getNumSelectorPieces(); - return {getTrailingObjects(), length}; + return getTrailingObjects(length); } public: @@ -1283,14 +1283,14 @@ class DynamicReplacementAttr final MutableArrayRef getTrailingLocations() { assert(Bits.DynamicReplacementAttr.HasTrailingLocationInfo); unsigned length = 2; - return {getTrailingObjects(), length}; + return getTrailingObjects(length); } /// Retrieve the trailing location information. ArrayRef getTrailingLocations() const { assert(Bits.DynamicReplacementAttr.HasTrailingLocationInfo); unsigned length = 2; // lParens, rParens - return {getTrailingObjects(), length}; + return getTrailingObjects(length); } public: @@ -1480,8 +1480,7 @@ class SPIAccessControlAttr final : public DeclAttribute, /// Note: A single SPI name per attribute is currently supported but this /// may change with the syntax change. ArrayRef getSPIGroups() const { - return { this->template getTrailingObjects(), - numSPIGroups }; + return getTrailingObjects(numSPIGroups); } static bool classof(const DeclAttribute *DA) { @@ -2059,11 +2058,11 @@ class StorageRestrictionsAttr final unsigned getNumAccessesProperties() const { return NumAccesses; } ArrayRef getInitializesNames() const { - return {getTrailingObjects(), NumInitializes}; + return getTrailingObjects(NumInitializes); } ArrayRef getAccessesNames() const { - return {getTrailingObjects() + NumInitializes, NumAccesses}; + return {getTrailingObjects() + NumInitializes, NumAccesses}; } ArrayRef getInitializesProperties(AccessorDecl *attachedTo) const; @@ -2562,10 +2561,10 @@ class DifferentiableAttr final /// The parsed differentiability parameters, i.e. the list of parameters /// specified in 'wrt:'. ArrayRef getParsedParameters() const { - return {getTrailingObjects(), NumParsedParameters}; + return getTrailingObjects(NumParsedParameters); } MutableArrayRef getParsedParameters() { - return {getTrailingObjects(), NumParsedParameters}; + return getTrailingObjects(NumParsedParameters); } size_t numTrailingObjects(OverloadToken) const { return NumParsedParameters; @@ -2747,10 +2746,10 @@ class DerivativeAttr final /// The parsed differentiability parameters, i.e. the list of parameters /// specified in 'wrt:'. ArrayRef getParsedParameters() const { - return {getTrailingObjects(), NumParsedParameters}; + return getTrailingObjects(NumParsedParameters); } MutableArrayRef getParsedParameters() { - return {getTrailingObjects(), NumParsedParameters}; + return getTrailingObjects(NumParsedParameters); } size_t numTrailingObjects(OverloadToken) const { return NumParsedParameters; @@ -2838,10 +2837,10 @@ class TransposeAttr final /// The parsed linearity parameters, i.e. the list of parameters specified in /// 'wrt:'. ArrayRef getParsedParameters() const { - return {getTrailingObjects(), NumParsedParameters}; + return getTrailingObjects(NumParsedParameters); } MutableArrayRef getParsedParameters() { - return {getTrailingObjects(), NumParsedParameters}; + return getTrailingObjects(NumParsedParameters); } size_t numTrailingObjects(OverloadToken) const { return NumParsedParameters; @@ -3492,8 +3491,8 @@ class AllowFeatureSuppressionAttr final bool getInverted() const { return Bits.AllowFeatureSuppressionAttr.Inverted; } ArrayRef getSuppressedFeatures() const { - return {getTrailingObjects(), - static_cast(Bits.AllowFeatureSuppressionAttr.NumFeatures)}; + return getTrailingObjects( + static_cast(Bits.AllowFeatureSuppressionAttr.NumFeatures)); } static bool classof(const DeclAttribute *DA) { diff --git a/include/swift/AST/AvailabilityContextStorage.h b/include/swift/AST/AvailabilityContextStorage.h index a110d8ccdce1d..beae4a6df6ba1 100644 --- a/include/swift/AST/AvailabilityContextStorage.h +++ b/include/swift/AST/AvailabilityContextStorage.h @@ -82,7 +82,7 @@ class AvailabilityContext::Storage final const ASTContext &ctx); llvm::ArrayRef getDomainInfos() const { - return llvm::ArrayRef(getTrailingObjects(), domainInfoCount); + return getTrailingObjects(domainInfoCount); } llvm::SmallVector copyDomainInfos() const { diff --git a/include/swift/AST/Builtins.h b/include/swift/AST/Builtins.h index 799fd3514feec..213a61ff50a70 100644 --- a/include/swift/AST/Builtins.h +++ b/include/swift/AST/Builtins.h @@ -121,12 +121,13 @@ class BuiltinInfo { /// The information identifying the llvm intrinsic - its id and types. class IntrinsicInfo { - mutable llvm::AttributeList Attrs = - llvm::DenseMapInfo::getEmptyKey(); + mutable llvm::AttributeSet FnAttrs = + llvm::DenseMapInfo::getEmptyKey(); + public: llvm::Intrinsic::ID ID; SmallVector Types; - const llvm::AttributeList &getOrCreateAttributes(ASTContext &Ctx) const; + const llvm::AttributeSet &getOrCreateFnAttributes(ASTContext &Ctx) const; }; /// Turn a string like "release" into the LLVM enum. diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 89a203f3708ac..09c780101eece 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -1777,8 +1777,8 @@ class ImportDecl final : public Decl, /// path will include 'Foo'. This return value is always owned by \c ImportDecl /// (which is owned by the AST context), so it can be persisted. ImportPath getImportPath() const { - return ImportPath({ getTrailingObjects(), - static_cast(Bits.ImportDecl.NumPathElements) }); + return ImportPath(getTrailingObjects( + static_cast(Bits.ImportDecl.NumPathElements))); } /// Retrieves the import path, replacing any module aliases with real names. @@ -2824,7 +2824,7 @@ class PatternBindingDecl final : public Decl, private: MutableArrayRef getMutablePatternList() { // Pattern entries are tail allocated. - return {getTrailingObjects(), getNumPatternEntries()}; + return getTrailingObjects(getNumPatternEntries()); } }; @@ -3676,10 +3676,7 @@ class OpaqueTypeDecl final : /// Retrieve the buffer containing the opaque return type /// representations that correspond to the opaque generic parameters. ArrayRef getOpaqueReturnTypeReprs() const { - return { - getTrailingObjects(), - getNumOpaqueReturnTypeReprs() - }; + return getTrailingObjects(getNumOpaqueReturnTypeReprs()); } /// Should the underlying type be visible to clients outside of the module? @@ -3745,13 +3742,12 @@ class OpaqueTypeDecl final : Substitutions(substitutions) { assert(!availabilityQueries.empty()); std::uninitialized_copy(availabilityQueries.begin(), - availabilityQueries.end(), - getTrailingObjects()); + availabilityQueries.end(), getTrailingObjects()); } public: ArrayRef getAvailabilityQueries() const { - return {getTrailingObjects(), NumAvailabilityQueries}; + return getTrailingObjects(NumAvailabilityQueries); } SubstitutionMap getSubstitutions() const { return Substitutions; } @@ -5945,7 +5941,7 @@ class AbstractStorageDecl : public ValueDecl { inline AccessorDecl *getAccessor(AccessorKind kind) const; ArrayRef getAllAccessors() const { - return { getTrailingObjects(), NumAccessors }; + return getTrailingObjects(NumAccessors); } void addOpaqueAccessor(AccessorDecl *accessor); @@ -5954,7 +5950,7 @@ class AbstractStorageDecl : public ValueDecl { private: MutableArrayRef getAccessorsBuffer() { - return { getTrailingObjects(), NumAccessors }; + return getTrailingObjects(NumAccessors); } bool registerAccessor(AccessorDecl *accessor, AccessorIndex index); @@ -8807,7 +8803,7 @@ class EnumCaseDecl final : public Decl, { Bits.EnumCaseDecl.NumElements = Elements.size(); std::uninitialized_copy(Elements.begin(), Elements.end(), - getTrailingObjects()); + getTrailingObjects()); } SourceLoc getLocFromSource() const { return CaseLoc; } @@ -8818,8 +8814,8 @@ class EnumCaseDecl final : public Decl, /// Get the list of elements declared in this case. ArrayRef getElements() const { - return {getTrailingObjects(), - static_cast(Bits.EnumCaseDecl.NumElements)}; + return getTrailingObjects( + static_cast(Bits.EnumCaseDecl.NumElements)); } SourceRange getSourceRange() const; diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h index ae80a3f70a27b..08980a8f85989 100644 --- a/include/swift/AST/Expr.h +++ b/include/swift/AST/Expr.h @@ -154,12 +154,12 @@ class alignas(8) Expr : public ASTAllocated { Implicit : 1 ); - SWIFT_INLINE_BITFIELD_FULL(CollectionExpr, Expr, 64-NumExprBits, + SWIFT_INLINE_BITFIELD_FULL(CollectionExpr, Expr, 64-NumberOfExprBits, /// True if the type of this collection expr was inferred by the collection /// fallback type, like [Any]. IsTypeDefaulted : 1, /// Number of comma source locations. - NumCommas : 32 - 1 - NumExprBits, + NumCommas : 32 - 1 - NumberOfExprBits, /// Number of entries in the collection. If this is a DictionaryExpr, /// each entry is a Tuple with the key and value pair. NumSubExprs : 32 @@ -256,8 +256,8 @@ class alignas(8) Expr : public ASTAllocated { LitKind : 3 ); - SWIFT_INLINE_BITFIELD(AbstractClosureExpr, Expr, (16-NumExprBits)+16, - : 16 - NumExprBits, // Align and leave room for subclasses + SWIFT_INLINE_BITFIELD(AbstractClosureExpr, Expr, (16-NumberOfExprBits)+16, + : 16 - NumberOfExprBits, // Align and leave room for subclasses Discriminator : 16 ); @@ -3293,8 +3293,7 @@ class DestructureTupleExpr final : public ImplicitConversionExpr, DstExpr(dstExpr) { Bits.DestructureTupleExpr.NumElements = destructuredElements.size(); std::uninitialized_copy(destructuredElements.begin(), - destructuredElements.end(), - getTrailingObjects()); + destructuredElements.end(), getTrailingObjects()); } public: @@ -3306,8 +3305,8 @@ class DestructureTupleExpr final : public ImplicitConversionExpr, Expr *srcExpr, Expr *dstExpr, Type ty); ArrayRef getDestructuredElements() const { - return {getTrailingObjects(), - static_cast(Bits.DestructureTupleExpr.NumElements)}; + return getTrailingObjects( + static_cast(Bits.DestructureTupleExpr.NumElements)); } Expr *getResultExpr() const { @@ -3712,7 +3711,7 @@ class UnresolvedSpecializeExpr final : public Expr, SubExpr(SubExpr), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) { Bits.UnresolvedSpecializeExpr.NumUnresolvedParams = UnresolvedParams.size(); std::uninitialized_copy(UnresolvedParams.begin(), UnresolvedParams.end(), - getTrailingObjects()); + getTrailingObjects()); } public: @@ -3726,8 +3725,8 @@ class UnresolvedSpecializeExpr final : public Expr, /// Retrieve the list of type parameters. These parameters have not yet /// been bound to archetypes of the entity to be specialized. ArrayRef getUnresolvedParams() const { - return {getTrailingObjects(), - static_cast(Bits.UnresolvedSpecializeExpr.NumUnresolvedParams)}; + return getTrailingObjects( + static_cast(Bits.UnresolvedSpecializeExpr.NumUnresolvedParams)); } SourceLoc getLoc() const { return LAngleLoc; } @@ -3984,7 +3983,7 @@ class SequenceExpr final : public Expr, Bits.SequenceExpr.NumElements = elements.size(); assert(Bits.SequenceExpr.NumElements > 0 && "zero-length sequence!"); std::uninitialized_copy(elements.begin(), elements.end(), - getTrailingObjects()); + getTrailingObjects()); } public: @@ -4000,11 +3999,13 @@ class SequenceExpr final : public Expr, unsigned getNumElements() const { return Bits.SequenceExpr.NumElements; } MutableArrayRef getElements() { - return {getTrailingObjects(), static_cast(Bits.SequenceExpr.NumElements)}; + return getTrailingObjects( + static_cast(Bits.SequenceExpr.NumElements)); } ArrayRef getElements() const { - return {getTrailingObjects(), static_cast(Bits.SequenceExpr.NumElements)}; + return getTrailingObjects( + static_cast(Bits.SequenceExpr.NumElements)); } Expr *getElement(unsigned i) const { @@ -4641,7 +4642,7 @@ class CaptureListExpr final : public Expr, assert(closureBody); Bits.CaptureListExpr.NumCaptures = captureList.size(); std::uninitialized_copy(captureList.begin(), captureList.end(), - getTrailingObjects()); + getTrailingObjects()); } public: @@ -4650,8 +4651,8 @@ class CaptureListExpr final : public Expr, AbstractClosureExpr *closureBody); ArrayRef getCaptureList() { - return {getTrailingObjects(), - static_cast(Bits.CaptureListExpr.NumCaptures)}; + return getTrailingObjects( + static_cast(Bits.CaptureListExpr.NumCaptures)); } AbstractClosureExpr *getClosureBody() { return closureBody; } const AbstractClosureExpr *getClosureBody() const { return closureBody; } @@ -6591,7 +6592,7 @@ class TypeJoinExpr final : public Expr, } MutableArrayRef getMutableElements() { - return { getTrailingObjects(), getNumElements() }; + return getTrailingObjects(getNumElements()); } TypeJoinExpr(llvm::PointerUnion result, @@ -6634,7 +6635,7 @@ class TypeJoinExpr final : public Expr, } ArrayRef getElements() const { - return { getTrailingObjects(), getNumElements() }; + return getTrailingObjects(getNumElements()); } Expr *getElement(unsigned i) const { diff --git a/include/swift/AST/GenericParamList.h b/include/swift/AST/GenericParamList.h index fc3ebe33941cf..3c29a0793a453 100644 --- a/include/swift/AST/GenericParamList.h +++ b/include/swift/AST/GenericParamList.h @@ -277,11 +277,11 @@ class GenericParamList final : SourceLoc RAngleLoc); MutableArrayRef getParams() { - return {getTrailingObjects(), NumParams}; + return getTrailingObjects(NumParams); } ArrayRef getParams() const { - return {getTrailingObjects(), NumParams}; + return getTrailingObjects(NumParams); } using iterator = GenericTypeParamDecl **; @@ -387,12 +387,12 @@ class alignas(RequirementRepr) TrailingWhereClause final : /// Retrieve the set of requirements. MutableArrayRef getRequirements() { - return {getTrailingObjects(), NumRequirements}; + return getTrailingObjects(NumRequirements); } /// Retrieve the set of requirements. ArrayRef getRequirements() const { - return {getTrailingObjects(), NumRequirements}; + return getTrailingObjects(NumRequirements); } /// Compute the source range containing this trailing where clause. diff --git a/include/swift/AST/IRGenOptions.h b/include/swift/AST/IRGenOptions.h index 6de88bebc3793..eddbc98292bb3 100644 --- a/include/swift/AST/IRGenOptions.h +++ b/include/swift/AST/IRGenOptions.h @@ -29,9 +29,9 @@ #include "llvm/IR/CallingConv.h" // FIXME: This include is just for llvm::SanitizerCoverageOptions. We should // split the header upstream so we don't include so much. -#include "llvm/Transforms/Instrumentation.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/VersionTuple.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/Utils/Instrumentation.h" #include #include #include diff --git a/include/swift/AST/Identifier.h b/include/swift/AST/Identifier.h index 7efec38a97bab..814e995871c44 100644 --- a/include/swift/AST/Identifier.h +++ b/include/swift/AST/Identifier.h @@ -518,10 +518,10 @@ class DeclName { : BaseName(BaseName), NumArgs(NumArgs) { } ArrayRef getArgumentNames() const { - return {getTrailingObjects(), NumArgs}; + return getTrailingObjects(NumArgs); } MutableArrayRef getArgumentNames() { - return {getTrailingObjects(), NumArgs}; + return getTrailingObjects(NumArgs); } /// Uniquing for the ASTContext. diff --git a/include/swift/AST/ImportCache.h b/include/swift/AST/ImportCache.h index 7c573d94b5ef8..8c9059f14d5fe 100644 --- a/include/swift/AST/ImportCache.h +++ b/include/swift/AST/ImportCache.h @@ -87,25 +87,20 @@ class ImportSet final : } ArrayRef getTopLevelImports() const { - return {getTrailingObjects(), - NumTopLevelImports}; + return getTrailingObjects(NumTopLevelImports); } ArrayRef getTransitiveImports() const { - return {getTrailingObjects() + - NumTopLevelImports, - NumTransitiveImports}; + return {getTrailingObjects() + NumTopLevelImports, NumTransitiveImports}; } ArrayRef getTransitiveSwiftOnlyImports() const { - return {getTrailingObjects() + - NumTopLevelImports + NumTransitiveImports, + return {getTrailingObjects() + NumTopLevelImports + NumTransitiveImports, NumTransitiveSwiftOnlyImports}; } ArrayRef getAllImports() const { - return {getTrailingObjects(), - NumTopLevelImports + NumTransitiveImports}; + return getTrailingObjects(NumTopLevelImports + NumTransitiveImports); } SWIFT_DEBUG_DUMP; diff --git a/include/swift/AST/LifetimeDependence.h b/include/swift/AST/LifetimeDependence.h index 6ecfe99d27564..7b501920d6cc0 100644 --- a/include/swift/AST/LifetimeDependence.h +++ b/include/swift/AST/LifetimeDependence.h @@ -160,7 +160,7 @@ class LifetimeEntry final : startLoc(startLoc), endLoc(endLoc), numSources(sources.size()), targetDescriptor(targetDescriptor) { std::uninitialized_copy(sources.begin(), sources.end(), - getTrailingObjects()); + getTrailingObjects()); } size_t numTrailingObjects(OverloadToken) const { @@ -179,7 +179,7 @@ class LifetimeEntry final SourceLoc getEndLoc() const { return endLoc; } ArrayRef getSources() const { - return {getTrailingObjects(), numSources}; + return getTrailingObjects(numSources); } std::optional getTargetDescriptor() const { diff --git a/include/swift/AST/ParameterList.h b/include/swift/AST/ParameterList.h index 344db0c3f045d..0ed8c758d5a6f 100644 --- a/include/swift/AST/ParameterList.h +++ b/include/swift/AST/ParameterList.h @@ -87,10 +87,10 @@ class alignas(ParamDecl *) ParameterList final : ParamDecl *back() const { return getArray().back(); } MutableArrayRef getArray() { - return {getTrailingObjects(), numParameters}; + return getTrailingObjects(numParameters); } ArrayRef getArray() const { - return {getTrailingObjects(), numParameters}; + return getTrailingObjects(numParameters); } size_t size() const { diff --git a/include/swift/AST/Pattern.h b/include/swift/AST/Pattern.h index 1351f3ef4e40a..dc2a836ed0bc5 100644 --- a/include/swift/AST/Pattern.h +++ b/include/swift/AST/Pattern.h @@ -349,10 +349,10 @@ class TuplePattern final : public Pattern, } MutableArrayRef getElements() { - return {getTrailingObjects(), getNumElements()}; + return getTrailingObjects(getNumElements()); } ArrayRef getElements() const { - return {getTrailingObjects(), getNumElements()}; + return getTrailingObjects(getNumElements()); } const TuplePatternElt &getElement(unsigned i) const {return getElements()[i];} diff --git a/include/swift/AST/SILLayout.h b/include/swift/AST/SILLayout.h index 1b5267bd7b33d..63c486e579263 100644 --- a/include/swift/AST/SILLayout.h +++ b/include/swift/AST/SILLayout.h @@ -141,10 +141,8 @@ class SILLayout final : public llvm::FoldingSetNode, } /// Get the fields inside the layout. - ArrayRef getFields() const { - return llvm::ArrayRef(getTrailingObjects(), NumFields); - } - + ArrayRef getFields() const { return getTrailingObjects(NumFields); } + /// Produce a profile of this layout, for use in a folding set. static void Profile(llvm::FoldingSetNodeID &id, CanGenericSignature Generics, diff --git a/include/swift/AST/Stmt.h b/include/swift/AST/Stmt.h index 933b2c5c07411..50238fef5fc39 100644 --- a/include/swift/AST/Stmt.h +++ b/include/swift/AST/Stmt.h @@ -215,12 +215,12 @@ class BraceStmt final : public Stmt, /// The elements contained within the BraceStmt. MutableArrayRef getElements() { - return {getTrailingObjects(), static_cast(Bits.BraceStmt.NumElements)}; + return getTrailingObjects(static_cast(Bits.BraceStmt.NumElements)); } /// The elements contained within the BraceStmt (const version). ArrayRef getElements() const { - return {getTrailingObjects(), static_cast(Bits.BraceStmt.NumElements)}; + return getTrailingObjects(static_cast(Bits.BraceStmt.NumElements)); } ASTNode findAsyncNode(); @@ -337,10 +337,10 @@ class YieldStmt final SourceLoc getEndLoc() const; ArrayRef getYields() const { - return {getTrailingObjects(), static_cast(Bits.YieldStmt.NumYields)}; + return getTrailingObjects(static_cast(Bits.YieldStmt.NumYields)); } MutableArrayRef getMutableYields() { - return {getTrailingObjects(), static_cast(Bits.YieldStmt.NumYields)}; + return getTrailingObjects(static_cast(Bits.YieldStmt.NumYields)); } static bool classof(const Stmt *S) { return S->getKind() == StmtKind::Yield; } @@ -505,7 +505,7 @@ class alignas(8) PoundAvailableInfo final : Flags.isInvalid = false; Flags.isUnavailability = isUnavailability; std::uninitialized_copy(queries.begin(), queries.end(), - getTrailingObjects()); + getTrailingObjects()); } public: @@ -519,7 +519,7 @@ class alignas(8) PoundAvailableInfo final : void setInvalid() { Flags.isInvalid = true; } ArrayRef getQueries() const { - return llvm::ArrayRef(getTrailingObjects(), NumQueries); + return getTrailingObjects(NumQueries); } /// Returns an iterator for the statement's type-checked availability specs. @@ -1431,8 +1431,7 @@ class SwitchStmt final : public LabeledStmt, /// Get the list of case clauses. ArrayRef getCases() const { - return {getTrailingObjects(), - static_cast(Bits.SwitchStmt.CaseCount)}; + return getTrailingObjects(static_cast(Bits.SwitchStmt.CaseCount)); } /// Retrieve the complete set of branches for this switch statement. @@ -1472,7 +1471,7 @@ class DoCatchStmt final Body(body) { Bits.DoCatchStmt.NumCatches = catches.size(); std::uninitialized_copy(catches.begin(), catches.end(), - getTrailingObjects()); + getTrailingObjects()); for (auto *catchStmt : getCatches()) catchStmt->setParentStmt(this); } @@ -1506,10 +1505,10 @@ class DoCatchStmt final void setBody(Stmt *s) { Body = s; } ArrayRef getCatches() const { - return {getTrailingObjects(), static_cast(Bits.DoCatchStmt.NumCatches)}; + return getTrailingObjects(static_cast(Bits.DoCatchStmt.NumCatches)); } MutableArrayRef getMutableCatches() { - return {getTrailingObjects(), static_cast(Bits.DoCatchStmt.NumCatches)}; + return getTrailingObjects(static_cast(Bits.DoCatchStmt.NumCatches)); } /// Retrieve the complete set of branches for this do-catch statement. diff --git a/include/swift/AST/TypeRepr.h b/include/swift/AST/TypeRepr.h index 89a2b69c1ba52..13c37817aec13 100644 --- a/include/swift/AST/TypeRepr.h +++ b/include/swift/AST/TypeRepr.h @@ -266,9 +266,7 @@ class AttributedTypeRepr final : TypeRepr(TypeReprKind::Attributed), Ty(Ty) { assert(!attrs.empty()); Bits.AttributedTypeRepr.NumAttributes = attrs.size(); - std::uninitialized_copy(attrs.begin(), attrs.end(), - getTrailingObjects()); - + std::uninitialized_copy(attrs.begin(), attrs.end(), getTrailingObjects()); } friend TrailingObjects; @@ -279,8 +277,7 @@ class AttributedTypeRepr final TypeRepr *ty); ArrayRef getAttrs() const { - return llvm::ArrayRef(getTrailingObjects(), - Bits.AttributedTypeRepr.NumAttributes); + return getTrailingObjects(Bits.AttributedTypeRepr.NumAttributes); } TypeAttribute *get(TypeAttrKind kind) const; @@ -870,12 +867,10 @@ class PackTypeRepr final SourceRange getBracesRange() const { return BraceLocs; } MutableArrayRef getMutableElements() { - return llvm::MutableArrayRef(getTrailingObjects(), - Bits.PackTypeRepr.NumElements); + return getTrailingObjects(Bits.PackTypeRepr.NumElements); } ArrayRef getElements() const { - return llvm::ArrayRef(getTrailingObjects(), - Bits.PackTypeRepr.NumElements); + return getTrailingObjects(Bits.PackTypeRepr.NumElements); } static bool classof(const TypeRepr *T) { @@ -958,8 +953,8 @@ class TupleTypeRepr final : public TypeRepr, } ArrayRef getElements() const { - return { getTrailingObjects(), - static_cast(Bits.TupleTypeRepr.NumElements) }; + return getTrailingObjects( + static_cast(Bits.TupleTypeRepr.NumElements)); } void getElementTypes(SmallVectorImpl &Types) const { @@ -1040,13 +1035,13 @@ class CompositionTypeRepr final : public TypeRepr, : TypeRepr(TypeReprKind::Composition), FirstTypeLoc(FirstTypeLoc), CompositionRange(CompositionRange) { Bits.CompositionTypeRepr.NumTypes = Types.size(); - std::uninitialized_copy(Types.begin(), Types.end(), - getTrailingObjects()); + std::uninitialized_copy(Types.begin(), Types.end(), getTrailingObjects()); } public: ArrayRef getTypes() const { - return {getTrailingObjects(), static_cast(Bits.CompositionTypeRepr.NumTypes)}; + return getTrailingObjects( + static_cast(Bits.CompositionTypeRepr.NumTypes)); } SourceLoc getSourceLoc() const { return FirstTypeLoc; } SourceRange getCompositionRange() const { return CompositionRange; } diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index 6b257866dc283..da0996d628cd6 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -2345,8 +2345,7 @@ class TypeAliasType final /// Retrieve the parent of this type as written, e.g., the part that was /// written before ".", if provided. Type getParent() const { - return Bits.TypeAliasType.HasParent ? *getTrailingObjects() - : Type(); + return Bits.TypeAliasType.HasParent ? *getTrailingObjects() : Type(); } /// Retrieve the substitution map applied to the declaration's underlying @@ -2361,10 +2360,9 @@ class TypeAliasType final /// arguments that are directly applied to the typealias declaration /// this type references. ArrayRef getDirectGenericArgs() const { - return ArrayRef( - getTrailingObjects() + - (Bits.TypeAliasType.HasParent ? 1 : 0), - Bits.TypeAliasType.GenericArgCount); + return ArrayRef(getTrailingObjects() + + (Bits.TypeAliasType.HasParent ? 1 : 0), + Bits.TypeAliasType.GenericArgCount); } SmallVector getExpandedGenericArgs(); @@ -2755,16 +2753,16 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode, /// getElements - Return the elements of this tuple. ArrayRef getElements() const { - return {getTrailingObjects(), getNumElements()}; + return getTrailingObjects(getNumElements()); } const TupleTypeElt &getElement(unsigned i) const { - return getTrailingObjects()[i]; + return getTrailingObjects()[i]; } /// getElementType - Return the type of the specified element. Type getElementType(unsigned ElementNo) const { - return getTrailingObjects()[ElementNo].getType(); + return getTrailingObjects()[ElementNo].getType(); } TupleEltTypeArrayRef getElementTypes() const { @@ -2794,7 +2792,7 @@ class TupleType final : public TypeBase, public llvm::FoldingSetNode, : TypeBase(TypeKind::Tuple, CanCtx, properties) { Bits.TupleType.Count = elements.size(); std::uninitialized_copy(elements.begin(), elements.end(), - getTrailingObjects()); + getTrailingObjects()); } }; BEGIN_CAN_TYPE_WRAPPER(TupleType, Type) @@ -6231,7 +6229,7 @@ class SILPackType final : public TypeBase, public llvm::FoldingSetNode, : TypeBase(TypeKind::SILPack, &ctx, properties) { Bits.SILPackType.Count = elements.size(); Bits.SILPackType.ElementIsAddress = info.ElementIsAddress; - memcpy(getTrailingObjects(), elements.data(), + memcpy(getTrailingObjects(), elements.data(), elements.size() * sizeof(CanType)); } @@ -6253,13 +6251,13 @@ class SILPackType final : public TypeBase, public llvm::FoldingSetNode, /// Retrieves the type of the elements in the pack. ArrayRef getElementTypes() const { - return {getTrailingObjects(), getNumElements()}; + return getTrailingObjects(getNumElements()); } /// Returns the type of the element at the given \p index. /// This is a lowered SIL type. CanType getElementType(unsigned index) const { - return getTrailingObjects()[index]; + return getTrailingObjects()[index]; } SILType getSILElementType(unsigned index) const; // in SILType.h @@ -6554,7 +6552,8 @@ class ProtocolCompositionType final : public TypeBase, /// a protocol composition type; you also have to look at /// hasExplicitAnyObject(). ArrayRef getMembers() const { - return {getTrailingObjects(), static_cast(Bits.ProtocolCompositionType.Count)}; + return getTrailingObjects( + static_cast(Bits.ProtocolCompositionType.Count)); } InvertibleProtocolSet getInverses() const { return Inverses; } @@ -6602,7 +6601,7 @@ class ProtocolCompositionType final : public TypeBase, Bits.ProtocolCompositionType.HasExplicitAnyObject = hasExplicitAnyObject; Bits.ProtocolCompositionType.Count = members.size(); std::uninitialized_copy(members.begin(), members.end(), - getTrailingObjects()); + getTrailingObjects()); } }; BEGIN_CAN_TYPE_WRAPPER(ProtocolCompositionType, Type) @@ -6651,8 +6650,8 @@ class ParameterizedProtocolType final : public TypeBase, } ArrayRef getArgs() const { - return {getTrailingObjects(), - static_cast(Bits.ParameterizedProtocolType.ArgCount)}; + return getTrailingObjects( + static_cast(Bits.ParameterizedProtocolType.ArgCount)); } bool requiresClass() const { @@ -7733,8 +7732,7 @@ class ErrorUnionType final RecursiveTypeProperties properties) : TypeBase(TypeKind::ErrorUnion, /*Context=*/ctx, properties) { Bits.ErrorUnionType.NumTerms = terms.size(); - std::uninitialized_copy(terms.begin(), terms.end(), - getTrailingObjects()); + std::uninitialized_copy(terms.begin(), terms.end(), getTrailingObjects()); } public: @@ -7742,7 +7740,8 @@ class ErrorUnionType final static Type get(const ASTContext &ctx, ArrayRef terms); ArrayRef getTerms() const { - return { getTrailingObjects(), static_cast(Bits.ErrorUnionType.NumTerms) }; + return getTrailingObjects( + static_cast(Bits.ErrorUnionType.NumTerms)); }; // Support for FoldingSet. @@ -7834,12 +7833,12 @@ class PackType final : public TypeBase, public llvm::FoldingSetNode, /// Retrieves the type of the elements in the pack. ArrayRef getElementTypes() const { - return {getTrailingObjects(), getNumElements()}; + return getTrailingObjects(getNumElements()); } /// Returns the type of the element at the given \p index. Type getElementType(unsigned index) const { - return getTrailingObjects()[index]; + return getTrailingObjects()[index]; } bool containsPackExpansionType() const; @@ -7865,7 +7864,7 @@ class PackType final : public TypeBase, public llvm::FoldingSetNode, : TypeBase(TypeKind::Pack, CanCtx, properties) { Bits.PackType.Count = elements.size(); std::uninitialized_copy(elements.begin(), elements.end(), - getTrailingObjects()); + getTrailingObjects()); } }; BEGIN_CAN_TYPE_WRAPPER(PackType, Type) @@ -8353,11 +8352,11 @@ inline ParameterTypeFlags ParameterTypeFlags::fromParameterType( inline const Type *BoundGenericType::getTrailingObjectsPointer() const { if (auto ty = dyn_cast(this)) - return ty->getTrailingObjects(); + return ty->getTrailingObjects(); if (auto ty = dyn_cast(this)) - return ty->getTrailingObjects(); + return ty->getTrailingObjects(); if (auto ty = dyn_cast(this)) - return ty->getTrailingObjects(); + return ty->getTrailingObjects(); llvm_unreachable("Unhandled BoundGenericType!"); } diff --git a/include/swift/Basic/EncodedSequence.h b/include/swift/Basic/EncodedSequence.h index 8b041731d5de3..81b5bc5ad32ec 100644 --- a/include/swift/Basic/EncodedSequence.h +++ b/include/swift/Basic/EncodedSequence.h @@ -102,14 +102,12 @@ class EncodedSequenceBase { } MutableArrayRef chunkStorage() { - return {getTrailingObjects(), Capacity}; + return getTrailingObjects(Capacity); } ArrayRef chunkStorage() const { - return {getTrailingObjects(), Capacity}; - } - ArrayRef chunks() const { - return {getTrailingObjects(), Size}; + return getTrailingObjects(Capacity); } + ArrayRef chunks() const { return getTrailingObjects(Size); } }; OutOfLineStorage *getOutOfLineStorage() { assert(hasOutOfLineStorage()); diff --git a/include/swift/Basic/InlineBitfield.h b/include/swift/Basic/InlineBitfield.h index b41ae018d4edf..1378115aee012 100644 --- a/include/swift/Basic/InlineBitfield.h +++ b/include/swift/Basic/InlineBitfield.h @@ -41,7 +41,7 @@ namespace swift { uint64_t : 64 - (C); /* Better code gen */ \ } T; \ LLVM_PACKED_END \ - enum { Num##T##Bits = (C) }; \ + enum { NumberOf##T##Bits = (C) }; \ static_assert(sizeof(T##Bitfield) <= 8, "Bitfield overflow") /// Define an bitfield for type 'T' with parent class 'U' and 'C' bits used. @@ -49,11 +49,11 @@ namespace swift { LLVM_PACKED_START \ class T##Bitfield { \ friend class T; \ - uint64_t : Num##U##Bits, __VA_ARGS__; \ - uint64_t : 64 - (Num##U##Bits + (HC) + (C)); /* Better code gen */ \ + uint64_t : NumberOf##U##Bits, __VA_ARGS__; \ + uint64_t : 64 - (NumberOf##U##Bits + (HC) + (C)); /* Better code gen */ \ } T; \ LLVM_PACKED_END \ - enum { Num##T##Bits = Num##U##Bits + (C) }; \ + enum { NumberOf##T##Bits = NumberOf##U##Bits + (C) }; \ static_assert(sizeof(T##Bitfield) <= 8, "Bitfield overflow") #define SWIFT_INLINE_BITFIELD(T, U, C, ...) \ @@ -75,8 +75,8 @@ namespace swift { LLVM_PACKED_START \ class T##Bitfield { \ friend class T; \ - enum { NumPadBits = 64 - (Num##U##Bits + (C)) }; \ - uint64_t : Num##U##Bits, __VA_ARGS__; \ + enum { NumPadBits = 64 - (NumberOf##U##Bits + (C)) }; \ + uint64_t : NumberOf##U##Bits, __VA_ARGS__; \ } T; \ LLVM_PACKED_END \ static_assert(sizeof(T##Bitfield) <= 8, "Bitfield overflow") @@ -101,15 +101,15 @@ namespace swift { class T##Bitfield { \ template \ friend class T; \ - enum { NumPadBits = 64 - (Num##U##Bits + (C)) }; \ - uint64_t : Num##U##Bits, __VA_ARGS__; \ + enum { NumPadBits = 64 - (NumberOf##U##Bits + (C)) }; \ + uint64_t : NumberOf##U##Bits, __VA_ARGS__; \ } T; \ LLVM_PACKED_END \ static_assert(sizeof(T##Bitfield) <= 8, "Bitfield overflow") /// Define an empty bitfield for type 'T'. #define SWIFT_INLINE_BITFIELD_EMPTY(T, U) \ - enum { Num##T##Bits = Num##U##Bits } + enum { NumberOf##T##Bits = NumberOf##U##Bits } // XXX/HACK: templated max() doesn't seem to work in a bitfield size context. constexpr unsigned bitmax(unsigned a, unsigned b) { diff --git a/include/swift/Basic/OwnedString.h b/include/swift/Basic/OwnedString.h index 109eb003e6819..c37370d18c052 100644 --- a/include/swift/Basic/OwnedString.h +++ b/include/swift/Basic/OwnedString.h @@ -35,8 +35,7 @@ class OwnedString { class TextOwner final : public llvm::ThreadSafeRefCountedBase, public llvm::TrailingObjects { TextOwner(StringRef Text) { - std::uninitialized_copy(Text.begin(), Text.end(), - getTrailingObjects()); + std::uninitialized_copy(Text.begin(), Text.end(), getTrailingObjects()); } public: @@ -50,7 +49,7 @@ class OwnedString { /// data. void operator delete(void *p) { ::operator delete(p); } - const char *getText() const { return getTrailingObjects(); } + const char *getText() const { return getTrailingObjects(); } }; /// The text this owned string represents diff --git a/include/swift/ClangImporter/SwiftAbstractBasicReader.h b/include/swift/ClangImporter/SwiftAbstractBasicReader.h index b5063c1c43493..8e31db659d2c1 100644 --- a/include/swift/ClangImporter/SwiftAbstractBasicReader.h +++ b/include/swift/ClangImporter/SwiftAbstractBasicReader.h @@ -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(); diff --git a/include/swift/ClangImporter/SwiftAbstractBasicWriter.h b/include/swift/ClangImporter/SwiftAbstractBasicWriter.h index be8e2bf3c0e57..f636cba5907ba 100644 --- a/include/swift/ClangImporter/SwiftAbstractBasicWriter.h +++ b/include/swift/ClangImporter/SwiftAbstractBasicWriter.h @@ -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); diff --git a/include/swift/IDE/CodeCompletionString.h b/include/swift/IDE/CodeCompletionString.h index 858d11090872e..0cedbae77cb9e 100644 --- a/include/swift/IDE/CodeCompletionString.h +++ b/include/swift/IDE/CodeCompletionString.h @@ -347,9 +347,7 @@ class alignas(detail::CodeCompletionStringChunk) CodeCompletionString final static CodeCompletionString *create(llvm::BumpPtrAllocator &Allocator, ArrayRef Chunks); - ArrayRef getChunks() const { - return {getTrailingObjects(), NumChunks}; - } + ArrayRef getChunks() const { return getTrailingObjects(NumChunks); } StringRef getFirstTextChunk(bool includeLeadingPunctuation = false) const; std::optional diff --git a/include/swift/Markup/AST.h b/include/swift/Markup/AST.h index c48e8fa624989..d1cfbb813053c 100644 --- a/include/swift/Markup/AST.h +++ b/include/swift/Markup/AST.h @@ -112,11 +112,11 @@ class Document final : public MarkupASTNode, ArrayRef Children); ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } static bool classof(const MarkupASTNode *N) { @@ -136,11 +136,11 @@ class BlockQuote final : public MarkupASTNode, static BlockQuote *create(MarkupContext &MC, ArrayRef Children); ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } static bool classof(const MarkupASTNode *N) { @@ -162,17 +162,16 @@ class List final : public MarkupASTNode, bool IsOrdered); ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } void setChildren(ArrayRef NewChildren) { assert(NewChildren.size() <= NumChildren); - std::copy(NewChildren.begin(), NewChildren.end(), - getTrailingObjects()); + std::copy(NewChildren.begin(), NewChildren.end(), getTrailingObjects()); NumChildren = NewChildren.size(); } @@ -197,11 +196,11 @@ class Item final : public MarkupASTNode, static Item *create(MarkupContext &MC, ArrayRef Children); ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } static bool classof(const MarkupASTNode *N) { @@ -265,11 +264,11 @@ class Paragraph final : public MarkupASTNode, ArrayRef Children); ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } static bool classof(const MarkupASTNode *N) { @@ -291,11 +290,11 @@ class Header final : public MarkupASTNode, ArrayRef Children); ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } unsigned getLevel() const { @@ -482,11 +481,11 @@ class Emphasis final : public InlineContent, ArrayRef Children); ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } static bool classof(const MarkupASTNode *N) { @@ -506,11 +505,11 @@ class Strong final : public InlineContent, ArrayRef Children); ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } static bool classof(const MarkupASTNode *N) { @@ -536,11 +535,11 @@ class Link final : public InlineContent, StringRef getDestination() const { return Destination; } ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } static bool classof(const MarkupASTNode *N) { @@ -577,11 +576,11 @@ class Image final : public InlineContent, } ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } static bool classof(const MarkupASTNode *N) { @@ -607,11 +606,11 @@ class InlineAttributes final : public InlineContent, private llvm::TrailingObjec StringRef getAttributes() const { return Attributes; } ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } static bool classof(const MarkupASTNode *N) { @@ -678,11 +677,11 @@ class ParamField final : public PrivateExtension, } ArrayRef getChildren() { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } ArrayRef getChildren() const { - return {getTrailingObjects(), NumChildren}; + return getTrailingObjects(NumChildren); } static bool classof(const MarkupASTNode *N) { @@ -703,11 +702,11 @@ public: \ static Id *create(MarkupContext &MC, ArrayRef Children); \ \ ArrayRef getChildren() { \ - return {getTrailingObjects(), NumChildren}; \ + return getTrailingObjects(NumChildren); \ } \ \ ArrayRef getChildren() const { \ - return {getTrailingObjects(), NumChildren}; \ + return getTrailingObjects(NumChildren); \ } \ \ static bool classof(const MarkupASTNode *N) { \ diff --git a/include/swift/Migrator/FixitApplyDiagnosticConsumer.h b/include/swift/Migrator/FixitApplyDiagnosticConsumer.h index 4937a881b827d..ce5aebf58f5e9 100644 --- a/include/swift/Migrator/FixitApplyDiagnosticConsumer.h +++ b/include/swift/Migrator/FixitApplyDiagnosticConsumer.h @@ -21,7 +21,7 @@ #include "swift/Migrator/FixitFilter.h" #include "swift/Migrator/Migrator.h" #include "swift/Migrator/Replacement.h" -#include "clang/Rewrite/Core/RewriteBuffer.h" +#include "llvm/ADT/RewriteBuffer.h" #include "llvm/ADT/SmallSet.h" namespace swift { @@ -37,7 +37,7 @@ struct Replacement; class FixitApplyDiagnosticConsumer final : public DiagnosticConsumer, public FixitFilter { - clang::RewriteBuffer RewriteBuf; + llvm::RewriteBuffer RewriteBuf; /// The entire text of the input file. const StringRef Text; diff --git a/include/swift/Migrator/RewriteBufferEditsReceiver.h b/include/swift/Migrator/RewriteBufferEditsReceiver.h index 91c86d893bc6d..e9366ead711f5 100644 --- a/include/swift/Migrator/RewriteBufferEditsReceiver.h +++ b/include/swift/Migrator/RewriteBufferEditsReceiver.h @@ -16,7 +16,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceLocation.h" #include "clang/Edit/EditsReceiver.h" -#include "clang/Rewrite/Core/RewriteBuffer.h" +#include "llvm/ADT/RewriteBuffer.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/raw_ostream.h" @@ -26,12 +26,13 @@ namespace swift { namespace migrator { /// An EditsReceiver that collects edits from an EditedSource and directly -/// applies it to a clang::RewriteBuffer. +/// applies it to a llvm::RewriteBuffer. class RewriteBufferEditsReceiver final : public clang::edit::EditsReceiver { const clang::SourceManager &ClangSourceManager; const clang::FileID InputFileID; const StringRef InputText; - clang::RewriteBuffer RewriteBuf; + llvm::RewriteBuffer RewriteBuf; + public: RewriteBufferEditsReceiver(const clang::SourceManager &ClangSourceManager, const clang::FileID InputFileID, diff --git a/include/swift/Option/SanitizerOptions.h b/include/swift/Option/SanitizerOptions.h index faa394f39b072..ab7f3bbdb8776 100644 --- a/include/swift/Option/SanitizerOptions.h +++ b/include/swift/Option/SanitizerOptions.h @@ -20,7 +20,7 @@ #include "llvm/Option/ArgList.h" // FIXME: This include is just for llvm::SanitizerCoverageOptions. We should // split the header upstream so we don't include so much. -#include "llvm/Transforms/Instrumentation.h" +#include "llvm/Transforms/Utils/Instrumentation.h" namespace swift { class DiagnosticEngine; diff --git a/include/swift/RemoteInspection/ReflectionContext.h b/include/swift/RemoteInspection/ReflectionContext.h index ac475a82930e4..329878e6356bb 100644 --- a/include/swift/RemoteInspection/ReflectionContext.h +++ b/include/swift/RemoteInspection/ReflectionContext.h @@ -18,13 +18,14 @@ #ifndef SWIFT_REFLECTION_REFLECTIONCONTEXT_H #define SWIFT_REFLECTION_REFLECTIONCONTEXT_H +#include "llvm/ADT/STLExtras.h" #include "llvm/BinaryFormat/COFF.h" -#include "llvm/BinaryFormat/MachO.h" #include "llvm/BinaryFormat/ELF.h" +#include "llvm/BinaryFormat/MachO.h" +#include "llvm/BinaryFormat/Wasm.h" #include "llvm/Object/COFF.h" #include "llvm/Support/Error.h" #include "llvm/Support/Memory.h" -#include "llvm/ADT/STLExtras.h" #include "swift/ABI/Enum.h" #include "swift/ABI/ObjectFile.h" @@ -40,6 +41,8 @@ #include "swift/RemoteInspection/TypeRefBuilder.h" #include "swift/Basic/Unreachable.h" +#include +#include #include #include #include @@ -72,6 +75,11 @@ #define HAS_DISPATCH_LOCK_IS_LOCKED 1 #endif +#define DEBUG_TYPE "reflection" +#ifdef SWIFT_RUNTIME +#undef LLVM_DEBUG +#define LLVM_DEBUG(IGNORE) +#endif namespace { template struct MachOTraits; @@ -799,6 +807,297 @@ class ReflectionContext } } + /// Parses metadata information from a WebAssembly image. + /// + /// + /// \param[in] ImageStart + /// A remote address pointing to the start of the image in the running + /// process. + /// + /// \param[in] FileBuffer + /// A buffer which contains the contents of the image's file + /// in disk. If missing, all the information will be read using the + /// instance's memory reader. + /// + /// \return The newly added reflection info ID if successful, \b std::nullopt + /// otherwise. + std::optional + readWasm(RemoteAddress ImageStart, + std::optional FileBuffer, + llvm::SmallVector PotentialModuleNames) { + /// A WASM data segment. The reflection metadata "sections" are DATA + /// segments. + struct Segment { + RemoteAddress remoteAddr; + uint64_t offset; + uint64_t size; + }; + std::map sections; + std::vector segments; + auto &reader = getReader(); + RemoteAddress cursor = ImageStart; + cursor += sizeof(llvm::wasm::WasmMagic) + sizeof(llvm::wasm::WasmVersion); + + /// Decode one byte and move the cursor. + auto decodeU8 = [&reader, &cursor](uint8_t &b) -> bool { + if (!reader.readInteger(cursor, 1, &b)) + return false; + cursor += 1; + return true; + }; + + /// Decode 32-bit ULEB constants. + auto decodeULEB32 = [&](uint32_t &val) -> bool { + uint64_t result = 0; + uint8_t b; + for (uint8_t n = 0; n < 5; ++n) { + if (!decodeU8(b)) + return false; + result |= (b & ~(1 << 7)) << 7 * n; + if ((b & (1 << 7)) == 0) + break; + } + if (result > std::numeric_limits::max()) + return false; + memcpy(&val, &result, 4); + return true; + }; + + /// Decode a string. + auto decodeString = [&](std::string &str) -> bool { + uint32_t len; + if (!decodeULEB32(len)) + return false; + auto chars = reader.readBytes(cursor, len); + if (!chars) + return false; + str = std::string((const char *)chars.get(), len); + cursor += len; + chars.release(); + return true; + }; + + /// Decode one section header. + auto decodeSection = [&]() -> bool { + uint8_t sectionID; + if (!decodeU8(sectionID)) + return false; + + if (sectionID > llvm::wasm::WASM_SEC_LAST_KNOWN) + return false; + + uint32_t payloadLen; + if (!decodeULEB32(payloadLen)) + return false; + RemoteAddress payloadStart = cursor; + std::string sectName; + if (sectionID == llvm::wasm::WASM_SEC_CUSTOM) { + if (!decodeString(sectName)) + return false; + RemoteAddress sectionStart = cursor; + sections.insert( + {sectName, {cursor, 0, payloadLen - (sectionStart - cursor)}}); + } else { + sectName = llvm::wasm::sectionTypeToString(sectionID); + sections.insert({sectName, {cursor, 0, payloadLen}}); + } + LLVM_DEBUG(llvm::dbgs() + << "section " << sectName << " size=" << payloadLen << "\n"); + + cursor = payloadStart + payloadLen; + return true; + }; + + // Decode the DATA segments. + auto decodeData = [&](uint64_t sectLength) -> bool { + RemoteAddress start = cursor; + RemoteAddress end = start + sectLength; + uint32_t count; + + auto decodeActiveSegmentOffset = [&]() -> std::optional { + uint32_t offset = 0; + while (true) { + uint8_t b; + if (!decodeU8(b)) + return {}; + + if (b == llvm::wasm::WASM_OPCODE_I32_CONST) { + if (!decodeULEB32(offset)) // FIXME: Actually an SLEB. + return {}; + } else if (b == llvm::wasm::WASM_OPCODE_END) { + break; + } else { + // Unhandled opcode. + return {}; + } + } + return offset; + }; + + if (!decodeULEB32(count)) + return false; + // Parse the segment header. + for (uint32_t i = 0; i < count && cursor < end; ++i) { + uint32_t flags; + uint32_t offset = 0; + if (!decodeULEB32(flags)) + return false; + if ((flags & 2) == 2) { + uint32_t memidx; + if (!decodeULEB32(memidx)) + return false; + } + if ((flags & 1) == 0) { + auto offsOrErr = decodeActiveSegmentOffset(); + if (!offsOrErr) + return false; + offset = *offsOrErr; + } + uint32_t size; + if (!decodeULEB32(size)) + return false; + LLVM_DEBUG(llvm::dbgs() + << "Segment[" << i << "]: flags=" << flags + << " offset=" << offset << " size=" << size << "\n"); + segments.push_back({cursor, offset, size}); + cursor += size; + } + return true; + }; + // Decode the NAMES table pointing to the DATA segments. + auto decodeNames = [&](uint64_t sectLength) -> bool { + RemoteAddress start = cursor; + RemoteAddress end = start + sectLength; + while (cursor < end) { + uint8_t type; + if (!decodeU8(type)) + return false; + uint32_t len; + if (!decodeULEB32(len)) + return false; + if (type == llvm::wasm::WASM_NAMES_DATA_SEGMENT) { + uint32_t count; + if (!decodeULEB32(count)) + return false; + for (uint32_t i = 0; i < count; ++i) { + uint32_t idx; + if (!decodeULEB32(idx)) + return false; + std::string sectName; + if (!decodeString(sectName)) + return false; + if (idx >= segments.size()) + return false; + LLVM_DEBUG(llvm::dbgs() << sectName << ": " << idx << "\n"); + sections.insert({sectName, segments[idx]}); + } + } + cursor += len; + } + return true; + }; + // Decode the LINK section of object files. + auto decodeLinking = [&](RemoteAddress dataStart, + uint64_t sectLength) -> bool { + RemoteAddress start = cursor; + RemoteAddress end = start + sectLength; + + uint32_t version; + if (!decodeULEB32(version) || version != 2) + return false; + while (cursor < end) { + uint8_t type; + if (!decodeU8(type)) + return false; + uint32_t len; + if (!decodeULEB32(len)) + return false; + if (type == llvm::wasm::WASM_SEGMENT_INFO) { + uint32_t count; + if (!decodeULEB32(count)) + return false; + for (uint32_t idx = 0; idx < count; ++idx) { + std::string sectName; + if (!decodeString(sectName)) + return false; + uint32_t align; + if (!decodeULEB32(align)) + return false; + uint32_t flags; + if (!decodeULEB32(flags)) + return false; + LLVM_DEBUG(llvm::dbgs() << sectName << ": " << idx << "\n"); + sections.insert({sectName, segments[idx]}); + } + } + cursor += len; + } + return true; + }; + + while (decodeSection()) { + }; + auto dataSect = sections.find("DATA"); + if (dataSect == sections.end()) + return false; + + auto [dataStart, _, dataLength] = dataSect->second; + cursor = dataStart; + if (!decodeData(dataLength)) + return false; + + auto nameSect = sections.find("name"); + if (nameSect != sections.end()) { + cursor = nameSect->second.remoteAddr; + if (!decodeNames(nameSect->second.size)) + return false; + } else { + // This may be an object file? + auto linkingSect = sections.find("linking"); + if (linkingSect == sections.end()) + return false; + cursor = linkingSect->second.remoteAddr; + if (!decodeLinking(dataStart, linkingSect->second.size)) + return false; + } + + // Find reflection sections within the data section segments. + auto lookup = + [&](const std::string &name) -> std::pair, uint64_t> { + auto sectionIt = sections.find(name); + if (sectionIt == sections.end()) + return {{}, 0}; + auto §ion = sectionIt->second; + RemoteAddress mappedSectionStart(0 + section.offset, + RemoteAddress::DefaultAddressSpace); + auto secBuf = reader.readBytes(section.remoteAddr, section.size); + auto secContents = RemoteRef(mappedSectionStart, secBuf.get()); + savedBuffers.push_back(std::move(secBuf)); + LLVM_DEBUG(llvm::dbgs() << name << " @ " << section.offset << "\n"); + return {secContents, section.size}; + }; + + auto FieldMdSec = lookup("swift5_fieldmd"); + auto AssocTySec = lookup("swift5_assocty"); + auto BuiltinTySec = lookup("swift5_builtin"); + auto CaptureSec = lookup("swift5_capture"); + auto TypeRefMdSec = lookup("swift5_typeref"); + auto ReflStrMdSec = lookup("swift5_reflstr"); + auto ConformMdSec = lookup("swift5_protocol_conformances"); + auto MPEnumMdSec = lookup("swift5_mpenum"); + + ReflectionInfo info = {{FieldMdSec.first, FieldMdSec.second}, + {AssocTySec.first, AssocTySec.second}, + {BuiltinTySec.first, BuiltinTySec.second}, + {CaptureSec.first, CaptureSec.second}, + {TypeRefMdSec.first, TypeRefMdSec.second}, + {ReflStrMdSec.first, ReflStrMdSec.second}, + {ConformMdSec.first, ConformMdSec.second}, + {MPEnumMdSec.first, MPEnumMdSec.second}, + PotentialModuleNames}; + return addReflectionInfo(info); + } + /// On success returns the ID of the newly registered Reflection Info. std::optional addImage(RemoteAddress ImageStart, @@ -827,7 +1126,6 @@ class ReflectionContext return readPECOFF(ImageStart, PotentialModuleNames); } - // ELF. if (MagicBytes[0] == llvm::ELF::ElfMagic[0] && MagicBytes[1] == llvm::ELF::ElfMagic[1] @@ -837,6 +1135,14 @@ class ReflectionContext PotentialModuleNames); } + // WASM. + if (MagicBytes[0] == llvm::wasm::WasmMagic[0] && + MagicBytes[1] == llvm::wasm::WasmMagic[1] && + MagicBytes[2] == llvm::wasm::WasmMagic[2] && + MagicBytes[3] == llvm::wasm::WasmMagic[3]) { + return readWasm(ImageStart, std::optional(), + PotentialModuleNames); + } // We don't recognize the format. return std::nullopt; } diff --git a/include/swift/RemoteInspection/RuntimeHeaders/llvm/BinaryFormat/Wasm.h b/include/swift/RemoteInspection/RuntimeHeaders/llvm/BinaryFormat/Wasm.h new file mode 100644 index 0000000000000..7c6e6494500bf --- /dev/null +++ b/include/swift/RemoteInspection/RuntimeHeaders/llvm/BinaryFormat/Wasm.h @@ -0,0 +1,581 @@ +//===- Wasm.h - Wasm object file format -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines manifest constants for the wasm object file format. +// See: https://github.com/WebAssembly/design/blob/main/BinaryEncoding.md +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_BINARYFORMAT_WASM_H +#define LLVM_BINARYFORMAT_WASM_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Compiler.h" +#include + +namespace llvm { +namespace wasm { + +// Object file magic string. +const char WasmMagic[] = {'\0', 'a', 's', 'm'}; +// Wasm binary format version +const uint32_t WasmVersion = 0x1; +// Wasm linking metadata version +const uint32_t WasmMetadataVersion = 0x2; +// Wasm uses a 64k page size by default (but the custom-page-sizes proposal +// allows changing it) +const uint32_t WasmDefaultPageSize = 65536; + +enum : unsigned { + WASM_SEC_CUSTOM = 0, // Custom / User-defined section + WASM_SEC_TYPE = 1, // Function signature declarations + WASM_SEC_IMPORT = 2, // Import declarations + WASM_SEC_FUNCTION = 3, // Function declarations + WASM_SEC_TABLE = 4, // Indirect function table and other tables + WASM_SEC_MEMORY = 5, // Memory attributes + WASM_SEC_GLOBAL = 6, // Global declarations + WASM_SEC_EXPORT = 7, // Exports + WASM_SEC_START = 8, // Start function declaration + WASM_SEC_ELEM = 9, // Elements section + WASM_SEC_CODE = 10, // Function bodies (code) + WASM_SEC_DATA = 11, // Data segments + WASM_SEC_DATACOUNT = 12, // Data segment count + WASM_SEC_TAG = 13, // Tag declarations + WASM_SEC_LAST_KNOWN = WASM_SEC_TAG, +}; + +// Type immediate encodings used in various contexts. +enum : unsigned { + WASM_TYPE_I32 = 0x7F, + WASM_TYPE_I64 = 0x7E, + WASM_TYPE_F32 = 0x7D, + WASM_TYPE_F64 = 0x7C, + WASM_TYPE_V128 = 0x7B, + WASM_TYPE_NULLFUNCREF = 0x73, + WASM_TYPE_NULLEXTERNREF = 0x72, + WASM_TYPE_NULLEXNREF = 0x74, + WASM_TYPE_NULLREF = 0x71, + WASM_TYPE_FUNCREF = 0x70, + WASM_TYPE_EXTERNREF = 0x6F, + WASM_TYPE_EXNREF = 0x69, + WASM_TYPE_ANYREF = 0x6E, + WASM_TYPE_EQREF = 0x6D, + WASM_TYPE_I31REF = 0x6C, + WASM_TYPE_STRUCTREF = 0x6B, + WASM_TYPE_ARRAYREF = 0x6A, + WASM_TYPE_NONNULLABLE = 0x64, + WASM_TYPE_NULLABLE = 0x63, + WASM_TYPE_FUNC = 0x60, + WASM_TYPE_ARRAY = 0x5E, + WASM_TYPE_STRUCT = 0x5F, + WASM_TYPE_SUB = 0x50, + WASM_TYPE_SUB_FINAL = 0x4F, + WASM_TYPE_REC = 0x4E, + WASM_TYPE_NORESULT = 0x40, // for blocks with no result values +}; + +// Kinds of externals (for imports and exports). +enum : unsigned { + WASM_EXTERNAL_FUNCTION = 0x0, + WASM_EXTERNAL_TABLE = 0x1, + WASM_EXTERNAL_MEMORY = 0x2, + WASM_EXTERNAL_GLOBAL = 0x3, + WASM_EXTERNAL_TAG = 0x4, +}; + +// Opcodes used in initializer expressions. +enum : unsigned { + WASM_OPCODE_END = 0x0b, + WASM_OPCODE_CALL = 0x10, + WASM_OPCODE_LOCAL_GET = 0x20, + WASM_OPCODE_LOCAL_SET = 0x21, + WASM_OPCODE_LOCAL_TEE = 0x22, + WASM_OPCODE_GLOBAL_GET = 0x23, + WASM_OPCODE_GLOBAL_SET = 0x24, + WASM_OPCODE_I32_STORE = 0x36, + WASM_OPCODE_I64_STORE = 0x37, + WASM_OPCODE_I32_CONST = 0x41, + WASM_OPCODE_I64_CONST = 0x42, + WASM_OPCODE_F32_CONST = 0x43, + WASM_OPCODE_F64_CONST = 0x44, + WASM_OPCODE_I32_ADD = 0x6a, + WASM_OPCODE_I32_SUB = 0x6b, + WASM_OPCODE_I32_MUL = 0x6c, + WASM_OPCODE_I64_ADD = 0x7c, + WASM_OPCODE_I64_SUB = 0x7d, + WASM_OPCODE_I64_MUL = 0x7e, + WASM_OPCODE_REF_NULL = 0xd0, + WASM_OPCODE_REF_FUNC = 0xd2, + WASM_OPCODE_GC_PREFIX = 0xfb, +}; + +// Opcodes in the GC-prefixed space (0xfb) +enum : unsigned { + WASM_OPCODE_STRUCT_NEW = 0x00, + WASM_OPCODE_STRUCT_NEW_DEFAULT = 0x01, + WASM_OPCODE_ARRAY_NEW = 0x06, + WASM_OPCODE_ARRAY_NEW_DEFAULT = 0x07, + WASM_OPCODE_ARRAY_NEW_FIXED = 0x08, + WASM_OPCODE_REF_I31 = 0x1c, + // any.convert_extern and extern.convert_any don't seem to be supported by + // Binaryen. +}; + +// Opcodes used in synthetic functions. +enum : unsigned { + WASM_OPCODE_BLOCK = 0x02, + WASM_OPCODE_BR = 0x0c, + WASM_OPCODE_BR_TABLE = 0x0e, + WASM_OPCODE_RETURN = 0x0f, + WASM_OPCODE_DROP = 0x1a, + WASM_OPCODE_MISC_PREFIX = 0xfc, + WASM_OPCODE_MEMORY_INIT = 0x08, + WASM_OPCODE_MEMORY_FILL = 0x0b, + WASM_OPCODE_DATA_DROP = 0x09, + WASM_OPCODE_ATOMICS_PREFIX = 0xfe, + WASM_OPCODE_ATOMIC_NOTIFY = 0x00, + WASM_OPCODE_I32_ATOMIC_WAIT = 0x01, + WASM_OPCODE_I32_ATOMIC_STORE = 0x17, + WASM_OPCODE_I32_RMW_CMPXCHG = 0x48, +}; + +// Sub-opcodes for catch clauses in a try_table instruction +enum : unsigned { + WASM_OPCODE_CATCH = 0x00, + WASM_OPCODE_CATCH_REF = 0x01, + WASM_OPCODE_CATCH_ALL = 0x02, + WASM_OPCODE_CATCH_ALL_REF = 0x03, +}; + +enum : unsigned { + WASM_LIMITS_FLAG_NONE = 0x0, + WASM_LIMITS_FLAG_HAS_MAX = 0x1, + WASM_LIMITS_FLAG_IS_SHARED = 0x2, + WASM_LIMITS_FLAG_IS_64 = 0x4, + WASM_LIMITS_FLAG_HAS_PAGE_SIZE = 0x8, +}; + +enum : unsigned { + WASM_DATA_SEGMENT_IS_PASSIVE = 0x01, + WASM_DATA_SEGMENT_HAS_MEMINDEX = 0x02, +}; + +enum : unsigned { + WASM_ELEM_SEGMENT_IS_PASSIVE = 0x01, + WASM_ELEM_SEGMENT_IS_DECLARATIVE = 0x02, // if passive == 1 + WASM_ELEM_SEGMENT_HAS_TABLE_NUMBER = 0x02, // if passive == 0 + WASM_ELEM_SEGMENT_HAS_INIT_EXPRS = 0x04, +}; +const unsigned WASM_ELEM_SEGMENT_MASK_HAS_ELEM_DESC = 0x3; + +// Feature policy prefixes used in the custom "target_features" section +enum : uint8_t { + WASM_FEATURE_PREFIX_USED = '+', + WASM_FEATURE_PREFIX_DISALLOWED = '-', +}; + +// Kind codes used in the custom "name" section +enum : unsigned { + WASM_NAMES_MODULE = 0, + WASM_NAMES_FUNCTION = 1, + WASM_NAMES_LOCAL = 2, + WASM_NAMES_GLOBAL = 7, + WASM_NAMES_DATA_SEGMENT = 9, +}; + +// Kind codes used in the custom "linking" section +enum : unsigned { + WASM_SEGMENT_INFO = 0x5, + WASM_INIT_FUNCS = 0x6, + WASM_COMDAT_INFO = 0x7, + WASM_SYMBOL_TABLE = 0x8, +}; + +// Kind codes used in the custom "dylink" section +enum : unsigned { + WASM_DYLINK_MEM_INFO = 0x1, + WASM_DYLINK_NEEDED = 0x2, + WASM_DYLINK_EXPORT_INFO = 0x3, + WASM_DYLINK_IMPORT_INFO = 0x4, + WASM_DYLINK_RUNTIME_PATH = 0x5, +}; + +// Kind codes used in the custom "linking" section in the WASM_COMDAT_INFO +enum : unsigned { + WASM_COMDAT_DATA = 0x0, + WASM_COMDAT_FUNCTION = 0x1, + // GLOBAL, TAG, and TABLE are in here but LLVM doesn't use them yet. + WASM_COMDAT_SECTION = 0x5, +}; + +// Kind codes used in the custom "linking" section in the WASM_SYMBOL_TABLE +enum WasmSymbolType : unsigned { + WASM_SYMBOL_TYPE_FUNCTION = 0x0, + WASM_SYMBOL_TYPE_DATA = 0x1, + WASM_SYMBOL_TYPE_GLOBAL = 0x2, + WASM_SYMBOL_TYPE_SECTION = 0x3, + WASM_SYMBOL_TYPE_TAG = 0x4, + WASM_SYMBOL_TYPE_TABLE = 0x5, +}; + +enum WasmSegmentFlag : unsigned { + WASM_SEG_FLAG_STRINGS = 0x1, + WASM_SEG_FLAG_TLS = 0x2, + WASM_SEG_FLAG_RETAIN = 0x4, +}; + +// Kinds of tag attributes. +enum WasmTagAttribute : uint8_t { + WASM_TAG_ATTRIBUTE_EXCEPTION = 0x0, +}; + +const unsigned WASM_SYMBOL_BINDING_MASK = 0x3; +const unsigned WASM_SYMBOL_VISIBILITY_MASK = 0xc; + +const unsigned WASM_SYMBOL_BINDING_GLOBAL = 0x0; +const unsigned WASM_SYMBOL_BINDING_WEAK = 0x1; +const unsigned WASM_SYMBOL_BINDING_LOCAL = 0x2; +const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT = 0x0; +const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN = 0x4; +const unsigned WASM_SYMBOL_UNDEFINED = 0x10; +const unsigned WASM_SYMBOL_EXPORTED = 0x20; +const unsigned WASM_SYMBOL_EXPLICIT_NAME = 0x40; +const unsigned WASM_SYMBOL_NO_STRIP = 0x80; +const unsigned WASM_SYMBOL_TLS = 0x100; +const unsigned WASM_SYMBOL_ABSOLUTE = 0x200; + +#define WASM_RELOC(name, value) name = value, + +enum WasmRelocType : unsigned { +#include "WasmRelocs.def" +}; + +#undef WASM_RELOC + +struct WasmObjectHeader { + StringRef Magic; + uint32_t Version; +}; + +// Subset of types that a value can have +enum class ValType { + I32 = WASM_TYPE_I32, + I64 = WASM_TYPE_I64, + F32 = WASM_TYPE_F32, + F64 = WASM_TYPE_F64, + V128 = WASM_TYPE_V128, + FUNCREF = WASM_TYPE_FUNCREF, + EXTERNREF = WASM_TYPE_EXTERNREF, + EXNREF = WASM_TYPE_EXNREF, + // Unmodeled value types include ref types with heap types other than + // func, extern or exn, and type-specialized funcrefs + OTHERREF = 0xff, +}; + +struct WasmDylinkImportInfo { + StringRef Module; + StringRef Field; + uint32_t Flags; +}; + +struct WasmDylinkExportInfo { + StringRef Name; + uint32_t Flags; +}; + +struct WasmDylinkInfo { + uint32_t MemorySize; // Memory size in bytes + uint32_t MemoryAlignment; // P2 alignment of memory + uint32_t TableSize; // Table size in elements + uint32_t TableAlignment; // P2 alignment of table + std::vector Needed; // Shared library dependencies + std::vector ImportInfo; + std::vector ExportInfo; + std::vector RuntimePath; +}; + +struct WasmProducerInfo { + std::vector> Languages; + std::vector> Tools; + std::vector> SDKs; +}; + +struct WasmFeatureEntry { + uint8_t Prefix; + std::string Name; +}; + +struct WasmExport { + StringRef Name; + uint8_t Kind; + uint32_t Index; +}; + +struct WasmLimits { + uint8_t Flags; + uint64_t Minimum; + uint64_t Maximum; + uint32_t PageSize; +}; + +struct WasmTableType { + ValType ElemType; + WasmLimits Limits; +}; + +struct WasmTable { + uint32_t Index; + WasmTableType Type; + StringRef SymbolName; // from the "linking" section +}; + +struct WasmInitExprMVP { + uint8_t Opcode; + union { + int32_t Int32; + int64_t Int64; + uint32_t Float32; + uint64_t Float64; + uint32_t Global; + } Value; +}; + +// Extended-const init exprs and exprs with GC types are not explicitly +// modeled, but the raw body of the expr is attached. +struct WasmInitExpr { + uint8_t Extended; // Set to non-zero if extended const is used (i.e. more than + // one instruction) + WasmInitExprMVP Inst; + ArrayRef Body; +}; + +struct WasmGlobalType { + uint8_t Type; // TODO: make this a ValType? + bool Mutable; +}; + +struct WasmGlobal { + uint32_t Index; + WasmGlobalType Type; + WasmInitExpr InitExpr; + StringRef SymbolName; // from the "linking" section + uint32_t Offset; // Offset of the definition in the binary's Global section + uint32_t Size; // Size of the definition in the binary's Global section +}; + +struct WasmTag { + uint32_t Index; + uint32_t SigIndex; + StringRef SymbolName; // from the "linking" section +}; + +struct WasmImport { + StringRef Module; + StringRef Field; + uint8_t Kind; + union { + uint32_t SigIndex; + WasmGlobalType Global; + WasmTableType Table; + WasmLimits Memory; + }; +}; + +struct WasmLocalDecl { + uint8_t Type; + uint32_t Count; +}; + +struct WasmFunction { + uint32_t Index; + uint32_t SigIndex; + std::vector Locals; + ArrayRef Body; + uint32_t CodeSectionOffset; + uint32_t Size; + uint32_t CodeOffset; // start of Locals and Body + std::optional ExportName; // from the "export" section + StringRef SymbolName; // from the "linking" section + StringRef DebugName; // from the "name" section + uint32_t Comdat; // from the "comdat info" section +}; + +struct WasmDataSegment { + uint32_t InitFlags; + // Present if InitFlags & WASM_DATA_SEGMENT_HAS_MEMINDEX. + uint32_t MemoryIndex; + // Present if InitFlags & WASM_DATA_SEGMENT_IS_PASSIVE == 0. + WasmInitExpr Offset; + + ArrayRef Content; + StringRef Name; // from the "segment info" section + uint32_t Alignment; + uint32_t LinkingFlags; + uint32_t Comdat; // from the "comdat info" section +}; + +// 3 different element segment modes are encodable. This class is currently +// only used during decoding (see WasmElemSegment below). +enum class ElemSegmentMode { Active, Passive, Declarative }; + +// Represents a Wasm element segment, with some limitations compared the spec: +// 1) Does not model passive or declarative segments (Segment will end up with +// an Offset field of i32.const 0) +// 2) Does not model init exprs (Segment will get an empty Functions list) +// 3) Does not model types other than basic funcref/externref/exnref (see +// ValType) +struct WasmElemSegment { + uint32_t Flags; + uint32_t TableNumber; + ValType ElemKind; + WasmInitExpr Offset; + std::vector Functions; +}; + +// Represents the location of a Wasm data symbol within a WasmDataSegment, as +// the index of the segment, and the offset and size within the segment. +struct WasmDataReference { + uint32_t Segment; + uint64_t Offset; + uint64_t Size; +}; + +struct WasmRelocation { + uint8_t Type; // The type of the relocation. + uint32_t Index; // Index into either symbol or type index space. + uint64_t Offset; // Offset from the start of the section. + int64_t Addend; // A value to add to the symbol. + + WasmRelocType getType() const { return static_cast(Type); } +}; + +struct WasmInitFunc { + uint32_t Priority; + uint32_t Symbol; +}; + +struct WasmSymbolInfo { + StringRef Name; + uint8_t Kind; + uint32_t Flags; + // For undefined symbols the module of the import + std::optional ImportModule; + // For undefined symbols the name of the import + std::optional ImportName; + // For symbols to be exported from the final module + std::optional ExportName; + union { + // For function, table, or global symbols, the index in function, table, or + // global index space. + uint32_t ElementIndex; + // For a data symbols, the address of the data relative to segment. + WasmDataReference DataRef; + }; +}; + +enum class NameType { + FUNCTION, + GLOBAL, + DATA_SEGMENT, +}; + +struct WasmDebugName { + NameType Type; + uint32_t Index; + StringRef Name; +}; + +// Info from the linking metadata section of a wasm object file. +struct WasmLinkingData { + uint32_t Version; + std::vector InitFunctions; + std::vector Comdats; + // The linking section also contains a symbol table. This info (represented + // in a WasmSymbolInfo struct) is stored inside the WasmSymbol object instead + // of in this structure; this allows vectors of WasmSymbols and + // WasmLinkingDatas to be reallocated. +}; + +struct WasmSignature { + SmallVector Returns; + SmallVector Params; + // LLVM can parse types other than functions encoded in the type section, + // but does not actually model them. Instead a placeholder signature is + // created in the Object's signature list. + enum { Function, Tag, Placeholder } Kind = Function; + // Support empty and tombstone instances, needed by DenseMap. + enum { Plain, Empty, Tombstone } State = Plain; + + WasmSignature(SmallVector &&InReturns, + SmallVector &&InParams) + : Returns(InReturns), Params(InParams) {} + WasmSignature() = default; +}; + +// Useful comparison operators +inline bool operator==(const WasmSignature &LHS, const WasmSignature &RHS) { + return LHS.State == RHS.State && LHS.Returns == RHS.Returns && + LHS.Params == RHS.Params; +} + +inline bool operator!=(const WasmSignature &LHS, const WasmSignature &RHS) { + return !(LHS == RHS); +} + +inline bool operator==(const WasmGlobalType &LHS, const WasmGlobalType &RHS) { + return LHS.Type == RHS.Type && LHS.Mutable == RHS.Mutable; +} + +inline bool operator!=(const WasmGlobalType &LHS, const WasmGlobalType &RHS) { + return !(LHS == RHS); +} + +inline bool operator==(const WasmLimits &LHS, const WasmLimits &RHS) { + return LHS.Flags == RHS.Flags && LHS.Minimum == RHS.Minimum && + (LHS.Flags & WASM_LIMITS_FLAG_HAS_MAX ? LHS.Maximum == RHS.Maximum + : true) && + (LHS.Flags & WASM_LIMITS_FLAG_HAS_PAGE_SIZE + ? LHS.PageSize == RHS.PageSize + : true); +} + +inline bool operator==(const WasmTableType &LHS, const WasmTableType &RHS) { + return LHS.ElemType == RHS.ElemType && LHS.Limits == RHS.Limits; +} + +inline llvm::StringRef sectionTypeToString(uint32_t type) { +#define ECase(X) \ + case wasm::WASM_SEC_##X: \ + return #X; + switch (type) { + ECase(CUSTOM); + ECase(TYPE); + ECase(IMPORT); + ECase(FUNCTION); + ECase(TABLE); + ECase(MEMORY); + ECase(GLOBAL); + ECase(EXPORT); + ECase(START); + ECase(ELEM); + ECase(CODE); + ECase(DATA); + ECase(DATACOUNT); + ECase(TAG); + default: + llvm_unreachable("unknown section type"); + } +#undef ECase +} + +} // end namespace wasm +} // end namespace llvm + +#endif diff --git a/include/swift/RemoteInspection/RuntimeHeaders/llvm/BinaryFormat/WasmRelocs.def b/include/swift/RemoteInspection/RuntimeHeaders/llvm/BinaryFormat/WasmRelocs.def new file mode 100644 index 0000000000000..6f5a946b1c63d --- /dev/null +++ b/include/swift/RemoteInspection/RuntimeHeaders/llvm/BinaryFormat/WasmRelocs.def @@ -0,0 +1,31 @@ +#ifndef WASM_RELOC +#error "WASM_RELOC must be defined" +#endif + +WASM_RELOC(R_WASM_FUNCTION_INDEX_LEB, 0) +WASM_RELOC(R_WASM_TABLE_INDEX_SLEB, 1) +WASM_RELOC(R_WASM_TABLE_INDEX_I32, 2) +WASM_RELOC(R_WASM_MEMORY_ADDR_LEB, 3) +WASM_RELOC(R_WASM_MEMORY_ADDR_SLEB, 4) +WASM_RELOC(R_WASM_MEMORY_ADDR_I32, 5) +WASM_RELOC(R_WASM_TYPE_INDEX_LEB, 6) +WASM_RELOC(R_WASM_GLOBAL_INDEX_LEB, 7) +WASM_RELOC(R_WASM_FUNCTION_OFFSET_I32, 8) +WASM_RELOC(R_WASM_SECTION_OFFSET_I32, 9) +WASM_RELOC(R_WASM_TAG_INDEX_LEB, 10) +WASM_RELOC(R_WASM_MEMORY_ADDR_REL_SLEB, 11) +WASM_RELOC(R_WASM_TABLE_INDEX_REL_SLEB, 12) +WASM_RELOC(R_WASM_GLOBAL_INDEX_I32, 13) +WASM_RELOC(R_WASM_MEMORY_ADDR_LEB64, 14) +WASM_RELOC(R_WASM_MEMORY_ADDR_SLEB64, 15) +WASM_RELOC(R_WASM_MEMORY_ADDR_I64, 16) +WASM_RELOC(R_WASM_MEMORY_ADDR_REL_SLEB64, 17) +WASM_RELOC(R_WASM_TABLE_INDEX_SLEB64, 18) +WASM_RELOC(R_WASM_TABLE_INDEX_I64, 19) +WASM_RELOC(R_WASM_TABLE_NUMBER_LEB, 20) +WASM_RELOC(R_WASM_MEMORY_ADDR_TLS_SLEB, 21) +WASM_RELOC(R_WASM_FUNCTION_OFFSET_I64, 22) +WASM_RELOC(R_WASM_MEMORY_ADDR_LOCREL_I32, 23) +WASM_RELOC(R_WASM_TABLE_INDEX_REL_SLEB64, 24) +WASM_RELOC(R_WASM_MEMORY_ADDR_TLS_SLEB64, 25) +WASM_RELOC(R_WASM_FUNCTION_INDEX_I32, 26) diff --git a/include/swift/SIL/MemAccessUtils.h b/include/swift/SIL/MemAccessUtils.h index 41a42f10275bd..955a55ff3039c 100644 --- a/include/swift/SIL/MemAccessUtils.h +++ b/include/swift/SIL/MemAccessUtils.h @@ -383,12 +383,12 @@ class AccessRepresentation { // Define bits for use in AccessStorageAnalysis. Each identified storage // object is mapped to one instance of this subclass. SWIFT_INLINE_BITFIELD_FULL(StorageAccessInfo, AccessRepresentation, - 64 - NumAccessRepresentationBits, + 64 - NumberOfAccessRepresentationBits, accessKind : NumSILAccessKindBits, noNestedConflict : 1, - storageIndex : 64 - (NumAccessRepresentationBits - + NumSILAccessKindBits - + 1)); + storageIndex : 64 - + (NumberOfAccessRepresentationBits + + NumSILAccessKindBits + 1)); // Define bits for use in the AccessEnforcementOpts pass. Each begin_access // in the function is mapped to one instance of this subclass. Reserve a @@ -398,13 +398,11 @@ class AccessRepresentation { // // `AccessRepresentation` refers to the AccessRepresentationBitfield defined // above, setting aside enough bits for common data. - SWIFT_INLINE_BITFIELD_FULL(AccessEnforcementOptsInfo, - AccessRepresentation, - 64 - NumAccessRepresentationBits, - seenNestedConflict : 1, - seenIdenticalStorage : 1, - beginAccessIndex : - 62 - NumAccessRepresentationBits); + SWIFT_INLINE_BITFIELD_FULL(AccessEnforcementOptsInfo, AccessRepresentation, + 64 - NumberOfAccessRepresentationBits, + seenNestedConflict : 1, seenIdenticalStorage : 1, + beginAccessIndex : 62 - + NumberOfAccessRepresentationBits); // Define data flow bits for use in the AccessEnforcementDom pass. Each // begin_access in the function is mapped to one instance of this subclass. diff --git a/include/swift/SIL/SILConstants.h b/include/swift/SIL/SILConstants.h index 9c829ac42322a..51cc6e3b495e9 100644 --- a/include/swift/SIL/SILConstants.h +++ b/include/swift/SIL/SILConstants.h @@ -737,7 +737,7 @@ struct SymbolicClosure final SymbolicValueAllocator &allocator); ArrayRef getCaptures() const { - return {getTrailingObjects(), numCaptures}; + return getTrailingObjects(numCaptures); } // This is used by the llvm::TrailingObjects base class. diff --git a/include/swift/SIL/SILInstruction.h b/include/swift/SIL/SILInstruction.h index f246b9cb1f9ce..40618b7b580c6 100644 --- a/include/swift/SIL/SILInstruction.h +++ b/include/swift/SIL/SILInstruction.h @@ -1737,7 +1737,7 @@ class InstructionBaseWithTrailingOperands // Destruct tail allocated objects. ~InstructionBaseWithTrailingOperands() { - Operand *Operands = TrailingObjects::template getTrailingObjects(); + Operand *Operands = this->template getTrailingObjectsNonStrict(); auto end = sharedUInt32().InstructionBaseWithTrailingOperands.numOperands; for (unsigned i = 0; i < end; ++i) { Operands[i].~Operand(); @@ -1750,13 +1750,13 @@ class InstructionBaseWithTrailingOperands } ArrayRef getAllOperands() const { - return {TrailingObjects::template getTrailingObjects(), - sharedUInt32().InstructionBaseWithTrailingOperands.numOperands}; + return this->template getTrailingObjectsNonStrict( + sharedUInt32().InstructionBaseWithTrailingOperands.numOperands); } MutableArrayRef getAllOperands() { - return {TrailingObjects::template getTrailingObjects(), - sharedUInt32().InstructionBaseWithTrailingOperands.numOperands}; + return this->template getTrailingObjectsNonStrict( + sharedUInt32().InstructionBaseWithTrailingOperands.numOperands); } }; @@ -2839,13 +2839,13 @@ class ApplyInstBase : public Base { /// - the formal arguments /// - the type-dependency arguments MutableArrayRef getAllOperands() { - return { asImpl().template getTrailingObjects(), - getNumAllOperands() }; + return asImpl().template getTrailingObjectsNonStrict( + getNumAllOperands()); } ArrayRef getAllOperands() const { - return { asImpl().template getTrailingObjects(), - getNumAllOperands() }; + return asImpl().template getTrailingObjectsNonStrict( + getNumAllOperands()); } /// Check whether the given operand index is a call-argument index @@ -4337,7 +4337,7 @@ class IncrementProfilerCounterInst final /// The PGO function name for the function in which the counter resides. StringRef getPGOFuncName() const { - return StringRef(getTrailingObjects(), PGOFuncNameLength); + return StringRef(getTrailingObjects(), PGOFuncNameLength); } /// The total number of counters within the function. @@ -4560,7 +4560,7 @@ class StringLiteralInst final public: /// getValue - Return the string data for the literal, in UTF-8. StringRef getValue() const { - return {getTrailingObjects(), sharedUInt32().StringLiteralInst.length}; + return {getTrailingObjects(), sharedUInt32().StringLiteralInst.length}; } /// getEncoding - Return the desired encoding of the text. @@ -5620,7 +5620,7 @@ class SpecifyTestInst final void setValueForName(StringRef name, SILValue value) { values[name] = value; } llvm::StringMap const &getValues() { return values; } StringRef getArgumentsSpecification() const { - return StringRef(getTrailingObjects(), ArgumentsSpecificationLength); + return StringRef(getTrailingObjects(), ArgumentsSpecificationLength); } ArrayRef getAllOperands() const { return {}; } @@ -9884,9 +9884,7 @@ class CondFailInst final StringRef Message, SILModule &M); public: - StringRef getMessage() const { - return {getTrailingObjects(), MessageSize}; - } + StringRef getMessage() const { return {getTrailingObjects(), MessageSize}; } }; //===----------------------------------------------------------------------===// diff --git a/include/swift/SIL/SILVTable.h b/include/swift/SIL/SILVTable.h index 0285c87e332c0..21ad8294bbc77 100644 --- a/include/swift/SIL/SILVTable.h +++ b/include/swift/SIL/SILVTable.h @@ -173,15 +173,13 @@ class SILVTable final : public SILAllocated, } /// Return all of the method entries. - ArrayRef getEntries() const { - return {getTrailingObjects(), NumEntries}; - } + ArrayRef getEntries() const { return getTrailingObjects(NumEntries); } /// Return all of the method entries mutably. /// If you do modify entries, make sure to invoke `updateVTableCache` to update the /// SILModule's cache entry. MutableArrayRef getMutableEntries() { - return {getTrailingObjects(), NumEntries}; + return getTrailingObjects(NumEntries); } void updateVTableCache(const Entry &entry); diff --git a/include/swift/SILOptimizer/Analysis/Analysis.h b/include/swift/SILOptimizer/Analysis/Analysis.h index 3a3afbd75b8db..deed38a88d6e5 100644 --- a/include/swift/SILOptimizer/Analysis/Analysis.h +++ b/include/swift/SILOptimizer/Analysis/Analysis.h @@ -233,19 +233,19 @@ class FunctionAnalysisBase : public SILAnalysis { // Check that the analysis can handle this function. verifyFunction(f); - auto &it = storage.FindAndConstruct(f); - if (!it.second) - it.second = newFunctionAnalysis(f); - return it.second.get(); + auto &value = storage[f]; + if (!value) + value = newFunctionAnalysis(f); + return value.get(); } virtual void forcePrecompute(SILFunction *f) override { // Check that the analysis can handle this function. verifyFunction(f); - auto &it = storage.FindAndConstruct(f); - if (!it.second) - it.second = newFunctionAnalysis(f); + auto &value = storage[f]; + if (!value) + value = newFunctionAnalysis(f); } /// Invalidate all information in this analysis. diff --git a/include/swift/SILOptimizer/Utils/PartitionUtils.h b/include/swift/SILOptimizer/Utils/PartitionUtils.h index db5008bfbf1f8..8c4d56280bd30 100644 --- a/include/swift/SILOptimizer/Utils/PartitionUtils.h +++ b/include/swift/SILOptimizer/Utils/PartitionUtils.h @@ -282,7 +282,7 @@ class IsolationHistory::Node final /// Access the tail allocated buffer of additional element arguments. MutableArrayRef getAdditionalElementArgs() { - return {getTrailingObjects(), numAdditionalElements}; + return getTrailingObjects(numAdditionalElements); } Node(Kind kind, Node *parent) diff --git a/include/swift/Sema/CSFix.h b/include/swift/Sema/CSFix.h index c6e5be5319005..dbfff2be4ea47 100644 --- a/include/swift/Sema/CSFix.h +++ b/include/swift/Sema/CSFix.h @@ -663,7 +663,7 @@ class RelabelArguments final std::string getName() const override { return "re-label argument(s)"; } ArrayRef getLabels() const { - return {getTrailingObjects(), NumLabels}; + return getTrailingObjects(NumLabels); } bool diagnose(const Solution &solution, bool asNote = false) const override; @@ -680,7 +680,7 @@ class RelabelArguments final private: MutableArrayRef getLabelsBuffer() { - return {getTrailingObjects(), NumLabels}; + return getTrailingObjects(NumLabels); } }; @@ -1201,7 +1201,7 @@ class GenericArgumentsMismatch final } ArrayRef getMismatches() const { - return {getTrailingObjects(), NumMismatches}; + return getTrailingObjects(NumMismatches); } bool coalesceAndDiagnose(const Solution &solution, @@ -1224,7 +1224,7 @@ class GenericArgumentsMismatch final bool asNote = false) const; MutableArrayRef getMismatchesBuf() { - return {getTrailingObjects(), NumMismatches}; + return getTrailingObjects(NumMismatches); } }; @@ -1794,7 +1794,7 @@ class AddMissingArguments final std::string getName() const override { return "synthesize missing argument(s)"; } ArrayRef getSynthesizedArguments() const { - return {getTrailingObjects(), NumSynthesized}; + return getTrailingObjects(NumSynthesized); } bool diagnose(const Solution &solution, bool asNote = false) const override; @@ -1813,7 +1813,7 @@ class AddMissingArguments final private: MutableArrayRef getSynthesizedArgumentsBuf() { - return {getTrailingObjects(), NumSynthesized}; + return getTrailingObjects(NumSynthesized); } }; @@ -1842,7 +1842,7 @@ class RemoveExtraneousArguments final std::string getName() const override { return "remove extraneous argument(s)"; } ArrayRef getExtraArguments() const { - return {getTrailingObjects(), NumExtraneous}; + return getTrailingObjects(NumExtraneous); } bool diagnose(const Solution &solution, bool asNote = false) const override; @@ -1870,7 +1870,7 @@ class RemoveExtraneousArguments final private: MutableArrayRef getExtraArgumentsBuf() { - return {getTrailingObjects(), NumExtraneous}; + return getTrailingObjects(NumExtraneous); } }; @@ -2274,7 +2274,7 @@ class CollectionElementContextualMismatch final } ArrayRef getElements() const { - return {getTrailingObjects(), NumElements}; + return getTrailingObjects(NumElements); } bool diagnose(const Solution &solution, bool asNote = false) const override; @@ -2289,7 +2289,7 @@ class CollectionElementContextualMismatch final private: MutableArrayRef getElementBuffer() { - return {getTrailingObjects(), NumElements}; + return getTrailingObjects(NumElements); } }; @@ -3528,14 +3528,14 @@ class RenameConflictingPatternVariables final } MutableArrayRef getConflictingBuffer() { - return {getTrailingObjects(), NumConflicts}; + return getTrailingObjects(NumConflicts); } public: std::string getName() const override { return "rename pattern variables"; } ArrayRef getConflictingVars() const { - return {getTrailingObjects(), NumConflicts}; + return getTrailingObjects(NumConflicts); } bool diagnose(const Solution &solution, bool asNote = false) const override; diff --git a/include/swift/Sema/PreparedOverload.h b/include/swift/Sema/PreparedOverload.h index 0d678214a6126..de316eb988b1d 100644 --- a/include/swift/Sema/PreparedOverload.h +++ b/include/swift/Sema/PreparedOverload.h @@ -171,7 +171,7 @@ class PreparedOverload final : : OpenedType(openedType), ThrownErrorType(thrownErrorType), Count(changes.size()) { std::uninitialized_copy(changes.begin(), changes.end(), - getTrailingObjects()); + getTrailingObjects()); } Type getOpenedType() const { @@ -182,9 +182,7 @@ class PreparedOverload final : return ThrownErrorType; } - ArrayRef getChanges() const { - return ArrayRef(getTrailingObjects(), Count); - } + ArrayRef getChanges() const { return getTrailingObjects(Count); } }; struct PreparedOverloadBuilder { diff --git a/include/swift/StaticMirror/ObjectFileContext.h b/include/swift/StaticMirror/ObjectFileContext.h index 927418cf5b7c7..5b53b3670aa82 100644 --- a/include/swift/StaticMirror/ObjectFileContext.h +++ b/include/swift/StaticMirror/ObjectFileContext.h @@ -57,6 +57,8 @@ class Image { void scanCOFF(const llvm::object::COFFObjectFile *O); + void scanWasm(const llvm::object::WasmObjectFile *O); + bool isMachOWithPtrAuth() const; public: diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 4a1d8b9be6db0..a3ed0a899d5c8 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -2518,8 +2518,7 @@ void OverriddenDeclsRequest::cacheResult( // Record the overrides in the context. auto &ctx = decl->getASTContext(); - auto overriddenCopy = - ctx.AllocateCopy(value.operator ArrayRef()); + auto overriddenCopy = ctx.AllocateCopy(ArrayRef(value)); (void)ctx.getImpl().Overrides.insert({decl, overriddenCopy}); } @@ -3473,7 +3472,7 @@ TypeAliasType::TypeAliasType(TypeAliasDecl *typealias, Type parent, // Record the parent (or absence of a parent). if (parent) { Bits.TypeAliasType.HasParent = true; - *getTrailingObjects() = parent; + *getTrailingObjects() = parent; } else { Bits.TypeAliasType.HasParent = false; } @@ -3486,8 +3485,7 @@ TypeAliasType::TypeAliasType(TypeAliasDecl *typealias, Type parent, ASSERT(params->size() == count); Bits.TypeAliasType.GenericArgCount = count; std::uninitialized_copy(genericArgs.begin(), genericArgs.end(), - getTrailingObjects() + - (parent ? 1 : 0)); + getTrailingObjects() + (parent ? 1 : 0)); } else { ASSERT(params == nullptr); Bits.TypeAliasType.GenericArgCount = 0; @@ -5919,9 +5917,8 @@ const AvailabilityContext::Storage *AvailabilityContext::Storage::get( ctx.Allocate(storageToAlloc, alignof(AvailabilityContext::Storage)); auto *newNode = ::new (mem) AvailabilityContext::Storage( platformRange, isDeprecated, domainInfos.size()); - std::uninitialized_copy( - domainInfos.begin(), domainInfos.end(), - newNode->getTrailingObjects()); + std::uninitialized_copy(domainInfos.begin(), domainInfos.end(), + newNode->getTrailingObjects()); foldingSet.InsertNode(newNode, insertPos); return newNode; diff --git a/lib/AST/Attr.cpp b/lib/AST/Attr.cpp index ee971084a0b04..63ade446016e7 100644 --- a/lib/AST/Attr.cpp +++ b/lib/AST/Attr.cpp @@ -2724,7 +2724,7 @@ SPIAccessControlAttr::SPIAccessControlAttr(SourceLoc atLoc, SourceRange range, /*Implicit=*/false), numSPIGroups(spiGroups.size()) { std::uninitialized_copy(spiGroups.begin(), spiGroups.end(), - getTrailingObjects()); + getTrailingObjects()); } SPIAccessControlAttr * @@ -2762,8 +2762,7 @@ DifferentiableAttr::DifferentiableAttr(bool implicit, SourceLoc atLoc, assert((diffKind != DifferentiabilityKind::Normal && diffKind != DifferentiabilityKind::Forward) && "'Normal' and 'Forward' are not supported"); - std::copy(params.begin(), params.end(), - getTrailingObjects()); + std::copy(params.begin(), params.end(), getTrailingObjects()); } DifferentiableAttr::DifferentiableAttr(Decl *original, bool implicit, @@ -2865,8 +2864,7 @@ DerivativeAttr::DerivativeAttr(bool implicit, SourceLoc atLoc, : DeclAttribute(DeclAttrKind::Derivative, atLoc, baseRange, implicit), BaseTypeRepr(baseTypeRepr), OriginalFunctionName(std::move(originalName)), NumParsedParameters(params.size()) { - std::copy(params.begin(), params.end(), - getTrailingObjects()); + std::copy(params.begin(), params.end(), getTrailingObjects()); } DerivativeAttr::DerivativeAttr(bool implicit, SourceLoc atLoc, @@ -2932,8 +2930,7 @@ TransposeAttr::TransposeAttr(bool implicit, SourceLoc atLoc, : DeclAttribute(DeclAttrKind::Transpose, atLoc, baseRange, implicit), BaseTypeRepr(baseTypeRepr), OriginalFunctionName(std::move(originalName)), NumParsedParameters(params.size()) { - std::uninitialized_copy(params.begin(), params.end(), - getTrailingObjects()); + std::uninitialized_copy(params.begin(), params.end(), getTrailingObjects()); } TransposeAttr::TransposeAttr(bool implicit, SourceLoc atLoc, @@ -2971,9 +2968,9 @@ StorageRestrictionsAttr::StorageRestrictionsAttr( : DeclAttribute(DeclAttrKind::StorageRestrictions, AtLoc, Range, Implicit), NumInitializes(initializes.size()), NumAccesses(accesses.size()) { std::uninitialized_copy(initializes.begin(), initializes.end(), - getTrailingObjects()); + getTrailingObjects()); std::uninitialized_copy(accesses.begin(), accesses.end(), - getTrailingObjects() + NumInitializes); + getTrailingObjects() + NumInitializes); } StorageRestrictionsAttr * @@ -3233,7 +3230,7 @@ AllowFeatureSuppressionAttr::AllowFeatureSuppressionAttr( Bits.AllowFeatureSuppressionAttr.Inverted = inverted; Bits.AllowFeatureSuppressionAttr.NumFeatures = features.size(); std::uninitialized_copy(features.begin(), features.end(), - getTrailingObjects()); + getTrailingObjects()); } AllowFeatureSuppressionAttr *AllowFeatureSuppressionAttr::create( diff --git a/lib/AST/Builtins.cpp b/lib/AST/Builtins.cpp index 6778477c96966..b2d5dd8af304f 100644 --- a/lib/AST/Builtins.cpp +++ b/lib/AST/Builtins.cpp @@ -49,13 +49,14 @@ bool BuiltinInfo::isReadNone() const { return strchr(BuiltinExtraInfo[(unsigned)ID].Attributes, 'n') != nullptr; } -const llvm::AttributeList & -IntrinsicInfo::getOrCreateAttributes(ASTContext &Ctx) const { - using DenseMapInfo = llvm::DenseMapInfo; - if (DenseMapInfo::isEqual(Attrs, DenseMapInfo::getEmptyKey())) { - Attrs = llvm::Intrinsic::getAttributes(Ctx.getIntrinsicScratchContext(), ID); +const llvm::AttributeSet & +IntrinsicInfo::getOrCreateFnAttributes(ASTContext &Ctx) const { + using DenseMapInfo = llvm::DenseMapInfo; + if (DenseMapInfo::isEqual(FnAttrs, DenseMapInfo::getEmptyKey())) { + FnAttrs = + llvm::Intrinsic::getFnAttributes(Ctx.getIntrinsicScratchContext(), ID); } - return Attrs; + return FnAttrs; } Type swift::getBuiltinType(ASTContext &Context, StringRef Name) { @@ -2427,18 +2428,6 @@ bool swift::canBuiltinBeOverloadedForType(BuiltinValueKind ID, Type Ty) { return isBuiltinTypeOverloaded(Ty, OverloadedBuiltinKinds[unsigned(ID)]); } -/// Table of string intrinsic names indexed by enum value. -static const char *const IntrinsicNameTable[] = { - "not_intrinsic", -#define GET_INTRINSIC_NAME_TABLE -#include "llvm/IR/IntrinsicImpl.inc" -#undef GET_INTRINSIC_NAME_TABLE -}; - -#define GET_INTRINSIC_TARGET_DATA -#include "llvm/IR/IntrinsicImpl.inc" -#undef GET_INTRINSIC_TARGET_DATA - llvm::Intrinsic::ID swift::getLLVMIntrinsicID(StringRef InName) { using namespace llvm; @@ -2454,10 +2443,8 @@ llvm::Intrinsic::ID swift::getLLVMIntrinsicID(StringRef InName) { NameS.push_back(C == '_' ? '.' : C); const char *Name = NameS.c_str(); - ArrayRef NameTable(&IntrinsicNameTable[1], - TargetInfos[1].Offset); - int Idx = Intrinsic::lookupLLVMIntrinsicByName(NameTable, Name); - return static_cast(Idx + 1); + + return Intrinsic::lookupIntrinsicID(Name); } llvm::Intrinsic::ID @@ -2543,7 +2530,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: @@ -2552,6 +2538,7 @@ Type IntrinsicTypeDecoder::decodeImmediate() { case IITDescriptor::Subdivide4Argument: case IITDescriptor::PPCQuad: case IITDescriptor::AArch64Svcount: + case IITDescriptor::OneNthEltsVecArgument: // These types cannot be expressed in swift yet. return Type(); @@ -2649,8 +2636,8 @@ getSwiftFunctionTypeForIntrinsic(llvm::Intrinsic::ID ID, // Translate LLVM function attributes to Swift function attributes. IntrinsicInfo II; II.ID = ID; - auto attrs = II.getOrCreateAttributes(Context); - if (attrs.hasFnAttr(llvm::Attribute::NoReturn)) { + auto &attrs = II.getOrCreateFnAttributes(Context); + if (attrs.hasAttribute(llvm::Attribute::NoReturn)) { ResultTy = Context.getNeverType(); if (!ResultTy) return false; diff --git a/lib/AST/ClangTypeConverter.cpp b/lib/AST/ClangTypeConverter.cpp index efa8a0e8e9122..464a595942de1 100644 --- a/lib/AST/ClangTypeConverter.cpp +++ b/lib/AST/ClangTypeConverter.cpp @@ -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; @@ -84,10 +84,14 @@ getClangBuiltinTypeFromKind(const clang::ASTContext &context, case clang::BuiltinType::Id: \ return context.SingletonId; #include "clang/Basic/WebAssemblyReferenceTypes.def" -#define AMDGPU_TYPE(Name, Id, SingletonId) \ +#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \ case clang::BuiltinType::Id: \ return context.SingletonId; #include "clang/Basic/AMDGPUTypes.def" +#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \ + case clang::BuiltinType::Id: \ + return context.SingletonId; +#include "clang/Basic/HLSLIntangibleTypes.def" } // Not a valid BuiltinType. diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index fff6a6e2a26a8..e5bfc0fdeb988 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1731,8 +1731,7 @@ ImportDecl::ImportDecl(DeclContext *DC, SourceLoc ImportLoc, ImportKind K, assert(Bits.ImportDecl.NumPathElements == Path.size() && "Truncation error"); Bits.ImportDecl.ImportKind = static_cast(K); assert(getImportKind() == K && "not enough bits for ImportKind"); - std::uninitialized_copy(Path.begin(), Path.end(), - getTrailingObjects()); + std::uninitialized_copy(Path.begin(), Path.end(), getTrailingObjects()); } ImportKind ImportDecl::getBestImportKind(const ValueDecl *VD) { @@ -2334,7 +2333,7 @@ PatternBindingDecl::create(ASTContext &Ctx, SourceLoc StaticLoc, PatternList.size(), Parent); // Set up the patterns. std::uninitialized_copy(PatternList.begin(), PatternList.end(), - PBD->getTrailingObjects()); + PBD->getTrailingObjects()); for (auto idx : range(PBD->getNumPatternEntries())) { auto *initContext = PBD->getInitContext(idx); @@ -10761,9 +10760,8 @@ OpaqueTypeDecl::OpaqueTypeDecl(ValueDecl *NamingDecl, assert(OpaqueReturnTypeReprs.empty() || OpaqueReturnTypeReprs.size() == OpaqueInterfaceGenericSignature.getInnermostGenericParams().size()); - std::uninitialized_copy( - OpaqueReturnTypeReprs.begin(), OpaqueReturnTypeReprs.end(), - getTrailingObjects()); + std::uninitialized_copy(OpaqueReturnTypeReprs.begin(), + OpaqueReturnTypeReprs.end(), getTrailingObjects()); } OpaqueTypeDecl *OpaqueTypeDecl::get( diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index a8f3f57f8eefc..881e269d348c0 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -2915,7 +2915,7 @@ TypeJoinExpr::TypeJoinExpr(llvm::PointerUnion result, Bits.TypeJoinExpr.NumElements = elements.size(); // Copy elements. std::uninitialized_copy(elements.begin(), elements.end(), - getTrailingObjects()); + getTrailingObjects()); } TypeJoinExpr *TypeJoinExpr::createImpl( diff --git a/lib/AST/GenericParamList.cpp b/lib/AST/GenericParamList.cpp index 7ca5ffbb42f36..3dbfe884992d5 100644 --- a/lib/AST/GenericParamList.cpp +++ b/lib/AST/GenericParamList.cpp @@ -39,8 +39,7 @@ GenericParamList::GenericParamList(SourceLoc LAngleLoc, WhereLoc(WhereLoc), Requirements(Requirements), OuterParameters(nullptr) { - std::uninitialized_copy(Params.begin(), Params.end(), - getTrailingObjects()); + std::uninitialized_copy(Params.begin(), Params.end(), getTrailingObjects()); } GenericParamList * @@ -123,7 +122,7 @@ TrailingWhereClause::TrailingWhereClause( NumRequirements(requirements.size()) { std::uninitialized_copy(requirements.begin(), requirements.end(), - getTrailingObjects()); + getTrailingObjects()); } TrailingWhereClause *TrailingWhereClause::create( diff --git a/lib/AST/ImportCache.cpp b/lib/AST/ImportCache.cpp index 0567151a37dac..3a8db740179c9 100644 --- a/lib/AST/ImportCache.cpp +++ b/lib/AST/ImportCache.cpp @@ -35,7 +35,7 @@ ImportSet::ImportSet(bool hasHeaderImportModule, NumTopLevelImports(topLevelImports.size()), NumTransitiveImports(transitiveImports.size()), NumTransitiveSwiftOnlyImports(transitiveSwiftOnlyImports.size()) { - auto buffer = getTrailingObjects(); + auto *buffer = getTrailingObjects(); std::uninitialized_copy(topLevelImports.begin(), topLevelImports.end(), buffer); std::uninitialized_copy(transitiveImports.begin(), transitiveImports.end(), diff --git a/lib/AST/PackConformance.cpp b/lib/AST/PackConformance.cpp index c6d3bdfec01c3..e2f6250b1e71d 100644 --- a/lib/AST/PackConformance.cpp +++ b/lib/AST/PackConformance.cpp @@ -48,7 +48,7 @@ PackConformance::PackConformance(PackType *conformingType, assert(ConformingType->getNumElements() == conformances.size()); std::uninitialized_copy(conformances.begin(), conformances.end(), - getTrailingObjects()); + getTrailingObjects()); } size_t PackConformance::numTrailingObjects( @@ -63,8 +63,7 @@ bool PackConformance::isInvalid() const { ArrayRef PackConformance::getPatternConformances() const { - return {getTrailingObjects(), - ConformingType->getNumElements()}; + return getTrailingObjects(ConformingType->getNumElements()); } bool PackConformance::isCanonical() const { diff --git a/lib/AST/Pattern.cpp b/lib/AST/Pattern.cpp index 53ed6442ec106..94a2fc40be5c3 100644 --- a/lib/AST/Pattern.cpp +++ b/lib/AST/Pattern.cpp @@ -466,7 +466,7 @@ TuplePattern *TuplePattern::create(ASTContext &C, SourceLoc lp, alignof(TuplePattern)); TuplePattern *pattern = ::new (buffer) TuplePattern(lp, n, rp); std::uninitialized_copy(elts.begin(), elts.end(), - pattern->getTrailingObjects()); + pattern->getTrailingObjects()); return pattern; } diff --git a/lib/AST/RequirementMachine/ApplyInverses.cpp b/lib/AST/RequirementMachine/ApplyInverses.cpp index a37726b7c4a48..bed9797a7ec3d 100644 --- a/lib/AST/RequirementMachine/ApplyInverses.cpp +++ b/lib/AST/RequirementMachine/ApplyInverses.cpp @@ -212,7 +212,7 @@ void swift::rewriting::applyInverses( continue; } - auto state = inverses.getOrInsertDefault(representativeSubject); + auto &state = inverses[representativeSubject]; // Check if this inverse has already been seen. auto inverseKind = inverse.getKind(); diff --git a/lib/AST/RequirementMachine/Term.cpp b/lib/AST/RequirementMachine/Term.cpp index 5455fb348fa56..62cd07e6bd201 100644 --- a/lib/AST/RequirementMachine/Term.cpp +++ b/lib/AST/RequirementMachine/Term.cpp @@ -39,13 +39,9 @@ struct Term::Storage final return Size; } - MutableArrayRef getElements() { - return {getTrailingObjects(), Size}; - } + MutableArrayRef getElements() { return getTrailingObjects(Size); } - ArrayRef getElements() const { - return {getTrailingObjects(), Size}; - } + ArrayRef getElements() const { return getTrailingObjects(Size); } void Profile(llvm::FoldingSetNodeID &id) const; }; diff --git a/lib/AST/SILLayout.cpp b/lib/AST/SILLayout.cpp index 2a4599b7baf6d..efcf5ac734934 100644 --- a/lib/AST/SILLayout.cpp +++ b/lib/AST/SILLayout.cpp @@ -82,7 +82,7 @@ SILLayout::SILLayout(CanGenericSignature Sig, #ifndef NDEBUG verifyFields(Sig, Fields); #endif - auto FieldsMem = getTrailingObjects(); + auto *FieldsMem = getTrailingObjects(); for (unsigned i : indices(Fields)) { new (FieldsMem + i) SILField(Fields[i]); } diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 68e5dcd8e38af..95529d2af8216 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -184,8 +184,7 @@ BraceStmt::BraceStmt(SourceLoc lbloc, ArrayRef elts, SourceLoc rbloc, : Stmt(StmtKind::Brace, getDefaultImplicitFlag(implicit, lbloc)), LBLoc(lbloc), RBLoc(rbloc) { Bits.BraceStmt.NumElements = elts.size(); - std::uninitialized_copy(elts.begin(), elts.end(), - getTrailingObjects()); + std::uninitialized_copy(elts.begin(), elts.end(), getTrailingObjects()); #ifndef NDEBUG for (auto elt : elts) @@ -998,7 +997,7 @@ SwitchStmt *SwitchStmt::create(LabeledStmtInfo LabelInfo, SourceLoc SwitchLoc, EndLoc); std::uninitialized_copy(Cases.begin(), Cases.end(), - theSwitch->getTrailingObjects()); + theSwitch->getTrailingObjects()); for (auto *caseStmt : theSwitch->getCases()) caseStmt->setParentStmt(theSwitch); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index ba6a64f87c442..6f5ba55d4637a 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -3651,7 +3651,7 @@ bool TypeBase::matchesFunctionType(Type other, TypeMatchOptions matchMode, /// return the field index, otherwise return -1. int TupleType::getNamedElementId(Identifier I) const { for (unsigned i = 0, e = Bits.TupleType.Count; i != e; ++i) { - if (getTrailingObjects()[i].getName() == I) + if (getTrailingObjects()[i].getName() == I) return i; } @@ -3987,7 +3987,7 @@ ParameterizedProtocolType::ParameterizedProtocolType( assert(args.size() > 0); Bits.ParameterizedProtocolType.ArgCount = args.size(); for (unsigned i : indices(args)) - getTrailingObjects()[i] = args[i]; + getTrailingObjects()[i] = args[i]; } void ParameterizedProtocolType::Profile(llvm::FoldingSetNodeID &ID, diff --git a/lib/AST/TypeRepr.cpp b/lib/AST/TypeRepr.cpp index c19587b38aa02..f614e2dc98d8c 100644 --- a/lib/AST/TypeRepr.cpp +++ b/lib/AST/TypeRepr.cpp @@ -525,7 +525,7 @@ TupleTypeRepr::TupleTypeRepr(ArrayRef Elements, Bits.TupleTypeRepr.NumElements = Elements.size(); std::uninitialized_copy(Elements.begin(), Elements.end(), - getTrailingObjects()); + getTrailingObjects()); } TupleTypeRepr *TupleTypeRepr::create(const ASTContext &C, @@ -682,7 +682,7 @@ PackTypeRepr::PackTypeRepr(SourceLoc keywordLoc, SourceRange braceLocs, : TypeRepr(TypeReprKind::Pack), KeywordLoc(keywordLoc), BraceLocs(braceLocs) { Bits.PackTypeRepr.NumElements = elements.size(); - memcpy(getTrailingObjects(), elements.data(), + memcpy(getTrailingObjects(), elements.data(), elements.size() * sizeof(TypeRepr*)); } diff --git a/lib/Basic/Platform.cpp b/lib/Basic/Platform.cpp index 8060efeab0d36..8906bce54be32 100644 --- a/lib/Basic/Platform.cpp +++ b/lib/Basic/Platform.cpp @@ -282,6 +282,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"); diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 0a80a98d6b0de..36e1512d1d103 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -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 TO = - std::make_shared(); - 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\": " diff --git a/lib/ClangImporter/ClangAdapter.cpp b/lib/ClangImporter/ClangAdapter.cpp index f832a5af21f05..363425226914e 100644 --- a/lib/ClangImporter/ClangAdapter.cpp +++ b/lib/ClangImporter/ClangAdapter.cpp @@ -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. @@ -450,6 +450,11 @@ OmissionTypeName importer::getClangTypeNameForOmission(clang::ASTContext &ctx, #define AMDGPU_TYPE(Name, Id, ...) case clang::BuiltinType::Id: #include "clang/Basic/AMDGPUTypes.def" return OmissionTypeName(); + + // HLSL intangible builtin types that don't have Swift equivalents. +#define HLSL_INTANGIBLE_TYPE(Name, Id, ...) case clang::BuiltinType::Id: +#include "clang/Basic/HLSLIntangibleTypes.def" + return OmissionTypeName(); } } diff --git a/lib/ClangImporter/ClangDiagnosticConsumer.cpp b/lib/ClangImporter/ClangDiagnosticConsumer.cpp index 910e46fa8ef8d..185165cca43b7 100644 --- a/lib/ClangImporter/ClangDiagnosticConsumer.cpp +++ b/lib/ClangImporter/ClangDiagnosticConsumer.cpp @@ -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 @@ -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, @@ -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, diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index cbaf9a0bc67e3..8f5648145d350 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -329,7 +329,7 @@ class BridgingPPTracker : public clang::PPCallbacks { return; SmallVector IdLocs; for (auto &P : Path) - IdLocs.push_back(P.second); + IdLocs.push_back(P.getLoc()); handleImport(ImportLoc, IdLocs, Imported); } @@ -862,6 +862,10 @@ importer::addCommonInvocationArguments( invocationArgStrs.push_back("-mcx16"); } + // REPL and LLDB unconditionally want debug info in pcm files. + if (importerOpts.DebuggerSupport) + invocationArgStrs.push_back("-g"); + if (triple.isOSDarwin()) { if (auto variantTriple = ctx.LangOpts.TargetVariant) { // Passing the -target-variant along to clang causes clang's @@ -985,10 +989,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(*Impl.Invocation); invocation->getPreprocessorOpts().DisablePCHOrModuleValidation = @@ -1003,10 +1005,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(new clang::DiagnosticOptions())); + CI.setDiagnostics(&*clang::CompilerInstance::createDiagnostics( + 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. @@ -1146,6 +1151,8 @@ ClangImporter::getClangDriverArguments(ASTContext &ctx, bool ignoreClangTarget) std::optional> ClangImporter::getClangCC1Arguments( ASTContext &ctx, llvm::IntrusiveRefCntPtr VFS, bool ignoreClangTarget) { + ASSERT(VFS && "Expected non-null file system"); + std::unique_ptr CI; // Set up a temporary diagnostic client to report errors from parsing the @@ -1156,13 +1163,11 @@ std::optional> ClangImporter::getClangCC1Arguments( // // The long-term client for Clang diagnostics is set up afterwards, after the // clang::CompilerInstance is created. - llvm::IntrusiveRefCntPtr 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( - tempDiagOpts.get(), tempDiagClient, + *VFS, tempDiagOpts, tempDiagClient, /*owned*/ true); // If using direct cc1 module build, use extra args to setup ClangImporter. @@ -1246,9 +1251,7 @@ std::optional> ClangImporter::getClangCC1Arguments( // to missing files and report the error that clang would throw manually. // rdar://77516546 is tracking that the clang importer should be more // resilient and provide a module even if there were building it. - auto TempVFS = clang::createVFSFromCompilerInvocation( - *CI, *clangDiags, - VFS ? VFS : Impl.SwiftContext.SourceMgr.getFileSystem()); + auto TempVFS = clang::createVFSFromCompilerInvocation(*CI, *clangDiags, VFS); std::vector FilteredModuleMapFiles; for (auto ModuleMapFile : CI->getFrontendOpts().ModuleMapFiles) { @@ -1284,10 +1287,10 @@ std::unique_ptr 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 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. @@ -1374,6 +1377,9 @@ std::unique_ptr ClangImporter::create( // The Clang modules produced by ClangImporter are always embedded in an // ObjectFilePCHContainer and contain -gmodules debug info. importer->Impl.Invocation->getCodeGenOpts().DebugTypeExtRefs = true; + if (importerOpts.DebuggerSupport) + importer->Impl.Invocation->getCodeGenOpts().setDebugInfo( + llvm::codegenoptions::FullDebugInfo); auto PCHContainerOperations = std::make_shared(); @@ -1381,12 +1387,10 @@ std::unique_ptr ClangImporter::create( std::make_unique()); PCHContainerOperations->registerReader( std::make_unique()); - 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()); @@ -1396,7 +1400,7 @@ std::unique_ptr ClangImporter::create( auto actualDiagClient = std::make_unique( importer->Impl, instance.getDiagnosticOpts(), importerOpts.DumpClangDiagnostics); - instance.createDiagnostics(actualDiagClient.release()); + instance.createDiagnostics(*VFS, actualDiagClient.release()); } // Set up the file manager. @@ -1430,22 +1434,12 @@ std::unique_ptr ClangImporter::create( importer.get(), importerOpts, VFS, *swiftTargetClangArgs); if (!swiftTargetClangInvocation) return nullptr; - auto targetInfo = clang::TargetInfo::CreateTargetInfo( - clangDiags, swiftTargetClangInvocation->TargetOpts); - // Ensure the target info has configured target-specific defines - std::string defineBuffer; - llvm::raw_string_ostream predefines(defineBuffer); - clang::MacroBuilder builder(predefines); - targetInfo->getTargetDefines(instance.getLangOpts(), builder); - importer->Impl.setSwiftTargetInfo(targetInfo); - importer->Impl.setSwiftCodeGenOptions(new clang::CodeGenOptions( - swiftTargetClangInvocation->getCodeGenOpts())); + + importer->Impl.configureOptionsForCodeGen(clangDiags, + swiftTargetClangInvocation.get()); } else { - // Just use the existing Invocation's directly - importer->Impl.setSwiftTargetInfo(clang::TargetInfo::CreateTargetInfo( - clangDiags, importer->Impl.Invocation->TargetOpts)); - importer->Impl.setSwiftCodeGenOptions( - new clang::CodeGenOptions(importer->Impl.Invocation->getCodeGenOpts())); + // Set using the existing invocation. + importer->Impl.configureOptionsForCodeGen(clangDiags); } // Create the associated action. @@ -1462,9 +1456,8 @@ std::unique_ptr ClangImporter::create( // 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; @@ -1472,7 +1465,8 @@ std::unique_ptr ClangImporter::create( // // FIXME: We shouldn't need to do this, the target should be immutable once // created. This complexity should be lifted elsewhere. - instance.getTarget().adjust(clangDiags, instance.getLangOpts()); + instance.getTarget().adjust(clangDiags, instance.getLangOpts(), + /*AuxTarget=*/nullptr); if (importerOpts.Mode == ClangImporterOptions::Modes::EmbedBitcode) return importer; @@ -1792,7 +1786,7 @@ bool ClangImporter::importHeader(StringRef header, ModuleDecl *adapter, // serialized preprocessed contents when debugger support is on. if (!Impl.SwiftContext.ClangImporterOpts.PreferSerializedBridgingHeader || cachedContents.empty()) { - auto headerFile = fileManager.getFile(header, /*OpenFile=*/true); + auto headerFile = fileManager.getOptionalFileRef(header, /*OpenFile=*/true); // Prefer importing the header directly if the header content matches by // checking size and mod time. This allows correct import if some no-modular // headers are already imported into clang importer. If mod time is zero, @@ -1800,9 +1794,9 @@ bool ClangImporter::importHeader(StringRef header, ModuleDecl *adapter, // verify. LLDB prefers the serialized bridging header because, in an // explicit modules project, LLDB might not know all the search paths needed // to imported the on disk header. - if (headerFile && (*headerFile)->getSize() == expectedSize && + if (headerFile && headerFile->getSize() == expectedSize && (expectedModTime == 0 || - (*headerFile)->getModificationTime() == expectedModTime)) { + headerFile->getModificationTime() == expectedModTime)) { return importBridgingHeader(header, adapter, diagLoc, false, true); } } @@ -1829,7 +1823,7 @@ bool ClangImporter::importBridgingHeader(StringRef header, ModuleDecl *adapter, } clang::FileManager &fileManager = Impl.Instance->getFileManager(); - auto headerFile = fileManager.getFile(header, /*OpenFile=*/true); + auto headerFile = fileManager.getOptionalFileRef(header, /*OpenFile=*/true); if (!headerFile) { Impl.diagnose(diagLoc, diag::bridging_header_missing, header); return true; @@ -1922,13 +1916,13 @@ std::string ClangImporter::getBridgingHeaderContents( invocation->getPreprocessorOpts().resetNonModularOptions(); - clang::CompilerInstance rewriteInstance( - Impl.Instance->getPCHContainerOperations(), - &Impl.Instance->getModuleCache()); - rewriteInstance.setInvocation(invocation); - rewriteInstance.createDiagnostics(new clang::IgnoringDiagConsumer); - clang::FileManager &fileManager = Impl.Instance->getFileManager(); + + clang::CompilerInstance rewriteInstance( + std::move(invocation), Impl.Instance->getPCHContainerOperations(), + &Impl.Instance->getModuleCache()); + rewriteInstance.createDiagnostics(fileManager.getVirtualFileSystem(), + new clang::IgnoringDiagConsumer); rewriteInstance.setFileManager(&fileManager); rewriteInstance.createSourceManager(fileManager); rewriteInstance.setTarget(&Impl.Instance->getTarget()); @@ -1978,9 +1972,9 @@ std::string ClangImporter::getBridgingHeaderContents( return ""; } - if (auto fileInfo = fileManager.getFile(headerPath)) { - fileSize = (*fileInfo)->getSize(); - fileModTime = (*fileInfo)->getModificationTime(); + if (auto fileInfo = fileManager.getOptionalFileRef(headerPath)) { + fileSize = fileInfo->getSize(); + fileModTime = fileInfo->getModificationTime(); } return result; } @@ -2027,14 +2021,14 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() { // Share the CASOption and the underlying CAS. invocation->setCASOption(Impl.Invocation->getCASOptsPtr()); + clang::FileManager &fileManager = Impl.Instance->getFileManager(); + auto clonedInstance = std::make_unique( - Impl.Instance->getPCHContainerOperations(), - &Impl.Instance->getModuleCache()); - clonedInstance->setInvocation(std::move(invocation)); - clonedInstance->createDiagnostics(&Impl.Instance->getDiagnosticClient(), + std::move(invocation), Impl.Instance->getPCHContainerOperations(), + &Impl.Instance->getModuleCache()); + clonedInstance->createDiagnostics(fileManager.getVirtualFileSystem(), + &Impl.Instance->getDiagnosticClient(), /*ShouldOwnClient=*/false); - - clang::FileManager &fileManager = Impl.Instance->getFileManager(); clonedInstance->setFileManager(&fileManager); clonedInstance->createSourceManager(fileManager); clonedInstance->setTarget(&Impl.Instance->getTarget()); @@ -2320,17 +2314,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, 4> - clangPath; + SmallVector 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(); @@ -2340,14 +2332,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; @@ -4237,7 +4228,7 @@ clang::TargetInfo &ClangImporter::getModuleAvailabilityTarget() const { } clang::TargetInfo &ClangImporter::getTargetInfo() const { - return *Impl.getSwiftTargetInfo(); + return Impl.getCodeGenTargetInfo(); } clang::ASTContext &ClangImporter::getClangASTContext() const { @@ -4270,7 +4261,7 @@ clang::Sema &ClangImporter::getClangSema() const { } clang::CodeGenOptions &ClangImporter::getCodeGenOpts() const { - return *Impl.getSwiftCodeGenOptions(); + return Impl.getCodeGenOptions(); } std::string ClangImporter::getClangModuleHash() const { @@ -4286,8 +4277,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); @@ -4717,6 +4708,37 @@ void ClangImporter::Implementation::getMangledName( } } +void ClangImporter::Implementation::configureOptionsForCodeGen( + clang::DiagnosticsEngine &Diags, clang::CompilerInvocation *CI) { + clang::TargetInfo *targetInfo = nullptr; + if (CI) { + TargetOpts.reset(new clang::TargetOptions(std::move(CI->getTargetOpts()))); + CodeGenOpts.reset( + new clang::CodeGenOptions(std::move(CI->getCodeGenOpts()))); + targetInfo = clang::TargetInfo::CreateTargetInfo(Diags, *TargetOpts); + + // Ensure the target info has configured target-specific defines + std::string defineBuffer; + llvm::raw_string_ostream predefines(defineBuffer); + clang::MacroBuilder builder(predefines); + targetInfo->getTargetDefines(Instance->getLangOpts(), builder); + } else { + targetInfo = + clang::TargetInfo::CreateTargetInfo(Diags, Invocation->getTargetOpts()); + } + + CodeGenTargetInfo.reset(targetInfo); +} + +clang::CodeGenOptions & +ClangImporter::Implementation::getCodeGenOptions() const { + if (CodeGenOpts) { + return *CodeGenOpts.get(); + } + + return Invocation->getCodeGenOpts(); +} + // --------------------------------------------------------------------------- // Swift lookup tables // --------------------------------------------------------------------------- @@ -7301,7 +7323,8 @@ ClangImporter::instantiateCXXClassTemplate( ctsd = clang::ClassTemplateSpecializationDecl::Create( decl->getASTContext(), decl->getTemplatedDecl()->getTagKind(), decl->getDeclContext(), decl->getTemplatedDecl()->getBeginLoc(), - decl->getLocation(), decl, arguments, nullptr); + decl->getLocation(), decl, arguments, /*StrictPackMatch*/ false, + nullptr); decl->AddSpecialization(ctsd, InsertPos); } diff --git a/lib/ClangImporter/ClangIncludePaths.cpp b/lib/ClangImporter/ClangIncludePaths.cpp index 4eb9548656465..13fb11e164f96 100644 --- a/lib/ClangImporter/ClangIncludePaths.cpp +++ b/lib/ClangImporter/ClangIncludePaths.cpp @@ -127,9 +127,13 @@ std::pair vfs) { + + auto diagVFS = vfs ? vfs : llvm::vfs::getRealFileSystem(); + + clang::DiagnosticOptions diagOpts; auto *silentDiagConsumer = new clang::DiagnosticConsumer(); auto clangDiags = clang::CompilerInstance::createDiagnostics( - new clang::DiagnosticOptions(), silentDiagConsumer); + *diagVFS, diagOpts, silentDiagConsumer); clang::driver::Driver clangDriver(ClangImporterOpts.clangPath, LangOpts.Target.str(), *clangDiags, "clang LLVM compiler", vfs); diff --git a/lib/ClangImporter/ClangModuleDependencyScanner.cpp b/lib/ClangImporter/ClangModuleDependencyScanner.cpp index 6eb7e99d9ac76..7051051cf29bb 100644 --- a/lib/ClangImporter/ClangModuleDependencyScanner.cpp +++ b/lib/ClangImporter/ClangModuleDependencyScanner.cpp @@ -106,8 +106,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 clangArgs; diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index a2f5c792560d8..e08e84653f2ed 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -399,6 +399,7 @@ getSwiftStdlibType(const clang::TypedefNameDecl *D, case clang::TargetInfo::PNaClABIBuiltinVaList: case clang::TargetInfo::SystemZBuiltinVaList: case clang::TargetInfo::X86_64ABIBuiltinVaList: + case clang::TargetInfo::XtensaABIBuiltinVaList: return std::make_pair(Type(), ""); } break; @@ -3300,7 +3301,7 @@ namespace { decl->getLocation(), const_cast(decl), clang::TemplateSpecializationKind::TSK_ImplicitInstantiation, - /*Complain*/ false); + /*Complain*/ false, /*PrimaryStrictPackMatch*/ false); // If the template can't be instantiated, bail. if (notInstantiated) return nullptr; @@ -4273,14 +4274,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(decl) && - param == clang::LifetimeCaptureByAttr::THIS) { + param == clang::LifetimeCaptureByAttr::This) { auto [it, inserted] = inheritedArgDependences.try_emplace( result->getSelfIndex(), SmallBitVector(dependencyVecSize)); it->second[idx] = true; diff --git a/lib/ClangImporter/ImportMacro.cpp b/lib/ClangImporter/ImportMacro.cpp index ada666b6b8612..db511fa3d372b 100644 --- a/lib/ClangImporter/ImportMacro.cpp +++ b/lib/ClangImporter/ImportMacro.cpp @@ -621,7 +621,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(R.getFoundDecl())) return importDeclAlias(impl, DC, VD, name); } diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index 91de6cf22ee6e..037568715be21 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -347,7 +347,7 @@ namespace { // 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 Type(); // PPC SVE builtin types that don't have Swift equivalents. @@ -365,10 +365,15 @@ namespace { return Type(); // AMDGPU builtin types that don't have Swift equivalents. -#define AMDGPU_TYPE(Name, Id, SingletonId) case clang::BuiltinType::Id: +#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \ + case clang::BuiltinType::Id: #include "clang/Basic/AMDGPUTypes.def" return Type(); + // HLSL intangible builtin types that don't have Swift equivalents. +#define HLSL_INTANGIBLE_TYPE(Name, Id, ...) case clang::BuiltinType::Id: +#include "clang/Basic/HLSLIntangibleTypes.def" + return Type(); } llvm_unreachable("Invalid BuiltinType."); @@ -414,6 +419,26 @@ namespace { return Type(); } + ImportResult VisitHLSLAttributedResourceType( + const clang::HLSLAttributedResourceType *type) { + Impl.addImportDiagnostic( + type, + Diagnostic(diag::unsupported_builtin_type, type->getTypeClassName()), + clang::SourceLocation()); + // FIXME: (?) HLSL types are not supported in Swift. + return Type(); + } + + ImportResult + VisitHLSLInlineSpirvType(const clang::HLSLInlineSpirvType *type) { + Impl.addImportDiagnostic( + type, + Diagnostic(diag::unsupported_builtin_type, type->getTypeClassName()), + clang::SourceLocation()); + // FIXME: (?) HLSL types are not supported in Swift. + return Type(); + } + ImportResult VisitCountAttributedType(const clang::CountAttributedType *type) { return Visit(type->desugar()); diff --git a/lib/ClangImporter/ImporterImpl.h b/lib/ClangImporter/ImporterImpl.h index c409b20305fbc..ed4c18dd1ca7a 100644 --- a/lib/ClangImporter/ImporterImpl.h +++ b/lib/ClangImporter/ImporterImpl.h @@ -641,22 +641,22 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation /// corresponding to the instantiating Swift compilation's triple. These are /// to be used by all IRGen/CodeGen clients of `ClangImporter`. std::unique_ptr CodeGenTargetInfo; + /// - Important: Do not access directly. This field exists only to make sure + /// we own the target options stored in `CodeGenTargetInfo` because + /// `clang::TargetOptions` no longer co-owns them: + /// https://github.com/llvm/llvm-project/pull/106271. + std::unique_ptr TargetOpts; std::unique_ptr CodeGenOpts; -public: - void setSwiftTargetInfo(clang::TargetInfo *SwiftTargetInfo) { - CodeGenTargetInfo.reset(SwiftTargetInfo); - } - clang::TargetInfo *getSwiftTargetInfo() const { - return CodeGenTargetInfo.get(); - } + /// Sets the target & code generation options for use by IRGen/CodeGen + /// clients of `ClangImporter`. If `CI` is null, the data is drawn from the + /// importer's invocation. + void configureOptionsForCodeGen(clang::DiagnosticsEngine &Diags, + clang::CompilerInvocation *CI = nullptr); - void setSwiftCodeGenOptions(clang::CodeGenOptions *SwiftCodeGenOpts) { - CodeGenOpts.reset(SwiftCodeGenOpts); - } - clang::CodeGenOptions *getSwiftCodeGenOptions() const { - return CodeGenOpts.get(); - } + clang::TargetInfo &getCodeGenTargetInfo() const { return *CodeGenTargetInfo; } + + clang::CodeGenOptions &getCodeGenOptions() const; private: /// Generation number that is used for crude versioning. diff --git a/lib/ClangImporter/Serializability.cpp b/lib/ClangImporter/Serializability.cpp index b57c47dce21c9..4802ea506f3d3 100644 --- a/lib/ClangImporter/Serializability.cpp +++ b/lib/ClangImporter/Serializability.cpp @@ -330,6 +330,9 @@ namespace { void writeTypeCoupledDeclRefInfo(clang::TypeCoupledDeclRefInfo info) { llvm_unreachable("TypeCoupledDeclRefInfo shouldn't be reached from swift"); } + void writeHLSLSpirvOperand(clang::SpirvOperand) { + llvm_unreachable("SpirvOperand shouldn't be reached from swift"); + } }; } diff --git a/lib/ClangImporter/SwiftDeclSynthesizer.cpp b/lib/ClangImporter/SwiftDeclSynthesizer.cpp index 1f310fe3086d8..1059413ada45e 100644 --- a/lib/ClangImporter/SwiftDeclSynthesizer.cpp +++ b/lib/ClangImporter/SwiftDeclSynthesizer.cpp @@ -2628,11 +2628,12 @@ SwiftDeclSynthesizer::synthesizeStaticFactoryForCXXForeignRef( clang::FunctionDecl *operatorNew = nullptr; clang::FunctionDecl *operatorDelete = nullptr; - bool passAlignment = false; + clang::ImplicitAllocationParameters IAP(clang::AlignedAllocationMode::No); clang::Sema::SFINAETrap trap(clangSema); bool findingAllocFuncFailed = clangSema.FindAllocationFunctions( - cxxRecordDeclLoc, clang::SourceRange(), clang::Sema::AFS_Both, - clang::Sema::AFS_Both, cxxRecordTy, /*IsArray=*/false, passAlignment, + cxxRecordDeclLoc, clang::SourceRange(), + clang::AllocationFunctionScope::Both, + clang::AllocationFunctionScope::Both, cxxRecordTy, /*IsArray=*/false, IAP, clang::MultiExprArg(), operatorNew, operatorDelete, /*Diagnose=*/false); if (trap.hasErrorOccurred() || findingAllocFuncFailed || !operatorNew || diff --git a/lib/ClangImporter/SwiftLookupTable.cpp b/lib/ClangImporter/SwiftLookupTable.cpp index a203c00dfe618..235e9531d7af0 100644 --- a/lib/ClangImporter/SwiftLookupTable.cpp +++ b/lib/ClangImporter/SwiftLookupTable.cpp @@ -1136,7 +1136,8 @@ namespace { ids = StoredSingleEntry::forSerializedDecl( astWriter.getDeclID(decl).getRawValue()); } else if (auto *macro = mappedEntry.dyn_cast()) { - ids = StoredSingleEntry::forSerializedMacro(astWriter.getMacroID(macro)); + ids = StoredSingleEntry::forSerializedMacro( + astWriter.getMacroRef(macro, /*Name=*/nullptr)); } else { auto *moduleMacro = cast(mappedEntry); StoredSingleEntry::SerializationID nameID = diff --git a/lib/Demangling/NodePrinter.cpp b/lib/Demangling/NodePrinter.cpp index db8f4956cb9a2..8885f9a8494df 100644 --- a/lib/Demangling/NodePrinter.cpp +++ b/lib/Demangling/NodePrinter.cpp @@ -2371,14 +2371,28 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth, Printer << "merged "; } return nullptr; - case Node::Kind::TypeSymbolicReference: + case Node::Kind::TypeSymbolicReference: { Printer << "type symbolic reference 0x"; - Printer.writeHex(Node->getIndex()); + if (Node->hasRemoteAddress()) { + auto ra = Node->getRemoteAddress(); + Printer.writeHex(ra.first); + Printer << " (" << ra.second << ")"; + } else if (Node->hasIndex()) { + Printer.writeHex(Node->getIndex()); + } return nullptr; - case Node::Kind::OpaqueTypeDescriptorSymbolicReference: + } + case Node::Kind::OpaqueTypeDescriptorSymbolicReference: { Printer << "opaque type symbolic reference 0x"; - Printer.writeHex(Node->getIndex()); + if (Node->hasRemoteAddress()) { + auto ra = Node->getRemoteAddress(); + Printer.writeHex(ra.first); + Printer << " (" << ra.second << ")"; + } else if (Node->hasIndex()) { + Printer.writeHex(Node->getIndex()); + } return nullptr; + } case Node::Kind::DistributedThunk: if (!Options.ShortenThunk) { Printer << "distributed thunk "; diff --git a/lib/DependencyScan/ModuleDependencyScanner.cpp b/lib/DependencyScan/ModuleDependencyScanner.cpp index 0db8bc41eb60d..d6dcd926b79f2 100644 --- a/lib/DependencyScan/ModuleDependencyScanner.cpp +++ b/lib/DependencyScan/ModuleDependencyScanner.cpp @@ -1915,7 +1915,7 @@ ModuleDependencyInfo ModuleDependencyScanner::bridgeClangModuleDependency( // CASFileSystemRootID. std::string RootID = clangModuleDep.CASFileSystemRootID - ? clangModuleDep.CASFileSystemRootID->toString() + ? clangModuleDep.CASFileSystemRootID.value() : ""; std::string IncludeTree = diff --git a/lib/DriverTool/swift_cache_tool_main.cpp b/lib/DriverTool/swift_cache_tool_main.cpp index 7fc902e4483d2..d32519b0928a9 100644 --- a/lib/DriverTool/swift_cache_tool_main.cpp +++ b/lib/DriverTool/swift_cache_tool_main.cpp @@ -65,12 +65,13 @@ enum ID { #undef OPTION }; -#define PREFIX(NAME, VALUE) \ - constexpr llvm::StringLiteral NAME##_init[] = VALUE; \ - constexpr llvm::ArrayRef NAME( \ - NAME##_init, std::size(NAME##_init) - 1); +#define OPTTABLE_STR_TABLE_CODE #include "SwiftCacheToolOptions.inc" -#undef PREFIX +#undef OPTTABLE_STR_TABLE_CODE + +#define OPTTABLE_PREFIXES_TABLE_CODE +#include "SwiftCacheToolOptions.inc" +#undef OPTTABLE_PREFIXES_TABLE_CODE static const OptTable::Info InfoTable[] = { #define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__), @@ -80,7 +81,8 @@ static const OptTable::Info InfoTable[] = { class CacheToolOptTable : public llvm::opt::GenericOptTable { public: - CacheToolOptTable() : GenericOptTable(InfoTable) {} + CacheToolOptTable() + : GenericOptTable(OptionStrTable, OptionPrefixesTable, InfoTable) {} }; class SwiftCacheToolInvocation { diff --git a/lib/DriverTool/swift_llvm_opt_main.cpp b/lib/DriverTool/swift_llvm_opt_main.cpp index 00b97178dee56..6620418f3ddc9 100644 --- a/lib/DriverTool/swift_llvm_opt_main.cpp +++ b/lib/DriverTool/swift_llvm_opt_main.cpp @@ -135,7 +135,7 @@ getTargetMachine(llvm::Triple TheTriple, StringRef CPUStr, } return TheTarget->createTargetMachine( - TheTriple.getTriple(), CPUStr, FeaturesStr, targetOptions, + TheTriple, CPUStr, FeaturesStr, targetOptions, std::optional(llvm::codegen::getExplicitRelocModel()), llvm::codegen::getExplicitCodeModel(), GetCodeGenOptLevel(options)); } @@ -174,7 +174,8 @@ int swift_llvm_opt_main(ArrayRef argv, void *MainAddr) { // If we are supposed to override the target triple, do so now. if (!options.TargetTriple.empty()) - M->setTargetTriple(llvm::Triple::normalize(options.TargetTriple)); + M->setTargetTriple( + llvm::Triple(llvm::Triple::normalize(options.TargetTriple))); // Figure out what stream we are supposed to write to... std::unique_ptr Out; diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp index 0902ea421ba02..27c3b70862dbb 100644 --- a/lib/Frontend/ModuleInterfaceLoader.cpp +++ b/lib/Frontend/ModuleInterfaceLoader.cpp @@ -2058,6 +2058,17 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl( GenericArgs.push_back("-enable-experimental-feature"); GenericArgs.push_back("Embedded"); } + + if (langOpts.DebuggerSupport) { + if (clangImporterOpts.DirectClangCC1ModuleBuild) { + subClangImporterOpts.ExtraArgs.push_back("-dwarf-ext-refs"); + subClangImporterOpts.ExtraArgs.push_back("-fmodule-format=obj"); + subClangImporterOpts.ExtraArgs.push_back("-debug-info-kind=standalone"); + } else { + subClangImporterOpts.ExtraArgs.push_back("-gmodules"); + subClangImporterOpts.ExtraArgs.push_back("-g"); + } + } } /// Calculate an output filename in \p genericSubInvocation's cache path that diff --git a/lib/IDE/CodeCompletionString.cpp b/lib/IDE/CodeCompletionString.cpp index cc7d57bcc6108..6479b3a1e87df 100644 --- a/lib/IDE/CodeCompletionString.cpp +++ b/lib/IDE/CodeCompletionString.cpp @@ -18,8 +18,7 @@ using namespace swift; using namespace swift::ide; CodeCompletionString::CodeCompletionString(ArrayRef Chunks) { - std::uninitialized_copy(Chunks.begin(), Chunks.end(), - getTrailingObjects()); + std::uninitialized_copy(Chunks.begin(), Chunks.end(), getTrailingObjects()); NumChunks = Chunks.size(); } diff --git a/lib/IDE/Utils.cpp b/lib/IDE/Utils.cpp index 2d33d32ab0e2b..9e6721b5f9c5d 100644 --- a/lib/IDE/Utils.cpp +++ b/lib/IDE/Utils.cpp @@ -20,7 +20,7 @@ #include "swift/Parse/Parser.h" #include "swift/Subsystems.h" #include "clang/AST/ASTContext.h" -#include "clang/Rewrite/Core/RewriteBuffer.h" +#include "llvm/ADT/RewriteBuffer.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/MemoryBuffer.h" @@ -782,11 +782,11 @@ accept(SourceManager &SM, RegionType Type, ArrayRef Replacements) { namespace { class ClangFileRewriterHelper { unsigned InterestedId; - clang::RewriteBuffer RewriteBuf; + llvm::RewriteBuffer RewriteBuf; bool HasChange; llvm::raw_ostream &OS; - void removeCommentLines(clang::RewriteBuffer &Buffer, StringRef Input, + void removeCommentLines(llvm::RewriteBuffer &Buffer, StringRef Input, StringRef LineHeader) { size_t Pos = 0; while (true) { diff --git a/lib/IDETool/CompilerInvocation.cpp b/lib/IDETool/CompilerInvocation.cpp index 278d579b6dd2f..1e1dfa05ace27 100644 --- a/lib/IDETool/CompilerInvocation.cpp +++ b/lib/IDETool/CompilerInvocation.cpp @@ -267,13 +267,12 @@ bool ide::initCompilerInvocation( bool ide::initInvocationByClangArguments(ArrayRef ArgList, CompilerInvocation &Invok, std::string &Error) { - llvm::IntrusiveRefCntPtr DiagOpts{ - new clang::DiagnosticOptions() - }; + const auto VFS = llvm::vfs::getRealFileSystem(); clang::TextDiagnosticBuffer DiagBuf; + clang::DiagnosticOptions DiagOpts; llvm::IntrusiveRefCntPtr ClangDiags = - clang::CompilerInstance::createDiagnostics(DiagOpts.get(), &DiagBuf, + clang::CompilerInstance::createDiagnostics(*VFS, DiagOpts, &DiagBuf, /*ShouldOwnClient=*/false); // Clang expects this to be like an actual command line. So we need to pass in @@ -351,7 +350,7 @@ bool ide::initInvocationByClangArguments(ArrayRef ArgList, if (!PPOpts.ImplicitPCHInclude.empty()) { clang::FileSystemOptions FileSysOpts; - clang::FileManager FileMgr(FileSysOpts); + clang::FileManager FileMgr(FileSysOpts, VFS); auto PCHContainerOperations = std::make_shared(); std::string HeaderFile = clang::ASTReader::getOriginalSourceFile( diff --git a/lib/IRGen/CallEmission.h b/lib/IRGen/CallEmission.h index 89ac2baa265f7..e6c6ac8b36ebd 100644 --- a/lib/IRGen/CallEmission.h +++ b/lib/IRGen/CallEmission.h @@ -152,11 +152,12 @@ class CallEmission { WitnessMetadata *witnessMetadata); virtual Address getCalleeErrorSlot(SILType errorType, bool isCalleeAsync) = 0; - void addFnAttribute(llvm::Attribute::AttrKind Attr); + void addFnAttribute(llvm::Attribute::AttrKind kind); void setIndirectReturnAddress(Address addr) { indirectReturnAddress = addr; } - void addParamAttribute(unsigned ParamIndex, llvm::Attribute::AttrKind Attr); + void addParamAttribute(unsigned paramIndex, llvm::Attribute::AttrKind kind); + void addParamAttribute(unsigned paramIndex, llvm::Attribute attr); void emitToMemory(Address addr, const LoadableTypeInfo &substResultTI, bool isOutlined); diff --git a/lib/IRGen/GenBuiltin.cpp b/lib/IRGen/GenBuiltin.cpp index 21bba9a29f133..b2d38181012da 100644 --- a/lib/IRGen/GenBuiltin.cpp +++ b/lib/IRGen/GenBuiltin.cpp @@ -446,9 +446,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, SmallVector ArgTys; for (auto T : IInfo.Types) ArgTys.push_back(IGF.IGM.getStorageTypeForLowered(T->getCanonicalType())); - - auto F = llvm::Intrinsic::getDeclaration(&IGF.IGM.Module, - (llvm::Intrinsic::ID)IID, ArgTys); + + auto F = llvm::Intrinsic::getOrInsertDeclaration( + &IGF.IGM.Module, (llvm::Intrinsic::ID)IID, ArgTys); llvm::FunctionType *FT = F->getFunctionType(); SmallVector IRArgs; for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) @@ -514,7 +514,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, SmallVector ArgTys; \ auto opType = Builtin.Types[0]->getCanonicalType(); \ ArgTys.push_back(IGF.IGM.getStorageTypeForLowered(opType)); \ - auto F = llvm::Intrinsic::getDeclaration( \ + auto F = llvm::Intrinsic::getOrInsertDeclaration( \ &IGF.IGM.Module, getLLVMIntrinsicIDForBuiltinWithOverflow(Builtin.ID), \ ArgTys); \ SmallVector IRArgs; \ diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 6e622da2773d7..301251919cf6e 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -317,7 +317,7 @@ static void addIndirectValueParameterAttributes(IRGenModule &IGM, // Bitwise takable value types are guaranteed not to capture // a pointer into itself. if (!addressable && ti.isBitwiseTakable(ResilienceExpansion::Maximal)) - b.addAttribute(llvm::Attribute::NoCapture); + b.addCapturesAttr(llvm::CaptureInfo::none()); // The parameter must reference dereferenceable memory of the type. addDereferenceableAttributeToBuilder(IGM, b, ti); @@ -330,7 +330,7 @@ static void addPackParameterAttributes(IRGenModule &IGM, unsigned argIndex) { llvm::AttrBuilder b(IGM.getLLVMContext()); // Pack parameter pointers can't alias. - // Note: they are not marked `nocapture` as one + // Note: they are not marked `captures(none)` as one // pack parameter could be a value type (e.g. a C++ type) // that captures its own pointer in itself. b.addAttribute(llvm::Attribute::NoAlias); @@ -357,7 +357,7 @@ static void addInoutParameterAttributes(IRGenModule &IGM, SILType paramSILType, // Bitwise takable value types are guaranteed not to capture // a pointer into itself. if (!addressable && ti.isBitwiseTakable(ResilienceExpansion::Maximal)) - b.addAttribute(llvm::Attribute::NoCapture); + b.addCapturesAttr(llvm::CaptureInfo::none()); // The inout must reference dereferenceable memory of the type. addDereferenceableAttributeToBuilder(IGM, b, ti); @@ -411,7 +411,7 @@ static void addIndirectResultAttributes(IRGenModule &IGM, // Bitwise takable value types are guaranteed not to capture // a pointer into itself. if (typeInfo.isBitwiseTakable(ResilienceExpansion::Maximal)) - b.addAttribute(llvm::Attribute::NoCapture); + b.addCapturesAttr(llvm::CaptureInfo::none()); if (allowSRet) { assert(storageType); b.addStructRetAttr(storageType); @@ -530,7 +530,7 @@ void IRGenModule::addSwiftErrorAttributes(llvm::AttributeList &attrs, // The error result should not be aliased, captured, or pointed at invalid // addresses regardless. b.addAttribute(llvm::Attribute::NoAlias); - b.addAttribute(llvm::Attribute::NoCapture); + b.addCapturesAttr(llvm::CaptureInfo::none()); b.addDereferenceableAttr(getPointerSize().getValue()); attrs = attrs.addParamAttributes(this->getLLVMContext(), argIndex, b); @@ -1211,6 +1211,8 @@ namespace { } case clang::Type::ArrayParameter: + case clang::Type::HLSLAttributedResource: + case clang::Type::HLSLInlineSpirv: llvm_unreachable("HLSL type in ABI lowering"); @@ -1319,7 +1321,7 @@ namespace { // We should never see ARM SVE types at all. #define SVE_TYPE(Name, Id, ...) case clang::BuiltinType::Id: -#include "clang/Basic/AArch64SVEACLETypes.def" +#include "clang/Basic/AArch64ACLETypes.def" llvm_unreachable("ARM SVE type in ABI lowering"); // We should never see PPC MMA types at all. @@ -1341,6 +1343,11 @@ namespace { #include "clang/Basic/AMDGPUTypes.def" llvm_unreachable("AMDGPU type in ABI lowering"); + // We should never see HLSL intangible types at all. +#define HLSL_INTANGIBLE_TYPE(Name, Id, ...) case clang::BuiltinType::Id: +#include "clang/Basic/HLSLIntangibleTypes.def" + llvm_unreachable("HLSL intangible type in ABI lowering"); + // Handle all the integer types as opaque values. #define BUILTIN_TYPE(Id, SingletonId) #define SIGNED_TYPE(Id, SingletonId) \ @@ -1682,6 +1689,9 @@ void SignatureExpansion::expandExternalSignatureTypes() { paramTI.getStorageType(), paramTI); break; } + case clang::ParameterABI::HLSLOut: + case clang::ParameterABI::HLSLInOut: + llvm_unreachable("not implemented"); } // If the coercion type is a struct which can be flattened, we need to @@ -2846,7 +2856,9 @@ class SyncCallEmission final : public CallEmission { } } Args[--LastArgWritten] = errorResultSlot.getAddress(); - addParamAttribute(LastArgWritten, llvm::Attribute::NoCapture); + addParamAttribute(LastArgWritten, llvm::Attribute::getWithCaptureInfo( + IGF.IGM.getLLVMContext(), + llvm::CaptureInfo::none())); IGF.IGM.addSwiftErrorAttributes(CurCallee.getMutableAttributes(), LastArgWritten); @@ -5555,14 +5567,20 @@ void CallEmission::setArgs(Explosion &adjusted, bool isOutlined, } } -void CallEmission::addFnAttribute(llvm::Attribute::AttrKind attr) { +void CallEmission::addFnAttribute(llvm::Attribute::AttrKind kind) { assert(state == State::Emitting); auto &attrs = CurCallee.getMutableAttributes(); - attrs = attrs.addFnAttribute(IGF.IGM.getLLVMContext(), attr); + attrs = attrs.addFnAttribute(IGF.IGM.getLLVMContext(), kind); +} + +void CallEmission::addParamAttribute(unsigned paramIndex, + llvm::Attribute::AttrKind kind) { + addParamAttribute(paramIndex, + llvm::Attribute::get(IGF.IGM.getLLVMContext(), kind)); } void CallEmission::addParamAttribute(unsigned paramIndex, - llvm::Attribute::AttrKind attr) { + llvm::Attribute attr) { assert(state == State::Emitting); auto &attrs = CurCallee.getMutableAttributes(); attrs = attrs.addParamAttribute(IGF.IGM.getLLVMContext(), paramIndex, attr); diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 558255905517f..f54133e4ca5ef 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -5996,9 +5996,8 @@ void IRGenModule::emitExtension(ExtensionDecl *ext) { Address IRGenFunction::createAlloca(llvm::Type *type, Alignment alignment, const llvm::Twine &name) { - llvm::AllocaInst *alloca = - new llvm::AllocaInst(type, IGM.DataLayout.getAllocaAddrSpace(), name, - AllocaIP); + llvm::AllocaInst *alloca = new llvm::AllocaInst( + type, IGM.DataLayout.getAllocaAddrSpace(), name, AllocaIP->getIterator()); alloca->setAlignment(llvm::MaybeAlign(alignment.getValue()).valueOrOne()); return Address(alloca, type, alignment); } @@ -6008,9 +6007,10 @@ Address IRGenFunction::createAlloca(llvm::Type *type, llvm::Value *ArraySize, Alignment alignment, const llvm::Twine &name) { - llvm::AllocaInst *alloca = new llvm::AllocaInst( - type, IGM.DataLayout.getAllocaAddrSpace(), ArraySize, - llvm::MaybeAlign(alignment.getValue()).valueOrOne(), name, AllocaIP); + llvm::AllocaInst *alloca = + new llvm::AllocaInst(type, IGM.DataLayout.getAllocaAddrSpace(), ArraySize, + llvm::MaybeAlign(alignment.getValue()).valueOrOne(), + name, AllocaIP->getIterator()); return Address(alloca, type, alignment); } diff --git a/lib/IRGen/GenExistential.cpp b/lib/IRGen/GenExistential.cpp index 5e0d4af15359d..1c39124ce0e60 100644 --- a/lib/IRGen/GenExistential.cpp +++ b/lib/IRGen/GenExistential.cpp @@ -149,7 +149,7 @@ namespace { : Base(std::forward(args)...), NumStoredProtocols(protocols.size()) { std::uninitialized_copy(protocols.begin(), protocols.end(), - this->template getTrailingObjects()); + this->getTrailingObjects()); } public: @@ -180,8 +180,7 @@ namespace { /// type are not know to implement any protocols, although we do /// still know how to manipulate them. ArrayRef getStoredProtocols() const { - return {this->template getTrailingObjects(), - NumStoredProtocols}; + return this->getTrailingObjects(NumStoredProtocols); } /// Given the address of an existential object, find the witness diff --git a/lib/IRGen/GenPointerAuth.cpp b/lib/IRGen/GenPointerAuth.cpp index 9d094032747be..b28db161be422 100644 --- a/lib/IRGen/GenPointerAuth.cpp +++ b/lib/IRGen/GenPointerAuth.cpp @@ -26,6 +26,7 @@ #include "swift/SIL/TypeLowering.h" #include "clang/CodeGen/CodeGenABITypes.h" #include "llvm/ADT/APInt.h" +#include "llvm/Support/SipHash.h" #include "llvm/Support/raw_ostream.h" using namespace swift; @@ -324,16 +325,10 @@ PointerAuthInfo::getOtherDiscriminator(IRGenModule &IGM, llvm_unreachable("bad kind"); } -static llvm::ConstantInt *getDiscriminatorForHash(IRGenModule &IGM, - uint64_t rawHash) { - uint16_t reducedHash = (rawHash % 0xFFFF) + 1; - return llvm::ConstantInt::get(IGM.Int64Ty, reducedHash); -} - static llvm::ConstantInt *getDiscriminatorForString(IRGenModule &IGM, StringRef string) { - uint64_t rawHash = clang::CodeGen::computeStableStringHash(string); - return getDiscriminatorForHash(IGM, rawHash); + return llvm::ConstantInt::get(IGM.Int64Ty, + llvm::getPointerAuthStableSipHash(string)); } static std::string mangle(AssociatedTypeDecl *assocType) { @@ -570,7 +565,8 @@ static void hashStringForFunctionType(IRGenModule &IGM, CanSILFunctionType type, } } -static uint64_t getTypeHash(IRGenModule &IGM, CanSILFunctionType type) { +static llvm::ConstantInt *getTypeDiscriminator(IRGenModule &IGM, + CanSILFunctionType type) { // The hash we need to do here ignores: // - thickness, so that we can promote thin-to-thick without rehashing; // - error results, so that we can promote nonthrowing-to-throwing @@ -590,10 +586,11 @@ static uint64_t getTypeHash(IRGenModule &IGM, CanSILFunctionType type) { hashStringForFunctionType( IGM, type, Out, genericSig.getCanonicalSignature().getGenericEnvironment()); - return clang::CodeGen::computeStableStringHash(Out.str()); + return getDiscriminatorForString(IGM, Out.str()); } -static uint64_t getYieldTypesHash(IRGenModule &IGM, CanSILFunctionType type) { +static llvm::ConstantInt * +getCoroutineYieldTypesDiscriminator(IRGenModule &IGM, CanSILFunctionType type) { SmallString<32> buffer; llvm::raw_svector_ostream out(buffer); auto genericSig = type->getInvocationGenericSignature(); @@ -629,7 +626,7 @@ static uint64_t getYieldTypesHash(IRGenModule &IGM, CanSILFunctionType type) { out << ":"; } - return clang::CodeGen::computeStableStringHash(out.str()); + return getDiscriminatorForString(IGM, out.str()); } llvm::ConstantInt * @@ -649,8 +646,7 @@ PointerAuthEntity::getTypeDiscriminator(IRGenModule &IGM) const { llvm::ConstantInt *&cache = IGM.getPointerAuthCaches().Types[fnType]; if (cache) return cache; - auto hash = getTypeHash(IGM, fnType); - cache = getDiscriminatorForHash(IGM, hash); + cache = ::getTypeDiscriminator(IGM, fnType); return cache; } @@ -667,15 +663,6 @@ PointerAuthEntity::getTypeDiscriminator(IRGenModule &IGM) const { llvm_unreachable("invalid representation"); }; - auto getCoroutineYieldTypesDiscriminator = [&](CanSILFunctionType fnType) { - llvm::ConstantInt *&cache = IGM.getPointerAuthCaches().Types[fnType]; - if (cache) return cache; - - auto hash = getYieldTypesHash(IGM, fnType); - cache = getDiscriminatorForHash(IGM, hash); - return cache; - }; - switch (StoredKind) { case Kind::None: case Kind::Special: @@ -687,7 +674,13 @@ PointerAuthEntity::getTypeDiscriminator(IRGenModule &IGM) const { case Kind::CoroutineYieldTypes: { auto fnType = Storage.get(StoredKind); - return getCoroutineYieldTypesDiscriminator(fnType); + + llvm::ConstantInt *&cache = IGM.getPointerAuthCaches().Types[fnType]; + if (cache) + return cache; + + cache = getCoroutineYieldTypesDiscriminator(IGM, fnType); + return cache; } case Kind::CanSILFunctionType: { diff --git a/lib/IRGen/GenRecord.h b/lib/IRGen/GenRecord.h index 65acff49edccf..2aaf5df5c879c 100644 --- a/lib/IRGen/GenRecord.h +++ b/lib/IRGen/GenRecord.h @@ -138,7 +138,7 @@ class RecordTypeInfoImpl : public Base, NumFields(fields.size()), AreFieldsABIAccessible(fieldsABIAccessible) { std::uninitialized_copy(fields.begin(), fields.end(), - this->template getTrailingObjects()); + this->getTrailingObjects()); } void fillWithZerosIfSensitive(IRGenFunction &IGF, Address address, SILType T) const { @@ -169,7 +169,7 @@ class RecordTypeInfoImpl : public Base, } ArrayRef getFields() const { - return {this->template getTrailingObjects(), NumFields}; + return this->getTrailingObjects(NumFields); } /// The standard schema is just all the fields jumbled together. diff --git a/lib/IRGen/GenStruct.cpp b/lib/IRGen/GenStruct.cpp index 6816689777e03..d870143d153ea 100644 --- a/lib/IRGen/GenStruct.cpp +++ b/lib/IRGen/GenStruct.cpp @@ -657,7 +657,7 @@ namespace { }); bool hasRequiresClause = - copyConstructor->getTrailingRequiresClause() != nullptr; + !copyConstructor->getTrailingRequiresClause().isNull(); if (hasRequiresClause || hasCopyableIfAttr) { ctx.Diags.diagnose(copyConstructorLoc, diag::maybe_missing_annotation, @@ -1468,7 +1468,7 @@ class ClangRecordLowering { // Collect all of the following bitfields. unsigned bitStart = layout.getFieldOffset(clangField->getFieldIndex()); - unsigned bitEnd = bitStart + clangField->getBitWidthValue(ClangContext); + unsigned bitEnd = bitStart + clangField->getBitWidthValue(); while (cfi != cfe && (*cfi)->isBitField()) { clangField = *cfi++; @@ -1484,7 +1484,7 @@ class ClangRecordLowering { bitStart = nextStart; } - bitEnd = nextStart + clangField->getBitWidthValue(ClangContext); + bitEnd = nextStart + clangField->getBitWidthValue(); } addOpaqueBitField(bitStart, bitEnd); diff --git a/lib/IRGen/IRBuilder.h b/lib/IRGen/IRBuilder.h index 0770691fc2485..99a506888479b 100644 --- a/lib/IRGen/IRBuilder.h +++ b/lib/IRGen/IRBuilder.h @@ -139,11 +139,11 @@ class IRBuilder : public IRBuilderBase { using IRBuilderBase::CreateOr; llvm::Value *CreateOr(llvm::Value *LHS, llvm::Value *RHS, - const Twine &Name = "") { + const Twine &Name = "", bool IsDisjoint = false) { if (auto *RC = dyn_cast(RHS)) if (RC->isNullValue()) return LHS; // LHS | 0 -> LHS - return IRBuilderBase::CreateOr(LHS, RHS, Name); + return IRBuilderBase::CreateOr(LHS, RHS, Name, IsDisjoint); } llvm::Value *CreateOr(llvm::Value *LHS, const APInt &RHS, const Twine &Name = "") { @@ -311,8 +311,8 @@ class IRBuilder : public IRBuilderBase { // FunctionPointer. bool isTrapIntrinsic(llvm::Value *Callee) { - return Callee == - llvm::Intrinsic::getDeclaration(getModule(), llvm::Intrinsic::trap); + return Callee == llvm::Intrinsic::getOrInsertDeclaration( + getModule(), llvm::Intrinsic::trap); } bool isTrapIntrinsic(llvm::Intrinsic::ID intrinsicID) { return intrinsicID == llvm::Intrinsic::trap; @@ -382,7 +382,7 @@ class IRBuilder : public IRBuilderBase { const Twine &name = "") { assert(!isTrapIntrinsic(intrinsicID) && "Use CreateNonMergeableTrap"); auto intrinsicFn = - llvm::Intrinsic::getDeclaration(getModule(), intrinsicID); + llvm::Intrinsic::getOrInsertDeclaration(getModule(), intrinsicID); return CreateCallWithoutDbgLoc( cast(intrinsicFn->getValueType()), intrinsicFn, args, name); @@ -394,8 +394,8 @@ class IRBuilder : public IRBuilderBase { ArrayRef args, const Twine &name = "") { assert(!isTrapIntrinsic(intrinsicID) && "Use CreateNonMergeableTrap"); - auto intrinsicFn = - llvm::Intrinsic::getDeclaration(getModule(), intrinsicID, typeArgs); + auto intrinsicFn = llvm::Intrinsic::getOrInsertDeclaration( + getModule(), intrinsicID, typeArgs); return CreateCallWithoutDbgLoc( cast(intrinsicFn->getValueType()), intrinsicFn, args, name); diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index d70df477ef61c..2566667e69027 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -88,7 +88,6 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/AlwaysInliner.h" #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" -#include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Instrumentation/AddressSanitizer.h" #include "llvm/Transforms/Instrumentation/InstrProfiling.h" #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" @@ -96,6 +95,7 @@ #include "llvm/Transforms/ObjCARC.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/DCE.h" +#include "llvm/Transforms/Utils/Instrumentation.h" #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" #include "llvm/IR/DiagnosticInfo.h" @@ -135,6 +135,9 @@ swift::getIRTargetOptions(const IRGenOptions &Opts, ASTContext &Ctx) { // FIXME: We should do this entirely through Clang, for consistency. TargetOptions TargetOpts; + // Linker support for this is not widespread enough. + TargetOpts.SupportIndirectSymViaGOTPCRel_AArch64_ELF = false; + // Explicitly request debugger tuning for LLDB which is the default // on Darwin platforms but not on others. TargetOpts.DebuggerTuning = llvm::DebuggerKind::LLDB; @@ -345,7 +348,8 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts, FPM.addPass(SwiftARCOptPass()); }); PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM, - OptimizationLevel Level) { + OptimizationLevel Level, + llvm::ThinOrFullLTOPhase) { if (Level != OptimizationLevel::O0) MPM.addPass(createModuleToFunctionPassAdaptor(SwiftARCContractPass())); if (Level == OptimizationLevel::O0) @@ -360,7 +364,8 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts, if (Opts.Sanitizers & SanitizerKind::Address) { PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM, - OptimizationLevel Level) { + OptimizationLevel Level, + llvm::ThinOrFullLTOPhase) { AddressSanitizerOptions ASOpts; ASOpts.CompileKernel = false; ASOpts.Recover = bool(Opts.SanitizersWithRecoveryInstrumentation & @@ -379,17 +384,19 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts, } if (Opts.Sanitizers & SanitizerKind::Thread) { - PB.registerOptimizerLastEPCallback( - [&](ModulePassManager &MPM, OptimizationLevel Level) { - MPM.addPass(ModuleThreadSanitizerPass()); - MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); - }); + PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM, + OptimizationLevel Level, + llvm::ThinOrFullLTOPhase) { + MPM.addPass(ModuleThreadSanitizerPass()); + MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); + }); } if (Opts.SanitizeCoverage.CoverageType != llvm::SanitizerCoverageOptions::SCK_None) { PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM, - OptimizationLevel Level) { + OptimizationLevel Level, + llvm::ThinOrFullLTOPhase) { std::vector allowlistFiles; std::vector ignorelistFiles; MPM.addPass(SanitizerCoveragePass(Opts.SanitizeCoverage, @@ -398,14 +405,15 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts, } if (RunSwiftSpecificLLVMOptzns && !Opts.DisableLLVMMergeFunctions) { - PB.registerOptimizerLastEPCallback( - [&](ModulePassManager &MPM, OptimizationLevel Level) { - if (Level != OptimizationLevel::O0) { - const PointerAuthSchema &schema = Opts.PointerAuth.FunctionPointers; - unsigned key = (schema.isEnabled() ? schema.getKey() : 0); - MPM.addPass(SwiftMergeFunctionsPass(schema.isEnabled(), key)); - } - }); + PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM, + OptimizationLevel Level, + llvm::ThinOrFullLTOPhase) { + if (Level != OptimizationLevel::O0) { + const PointerAuthSchema &schema = Opts.PointerAuth.FunctionPointers; + unsigned key = (schema.isEnabled() ? schema.getKey() : 0); + MPM.addPass(SwiftMergeFunctionsPass(schema.isEnabled(), key)); + } + }); } if (Opts.GenerateProfile) { @@ -427,7 +435,13 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts, bool isThinLTO = Opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin; bool isFullLTO = Opts.LLVMLTOKind == IRGenLLVMLTOKind::Full; if (!Opts.shouldOptimize() || Opts.DisableLLVMOptzns) { - MPM = PB.buildO0DefaultPipeline(level, isFullLTO || isThinLTO); + auto phase = llvm::ThinOrFullLTOPhase::None; + if (isFullLTO) { + phase = llvm::ThinOrFullLTOPhase::FullLTOPreLink; + } else if (isThinLTO) { + phase = llvm::ThinOrFullLTOPhase::ThinLTOPreLink; + } + MPM = PB.buildO0DefaultPipeline(level, phase); } else if (isThinLTO) { MPM = PB.buildThinLTOPreLinkDefaultPipeline(level); } else if (isFullLTO) { @@ -1047,7 +1061,7 @@ swift::createTargetMachine(const IRGenOptions &Opts, ASTContext &Ctx) { // Create a target machine. llvm::TargetMachine *TargetMachine = Target->createTargetMachine( - EffectiveTriple.str(), CPU, targetFeatures, TargetOpts, Reloc::PIC_, + EffectiveTriple, CPU, targetFeatures, TargetOpts, Reloc::PIC_, cmodel, OptLevel); if (!TargetMachine) { Ctx.Diags.diagnose(SourceLoc(), diag::no_llvm_target, @@ -1148,8 +1162,8 @@ static void embedBitcode(llvm::Module *M, const IRGenOptions &Opts) static void initLLVMModule(IRGenModule &IGM, SILModule &SIL, std::optional idx = {}) { auto *Module = IGM.getModule(); assert(Module && "Expected llvm:Module for IR generation!"); - - Module->setTargetTriple(IGM.Triple.str()); + + Module->setTargetTriple(IGM.Triple); if (IGM.Context.LangOpts.SDKVersion) { if (Module->getSDKVersion().empty()) diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index 0ede779f729e6..a79c30268bfa8 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -1951,7 +1951,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { nullptr, PtrSize, 0, /* DWARFAddressSpace */ std::nullopt, MangledName); - return DBuilder.createObjectPointerType(PTy); + // FIXME: Set DIFlagObjectPointer and make sure it is only set for `self`. + return PTy; } case TypeKind::BuiltinExecutor: { return createDoublePointerSizedStruct( @@ -3684,16 +3685,16 @@ struct DbgIntrinsicEmitter { PointerUnion InsertPt; irgen::IRBuilder &IRBuilder; llvm::DIBuilder &DIBuilder; - AddrDbgInstrKind ForceDbgDeclare; + AddrDbgInstrKind ForceDbgDeclareOrCoro; /// Initialize the emitter and initialize the emitter to assume that it is /// going to insert an llvm.dbg.declare or an llvm.dbg.addr either at the /// current "generalized insertion point" of the IRBuilder. The "generalized /// insertion point" is DbgIntrinsicEmitter(irgen::IRBuilder &IRBuilder, llvm::DIBuilder &DIBuilder, - AddrDbgInstrKind ForceDebugDeclare) + AddrDbgInstrKind AddrDInstrKind) : InsertPt(), IRBuilder(IRBuilder), DIBuilder(DIBuilder), - ForceDbgDeclare(ForceDebugDeclare) { + ForceDbgDeclareOrCoro(AddrDInstrKind) { auto *ParentBB = IRBuilder.GetInsertBlock(); auto InsertBefore = IRBuilder.GetInsertPoint(); @@ -3720,19 +3721,29 @@ struct DbgIntrinsicEmitter { llvm::DIExpression *Expr, const llvm::DILocation *DL, llvm::Instruction *InsertBefore) { - if (ForceDbgDeclare == AddrDbgInstrKind::DbgDeclare) - return DIBuilder.insertDeclare(Addr, VarInfo, Expr, DL, InsertBefore); + if (ForceDbgDeclareOrCoro == AddrDbgInstrKind::DbgDeclare) + return DIBuilder.insertDeclare(Addr, VarInfo, Expr, DL, + InsertBefore->getIterator()); + + if (ForceDbgDeclareOrCoro == AddrDbgInstrKind::DbgCoroFrameEntry) + return DIBuilder.insertCoroFrameEntry(Addr, VarInfo, Expr, DL, + InsertBefore->getIterator()); + Expr = llvm::DIExpression::append(Expr, llvm::dwarf::DW_OP_deref); return DIBuilder.insertDbgValueIntrinsic(Addr, VarInfo, Expr, DL, - InsertBefore); + InsertBefore->getIterator()); } llvm::DbgInstPtr insert(llvm::Value *Addr, llvm::DILocalVariable *VarInfo, llvm::DIExpression *Expr, const llvm::DILocation *DL, llvm::BasicBlock *Block) { - if (ForceDbgDeclare == AddrDbgInstrKind::DbgDeclare) + if (ForceDbgDeclareOrCoro == AddrDbgInstrKind::DbgDeclare) return DIBuilder.insertDeclare(Addr, VarInfo, Expr, DL, Block); + + if (ForceDbgDeclareOrCoro == AddrDbgInstrKind::DbgCoroFrameEntry) + return DIBuilder.insertCoroFrameEntry(Addr, VarInfo, Expr, DL, Block); + Expr = llvm::DIExpression::append(Expr, llvm::dwarf::DW_OP_deref); return DIBuilder.insertDbgValueIntrinsic(Addr, VarInfo, Expr, DL, Block); } @@ -3792,13 +3803,17 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic( if (optimized && (!InCoroContext || !Var->isParameter())) AddrDInstKind = AddrDbgInstrKind::DbgValueDeref; + if (InCoroContext && AddrDInstKind != AddrDbgInstrKind::DbgValueDeref) + AddrDInstKind = AddrDbgInstrKind::DbgCoroFrameEntry; + DbgIntrinsicEmitter inserter{Builder, DBuilder, AddrDInstKind}; // If we have a single alloca... if (auto *Alloca = dyn_cast(Storage)) { auto InsertBefore = Builder.GetInsertPoint(); - if (AddrDInstKind == AddrDbgInstrKind::DbgDeclare) { + if (AddrDInstKind == AddrDbgInstrKind::DbgDeclare || + AddrDInstKind == AddrDbgInstrKind::DbgCoroFrameEntry) { ParentBlock = Alloca->getParent(); InsertBefore = std::next(Alloca->getIterator()); } @@ -3825,7 +3840,8 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic( // splitter that in split coroutines we always create debug info for values // in the coroutine context by creating a llvm.dbg.declare for the variable // in the entry block of each funclet. - if (AddrDInstKind == AddrDbgInstrKind::DbgDeclare) { + if (AddrDInstKind == AddrDbgInstrKind::DbgDeclare || + AddrDInstKind == AddrDbgInstrKind::DbgCoroFrameEntry) { // Function arguments in async functions are emitted without a shadow copy // (that would interfere with coroutine splitting) but with a // llvm.dbg.declare to give CoroSplit.cpp license to emit a shadow copy @@ -3868,19 +3884,23 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic( } // Insert a dbg.value at the current insertion point. - if (isa(Storage) && !Var->getArg() && - ParentBlock->getFirstNonPHIOrDbg()) - // SelectionDAGISel only generates debug info for a dbg.value - // that is associated with a llvm::Argument if either its !DIVariable - // is marked as argument or there is no non-debug intrinsic instruction - // before it. So In the case of associating a llvm::Argument with a - // non-argument debug variable -- usually via a !DIExpression -- we - // need to make sure that dbg.value is before any non-phi / no-dbg - // instruction. - DBuilder.insertDbgValueIntrinsic(Storage, Var, Expr, DL, - ParentBlock->getFirstNonPHIOrDbg()); - else - DBuilder.insertDbgValueIntrinsic(Storage, Var, Expr, DL, ParentBlock); + if (isa(Storage) && !Var->getArg()) { + const auto InsertPt = ParentBlock->getFirstNonPHIOrDbg(); + if (InsertPt != ParentBlock->end()) { + // SelectionDAGISel only generates debug info for a dbg.value + // that is associated with a llvm::Argument if either its !DIVariable + // is marked as argument or there is no non-debug intrinsic instruction + // before it. So In the case of associating a llvm::Argument with a + // non-argument debug variable -- usually via a !DIExpression -- we + // need to make sure that dbg.value is before any non-phi / no-dbg + // instruction. + DBuilder.insertDbgValueIntrinsic(Storage, Var, Expr, DL, InsertPt); + + return; + } + } + + DBuilder.insertDbgValueIntrinsic(Storage, Var, Expr, DL, ParentBlock->end()); } void IRGenDebugInfoImpl::emitGlobalVariableDeclaration( diff --git a/lib/IRGen/IRGenDebugInfo.h b/lib/IRGen/IRGenDebugInfo.h index 4007bf3178a25..364f357deb3a3 100644 --- a/lib/IRGen/IRGenDebugInfo.h +++ b/lib/IRGen/IRGenDebugInfo.h @@ -50,9 +50,10 @@ enum ArtificialKind : bool { RealValue = false, ArtificialValue = true }; /// instead of dbg.value + op_deref. By default, we now emit dbg.value instead of /// dbg.declare for normal variables. This is not true for metadata which /// truly are function wide and should be llvm.dbg.declare. -enum class AddrDbgInstrKind : bool { +enum class AddrDbgInstrKind : uint8_t { DbgDeclare, DbgValueDeref, + DbgCoroFrameEntry, }; /// Helper object that keeps track of the current CompileUnit, File, diff --git a/lib/IRGen/IRGenFunction.cpp b/lib/IRGen/IRGenFunction.cpp index e4ec6b07fe44b..34606f3353a9a 100644 --- a/lib/IRGen/IRGenFunction.cpp +++ b/lib/IRGen/IRGenFunction.cpp @@ -524,8 +524,8 @@ llvm::CallInst *IRBuilder::CreateNonMergeableTrap(IRGenModule &IGM, } // Emit the trap instruction. - llvm::Function *trapIntrinsic = - llvm::Intrinsic::getDeclaration(&IGM.Module, llvm::Intrinsic::trap); + llvm::Function *trapIntrinsic = llvm::Intrinsic::getOrInsertDeclaration( + &IGM.Module, llvm::Intrinsic::trap); if (EnableTrapDebugInfo && IGM.DebugInfo && !failureMsg.empty()) { IGM.DebugInfo->addFailureMessageToCurrentLoc(*this, failureMsg); } diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index b13893ff833d2..9ba09c542f9b8 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -2419,7 +2419,7 @@ bool swift::writeEmptyOutputFilesFor( auto *clangImporter = static_cast( Context.getClangModuleLoader()); llvmModule->setTargetTriple( - clangImporter->getTargetInfo().getTargetOpts().Triple); + llvm::Triple(clangImporter->getTargetInfo().getTargetOpts().Triple)); // Add LLVM module flags. auto &clangASTContext = clangImporter->getClangASTContext(); diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index adc1a267e061a..a8ca6585964b1 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -823,7 +823,7 @@ class IRGenSILFunction : if (DVI->getParent() == BB) IGM.DebugInfo->getBuilder().insertDbgValueIntrinsic( DVI->getValue(), DVI->getVariable(), DVI->getExpression(), - DVI->getDebugLoc(), &*CurBB->getFirstInsertionPt()); + DVI->getDebugLoc(), CurBB->getFirstInsertionPt()); } } } @@ -907,7 +907,7 @@ class IRGenSILFunction : llvm::Instruction *Cloned = Orig->clone(); Cloned->setOperand(0, Inner); - Cloned->insertBefore(Orig); + Cloned->insertBefore(Orig->getIterator()); return static_cast(Cloned); }; if (auto *LdInst = dyn_cast(Storage)) @@ -5747,7 +5747,7 @@ static Address isSafeForMemCpyPeephole(const TypeInfo &TI, SILArgument *arg, return Address(); } - lifetimeBegin->moveBefore(load); + lifetimeBegin->moveBefore(load->getIterator()); // Set insertPt to the first load such that we are within the lifetime of the // alloca marked by the lifetime intrinsic. diff --git a/lib/IRGen/ProtocolInfo.h b/lib/IRGen/ProtocolInfo.h index 8c4180cb549c1..a1c3fa9819bc6 100644 --- a/lib/IRGen/ProtocolInfo.h +++ b/lib/IRGen/ProtocolInfo.h @@ -222,8 +222,7 @@ class ProtocolInfo final : ProtocolInfo(ArrayRef table, ProtocolInfoKind kind) : NumTableEntries(table.size()), Kind(kind) { - std::uninitialized_copy(table.begin(), table.end(), - getTrailingObjects()); + std::uninitialized_copy(table.begin(), table.end(), getTrailingObjects()); } static std::unique_ptr create(ArrayRef table, @@ -249,7 +248,7 @@ class ProtocolInfo final : /// The addresses of the entries in this array can be passed to /// getBaseWitnessIndex/getNonBaseWitnessIndex, below. ArrayRef getWitnessEntries() const { - return {getTrailingObjects(), NumTableEntries}; + return getTrailingObjects(NumTableEntries); } /// Given the address of a witness entry from this PI for a base protocol diff --git a/lib/Immediate/SwiftMaterializationUnit.cpp b/lib/Immediate/SwiftMaterializationUnit.cpp index 7203a8ab141c8..0465188f2b270 100644 --- a/lib/Immediate/SwiftMaterializationUnit.cpp +++ b/lib/Immediate/SwiftMaterializationUnit.cpp @@ -197,11 +197,11 @@ renameFunctionBodies(llvm::orc::MaterializationResponsibility &MR, if (!Sym->hasName() || !Sym->isCallable()) continue; - if (ToRename.count(Sym->getName())) { - // FIXME: Get rid of the temporary when Swift's llvm-project is - // updated to LLVM 17. - auto NewName = G.allocateCString(Twine(mangle(Sym->getName()))); - Sym->setName({NewName.data(), NewName.size() - 1}); + const StringRef Name = *Sym->getName(); + + if (ToRename.count(Name)) { + auto NewName = G.intern(mangle(Name)); + Sym->setName(NewName); } } } diff --git a/lib/LLVMPasses/ARCEntryPointBuilder.h b/lib/LLVMPasses/ARCEntryPointBuilder.h index 9e92f3f2349de..8f069e7a3f097 100644 --- a/lib/LLVMPasses/ARCEntryPointBuilder.h +++ b/lib/LLVMPasses/ARCEntryPointBuilder.h @@ -251,11 +251,16 @@ class ARCEntryPointBuilder { auto *ObjectPtrTy = PtrTy; auto &M = getModule(); - auto AttrList = AttributeList::get(M.getContext(), 1, Attribute::NoCapture); - AttrList = AttrList.addFnAttribute(M.getContext(), Attribute::NoUnwind); + auto &C = M.getContext(); + + AttributeList AttrList; + AttrList = AttrList.addFnAttribute(C, Attribute::NoUnwind); + AttrList = AttrList.addParamAttribute( + C, 0, Attribute::getWithCaptureInfo(C, llvm::CaptureInfo::none())); + CheckUnowned = cast( M.getOrInsertFunction("swift_checkUnowned", AttrList, - Type::getVoidTy(M.getContext()), ObjectPtrTy) + Type::getVoidTy(C), ObjectPtrTy) .getCallee()); if (llvm::Triple(M.getTargetTriple()).isOSBinFormatCOFF() && !llvm::Triple(M.getTargetTriple()).isOSCygMing()) diff --git a/lib/LLVMPasses/LLVMARCOpts.cpp b/lib/LLVMPasses/LLVMARCOpts.cpp index e66650b1bfb1b..16d9d2874ff3c 100644 --- a/lib/LLVMPasses/LLVMARCOpts.cpp +++ b/lib/LLVMPasses/LLVMARCOpts.cpp @@ -398,7 +398,7 @@ static bool performLocalReleaseMotion(CallInst &Release, BasicBlock &BB, // there) move the release to the top of the block. // TODO: This is where we'd plug in some global algorithms someday. if (&*BBI != &Release) { - Release.moveBefore(&*BBI); + Release.moveBefore(BBI); return true; } @@ -520,7 +520,7 @@ static bool performLocalRetainMotion(CallInst &Retain, BasicBlock &BB, // If we were able to move the retain down, move it now. // TODO: This is where we'd plug in some global algorithms someday. if (MadeProgress) { - Retain.moveBefore(&*BBI); + Retain.moveBefore(BBI); return true; } diff --git a/lib/LLVMPasses/LLVMMergeFunctions.cpp b/lib/LLVMPasses/LLVMMergeFunctions.cpp index cc4d99e523a4b..89a58962a1637 100644 --- a/lib/LLVMPasses/LLVMMergeFunctions.cpp +++ b/lib/LLVMPasses/LLVMMergeFunctions.cpp @@ -30,7 +30,6 @@ #include "swift/Basic/Assertions.h" #include "swift/LLVMPasses/Passes.h" -#include "clang/AST/StableHash.h" #include "clang/Basic/PointerAuthOptions.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/FoldingSet.h" @@ -55,6 +54,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/SipHash.h" #include "llvm/TargetParser/Triple.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Utils/FunctionComparator.h" @@ -258,7 +258,7 @@ class SwiftMergeFunctions { FunctionEntry *First; /// A very cheap hash, used to early exit if functions do not match. - llvm::IRHash Hash; + llvm::stable_hash Hash; public: // Note the hash is recalculated potentially multiple times, but it is cheap. @@ -416,9 +416,10 @@ class SwiftMergeFunctions { if (auto *GO = dyn_cast(value)) concatenatedCalleeNames += GO->getName(); } - uint64_t rawHash = clang::getStableStringHash(concatenatedCalleeNames); + uint64_t hash = + llvm::getPointerAuthStableSipHash(concatenatedCalleeNames); IntegerType *discrTy = Type::getInt64Ty(Context); - discriminator = ConstantInt::get(discrTy, (rawHash % 0xFFFF) + 1); + discriminator = ConstantInt::get(discrTy, hash); } }; @@ -713,7 +714,7 @@ bool SwiftMergeFunctions::runOnModule(Module &M) { // All functions in the module, ordered by hash. Functions with a unique // hash value are easily eliminated. - std::vector> HashedFuncs; + std::vector> HashedFuncs; for (Function &Func : M) { if (isEligibleFunction(&Func)) { @@ -721,10 +722,11 @@ bool SwiftMergeFunctions::runOnModule(Module &M) { } } - std::stable_sort( - HashedFuncs.begin(), HashedFuncs.end(), - [](const std::pair &a, - const std::pair &b) { return a.first < b.first; }); + std::stable_sort(HashedFuncs.begin(), HashedFuncs.end(), + [](const std::pair &a, + const std::pair &b) { + return a.first < b.first; + }); std::vector FuncEntryStorage; FuncEntryStorage.reserve(HashedFuncs.size()); @@ -1044,8 +1046,9 @@ void SwiftMergeFunctions::replaceCallWithAddedPtrAuth(CallInst *origCall, copiedArgs.push_back(op); } - auto *newCall = CallInst::Create(origCall->getFunctionType(), - newCallee, copiedArgs, bundles, origCall->getName(), origCall); + auto *newCall = + CallInst::Create(origCall->getFunctionType(), newCallee, copiedArgs, + bundles, origCall->getName(), origCall->getIterator()); newCall->setAttributes(origCall->getAttributes()); newCall->setTailCallKind(origCall->getTailCallKind()); newCall->setCallingConv(origCall->getCallingConv()); @@ -1079,7 +1082,6 @@ void SwiftMergeFunctions::mergeWithParams(const FunctionInfos &FInfos, Function *NewFunction = Function::Create(funcType, FirstF->getLinkage(), FirstF->getName() + "Tm"); - NewFunction->setIsNewDbgInfoFormat(FirstF->IsNewDbgInfoFormat); NewFunction->copyAttributesFrom(FirstF); // NOTE: this function is not externally available, do ensure that we reset // the DLL storage diff --git a/lib/Markup/AST.cpp b/lib/Markup/AST.cpp index 2c94e1d49306e..92994f9ccc181 100644 --- a/lib/Markup/AST.cpp +++ b/lib/Markup/AST.cpp @@ -25,7 +25,7 @@ using namespace markup; Document::Document(ArrayRef Children) : MarkupASTNode(ASTNodeKind::Document), NumChildren(Children.size()) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } Document *Document::create(MarkupContext &MC, @@ -38,7 +38,7 @@ Document *Document::create(MarkupContext &MC, BlockQuote::BlockQuote(ArrayRef Children) : MarkupASTNode(ASTNodeKind::BlockQuote), NumChildren(Children.size()) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } BlockQuote *BlockQuote::create(MarkupContext &MC, ArrayRef Children) { @@ -72,7 +72,7 @@ List::List(ArrayRef Children, bool IsOrdered) : MarkupASTNode(ASTNodeKind::List), NumChildren(Children.size()), Ordered(IsOrdered) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } List *List::create(MarkupContext &MC, ArrayRef Children, @@ -85,7 +85,7 @@ List *List::create(MarkupContext &MC, ArrayRef Children, Item::Item(ArrayRef Children) : MarkupASTNode(ASTNodeKind::Item), NumChildren(Children.size()) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } Item *Item::create(MarkupContext &MC, ArrayRef Children) { @@ -98,7 +98,7 @@ Link::Link(StringRef Destination, ArrayRef Children) : InlineContent(ASTNodeKind::Link), NumChildren(Children.size()), Destination(Destination) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } Link *Link::create(MarkupContext &MC, StringRef Destination, @@ -114,7 +114,7 @@ Image::Image(StringRef Destination, std::optional Title, : InlineContent(ASTNodeKind::Image), NumChildren(Children.size()), Destination(Destination), Title(Title) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } Image *Image::create(MarkupContext &MC, StringRef Destination, @@ -133,7 +133,7 @@ Header::Header(unsigned Level, ArrayRef Children) : MarkupASTNode(ASTNodeKind::Header), NumChildren(Children.size()), Level(Level) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } Header *Header::create(MarkupContext &MC, unsigned Level, @@ -147,7 +147,7 @@ Paragraph::Paragraph(ArrayRef Children) : MarkupASTNode(ASTNodeKind::Paragraph), NumChildren(Children.size()) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } Paragraph *Paragraph::create(MarkupContext &MC, @@ -158,7 +158,8 @@ Paragraph *Paragraph::create(MarkupContext &MC, } InlineAttributes::InlineAttributes(StringRef Attributes, ArrayRef Children) : InlineContent(ASTNodeKind::InlineAttributes), NumChildren(Children.size()), Attributes(Attributes) { - std::uninitialized_copy(Children.begin(), Children.end(), getTrailingObjects()); + std::uninitialized_copy(Children.begin(), Children.end(), + getTrailingObjects()); } InlineAttributes *InlineAttributes::create(MarkupContext &MC, StringRef Attributes, ArrayRef Children) { @@ -190,7 +191,7 @@ LineBreak *LineBreak::create(MarkupContext &MC) { Emphasis::Emphasis(ArrayRef Children) : InlineContent(ASTNodeKind::Emphasis), NumChildren(Children.size()) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } Emphasis *Emphasis::create(MarkupContext &MC, @@ -203,7 +204,7 @@ Emphasis *Emphasis::create(MarkupContext &MC, Strong::Strong(ArrayRef Children) : InlineContent(ASTNodeKind::Strong), NumChildren(Children.size()) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } Strong *Strong::create(MarkupContext &MC, @@ -217,7 +218,7 @@ ParamField::ParamField(StringRef Name, ArrayRef Children) : PrivateExtension(ASTNodeKind::ParamField), NumChildren(Children.size()), Name(Name), Parts(std::nullopt) { std::uninitialized_copy(Children.begin(), Children.end(), - getTrailingObjects()); + getTrailingObjects()); } ParamField *ParamField::create(MarkupContext &MC, StringRef Name, @@ -237,7 +238,7 @@ Id *Id::create(MarkupContext &MC, ArrayRef Children) { \ Id::Id(ArrayRef Children) \ : PrivateExtension(ASTNodeKind::Id), NumChildren(Children.size()) { \ std::uninitialized_copy(Children.begin(), Children.end(), \ - getTrailingObjects()); \ + getTrailingObjects()); \ } #include "swift/Markup/SimpleFields.def" diff --git a/lib/Migrator/APIDiffMigratorPass.cpp b/lib/Migrator/APIDiffMigratorPass.cpp index 6052aaaa66b09..17ce0e7916f7e 100644 --- a/lib/Migrator/APIDiffMigratorPass.cpp +++ b/lib/Migrator/APIDiffMigratorPass.cpp @@ -29,7 +29,7 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Edit/EditedSource.h" -#include "clang/Rewrite/Core/RewriteBuffer.h" +#include "llvm/ADT/RewriteBuffer.h" #include "llvm/Support/FileSystem.h" using namespace swift; diff --git a/lib/Migrator/Migrator.cpp b/lib/Migrator/Migrator.cpp index 7549d14200480..857e30eb3dead 100644 --- a/lib/Migrator/Migrator.cpp +++ b/lib/Migrator/Migrator.cpp @@ -21,7 +21,7 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Edit/EditedSource.h" -#include "clang/Rewrite/Core/RewriteBuffer.h" +#include "llvm/ADT/RewriteBuffer.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" @@ -191,11 +191,11 @@ bool Migrator::performSyntacticPasses(SyntacticPassOptions Opts) { llvm::IntrusiveRefCntPtr DummyClangDiagIDs { new clang::DiagnosticIDs() }; - auto ClangDiags = - std::make_unique(DummyClangDiagIDs, - new clang::DiagnosticOptions, - new clang::DiagnosticConsumer(), - /*ShouldOwnClient=*/true); + + clang::DiagnosticOptions diagOpts; + auto ClangDiags = std::make_unique( + DummyClangDiagIDs, diagOpts, new clang::DiagnosticConsumer(), + /*ShouldOwnClient=*/true); clang::SourceManager ClangSourceManager { *ClangDiags, ClangFileManager }; clang::LangOptions ClangLangOpts; diff --git a/lib/Option/Options.cpp b/lib/Option/Options.cpp index 6a159de3150ba..5a334e131bcc1 100644 --- a/lib/Option/Options.cpp +++ b/lib/Option/Options.cpp @@ -16,15 +16,16 @@ #include "llvm/Option/OptTable.h" #include "llvm/Option/Option.h" -using namespace swift::options; -using namespace llvm::opt; +#define OPTTABLE_STR_TABLE_CODE +#include "swift/Option/Options.inc" +#undef OPTTABLE_STR_TABLE_CODE -#define PREFIX(NAME, VALUE) \ - constexpr llvm::StringLiteral NAME##_init[] = VALUE; \ - constexpr llvm::ArrayRef NAME( \ - NAME##_init, std::size(NAME##_init) - 1); +#define OPTTABLE_PREFIXES_TABLE_CODE #include "swift/Option/Options.inc" -#undef PREFIX +#undef OPTTABLE_PREFIXES_TABLE_CODE + +using namespace swift::options; +using namespace llvm::opt; static const llvm::opt::GenericOptTable::Info InfoTable[] = { #define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__), @@ -36,7 +37,8 @@ namespace { class SwiftOptTable : public llvm::opt::GenericOptTable { public: - SwiftOptTable() : GenericOptTable(InfoTable) {} + SwiftOptTable() + : GenericOptTable(OptionStrTable, OptionPrefixesTable, InfoTable) {} }; } // end anonymous namespace diff --git a/lib/PrintAsClang/_SwiftStdlibCxxOverlay.h b/lib/PrintAsClang/_SwiftStdlibCxxOverlay.h index a29ec356cb9e8..885bbb3773ad8 100644 --- a/lib/PrintAsClang/_SwiftStdlibCxxOverlay.h +++ b/lib/PrintAsClang/_SwiftStdlibCxxOverlay.h @@ -171,8 +171,13 @@ struct SymbolicP { } __attribute__((packed)); SWIFT_INLINE_THUNK const void *_Nullable getErrorMetadata() { +// We do not care about these symbols being duplicated across multiple shared +// libraries for now. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunique-object-duplication" static SymbolicP errorSymbol; static int *_Nonnull got_ss5ErrorMp = &$ss5ErrorMp; +#pragma clang diagnostic pop errorSymbol._1 = 2; errorSymbol._2 = static_cast(reinterpret_cast(&got_ss5ErrorMp) - diff --git a/lib/SIL/IR/SILConstants.cpp b/lib/SIL/IR/SILConstants.cpp index 3996a1c3694c4..7005fd7e2965b 100644 --- a/lib/SIL/IR/SILConstants.cpp +++ b/lib/SIL/IR/SILConstants.cpp @@ -455,7 +455,7 @@ struct AggregateSymbolicValue final auto *aggregate = ::new (rawMem) AggregateSymbolicValue(aggregateType, members.size()); std::uninitialized_copy(members.begin(), members.end(), - aggregate->getTrailingObjects()); + aggregate->getTrailingObjects()); return aggregate; } @@ -464,7 +464,7 @@ struct AggregateSymbolicValue final /// Return the symbolic values of members. ArrayRef getMemberValues() const { - return {getTrailingObjects(), numElements}; + return getTrailingObjects(numElements); } // This is used by the llvm::TrailingObjects base class. @@ -531,12 +531,12 @@ struct alignas(SourceLoc) UnknownSymbolicValue final auto value = ::new (rawMem) UnknownSymbolicValue( node, reason, static_cast(elements.size())); std::uninitialized_copy(elements.begin(), elements.end(), - value->getTrailingObjects()); + value->getTrailingObjects()); return value; } ArrayRef getCallStack() const { - return {getTrailingObjects(), callStackSize}; + return getTrailingObjects(callStackSize); } // This is used by the llvm::TrailingObjects base class. @@ -657,14 +657,14 @@ struct DerivedAddressValue final auto dav = ::new (rawMem) DerivedAddressValue(memoryObject, elements.size()); std::uninitialized_copy(elements.begin(), elements.end(), - dav->getTrailingObjects()); + dav->getTrailingObjects()); return dav; } /// Return the access path for this derived address, which is an array of /// indices drilling into the memory object. ArrayRef getElements() const { - return {getTrailingObjects(), numElements}; + return getTrailingObjects(numElements); } // This is used by the llvm::TrailingObjects base class. @@ -749,13 +749,13 @@ struct SymbolicArrayStorage final auto *storage = ::new (rawMem) SymbolicArrayStorage(elementType, elements.size()); std::uninitialized_copy(elements.begin(), elements.end(), - storage->getTrailingObjects()); + storage->getTrailingObjects()); return storage; } /// Return the stored elements. ArrayRef getElements() const { - return {getTrailingObjects(), numElements}; + return getTrailingObjects(numElements); } // This is used by the llvm::TrailingObjects base class. @@ -872,9 +872,8 @@ SymbolicClosure *SymbolicClosure::create(SILFunction *target, // Placement initialize the object. auto closure = ::new (rawMem) SymbolicClosure( target, args.size(), substMap, closureInst, hasNonConstantCapture); - std::uninitialized_copy( - args.begin(), args.end(), - closure->getTrailingObjects()); + std::uninitialized_copy(args.begin(), args.end(), + closure->getTrailingObjects()); return closure; } diff --git a/lib/SIL/IR/SILInstruction.cpp b/lib/SIL/IR/SILInstruction.cpp index 9c0d392ae5f42..137c57371e0e5 100644 --- a/lib/SIL/IR/SILInstruction.cpp +++ b/lib/SIL/IR/SILInstruction.cpp @@ -1026,15 +1026,15 @@ MemoryBehavior SILInstruction::getMemoryBehavior() const { // Handle LLVM intrinsic functions. const IntrinsicInfo &IInfo = BI->getIntrinsicInfo(); if (IInfo.ID != llvm::Intrinsic::not_intrinsic) { - auto IAttrs = IInfo.getOrCreateAttributes(getModule().getASTContext()); + auto &IAttrs = IInfo.getOrCreateFnAttributes(getModule().getASTContext()); auto MemEffects = IAttrs.getMemoryEffects(); // Read-only. if (MemEffects.onlyReadsMemory() && - IAttrs.hasFnAttr(llvm::Attribute::NoUnwind)) + IAttrs.hasAttribute(llvm::Attribute::NoUnwind)) return MemoryBehavior::MayRead; // Read-none? return MemEffects.doesNotAccessMemory() && - IAttrs.hasFnAttr(llvm::Attribute::NoUnwind) + IAttrs.hasAttribute(llvm::Attribute::NoUnwind) ? MemoryBehavior::None : MemoryBehavior::MayHaveSideEffects; } diff --git a/lib/SIL/IR/SILInstructions.cpp b/lib/SIL/IR/SILInstructions.cpp index 19892dafade05..06c61cc97af17 100644 --- a/lib/SIL/IR/SILInstructions.cpp +++ b/lib/SIL/IR/SILInstructions.cpp @@ -539,7 +539,7 @@ IncrementProfilerCounterInst *IncrementProfilerCounterInst::create( Loc, CounterIdx, PGOFuncNameLength, NumCounters, PGOFuncHash); std::uninitialized_copy(PGOFuncName.begin(), PGOFuncName.end(), - Inst->getTrailingObjects()); + Inst->getTrailingObjects()); return Inst; } @@ -554,7 +554,7 @@ SpecifyTestInst *SpecifyTestInst::create(SILDebugLocation Loc, ::new (Buffer) SpecifyTestInst(Loc, ArgumentsSpecificationLength); std::uninitialized_copy(ArgumentsSpecification.begin(), ArgumentsSpecification.end(), - Inst->getTrailingObjects()); + Inst->getTrailingObjects()); return Inst; } @@ -1121,7 +1121,7 @@ IntegerLiteralInst::IntegerLiteralInst(SILDebugLocation Loc, SILType Ty, : InstructionBase(Loc, Ty) { sharedUInt32().IntegerLiteralInst.numBits = Value.getBitWidth(); std::uninitialized_copy_n(Value.getRawData(), Value.getNumWords(), - getTrailingObjects()); + getTrailingObjects()); } IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc, @@ -1182,8 +1182,7 @@ IntegerLiteralInst *IntegerLiteralInst::create(IntegerLiteralExpr *E, /// getValue - Return the APInt for the underlying integer literal. APInt IntegerLiteralInst::getValue() const { auto numBits = sharedUInt32().IntegerLiteralInst.numBits; - return APInt(numBits, {getTrailingObjects(), - getWordsForBitWidth(numBits)}); + return APInt(numBits, getTrailingObjects(getWordsForBitWidth(numBits))); } FloatLiteralInst::FloatLiteralInst(SILDebugLocation Loc, SILType Ty, @@ -1191,7 +1190,7 @@ FloatLiteralInst::FloatLiteralInst(SILDebugLocation Loc, SILType Ty, : InstructionBase(Loc, Ty) { sharedUInt32().FloatLiteralInst.numBits = Bits.getBitWidth(); std::uninitialized_copy_n(Bits.getRawData(), Bits.getNumWords(), - getTrailingObjects()); + getTrailingObjects()); } FloatLiteralInst *FloatLiteralInst::create(SILDebugLocation Loc, SILType Ty, @@ -1222,8 +1221,7 @@ FloatLiteralInst *FloatLiteralInst::create(FloatLiteralExpr *E, APInt FloatLiteralInst::getBits() const { auto numBits = sharedUInt32().FloatLiteralInst.numBits; - return APInt(numBits, {getTrailingObjects(), - getWordsForBitWidth(numBits)}); + return APInt(numBits, getTrailingObjects(getWordsForBitWidth(numBits))); } APFloat FloatLiteralInst::getValue() const { @@ -1236,7 +1234,7 @@ StringLiteralInst::StringLiteralInst(SILDebugLocation Loc, StringRef Text, : InstructionBase(Loc, Ty) { sharedUInt8().StringLiteralInst.encoding = uint8_t(encoding); sharedUInt32().StringLiteralInst.length = Text.size(); - memcpy(getTrailingObjects(), Text.data(), Text.size()); + memcpy(getTrailingObjects(), Text.data(), Text.size()); // It is undefined behavior to feed ill-formed UTF-8 into `Swift.String`; // however, the compiler creates string literals in many places, so there's a @@ -1262,7 +1260,7 @@ CondFailInst::CondFailInst(SILDebugLocation DebugLoc, SILValue Operand, StringRef Message) : UnaryInstructionBase(DebugLoc, Operand), MessageSize(Message.size()) { - memcpy(getTrailingObjects(), Message.data(), Message.size()); + memcpy(getTrailingObjects(), Message.data(), Message.size()); } CondFailInst *CondFailInst::create(SILDebugLocation DebugLoc, SILValue Operand, @@ -3073,14 +3071,14 @@ KeyPathPattern::KeyPathPattern(CanGenericSignature signature, Signature(signature), RootType(rootType), ValueType(valueType), ObjCString(objcString) { - auto *componentsBuf = getTrailingObjects(); + auto *componentsBuf = getTrailingObjects(); std::uninitialized_copy(components.begin(), components.end(), componentsBuf); } ArrayRef KeyPathPattern::getComponents() const { - return {getTrailingObjects(), NumComponents}; + return getTrailingObjects(NumComponents); } void KeyPathPattern::Profile(llvm::FoldingSetNodeID &ID, @@ -3184,7 +3182,7 @@ KeyPathInst::KeyPathInst(SILDebugLocation Loc, Substitutions(Subs.getCanonical()) { assert(allOperands.size() >= numPatternOperands); - auto *operandsBuf = getTrailingObjects(); + auto *operandsBuf = getTrailingObjects(); for (unsigned i = 0; i < allOperands.size(); ++i) { ::new ((void*)&operandsBuf[i]) Operand(this, allOperands[i]); } @@ -3197,7 +3195,7 @@ KeyPathInst::KeyPathInst(SILDebugLocation Loc, MutableArrayRef KeyPathInst::getAllOperands() { - return {getTrailingObjects(), numPatternOperands + numTypeDependentOperands}; + return getTrailingObjects(numPatternOperands + numTypeDependentOperands); } KeyPathInst::~KeyPathInst() { diff --git a/lib/SIL/IR/SILModule.cpp b/lib/SIL/IR/SILModule.cpp index df0f588565155..ff87beb0d1b8d 100644 --- a/lib/SIL/IR/SILModule.cpp +++ b/lib/SIL/IR/SILModule.cpp @@ -888,8 +888,8 @@ void SILModule::notifyMovedInstruction(SILInstruction *inst, bool SILModule::isNoReturnBuiltinOrIntrinsic(Identifier Name) { const auto &IntrinsicInfo = getIntrinsicInfo(Name); if (IntrinsicInfo.ID != llvm::Intrinsic::not_intrinsic) { - return IntrinsicInfo.getOrCreateAttributes(getASTContext()) - .hasFnAttr(llvm::Attribute::NoReturn); + return IntrinsicInfo.getOrCreateFnAttributes(getASTContext()) + .hasAttribute(llvm::Attribute::NoReturn); } const auto &BuiltinInfo = getBuiltinInfo(Name); switch (BuiltinInfo.ID) { diff --git a/lib/SIL/IR/SILVTable.cpp b/lib/SIL/IR/SILVTable.cpp index c62e6d4764d00..241e127fb3ba8 100644 --- a/lib/SIL/IR/SILVTable.cpp +++ b/lib/SIL/IR/SILVTable.cpp @@ -95,8 +95,7 @@ SILVTable::SILVTable(ClassDecl *c, SILType classType, SerializedKind_t serialized, ArrayRef entries) : Class(c), classType(classType), SerializedKind(serialized), NumEntries(entries.size()) { - std::uninitialized_copy(entries.begin(), entries.end(), - getTrailingObjects()); + std::uninitialized_copy(entries.begin(), entries.end(), getTrailingObjects()); // Bump the reference count of functions referenced by this table. for (const Entry &entry : getEntries()) { diff --git a/lib/SILOptimizer/Analysis/ARCAnalysis.cpp b/lib/SILOptimizer/Analysis/ARCAnalysis.cpp index 4740b4b3090f4..702029bac29d3 100644 --- a/lib/SILOptimizer/Analysis/ARCAnalysis.cpp +++ b/lib/SILOptimizer/Analysis/ARCAnalysis.cpp @@ -104,7 +104,7 @@ static bool canApplyOfBuiltinUseNonTrivialValues(BuiltinInst *BInst) { auto &II = BInst->getIntrinsicInfo(); if (II.ID != llvm::Intrinsic::not_intrinsic) { - auto attrs = II.getOrCreateAttributes(F->getASTContext()); + auto &attrs = II.getOrCreateFnAttributes(F->getASTContext()); if (attrs.getMemoryEffects().doesNotAccessMemory()) { for (auto &Op : BInst->getAllOperands()) { if (!Op.get()->getType().isTrivial(*F)) { diff --git a/lib/SILOptimizer/Analysis/ColdBlockInfo.cpp b/lib/SILOptimizer/Analysis/ColdBlockInfo.cpp index f42fe7b60d449..9fde5f1ea0431 100644 --- a/lib/SILOptimizer/Analysis/ColdBlockInfo.cpp +++ b/lib/SILOptimizer/Analysis/ColdBlockInfo.cpp @@ -441,7 +441,7 @@ bool ColdBlockInfo::isCold(const SILBasicBlock *BB) const { } void ColdBlockInfo::resetToCold(const SILBasicBlock *BB) { - auto &entry = EnergyMap.getOrInsertDefault(BB); + auto &entry = EnergyMap[BB]; if (isColdEnergy(entry)) return; @@ -451,7 +451,7 @@ void ColdBlockInfo::resetToCold(const SILBasicBlock *BB) { } void ColdBlockInfo::set(const SILBasicBlock *BB, State::Temperature temp) { - auto &entry = EnergyMap.getOrInsertDefault(BB); + auto &entry = EnergyMap[BB]; if (entry.contains(temp)) return; diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 4646e9b0c5ef8..703cabb4c970e 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -8489,7 +8489,8 @@ class SwiftToClangBasicReader : bool isRegularKeywordAttribute = readBool(); clang::AttributeCommonInfo info( - name, scopeName, {rangeStart, rangeEnd}, scopeLoc, parsedKind, + name, clang::AttributeScopeInfo(scopeName, scopeLoc), + {rangeStart, rangeEnd}, parsedKind, {syntax, spellingListIndex, /*IsAlignas=*/false, isRegularKeywordAttribute}); @@ -8518,6 +8519,9 @@ class SwiftToClangBasicReader : clang::TypeCoupledDeclRefInfo readTypeCoupledDeclRefInfo() { llvm_unreachable("TypeCoupledDeclRefInfo shouldn't be reached from swift"); } + clang::SpirvOperand readHLSLSpirvOperand() { + llvm_unreachable("SpirvOperand shouldn't be reached from swift"); + } }; } // end anonymous namespace @@ -8773,7 +8777,7 @@ class LazyConformanceLoaderInfo final LazyConformanceLoaderInfo(ArrayRef ids) : NumConformances(ids.size()) { - auto buffer = getTrailingObjects(); + auto *buffer = getTrailingObjects(); for (unsigned i = 0, e = ids.size(); i != e; ++i) buffer[i] = ProtocolConformanceID(ids[i]); } @@ -8791,8 +8795,7 @@ class LazyConformanceLoaderInfo final ArrayRef claim() { // TODO: free the memory here (if it's not used in multiple places?) - return llvm::ArrayRef(getTrailingObjects(), - NumConformances); + return getTrailingObjects(NumConformances); } }; } // end anonymous namespace diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index a53aee6299c4d..413d7efe3adca 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -6317,6 +6317,9 @@ class ClangToSwiftBasicWriter : void writeTypeCoupledDeclRefInfo(clang::TypeCoupledDeclRefInfo info) { llvm_unreachable("TypeCoupledDeclRefInfo shouldn't be reached from swift"); } + void writeHLSLSpirvOperand(clang::SpirvOperand) { + llvm_unreachable("SpirvOperand shouldn't be reached from swift"); + } }; } diff --git a/lib/StaticMirror/ObjectFileContext.cpp b/lib/StaticMirror/ObjectFileContext.cpp index 4ad8d5c3ce3e5..ed8239ebb183d 100644 --- a/lib/StaticMirror/ObjectFileContext.cpp +++ b/lib/StaticMirror/ObjectFileContext.cpp @@ -29,6 +29,7 @@ #include "llvm/Object/ELFTypes.h" #include "llvm/Object/MachOUniversal.h" #include "llvm/Object/RelocationResolver.h" +#include "llvm/Object/Wasm.h" #include "llvm/Support/Error.h" #include "llvm/Support/StringSaver.h" @@ -266,6 +267,38 @@ void Image::scanCOFF(const llvm::object::COFFObjectFile *O) { Segments.push_back({HeaderAddress, O->getData()}); } +void Image::scanWasm(const llvm::object::WasmObjectFile *O) { + HeaderAddress = 0; + + auto resolver = getRelocationResolver(*O); + auto resolverSupports = resolver.first; + auto resolve = resolver.second; + + if (!resolverSupports || !resolve) + return; + + for (auto SectionRef : O->sections()) { + auto Section = O->getWasmSection(SectionRef); + for (auto &r : Section.Relocations) { + auto sym = O->symbol_begin(); + for (unsigned i = 0; sym != O->symbol_end() && i < r.Index; ++i) + ++sym; + if (sym == O->symbol_end()) + continue; + auto &wsym = O->getWasmSymbol(*sym); + if (!resolverSupports(r.Type)) { + llvm::errs() << "Unsupported +" << r.Offset << " " << wsym.Info.Name + << " +" << r.Addend << "\n"; + continue; + } + uint64_t offset = resolve(r.Type, r.Offset, 0, 0, r.Addend); + DynamicRelocations.insert({r.Offset, {wsym.Info.Name, offset}}); + } + } + + Segments.push_back({HeaderAddress, O->getData()}); +} + bool Image::isMachOWithPtrAuth() const { auto macho = dyn_cast(O); if (!macho) @@ -286,6 +319,8 @@ Image::Image(const llvm::object::ObjectFile *O) : O(O) { scanELF(elf); } else if (auto coff = dyn_cast(O)) { scanCOFF(coff); + } else if (auto wasm = dyn_cast(O)) { + scanWasm(wasm); } else { fputs("unsupported image format\n", stderr); abort(); diff --git a/test/CAS/debug_info_pcm.swift b/test/CAS/debug_info_pcm.swift new file mode 100644 index 0000000000000..2bd1f56b8eb43 --- /dev/null +++ b/test/CAS/debug_info_pcm.swift @@ -0,0 +1,43 @@ +// REQUIRES: OS=macosx +// RUN: %empty-directory(%t) +// RUN: split-file %s %t + +// RUN: %target-swift-frontend -scan-dependencies -module-name Test -module-cache-path %t/clang-module-cache -O \ +// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \ +// RUN: %t/test.swift -o %t/deps.json -cache-compile-job -cas-path %t/cas -I %t/include + +// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/shim.cmd +// RUN: %swift_frontend_plain @%t/shim.cmd +// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:B > %t/B.cmd +// RUN: %swift_frontend_plain @%t/B.cmd +// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json clang:A > %t/A.cmd +// RUN: %swift_frontend_plain @%t/A.cmd +// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json clang:A modulePath > %t/A.path + +// RUN: dwarfdump --debug-info @%t/A.path | %FileCheck %s + +// CHECK: DW_AT_GNU_dwo_name +// CHECK-SAME: BUILD_DIR + +//--- test.swift +import A + +//--- include/a.h +#include "b.h" +struct A { + int a; +}; + +//--- include/b.h +void b(void); + +//--- include/module.modulemap +module A { + header "a.h" + export * +} + +module B { + header "b.h" + export * +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 34eaf125dfc02..98fdb1942b5fe 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -135,7 +135,8 @@ function(get_test_dependencies SDK result_var_name) llvm-strings llvm-readtapi not - split-file) + split-file + yaml2obj) endif() if(("${SDK}" STREQUAL "IOS") OR diff --git a/test/ClangImporter/broken-modules.swift b/test/ClangImporter/broken-modules.swift index 7ca1bda9e8ca6..288d59791787b 100644 --- a/test/ClangImporter/broken-modules.swift +++ b/test/ClangImporter/broken-modules.swift @@ -1,6 +1,6 @@ // RUN: not %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules/ -enable-objc-interop -show-diagnostics-after-fatal -D MISSING_FROM_MODULE -o /dev/null 2>&1 | %FileCheck -check-prefix CHECK-MODULE-MAP %s // RUN: not %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules/ -enable-objc-interop -show-diagnostics-after-fatal -o /dev/null 2>&1 | %FileCheck -check-prefix CHECK -check-prefix CHECK-DIRECT %s -// RUN: not %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules/ -enable-objc-interop -show-diagnostics-after-fatal -D INDIRECT -o /dev/null 2>&1 | %FileCheck -check-prefix CHECK -check-prefix CHECK-INDIRECT %s +// RUN: not %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules/ -I %S/Inputs/custom-modules/more-custom-modules -enable-objc-interop -show-diagnostics-after-fatal -D INDIRECT -o /dev/null 2>&1 | %FileCheck -check-prefix CHECK -check-prefix CHECK-INDIRECT %s // FIXME: not every test here depends on Objective-C syntax, this test can be split. diff --git a/test/DebugInfo/EagerTypeMetadata.swift b/test/DebugInfo/EagerTypeMetadata.swift index 1f53cb5cae90e..e216d788fc7de 100644 --- a/test/DebugInfo/EagerTypeMetadata.swift +++ b/test/DebugInfo/EagerTypeMetadata.swift @@ -13,6 +13,6 @@ public class C } // CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "T", // CHECK-SAME: baseType: ![[PTRTY:[0-9]+]] -// CHECK: ![[PTRTY]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "$sBpD", baseType: null, size: {{64|32}}, flags: DIFlagArtificial | DIFlagObjectPointer) +// CHECK: ![[PTRTY]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "$sBpD", baseType: null, size: {{64|32}}) // CHECK: ![[LOC]] = !DILocation(line: 0, diff --git a/test/DebugInfo/Imports.swift b/test/DebugInfo/Imports.swift index ce98458c03040..d79a5fe62a37c 100644 --- a/test/DebugInfo/Imports.swift +++ b/test/DebugInfo/Imports.swift @@ -1,5 +1,5 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-frontend -emit-module-path %t/basic.swiftmodule %S/basic.swift +// RUN: %target-swift-frontend -emit-module-path %t/advanced.swiftmodule %S/advanced.swift // RUN: %target-swift-frontend -emit-ir -module-name Foo %s -I %t -g -o - | %FileCheck %s // RUN: %target-swift-frontend -c -module-name Foo %s -I %t -g -o %t.o @@ -10,13 +10,13 @@ // CHECK-DAG: ![[THISFILE]] = !DIFile(filename: "{{.*}}test{{/|\\\\}}DebugInfo{{/|\\\\}}Imports.swift", // CHECK-DAG: ![[SWIFTMODULE:[0-9]+]] = !DIModule({{.*}}, name: "Swift" // CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[THISFILE]], entity: ![[SWIFTMODULE]] -// CHECK-DAG: ![[BASICMODULE:[0-9]+]] = !DIModule({{.*}}, name: "basic" +// CHECK-DAG: ![[BASICMODULE:[0-9]+]] = !DIModule({{.*}}, name: "advanced" // CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[THISFILE]], entity: ![[BASICMODULE]] -import basic +import advanced import typealias Swift.Optional func markUsed(_ t: T) {} -markUsed(basic.foo(1, 2)) +markUsed(advanced.foo(1, 2)) // DWARF: .debug_info // DWARF: DW_TAG_module @@ -26,7 +26,7 @@ markUsed(basic.foo(1, 2)) // DWARF: DW_AT_name ("Swift") // DWARF: DW_AT_LLVM_include_path // DWARF: DW_TAG_module -// DWARF: DW_AT_name ("basic") +// DWARF: DW_AT_name ("advanced") // DWARF-NOT: "Swift.Optional" diff --git a/test/DebugInfo/ParseableInterfaceImports.swift b/test/DebugInfo/ParseableInterfaceImports.swift index e05c0533a8411..1a13c2543d56c 100644 --- a/test/DebugInfo/ParseableInterfaceImports.swift +++ b/test/DebugInfo/ParseableInterfaceImports.swift @@ -1,23 +1,23 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-frontend-typecheck %S/basic.swift \ -// RUN: -emit-module-interface-path %t/basic.swiftinterface +// RUN: %target-swift-frontend-typecheck %S/advanced.swift \ +// RUN: -emit-module-interface-path %t/advanced.swiftinterface // RUN: %target-swift-frontend -emit-ir -module-name Foo %s -I %t -g -o - \ // RUN: | %FileCheck %s // RUN: %target-swift-frontend -emit-ir -module-name Foo %s -I %t -g -o - \ // RUN: -sdk %t | %FileCheck %s --check-prefix=SDK -import basic +import advanced -// CHECK: !DIModule(scope: null, name: "basic", +// CHECK: !DIModule(scope: null, name: "advanced", // CHECK-SAME: includePath: " -// CHECK-SAME: basic.swiftinterface" +// CHECK-SAME: advanced.swiftinterface" // Even if the module interface is in the SDK, we still return the path // to the swiftinterface. -// SDK: !DIModule(scope: null, name: "basic", +// SDK: !DIModule(scope: null, name: "advanced", // SDK-SAME: includePath: " -// SDK-SAME: basic{{.*}}.swiftinterface" +// SDK-SAME: advanced{{.*}}.swiftinterface" func markUsed(_ t: T) {} -markUsed(basic.foo(1, 2)) +markUsed(advanced.foo(1, 2)) diff --git a/test/DebugInfo/advanced.swift b/test/DebugInfo/advanced.swift new file mode 100644 index 0000000000000..7fe50b54106b1 --- /dev/null +++ b/test/DebugInfo/advanced.swift @@ -0,0 +1,81 @@ +// A (no longer) basic test for debug info. +// -------------------------------------------------------------------- +// Verify that we don't emit any type info with -gline-tables-only. +// RUN: %target-swift-frontend %s -emit-ir -gline-tables-only -o - \ +// RUN: | %FileCheck %s --check-prefix CHECK-LINETABLES +// CHECK: !dbg +// CHECK-LINETABLES-NOT: DI{{.*}}Variable +// CHECK-LINETABLES-NOT: DW_TAG_structure_type +// CHECK-LINETABLES-NOT: DIBasicType +// -------------------------------------------------------------------- +// Now check that we do generate line+scope info with -g. +// RUN: %target-swift-frontend %/s -emit-ir -g -o - \ +// RUN: | %FileCheck %s --check-prefixes CHECK,DWARF-CHECK +// -------------------------------------------------------------------- +// Currently -gdwarf-types should give the same results as -g. +// RUN: %target-swift-frontend %/s -emit-ir -gdwarf-types -o - \ +// RUN: | %FileCheck %s --check-prefixes CHECK,DWARF-CHECK +// -------------------------------------------------------------------- +// Verify that -g -debug-info-format=dwarf gives the same results as -g. +// RUN: %target-swift-frontend %/s -emit-ir -g -debug-info-format=dwarf -o - \ +// RUN: | %FileCheck %s --check-prefixes CHECK,DWARF-CHECK +// -------------------------------------------------------------------- +// RUN: %target-swift-frontend %/s -emit-ir -g -debug-info-format=codeview -o - \ +// RUN: | %FileCheck %s --check-prefixes CHECK,CV-CHECK +// -------------------------------------------------------------------- +// +// CHECK: foo +// CHECK-DAG: ret{{.*}}, !dbg ![[RET:[0-9]+]] +// CHECK-DAG: ![[FOO:[0-9]+]] = distinct !DISubprogram(name: "foo",{{.*}} line: [[@LINE+2]],{{.*}} type: ![[FOOTYPE:[0-9]+]] +public +func foo(_ a: Int64, _ b: Int64) -> Int64 { + var a = a + var b = b + // CHECK-DAG: ![[ALOC:.*]] = !DILocation(line: [[@LINE-3]],{{.*}} scope: ![[FOO]]) + // Check that a is the first and b is the second argument. + // CHECK-DAG: store i64 %0, ptr [[AADDR:.*]], align + // CHECK-DAG: store i64 %1, ptr [[BADDR:.*]], align + // CHECK-DAG: [[AVAL:%.*]] = getelementptr inbounds {{.*}}, [[AMEM:.*]], i32 0, i32 0 + // CHECK-DAG: [[BVAL:%.*]] = getelementptr inbounds {{.*}}, [[BMEM:.*]], i32 0, i32 0 + // CHECK-DAG: #dbg_declare(ptr [[AADDR]], ![[AARG:.*]], !DIExpression(), ![[ALOC]] + // CHECK-DAG: #dbg_declare(ptr [[BADDR]], ![[BARG:.*]], !DIExpression() + // CHECK-DAG: ![[AARG]] = !DILocalVariable(name: "a", arg: 1 + // CHECK-DAG: ![[BARG]] = !DILocalVariable(name: "b", arg: 2 + if b != 0 { + // CHECK-DAG: !DILexicalBlock({{.*}} line: [[@LINE-1]] + // Transparent inlined multiply: + // CHECK-DAG: smul{{.*}}, !dbg ![[MUL:[0-9]+]] + // CHECK-DAG: [[MUL]] = !DILocation(line: [[@LINE+1]], + return a*b + } else { + // CHECK-DAG: ![[PARENT:[0-9]+]] = distinct !DILexicalBlock({{.*}} line: [[@LINE-1]] + // CHECK-DAG: ![[VARSCOPE:[0-9]+]] = distinct !DILexicalBlock({{.*}} line: [[@LINE+1]] + var c: Int64 = 42 + // CHECK-DAG: ![[CONDITION:[0-9]+]] = distinct !DILexicalBlock(scope: ![[VARSCOPE]], {{.*}}, line: [[@LINE+1]] + if a == 0 { + // CHECK-DAG: !DILexicalBlock(scope: ![[CONDITION]], {{.*}}, line: [[@LINE-1]] + // What about a nested scope? + return 0 + } + return c + } +} + +// CHECK-DAG: ![[MAINFILE:[0-9]+]] = !DIFile(filename: "{{.*}}DebugInfo/advanced.swift", directory: "{{.*}}") +// CHECK-DAG: !DICompileUnit(language: DW_LANG_Swift, file: ![[MAINFILE]],{{.*}} producer: "{{.*}}Swift version{{.*}},{{.*}} +// CHECK-DAG: !DISubprogram(name: "main", {{.*}}file: ![[MAINFILE]], + +// Function type for foo. +// CHECK-DAG: ![[FOOTYPE]] = !DISubroutineType(types: ![[PARAMTYPES:[0-9]+]]) +// CHECK-DAG: ![[INT64:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Int64", {{.*}}, identifier: "$ss5Int64VD") +// CHECK-DAG: ![[PARAMTYPES]] = !{![[INT64]], ![[INT64]], ![[INT64]]} +// Import of the main module with the implicit name. +// CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[MAINFILE]], entity: ![[MAINMODULE:[0-9]+]], file: ![[MAINFILE]]) +// CHECK-DAG: ![[MAINMODULE]] = !DIModule({{.*}}, name: "advanced" + +// DWARF Version +// DWARF-CHECK-DAG: i32 7, !"Dwarf Version", i32 4} +// CV-CHECK-DAG: i32 2, !"CodeView", i32 1} + +// Debug Info Version +// CHECK-DAG: i32 2, !"Debug Info Version", i32 diff --git a/test/DebugInfo/basic.swift b/test/DebugInfo/basic.swift index ca64ef87f9bf2..8f2ff92818b67 100644 --- a/test/DebugInfo/basic.swift +++ b/test/DebugInfo/basic.swift @@ -1,6 +1,8 @@ -// A (no longer) basic test for debug info. +// A basic test for debug info. +// UNSUPPORTED: OS=windows-msvc // -------------------------------------------------------------------- -// Verify that we don't emit any debug info by default. +// Verify that we don't emit any debug info by default. This test has a +// specific Windows implementation in debug_basic_windows.swift. // RUN: %target-swift-frontend %s -emit-ir -o - \ // RUN: | %FileCheck %s --check-prefix NDEBUG // NDEBUG: source_filename @@ -10,83 +12,7 @@ // Verify that we don't emit any debug info with -gnone. // RUN: %target-swift-frontend %s -emit-ir -gnone -o - \ // RUN: | %FileCheck %s --check-prefix NDEBUG -// -------------------------------------------------------------------- -// Verify that we don't emit any type info with -gline-tables-only. -// RUN: %target-swift-frontend %s -emit-ir -gline-tables-only -o - \ -// RUN: | %FileCheck %s --check-prefix CHECK-LINETABLES -// CHECK: !dbg -// CHECK-LINETABLES-NOT: DI{{.*}}Variable -// CHECK-LINETABLES-NOT: DW_TAG_structure_type -// CHECK-LINETABLES-NOT: DIBasicType -// -------------------------------------------------------------------- -// Now check that we do generate line+scope info with -g. -// RUN: %target-swift-frontend %/s -emit-ir -g -o - \ -// RUN: | %FileCheck %s --check-prefixes CHECK,DWARF-CHECK -// -------------------------------------------------------------------- -// Currently -gdwarf-types should give the same results as -g. -// RUN: %target-swift-frontend %/s -emit-ir -gdwarf-types -o - \ -// RUN: | %FileCheck %s --check-prefixes CHECK,DWARF-CHECK -// -------------------------------------------------------------------- -// Verify that -g -debug-info-format=dwarf gives the same results as -g. -// RUN: %target-swift-frontend %/s -emit-ir -g -debug-info-format=dwarf -o - \ -// RUN: | %FileCheck %s --check-prefixes CHECK,DWARF-CHECK -// -------------------------------------------------------------------- -// RUN: %target-swift-frontend %/s -emit-ir -g -debug-info-format=codeview -o - \ -// RUN: | %FileCheck %s --check-prefixes CHECK,CV-CHECK -// -------------------------------------------------------------------- -// -// CHECK: foo -// CHECK-DAG: ret{{.*}}, !dbg ![[RET:[0-9]+]] -// CHECK-DAG: ![[FOO:[0-9]+]] = distinct !DISubprogram(name: "foo",{{.*}} line: [[@LINE+2]],{{.*}} type: ![[FOOTYPE:[0-9]+]] -public -func foo(_ a: Int64, _ b: Int64) -> Int64 { - var a = a - var b = b - // CHECK-DAG: ![[ALOC:.*]] = !DILocation(line: [[@LINE-3]],{{.*}} scope: ![[FOO]]) - // Check that a is the first and b is the second argument. - // CHECK-DAG: store i64 %0, ptr [[AADDR:.*]], align - // CHECK-DAG: store i64 %1, ptr [[BADDR:.*]], align - // CHECK-DAG: [[AVAL:%.*]] = getelementptr inbounds {{.*}}, [[AMEM:.*]], i32 0, i32 0 - // CHECK-DAG: [[BVAL:%.*]] = getelementptr inbounds {{.*}}, [[BMEM:.*]], i32 0, i32 0 - // CHECK-DAG: #dbg_declare(ptr [[AADDR]], ![[AARG:.*]], !DIExpression(), ![[ALOC]] - // CHECK-DAG: #dbg_declare(ptr [[BADDR]], ![[BARG:.*]], !DIExpression() - // CHECK-DAG: ![[AARG]] = !DILocalVariable(name: "a", arg: 1 - // CHECK-DAG: ![[BARG]] = !DILocalVariable(name: "b", arg: 2 - if b != 0 { - // CHECK-DAG: !DILexicalBlock({{.*}} line: [[@LINE-1]] - // Transparent inlined multiply: - // CHECK-DAG: smul{{.*}}, !dbg ![[MUL:[0-9]+]] - // CHECK-DAG: [[MUL]] = !DILocation(line: [[@LINE+1]], - return a*b - } else { - // CHECK-DAG: ![[PARENT:[0-9]+]] = distinct !DILexicalBlock({{.*}} line: [[@LINE-1]] - // CHECK-DAG: ![[VARSCOPE:[0-9]+]] = distinct !DILexicalBlock({{.*}} line: [[@LINE+1]] - var c: Int64 = 42 - // CHECK-DAG: ![[CONDITION:[0-9]+]] = distinct !DILexicalBlock(scope: ![[VARSCOPE]], {{.*}}, line: [[@LINE+1]] - if a == 0 { - // CHECK-DAG: !DILexicalBlock(scope: ![[CONDITION]], {{.*}}, line: [[@LINE-1]] - // What about a nested scope? - return 0 - } - return c - } -} - -// CHECK-DAG: ![[MAINFILE:[0-9]+]] = !DIFile(filename: "{{.*}}DebugInfo/basic.swift", directory: "{{.*}}") -// CHECK-DAG: !DICompileUnit(language: DW_LANG_Swift, file: ![[MAINFILE]],{{.*}} producer: "{{.*}}Swift version{{.*}},{{.*}} -// CHECK-DAG: !DISubprogram(name: "main", {{.*}}file: ![[MAINFILE]], - -// Function type for foo. -// CHECK-DAG: ![[FOOTYPE]] = !DISubroutineType(types: ![[PARAMTYPES:[0-9]+]]) -// CHECK-DAG: ![[INT64:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Int64", {{.*}}, identifier: "$ss5Int64VD") -// CHECK-DAG: ![[PARAMTYPES]] = !{![[INT64]], ![[INT64]], ![[INT64]]} -// Import of the main module with the implicit name. -// CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_module, scope: ![[MAINFILE]], entity: ![[MAINMODULE:[0-9]+]], file: ![[MAINFILE]]) -// CHECK-DAG: ![[MAINMODULE]] = !DIModule({{.*}}, name: "basic" - -// DWARF Version -// DWARF-CHECK-DAG: i32 7, !"Dwarf Version", i32 4} -// CV-CHECK-DAG: i32 2, !"CodeView", i32 1} - -// Debug Info Version -// CHECK-DAG: i32 2, !"Debug Info Version", i32 +public func foo() -> Int { + let bar = 1 + return bar +} \ No newline at end of file diff --git a/test/DebugInfo/basic_windows.swift b/test/DebugInfo/basic_windows.swift new file mode 100644 index 0000000000000..e2195b08a1c12 --- /dev/null +++ b/test/DebugInfo/basic_windows.swift @@ -0,0 +1,17 @@ +// A basic test for debug info. +// REQUIRES: OS=windows-msvc +// -------------------------------------------------------------------- +// Verify that, by default, we exactly emit 1 DICompileUnit entry without dwoId. +// On Windows, we always emit minimal DebugInfo to match MSVC's behavior: +// See https://github.com/llvm/llvm-project/pull/142970 for more details. +// RUN: %target-swift-frontend %s -emit-ir -o - \ +// RUN: | %FileCheck %s --check-prefix NDEBUG +// NDEBUG: source_filename +// NDEBUG: !DICompileUnit( +// NDEBUG-NOT: dwoId: +// NDEBUG-SAME: ) +// NDEBUG-NOT: !DICompileUnit( +public func foo() -> Int { + let bar = 1 + return bar +} diff --git a/test/IRGen/annotated_cond_fail.swift b/test/IRGen/annotated_cond_fail.swift index bb754384aa3c9..ef50e578426da 100644 --- a/test/IRGen/annotated_cond_fail.swift +++ b/test/IRGen/annotated_cond_fail.swift @@ -19,7 +19,7 @@ public func test(_ a: [Int], _ i: Int) -> Int { // CHECK: [[SIZE_ADDR:%.*]] = getelementptr // CHECK: [[SIZE:%.*]] = load i64, ptr [[SIZE_ADDR]] -// CHECK: [[C1:%.*]] = icmp ult i64 [[IDX]], [[SIZE]] +// CHECK: [[C1:%.*]] = icmp samesign ult i64 [[IDX]], [[SIZE]] // CHECK: br i1 [[C1]], {{.*}}!annotation ![[ARRAY_INDEX_OUT_OF_BOUNDS]] diff --git a/test/IRGen/argument_attrs.sil b/test/IRGen/argument_attrs.sil index ee82eb7eb4ddb..4e2a98d6b732f 100644 --- a/test/IRGen/argument_attrs.sil +++ b/test/IRGen/argument_attrs.sil @@ -4,49 +4,49 @@ import Builtin struct Huge { var x, y, z, w, a, b, c, d, e, f: Builtin.Int32 } -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @arguments_in_def(ptr nocapture dereferenceable(4) %0, ptr noalias nocapture dereferenceable(4) %1, ptr noalias nocapture dereferenceable(4) %2, ptr noalias nocapture dereferenceable(40) %3, ptr noalias %4, ptr noalias nocapture %5, ptr %T) +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @arguments_in_def(ptr captures(none) dereferenceable(4) %0, ptr noalias captures(none) dereferenceable(4) %1, ptr noalias captures(none) dereferenceable(4) %2, ptr noalias captures(none) dereferenceable(40) %3, ptr noalias %4, ptr noalias captures(none) %5, ptr %T) sil @arguments_in_def : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> () { entry(%1 : $*Builtin.Int32, %2 : $*Builtin.Int32, %3 : $*Builtin.Int32, %4 : $Huge, %5 : $*T, %6 : $*()): - // CHECK: call swiftcc void @arguments_in_decl(ptr nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias nocapture {{%.*}}, ptr %T) + // CHECK: call swiftcc void @arguments_in_decl(ptr captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias captures(none) {{%.*}}, ptr %T) %f = function_ref @arguments_in_decl : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> () %x = apply %f(%1, %2, %3, %4, %5, %6) : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> () - // CHECK: call swiftcc void @arguments_in_def(ptr nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias nocapture {{%.*}}, ptr %T) + // CHECK: call swiftcc void @arguments_in_def(ptr captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias captures(none) {{%.*}}, ptr %T) %g = function_ref @arguments_in_def : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> () %y = apply %g(%1, %2, %3, %4, %5, %6) : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> () return undef : $() } -// CHECK-LABEL: declare{{( dllimport)?}} swiftcc void @arguments_in_decl(ptr nocapture dereferenceable(4), ptr noalias nocapture dereferenceable(4), ptr noalias nocapture dereferenceable(4), ptr noalias nocapture dereferenceable(40), ptr noalias, ptr noalias nocapture, ptr) +// CHECK-LABEL: declare{{( dllimport)?}} swiftcc void @arguments_in_decl(ptr captures(none) dereferenceable(4), ptr noalias captures(none) dereferenceable(4), ptr noalias captures(none) dereferenceable(4), ptr noalias captures(none) dereferenceable(40), ptr noalias, ptr noalias captures(none), ptr) sil @arguments_in_decl : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> () -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @arguments_in_def_out(ptr noalias nocapture sret({{.*}}) %0, ptr nocapture dereferenceable(4) %1, ptr noalias nocapture dereferenceable(4) %2, ptr noalias nocapture dereferenceable(4) %3, ptr noalias nocapture dereferenceable(40) %4, ptr noalias %5, ptr noalias nocapture %6, ptr %T) +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @arguments_in_def_out(ptr noalias sret({{.*}}) captures(none) %0, ptr captures(none) dereferenceable(4) %1, ptr noalias captures(none) dereferenceable(4) %2, ptr noalias captures(none) dereferenceable(4) %3, ptr noalias captures(none) dereferenceable(40) %4, ptr noalias %5, ptr noalias captures(none) %6, ptr %T) sil @arguments_in_def_out : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> @out Builtin.Int32 { entry(%0 : $*Builtin.Int32, %1 : $*Builtin.Int32, %2 : $*Builtin.Int32, %3 : $*Builtin.Int32, %4 : $Huge, %5 : $*T, %6 : $*()): - // CHECK: call swiftcc void @arguments_in_decl_out(ptr noalias nocapture sret({{.*}}) {{%.*}}, ptr nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias nocapture {{%.*}}, ptr {{%.*}}) + // CHECK: call swiftcc void @arguments_in_decl_out(ptr noalias sret({{.*}}) captures(none) {{%.*}}, ptr captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias captures(none) {{%.*}}, ptr {{%.*}}) %f = function_ref @arguments_in_decl_out : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> @out Builtin.Int32 %x = apply %f(%0, %1, %2, %3, %4, %5, %6) : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> @out Builtin.Int32 - // CHECK: call swiftcc void @arguments_in_def_out(ptr noalias nocapture sret({{.*}}) {{%.*}}, ptr nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias nocapture {{%.*}}, ptr {{%.*}}) + // CHECK: call swiftcc void @arguments_in_def_out(ptr noalias sret({{.*}}) captures(none) {{%.*}}, ptr captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias captures(none) {{%.*}}, ptr {{%.*}}) %g = function_ref @arguments_in_def_out : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> @out Builtin.Int32 %y = apply %g(%0, %1, %2, %3, %4, %5, %6) : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> @out Builtin.Int32 return undef : $() } -// CHECK-LABEL: declare{{( dllimport)?}} swiftcc void @arguments_in_decl_out(ptr noalias nocapture sret({{.*}}), ptr nocapture dereferenceable(4), ptr noalias nocapture dereferenceable(4), ptr noalias nocapture dereferenceable(4), ptr noalias nocapture dereferenceable(40), ptr noalias, ptr noalias nocapture, ptr) +// CHECK-LABEL: declare{{( dllimport)?}} swiftcc void @arguments_in_decl_out(ptr noalias sret({{.*}}) captures(none), ptr captures(none) dereferenceable(4), ptr noalias captures(none) dereferenceable(4), ptr noalias captures(none) dereferenceable(4), ptr noalias captures(none) dereferenceable(40), ptr noalias, ptr noalias captures(none), ptr) sil @arguments_in_decl_out : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> @out Builtin.Int32 -// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @arguments_in_def_huge_ret(ptr noalias nocapture sret({{.*}}V) %0, ptr nocapture dereferenceable(4) %1, ptr noalias nocapture dereferenceable(4) %2, ptr noalias nocapture dereferenceable(4) %3, ptr noalias nocapture dereferenceable(40) %4, ptr noalias %5, ptr noalias nocapture %6, ptr %T) +// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @arguments_in_def_huge_ret(ptr noalias sret({{.*}}V) captures(none) %0, ptr captures(none) dereferenceable(4) %1, ptr noalias captures(none) dereferenceable(4) %2, ptr noalias captures(none) dereferenceable(4) %3, ptr noalias captures(none) dereferenceable(40) %4, ptr noalias %5, ptr noalias captures(none) %6, ptr %T) sil @arguments_in_def_huge_ret : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> Huge { entry(%1 : $*Builtin.Int32, %2 : $*Builtin.Int32, %3 : $*Builtin.Int32, %4 : $Huge, %5 : $*T, %6 : $*()): %f = function_ref @arguments_in_decl_huge_ret : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> Huge - // CHECK: call swiftcc void @arguments_in_decl_huge_ret(ptr noalias nocapture sret({{.*}}) {{%.*}}, ptr nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias nocapture {{%.*}}, ptr {{%.*}}) + // CHECK: call swiftcc void @arguments_in_decl_huge_ret(ptr noalias sret({{.*}}) captures(none) {{%.*}}, ptr captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias captures(none) {{%.*}}, ptr {{%.*}}) %x = apply %f(%1, %2, %3, %4, %5, %6) : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> Huge - // CHECK: call swiftcc void @arguments_in_def_huge_ret(ptr noalias nocapture sret({{.*}}) {{%.*}}, ptr nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(4) {{%.*}}, ptr noalias nocapture dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias nocapture {{%.*}}, ptr {{%.*}}) + // CHECK: call swiftcc void @arguments_in_def_huge_ret(ptr noalias sret({{.*}}) captures(none) {{%.*}}, ptr captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(4) {{%.*}}, ptr noalias captures(none) dereferenceable(40) {{%.*}}, ptr noalias {{%.*}}, ptr noalias captures(none) {{%.*}}, ptr {{%.*}}) %g = function_ref @arguments_in_def_huge_ret : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> Huge %y = apply %g(%1, %2, %3, %4, %5, %6) : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> Huge return %y : $Huge } -// CHECK-LABEL: declare{{( dllimport)?}} swiftcc void @arguments_in_decl_huge_ret(ptr noalias nocapture sret({{.*}}), ptr nocapture dereferenceable(4), ptr noalias nocapture dereferenceable(4), ptr noalias nocapture dereferenceable(4), ptr noalias nocapture dereferenceable(40), ptr noalias, ptr noalias nocapture, ptr) +// CHECK-LABEL: declare{{( dllimport)?}} swiftcc void @arguments_in_decl_huge_ret(ptr noalias sret({{.*}}) captures(none), ptr captures(none) dereferenceable(4), ptr noalias captures(none) dereferenceable(4), ptr noalias captures(none) dereferenceable(4), ptr noalias captures(none) dereferenceable(40), ptr noalias, ptr noalias captures(none), ptr) sil @arguments_in_decl_huge_ret : $@convention(thin) (@inout Builtin.Int32, @in Builtin.Int32, @in_guaranteed Builtin.Int32, Huge, @in T, @in ()) -> Huge diff --git a/test/IRGen/integer-comparison.swift b/test/IRGen/integer-comparison.swift index ac7d4677ce13a..d5052c461cf4c 100644 --- a/test/IRGen/integer-comparison.swift +++ b/test/IRGen/integer-comparison.swift @@ -4,11 +4,11 @@ func f(_ x: Int, _ y: UInt32) -> Bool { x < y } // CHECK-LABEL: define {{.*}} @"$s4main1fySbSi_s6UInt32VtF"(i64 %0, i32 %1) // CHECK: %2 = zext i32 %1 to i64 -// CHECK-NEXT: %3 = icmp sgt i64 %2, %0 +// CHECK-NEXT: %3 = icmp slt i64 %0, %2 // CHECK-NEXT: ret i1 %3 func g(_ x: UInt32, _ y: Int) -> Bool { x < y } // CHECK-LABEL: define {{.*}} @"$s4main1gySbs6UInt32V_SitF"(i32 %0, i64 %1) // CHECK: %2 = zext i32 %0 to i64 -// CHECK-NEXT: %3 = icmp slt i64 %2, %1 +// CHECK-NEXT: %3 = icmp sgt i64 %1, %2 // CHECK-NEXT: ret i1 %3 diff --git a/test/Interop/C/swiftify-import/Inputs/TransitiveModules/module.modulemap b/test/Interop/C/swiftify-import/Inputs/TransitiveModules/module.modulemap deleted file mode 100644 index 7c3b96f1111b9..0000000000000 --- a/test/Interop/C/swiftify-import/Inputs/TransitiveModules/module.modulemap +++ /dev/null @@ -1,24 +0,0 @@ -module ModuleA { - header "module-a.h" - export * -} -module ModuleB { - header "module-b.h" -} -module ModuleOuter { - module ModuleC { - header "module-c.h" - export * - } - explicit module ModuleD { - header "module-d.h" - export * - } -} -module ModuleDeep { - module ModuleDeepNested { - module ModuleDeepNestedNested { - header "module-e.h" - } - } -} diff --git a/test/Interop/C/swiftify-import/Inputs/counted-by-lifetimebound.h b/test/Interop/C/swiftify-import/Inputs/counted-by-lifetimebound.h index 574bcccd0d57f..6a5bbf2ee5534 100644 --- a/test/Interop/C/swiftify-import/Inputs/counted-by-lifetimebound.h +++ b/test/Interop/C/swiftify-import/Inputs/counted-by-lifetimebound.h @@ -1,23 +1,24 @@ #pragma once #define __counted_by(x) __attribute__((__counted_by__(x))) +#define __counted_by_or_null(x) __attribute__((__counted_by_or_null__(x))) #define __lifetimebound __attribute__((lifetimebound)) -int * __counted_by(len) simple(int len, int len2, int * __counted_by(len2) __lifetimebound p); +int * __counted_by(len) simple(int len, int len2, int * p __counted_by(len2) __lifetimebound); -int * __counted_by(len) shared(int len, int * __counted_by(len) __lifetimebound p); +int * __counted_by(len) shared(int len, int * p __counted_by(len) __lifetimebound); -int * __counted_by(len - offset) complexExpr(int len, int offset, int len2, int * __counted_by(len2) __lifetimebound p); +int * __counted_by(len - offset) complexExpr(int len, int offset, int len2, int * p __counted_by(len2) __lifetimebound); -int * __counted_by(len) _Null_unspecified nullUnspecified(int len, int len2, int * __counted_by(len2) __lifetimebound _Null_unspecified p); +int * __counted_by(len) _Null_unspecified nullUnspecified(int len, int len2, int * _Null_unspecified p __counted_by(len2) __lifetimebound); -int * __counted_by(len) _Nonnull nonnull(int len, int len2, int * __counted_by(len2) __lifetimebound _Nonnull p); +int * __counted_by(len) _Nonnull nonnull(int len, int len2, int * _Nonnull p __counted_by(len2) __lifetimebound); -int * __counted_by(len) _Nullable nullable(int len, int len2, int * __counted_by(len2) __lifetimebound _Nullable p); +int * __counted_by(len) _Nullable nullable(int len, int len2, int * _Nullable p __counted_by(len2) __lifetimebound); typedef struct foo opaque_t; -opaque_t * __counted_by(len) opaque(int len, int len2, opaque_t * __counted_by(len2) __lifetimebound p); +opaque_t * __counted_by(len) opaque(int len, int len2, opaque_t * p __counted_by(len2) __lifetimebound); -int * __counted_by(len) noncountedLifetime(int len, int * __lifetimebound p); +int * __counted_by(len) noncountedLifetime(int len, int * p __lifetimebound); -int * __counted_by(13) _Nullable constant(int * __counted_by(13) __lifetimebound _Nullable p); +int * __counted_by(13) _Nullable constant(int * _Nullable p __counted_by_or_null(13) __lifetimebound); diff --git a/test/Interop/C/swiftify-import/Inputs/module.modulemap b/test/Interop/C/swiftify-import/Inputs/module.modulemap index 93416d69a4a97..29c1c6b295413 100644 --- a/test/Interop/C/swiftify-import/Inputs/module.modulemap +++ b/test/Interop/C/swiftify-import/Inputs/module.modulemap @@ -33,3 +33,29 @@ module ClangIncludesModule { module ClangIncludesNoExportModule { header "clang-includes.h" } + +// TransitiveModules/ +module ModuleA { + header "TransitiveModules/module-a.h" + export * +} +module ModuleB { + header "TransitiveModules/module-b.h" +} +module ModuleOuter { + module ModuleC { + header "TransitiveModules/module-c.h" + export * + } + explicit module ModuleD { + header "TransitiveModules/module-d.h" + export * + } +} +module ModuleDeep { + module ModuleDeepNested { + module ModuleDeepNestedNested { + header "TransitiveModules/module-e.h" + } + } +} diff --git a/test/Interop/C/swiftify-import/Inputs/sized-by-lifetimebound.h b/test/Interop/C/swiftify-import/Inputs/sized-by-lifetimebound.h index e158071e9c954..e66f2fa1ee80c 100644 --- a/test/Interop/C/swiftify-import/Inputs/sized-by-lifetimebound.h +++ b/test/Interop/C/swiftify-import/Inputs/sized-by-lifetimebound.h @@ -7,25 +7,25 @@ #endif #define __lifetimebound __attribute__((lifetimebound)) -const void * __sized_by(len) simple(int len, int len2, const void * __sized_by(len2) __lifetimebound p); +const void * __sized_by(len) simple(int len, int len2, const void * p __sized_by(len2) __lifetimebound); -const void * __sized_by(len) shared(int len, const void * __sized_by(len) __lifetimebound p); +const void * __sized_by(len) shared(int len, const void * p __sized_by(len) __lifetimebound); -const void * __sized_by(len - offset) complexExpr(int len, int offset, int len2, const void * __sized_by(len2) __lifetimebound p); +const void * __sized_by(len - offset) complexExpr(int len, int offset, int len2, const void * p __sized_by(len2) __lifetimebound); -const void * __sized_by(len) _Null_unspecified nullUnspecified(int len, int len2, const void * __sized_by(len2) __lifetimebound _Null_unspecified p); +const void * __sized_by(len) _Null_unspecified nullUnspecified(int len, int len2, const void * _Null_unspecified p __sized_by(len2) __lifetimebound); -const void * __sized_by(len) _Nonnull nonnull(int len, int len2, const void * __sized_by(len2) __lifetimebound _Nonnull p); +const void * __sized_by(len) _Nonnull nonnull(int len, int len2, const void * _Nonnull p __sized_by(len2) __lifetimebound); -const void * __sized_by(len) _Nullable nullable(int len, int len2, const void * __sized_by(len2) __lifetimebound _Nullable p); +const void * __sized_by(len) _Nullable nullable(int len, int len2, const void * _Nullable p __sized_by(len2) __lifetimebound); typedef struct foo opaque_t; -opaque_t * __sized_by(len) opaque(int len, int len2, opaque_t * __sized_by(len2) __lifetimebound p); +opaque_t * __sized_by(len) opaque(int len, int len2, opaque_t * p __sized_by(len2) __lifetimebound); -const void * __sized_by(len) nonsizedLifetime(int len, const void * __lifetimebound p); +const void * __sized_by(len) nonsizedLifetime(int len, const void * p __lifetimebound); -uint8_t *__sized_by(size) bytesized(int size, const uint8_t *__sized_by(size) __lifetimebound); +uint8_t *__sized_by(size) bytesized(int size, const uint8_t * p __sized_by(size) __lifetimebound); -char *__sized_by(size) charsized(char *__sized_by(size) __lifetimebound, int size); +char *__sized_by(size) charsized(char * p __sized_by(size) __lifetimebound, int size); -const uint16_t *__sized_by(size) doublebytesized(uint16_t *__sized_by(size) __lifetimebound, int size); +const uint16_t *__sized_by(size) doublebytesized(uint16_t * p __sized_by(size) __lifetimebound, int size); diff --git a/test/Interop/C/swiftify-import/clang-includes-aliasing-imports.swift b/test/Interop/C/swiftify-import/clang-includes-aliasing-imports.swift index 6e4419de54413..13588c6d76abd 100644 --- a/test/Interop/C/swiftify-import/clang-includes-aliasing-imports.swift +++ b/test/Interop/C/swiftify-import/clang-includes-aliasing-imports.swift @@ -6,8 +6,8 @@ // RUN: %target-swift-frontend -dump-source-file-imports -emit-module -plugin-path %swift-plugin-dir -o %t/ClangIncludesExplicit.swiftmodule -I %t/Inputs -enable-experimental-feature SafeInteropWrappers %t/test.swift 2>&1 | %FileCheck %s --check-prefix DUMP // RUN: %target-swift-frontend -dump-source-file-imports -emit-module -plugin-path %swift-plugin-dir -o %t/ClangIncludesExplicit.swiftmodule -I %t/Inputs -enable-experimental-feature SafeInteropWrappers %t/test.swift -cxx-interoperability-mode=default 2>&1 | %FileCheck %s --check-prefix DUMP --check-prefix DUMP-CXX -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-A1 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A2 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-A2 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-A1 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A2 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-A2 --implicit-check-not=import --match-full-lines //--- test.swift import A1 diff --git a/test/Interop/C/swiftify-import/clang-includes-indirect-explicit-modules.swift b/test/Interop/C/swiftify-import/clang-includes-indirect-explicit-modules.swift index e6131d7cee542..35a934ec4d2a8 100644 --- a/test/Interop/C/swiftify-import/clang-includes-indirect-explicit-modules.swift +++ b/test/Interop/C/swiftify-import/clang-includes-indirect-explicit-modules.swift @@ -6,10 +6,10 @@ // RUN: %target-swift-frontend -dump-source-file-imports -emit-module -plugin-path %swift-plugin-dir -o %t/ClangIncludesExplicit.swiftmodule -I %t/Inputs -enable-experimental-feature SafeInteropWrappers %t/test.swift 2>&1 | %FileCheck %s --check-prefix DUMP // RUN: %target-swift-frontend -dump-source-file-imports -emit-module -plugin-path %swift-plugin-dir -o %t/ClangIncludesExplicit.swiftmodule -I %t/Inputs -enable-experimental-feature SafeInteropWrappers %t/test.swift -cxx-interoperability-mode=default 2>&1 | %FileCheck %s --check-prefix DUMP --check-prefix DUMP-CXX -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.B1 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-B1 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.B1.C1 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-C1 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.B1 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-B1 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.B1.C1 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-C1 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A2.B2 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-B2 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A2.B2 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-B2 --implicit-check-not=import --match-full-lines //--- test.swift import A1.B1 diff --git a/test/Interop/C/swiftify-import/clang-includes-redundant-imports.swift b/test/Interop/C/swiftify-import/clang-includes-redundant-imports.swift index 34fec7dfc97e2..0ea13db6ee4c4 100644 --- a/test/Interop/C/swiftify-import/clang-includes-redundant-imports.swift +++ b/test/Interop/C/swiftify-import/clang-includes-redundant-imports.swift @@ -6,17 +6,17 @@ // RUN: %target-swift-frontend -dump-source-file-imports -emit-module -plugin-path %swift-plugin-dir -o %t/ClangIncludesExplicit.swiftmodule -I %t/Inputs -enable-experimental-feature SafeInteropWrappers %t/test.swift 2>&1 | %FileCheck %s --check-prefix DUMP // RUN: %target-swift-frontend -dump-source-file-imports -emit-module -plugin-path %swift-plugin-dir -o %t/ClangIncludesExplicit.swiftmodule -I %t/Inputs -enable-experimental-feature SafeInteropWrappers %t/test.swift -cxx-interoperability-mode=default 2>&1 | %FileCheck %s --check-prefix DUMP --check-prefix DUMP-CXX -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-A1 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.B1 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-B1 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.B1.C1 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-C1 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.B1.C1.D1 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-D1 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.E1 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-E1 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.E1.F1 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-F1 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.E1.G1 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-G1 --implicit-check-not=import --match-full-lines - -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A2.B2 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-B2 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A2.B2.C2 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-C2 --implicit-check-not=import --match-full-lines -// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A2.B2.C2.D2 -plugin-path %swift-plugin-dir -I %t -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-D2 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-A1 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.B1 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-B1 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.B1.C1 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-C1 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.B1.C1.D1 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-D1 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.E1 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-E1 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.E1.F1 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-F1 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A1.E1.G1 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-G1 --implicit-check-not=import --match-full-lines + +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A2.B2 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-B2 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A2.B2.C2 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-C2 --implicit-check-not=import --match-full-lines +// RUN: %target-swift-ide-test -print-module -module-print-hidden -module-to-print=A2.B2.C2.D2 -plugin-path %swift-plugin-dir -I %t/Inputs -source-filename=x -enable-experimental-feature SafeInteropWrappers | %FileCheck %s --check-prefix CHECK-D2 --implicit-check-not=import --match-full-lines //--- test.swift import A1 diff --git a/test/Interop/C/swiftify-import/sized-by-lifetimebound.swift b/test/Interop/C/swiftify-import/sized-by-lifetimebound.swift index 27250d41af53b..83ae29fd82920 100644 --- a/test/Interop/C/swiftify-import/sized-by-lifetimebound.swift +++ b/test/Interop/C/swiftify-import/sized-by-lifetimebound.swift @@ -13,14 +13,14 @@ import SizedByLifetimeboundClang // CHECK: /// This is an auto-generated wrapper for safer interop // CHECK-NEXT: @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) -// CHECK-NEXT: @_lifetime(copy _bytesized_param1) -// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func bytesized(_ _bytesized_param1: RawSpan) -> MutableRawSpan +// CHECK-NEXT: @_lifetime(copy p) +// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func bytesized(_ p: RawSpan) -> MutableRawSpan // CHECK-NEXT: /// This is an auto-generated wrapper for safer interop // CHECK-NEXT: @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) -// CHECK-NEXT: @_lifetime(copy _charsized_param0) -// CHECK-NEXT: @_lifetime(_charsized_param0: copy _charsized_param0) -// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func charsized(_ _charsized_param0: inout MutableRawSpan) -> MutableRawSpan +// CHECK-NEXT: @_lifetime(copy p) +// CHECK-NEXT: @_lifetime(p: copy p) +// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func charsized(_ p: inout MutableRawSpan) -> MutableRawSpan // CHECK-NEXT: /// This is an auto-generated wrapper for safer interop // CHECK-NEXT: @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *) diff --git a/test/Interop/Cxx/stdlib/msvcprt-module-interface.swift b/test/Interop/Cxx/stdlib/msvcprt-module-interface.swift index 63dd1a39e515c..3fbd3be898749 100644 --- a/test/Interop/Cxx/stdlib/msvcprt-module-interface.swift +++ b/test/Interop/Cxx/stdlib/msvcprt-module-interface.swift @@ -15,8 +15,9 @@ // CHECK-STRING: struct basic_string, std.allocator> : CxxRandomAccessCollection { // CHECK-STRING: typealias value_type = CChar // CHECK-STRING: } -// CHECK-STRING: struct basic_string, std.allocator> : CxxRandomAccessCollection { -// CHECK-STRING: typealias value_type = CWideChar +// CHECK-STRING: struct basic_string, std.allocator> : CxxRandomAccessCollection { +// CHECK-STRING: typealias value_type = UInt16 +// FIXME: why the value type is different from CChar16? // CHECK-STRING: } // CHECK-STRING: typealias string = std.basic_string, std.allocator> // CHECK-STRING: typealias wstring = std.basic_string, std.allocator> diff --git a/test/LLVMPasses/allocation-deletion.ll b/test/LLVMPasses/allocation-deletion.ll index 81d9b181dc576..3dc2ebb2ad3f7 100644 --- a/test/LLVMPasses/allocation-deletion.ll +++ b/test/LLVMPasses/allocation-deletion.ll @@ -7,7 +7,7 @@ target triple = "x86_64-apple-macosx10.9" %swift.heapmetadata = type { ptr, ptr } declare ptr @swift_allocObject(ptr , i64, i64) nounwind -declare void @swift_release(ptr nocapture) +declare void @swift_release(ptr captures(none)) declare void @swift_retain(ptr ) nounwind declare { i64, i64, i64 } @swift_retainAndReturnThree(ptr , i64, i64 , i64 ) @@ -36,7 +36,7 @@ entry: ; trivial_alloc_eliminate1 - Show that we can eliminate an allocation with a ; trivial destructor. @trivial_dtor_metadata = internal constant %swift.heapmetadata { ptr @trivial_dtor, ptr null } -define internal i64 @trivial_dtor(ptr nocapture) nounwind readonly { +define internal i64 @trivial_dtor(ptr captures(none)) nounwind readonly { entry: %1 = getelementptr inbounds %swift.refcounted, ptr %0, i64 1 %length = load i64, ptr %1, align 8 @@ -59,7 +59,7 @@ entry: ; trivial_alloc_eliminate2 - Show that we can eliminate an allocation with a ; destructor that does a retain on the 'self' object. @trivial_dtor_metadata2 = internal constant %swift.heapmetadata { ptr @trivial_dtor2, ptr null } -define internal i64 @trivial_dtor2(ptr nocapture %this) nounwind readonly { +define internal i64 @trivial_dtor2(ptr captures(none) %this) nounwind readonly { entry: %0 = getelementptr inbounds %swift.refcounted, ptr %this, i64 1, i32 0 store ptr inttoptr (i64 4 to ptr), ptr %0, align 8 diff --git a/test/LLVMPasses/basic.ll b/test/LLVMPasses/basic.ll index be8b54b3e16dc..f53e1f9fc66a1 100644 --- a/test/LLVMPasses/basic.ll +++ b/test/LLVMPasses/basic.ll @@ -16,7 +16,7 @@ declare void @swift_unknownObjectRelease(ptr) declare ptr @llvm.objc.retain(ptr) declare void @llvm.objc.release(ptr) declare ptr @swift_allocObject(ptr , i64, i64) nounwind -declare void @swift_release(ptr nocapture) +declare void @swift_release(ptr captures(none)) declare ptr @swift_retain(ptr returned) nounwind declare ptr @swift_bridgeObjectRetain(ptr) declare void @swift_bridgeObjectRelease(ptr) diff --git a/test/LLVMPasses/contract.ll b/test/LLVMPasses/contract.ll index d5081e5c9e3f9..23c05a02096b3 100644 --- a/test/LLVMPasses/contract.ll +++ b/test/LLVMPasses/contract.ll @@ -10,9 +10,9 @@ target triple = "x86_64-apple-macosx10.9" declare ptr @swift_allocObject(ptr , i64, i64) nounwind declare ptr @swift_bridgeObjectRetain(ptr) declare void @swift_bridgeObjectRelease(ptr ) -declare void @swift_release(ptr nocapture) +declare void @swift_release(ptr captures(none)) declare ptr @swift_retain(ptr ) nounwind -declare void @swift_unknownObjectRelease(ptr nocapture) +declare void @swift_unknownObjectRelease(ptr captures(none)) declare ptr @swift_unknownObjectRetain(ptr ) nounwind declare void @__swift_fixLifetime(ptr) declare void @noread_user(ptr) readnone diff --git a/test/LLVMPasses/crash.ll b/test/LLVMPasses/crash.ll index 020ce65262495..1aa748c1a9254 100644 --- a/test/LLVMPasses/crash.ll +++ b/test/LLVMPasses/crash.ll @@ -8,7 +8,7 @@ target triple = "x86_64-apple-macosx10.9" declare { ptr, i64, ptr } @_Tsop1pFT3lhsNs6String3rhsS__S_(ptr, i64, ptr, ptr, i64, ptr) declare { ptr, i64, ptr } @_TNs6String24convertFromStringLiteralFT3valp_S_(ptr) -declare void @swift_release(ptr nocapture) +declare void @swift_release(ptr captures(none)) @0 = private unnamed_addr constant [3 x i8] c"So\00" diff --git a/test/LLVMPasses/disable_llvm_optzns.ll b/test/LLVMPasses/disable_llvm_optzns.ll index e71f22ae88a5f..c0a4ba020c4bd 100644 --- a/test/LLVMPasses/disable_llvm_optzns.ll +++ b/test/LLVMPasses/disable_llvm_optzns.ll @@ -16,7 +16,7 @@ declare void @swift_unknownObjectRelease(ptr) declare ptr @llvm.objc.retain(ptr) declare void @llvm.objc.release(ptr) declare ptr @swift_allocObject(ptr , i64, i64) nounwind -declare void @swift_release(ptr nocapture) +declare void @swift_release(ptr captures(none)) declare ptr @swift_retain(ptr returned) nounwind declare ptr @swift_bridgeObjectRetain(ptr) declare void @swift_bridgeObjectRelease(ptr) diff --git a/test/LLVMPasses/missing_runtime_declarations.ll b/test/LLVMPasses/missing_runtime_declarations.ll index 3b5c20414afc0..f20263bc8472f 100644 --- a/test/LLVMPasses/missing_runtime_declarations.ll +++ b/test/LLVMPasses/missing_runtime_declarations.ll @@ -3,11 +3,11 @@ target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-apple-macosx10.9" -; CHECK: declare void @swift_bridgeObjectRelease(ptr nocapture) +; CHECK: declare void @swift_bridgeObjectRelease(ptr captures(none)) %a = type opaque -declare void @swift_bridgeObjectRelease(ptr nocapture) -declare ptr @swift_bridgeObjectRetain(ptr nocapture) +declare void @swift_bridgeObjectRelease(ptr captures(none)) +declare ptr @swift_bridgeObjectRetain(ptr captures(none)) ; CHECK-LABEL: define void @testcase1(ptr %0) { ; CHECK: entry: diff --git a/test/LLVMPasses/release_motion_landingpad.ll b/test/LLVMPasses/release_motion_landingpad.ll index 3a3c5ae4045f9..f6bee19d82dc5 100644 --- a/test/LLVMPasses/release_motion_landingpad.ll +++ b/test/LLVMPasses/release_motion_landingpad.ll @@ -3,7 +3,7 @@ target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-apple-macosx10.9" -declare void @swift_release(ptr nocapture) +declare void @swift_release(ptr captures(none)) declare void @swift_retain(ptr) nounwind declare ptr @_Znwm(i64) declare i32 @__gxx_personality_v0(...) diff --git a/test/Reflection/Inputs/wasm.yaml b/test/Reflection/Inputs/wasm.yaml new file mode 100644 index 0000000000000..4a5338b309acf --- /dev/null +++ b/test/Reflection/Inputs/wasm.yaml @@ -0,0 +1,443 @@ +--- !WASM +FileHeader: + Version: 0x1 +Sections: + - Type: TYPE + Signatures: + - Index: 0 + ParamTypes: + - I32 + - I32 + ReturnTypes: + - I32 + - Index: 1 + ParamTypes: + - I32 + ReturnTypes: [] + - Index: 2 + ParamTypes: [] + ReturnTypes: [] + - Index: 3 + ParamTypes: + - I32 + - I32 + ReturnTypes: [] + - Index: 4 + ParamTypes: + - I32 + - I32 + - I32 + - I32 + ReturnTypes: [] + - Index: 5 + ParamTypes: + - I32 + ReturnTypes: + - I32 + - Index: 6 + ParamTypes: + - I32 + - I32 + - I32 + ReturnTypes: + - I32 + - Index: 7 + ParamTypes: [] + ReturnTypes: + - I32 + - Type: IMPORT + Imports: + - Module: wasi_snapshot_preview1 + Field: args_get + Kind: FUNCTION + SigIndex: 0 + - Module: wasi_snapshot_preview1 + Field: args_sizes_get + Kind: FUNCTION + SigIndex: 0 + - Module: wasi_snapshot_preview1 + Field: proc_exit + Kind: FUNCTION + SigIndex: 1 + - Type: FUNCTION + FunctionTypes: [ 2, 1, 2, 2, 0, 3, 4, 4, 5, 5, 6, 1, 1, 0, 1, 7, + 0, 0, 1, 2, 5, 2, 2, 6 ] + - Type: TABLE + Tables: + - Index: 0 + ElemType: FUNCREF + Limits: + Flags: [ HAS_MAX ] + Minimum: 0x4 + Maximum: 0x4 + - Type: MEMORY + Memories: + - Minimum: 0x2 + - Type: GLOBAL + Globals: + - Index: 0 + Type: I32 + Mutable: true + InitExpr: + Opcode: I32_CONST + Value: 70624 + - Index: 1 + Type: I32 + Mutable: false + InitExpr: + Opcode: I32_CONST + Value: 0 + - Type: EXPORT + Exports: + - Name: memory + Kind: MEMORY + Index: 0 + - Name: _start + Kind: FUNCTION + Index: 5 + - Type: ELEM + Segments: + - Offset: + Opcode: I32_CONST + Value: 1 + Functions: [ 9, 10, 7 ] + - Type: CODE + Functions: + - Index: 3 + Locals: [] + Body: 10060B + - Index: 4 + Locals: [] + Body: 000B + - Index: 5 + Locals: + - Type: I32 + Count: 1 + Body: 0240024023818080800041D4A28080006A2802000D0023818080800041D4A28080006A4101360200108380808000109280808000210010998080800020000D010F0B000B2000109580808000000B + - Index: 6 + Locals: [] + Body: 410041BCA28080003602D8A3808000410041BCA28080003602D0A3808000410041BCA28080003602C8A3808000410041BCA28080003602C0A380800041004198A28080003602B8A380800041004180A28080003602B0A3808000410041BCA28080003602A8A3808000410041BCA28080003602A0A380800041004180A2808000360298A3808000410041C4A1808000360290A380800041004198A2808000360288A38080004100419CA2808000360280A3808000410041BCA18080003602F8A2808000410041B8A18080003602F0A2808000410041B4A18080003602E8A2808000410042003702E0A2808000410042043702D8A2808000410041BCA280800041BCA28080006B3602DCA3808000410041BCA280800041BCA28080006B3602D4A3808000410041BCA280800041BCA28080006B3602CCA3808000410041BCA280800041BCA28080006B3602C4A380800041004198A28080004198A28080006B3602BCA380800041004180A28080004180A28080006B3602B4A3808000410041BCA280800041BCA28080006B3602ACA3808000410041BCA280800041BCA28080006B3602A4A380800041004198A28080004180A28080006B36029CA380800041004180A280800041C4A18080006B360294A38080004100419CA28080004198A28080006B36028CA3808000410041BCA2808000419CA28080006B360284A3808000410041C4A180800041BCA18080006B3602FCA2808000410041BCA180800041B8A18080006B3602F4A2808000410041B8A180800041B4A18080006B3602ECA280800041D8A28080001084808080000B + - Index: 7 + Locals: + - Type: I32 + Count: 1 + Body: 4100210220020F0B + - Index: 8 + Locals: [] + Body: 0F0B + - Index: 9 + Locals: + - Type: I32 + Count: 6 + Body: 41002104200020043602044190A180800021052381808080002106200620056A210741082108200720086A2109200020093602000F0B + - Index: 10 + Locals: + - Type: I32 + Count: 6 + Body: 410021042000200436020441A0A180800021052381808080002106200620056A210741082108200720086A2109200020093602000F0B + - Index: 11 + Locals: [] + Body: 2000108C808080000B + - Index: 12 + Locals: + - Type: I32 + Count: 11 + Body: 23808080800041106B2201248080808000024002400240024002400240024002400240024002400240024041002802FCA380800022020D00024041002802BCA780800022030D004100427F3702C8A7808000410042808084808080C0003702C0A78080004100200141086A41707141D8AAD5AA057322033602BCA7808000410041003602D0A7808000410041003602A0A78080000B41808088800041E0A7848000490D014100210241808088800041E0A78480006B41D900490D0041002104410041E0A78480003602A4A7808000410041E0A78480003602F4A380800041002003360288A48080004100417F360284A4808000410041808088800041E0A78480006B22033602A8A780800041002003360298A780800041002003360294A78080000340200441A0A48080006A20044194A48080006A220336020020032004418CA48080006A220536020020044198A48080006A2005360200200441A8A48080006A2004419CA48080006A220536020020052003360200200441B0A48080006A200441A4A48080006A220336020020032005360200200441ACA48080006A2003360200200441206A2204418002470D000B418080888000414C6A4138360200410041002802CCA7808000360280A4808000410041E0A7848000417841E0A78480006B410F7122046A22023602FCA3808000410041808088800041E0A78480006B20046B41486A22043602F0A3808000200220044101723602040B02400240200041EC014B0D00024041002802E4A380800022064110200041136A41F003712000410B491B22054103762203762204410371450D0002400240200441017120037241017322054103742203418CA48080006A220420034194A48080006A28020022032802082200470D0041002006417E200577713602E4A38080000C010B200420003602082000200436020C0B200341086A2104200320054103742205410372360204200320056A220320032802044101723602040C0E0B200541002802ECA380800022074D0D0102402004450D0002400240200420037441022003742204410020046B72716822034103742204418CA48080006A220020044194A48080006A28020022042802082208470D0041002006417E2003777122063602E4A38080000C010B200020083602082008200036020C0B200420054103723602042004200341037422036A200320056B2200360200200420056A2208200041017236020402402007450D002007417871418CA48080006A210541002802F8A3808000210302400240200641012007410376742209710D00410020062009723602E4A3808000200521090C010B200528020821090B2009200336020C200520033602082003200536020C200320093602080B200441086A2104410020083602F8A3808000410020003602ECA38080000C0E0B41002802E8A3808000220A450D01200A684102744194A68080006A280200220828020441787120056B210320082100024003400240200028021022040D0020002802142204450D020B200428020441787120056B22002003200020034922001B21032004200820001B2108200421000C000B0B200828021821020240200828020C22042008460D0020082802082200200436020C200420003602080C0D0B0240024020082802142200450D00200841146A21090C010B20082802102200450D04200841106A21090B03402009210B2000220441146A2109200428021422000D00200441106A2109200428021022000D000B200B41003602000C0C0B417F2105200041BF7F4B0D00200041136A2204417071210541002802E8A3808000220A450D00411F21070240200041ECFFFF074B0D002005412620044108766722046B7641017120044101746B413E6A21070B410020056B2103024002400240024020074102744194A68080006A28020022000D0041002104410021090C010B4100210420054100411920074101766B2007411F461B7421084100210903400240200028020441787120056B220620034F0D00200621032000210920060D004100210320002109200021040C030B200420002802142206200620002008411D764104716A41106A280200220B461B200420061B210420084101742108200B2100200B0D000B0B024020042009720D004100210941022007742204410020046B72200A712204450D032004684102744194A68080006A28020021040B2004450D010B0340200428020441787120056B220620034921080240200428021022000D00200428021421000B2006200320081B21032004200920081B21092000210420000D000B0B2009450D00200341002802ECA380800020056B4F0D002009280218210B0240200928020C22042009460D0020092802082200200436020C200420003602080C0B0B0240024020092802142200450D00200941146A21080C010B20092802102200450D04200941106A21080B0340200821062000220441146A2108200428021422000D00200441106A2108200428021022000D000B200641003602000C0A0B024041002802ECA380800022042005490D0041002802F8A3808000210302400240200420056B22004110490D00200320056A22082000410172360204200320046A2000360200200320054103723602040C010B20032004410372360204200320046A2204200428020441017236020441002108410021000B410020003602ECA3808000410020083602F8A3808000200341086A21040C0C0B024041002802F0A3808000220020054D0D00200220056A2204200020056B2203410172360204410020043602FCA3808000410020033602F0A380800020022005410372360204200241086A21040C0C0B0240024041002802BCA7808000450D0041002802C4A780800021030C010B4100427F3702C8A7808000410042808084808080C0003702C0A780800041002001410C6A41707141D8AAD5AA05733602BCA7808000410041003602D0A7808000410041003602A0A78080004180800421030B4100210402402003200541C7006A220B6A2208410020036B220671220920054B0D00410041303602E0A38080000C0C0B0240410028029CA78080002204450D0002404100280294A7808000220320096A220720034D0D00200720044D0D010B41002104410041303602E0A38080000C0C0B41002D00A0A78080004104710D050240024002402002450D0041A4A78080002104034002402004280200220320024B0D00200320042802046A20024B0D030B200428020822040D000B0B41001097808080002208417F460D0620092106024041002802C0A78080002204417F6A2203200871450D00200920086B200320086A410020046B716A21060B200620054D0D06200641FEFFFFFF074B0D060240410028029CA78080002204450D004100280294A7808000220320066A220020034D0D07200020044B0D070B200610978080800022042008470D010C080B200820006B200671220641FEFFFFFF074B0D0520061097808080002208200428020020042802046A460D04200821040B02402006200541C8006A4F0D002004417F460D000240200B20066B41002802C4A780800022036A410020036B71220341FEFFFFFF074D0D00200421080C080B02402003109780808000417F460D00200320066A2106200421080C080B410020066B1097808080001A0C050B200421082004417F470D060C040B000B410021040C080B410021040C060B2008417F470D020B410041002802A0A78080004104723602A0A78080000B200941FEFFFFFF074B0D0120091097808080002108410010978080800021042008417F460D012004417F460D01200820044F0D01200420086B2206200541386A4D0D010B41004100280294A780800020066A2204360294A7808000024020044100280298A78080004D0D0041002004360298A78080000B024002400240024041002802FCA38080002203450D0041A4A780800021040340200820042802002200200428020422096A460D02200428020822040D000C030B0B0240024041002802F4A38080002204450D00200820044F0D010B410020083602F4A38080000B41002104410020063602A8A7808000410020083602A4A78080004100417F360284A4808000410041002802BCA7808000360288A4808000410041003602B0A78080000340200441A0A48080006A20044194A48080006A220336020020032004418CA48080006A220036020020044198A48080006A2000360200200441A8A48080006A2004419CA48080006A220036020020002003360200200441B0A48080006A200441A4A48080006A220336020020032000360200200441ACA48080006A2003360200200441206A2204418002470D000B2008417820086B410F7122046A2203200641486A220020046B2204410172360204410041002802CCA7808000360280A4808000410020043602F0A3808000410020033602FCA3808000200820006A41383602040C020B200320084F0D0020032000490D00200428020C4108710D002003417820036B410F7122006A220841002802F0A380800020066A220B20006B22004101723602042004200920066A360204410041002802CCA7808000360280A4808000410020003602F0A3808000410020083602FCA38080002003200B6A41383602040C010B0240200841002802F4A38080004F0D00410020083602F4A38080000B200820066A210041A4A78080002104024002400340200428020022092000460D01200428020822040D000C020B0B20042D000C410871450D030B41A4A780800021040240034002402004280200220020034B0D00200020042802046A220020034B0D020B200428020821040C000B0B2008417820086B410F7122046A220B200641486A220920046B2204410172360204200820096A413836020420032000413720006B410F716A41416A22092009200341106A491B22094123360204410041002802CCA7808000360280A4808000410020043602F0A38080004100200B3602FCA3808000200941106A41002902ACA7808000370200200941002902A4A78080003702084100200941086A3602ACA7808000410020063602A8A7808000410020083602A4A7808000410041003602B0A7808000200941246A2104034020044107360200200441046A22042000490D000B20092003460D0020092009280204417E713602042009200920036B22083602002003200841017236020402400240200841FF014B0D002008417871418CA48080006A21040240024041002802E4A3808000220041012008410376742208710D00410020002008723602E4A3808000200421000C010B200428020821000B2000200336020C20042003360208410C2108410821090C010B411F21040240200841FFFFFF074B0D002008412620084108766722046B7641017120044101746B413E6A21040B2003200436021C2003420037021020044102744194A68080006A210002400240024041002802E8A3808000220941012004742206710D0020002003360200410020092006723602E8A3808000200320003602180C010B20084100411920044101766B2004411F461B742104200028020021090340200922002802044178712008460D022004411D76210920044101742104200020094104716A41106A220628020022090D000B20062003360200200320003602180B41082108410C210920032100200321040C010B20002802082104200020033602082004200336020C200320043602084100210441182108410C21090B200320096A2000360200200320086A20043602000B41002802F0A3808000220420054D0D0041002802FCA3808000220320056A2200200420056B2204410172360204410020043602F0A3808000410020003602FCA380800020032005410372360204200341086A21040C040B41002104410041303602E0A38080000C030B200420083602002004200428020420066A360204200820092005108D8080800021040C020B0240200B450D00024002402009200928021C22084102744194A68080006A2200280200470D002000200436020020040D014100200A417E20087771220A3602E8A38080000C020B200B41104114200B2802102009461B6A20043602002004450D010B2004200B360218024020092802102200450D0020042000360210200020043602180B20092802142200450D0020042000360214200020043602180B024002402003410F4B0D00200920032005722204410372360204200920046A220420042802044101723602040C010B200920056A2208200341017236020420092005410372360204200820036A20033602000240200341FF014B0D002003417871418CA48080006A21040240024041002802E4A3808000220541012003410376742203710D00410020052003723602E4A3808000200421030C010B200428020821030B2003200836020C200420083602082008200436020C200820033602080C010B411F21040240200341FFFFFF074B0D002003412620034108766722046B7641017120044101746B413E6A21040B2008200436021C2008420037021020044102744194A68080006A21050240200A41012004742200710D00200520083602004100200A2000723602E8A380800020082005360218200820083602082008200836020C0C010B20034100411920044101766B2004411F461B7421042005280200210002400340200022052802044178712003460D012004411D76210020044101742104200520004104716A41106A220628020022000D000B20062008360200200820053602182008200836020C200820083602080C010B20052802082204200836020C20052008360208200841003602182008200536020C200820043602080B200941086A21040C010B02402002450D00024002402008200828021C22094102744194A68080006A2200280200470D002000200436020020040D014100200A417E200977713602E8A38080000C020B20024110411420022802102008461B6A20043602002004450D010B20042002360218024020082802102200450D0020042000360210200020043602180B20082802142200450D0020042000360214200020043602180B024002402003410F4B0D00200820032005722204410372360204200820046A220420042802044101723602040C010B200820056A2200200341017236020420082005410372360204200020036A200336020002402007450D002007417871418CA48080006A210541002802F8A3808000210402400240410120074103767422092006710D00410020092006723602E4A3808000200521090C010B200528020821090B2009200436020C200520043602082004200536020C200420093602080B410020003602F8A3808000410020033602ECA38080000B200841086A21040B200141106A24808080800020040B + - Index: 13 + Locals: + - Type: I32 + Count: 7 + Body: 2000417820006B410F716A220320024103723602042001417820016B410F716A2204200320026A22056B210002400240200441002802FCA3808000470D00410020053602FCA3808000410041002802F0A380800020006A22023602F0A3808000200520024101723602040C010B0240200441002802F8A3808000470D00410020053602F8A3808000410041002802ECA380800020006A22023602ECA380800020052002410172360204200520026A20023602000C010B0240200428020422014103714101470D0020014178712106200428020C210202400240200141FF014B0D000240200220042802082207470D00410041002802E4A3808000417E200141037677713602E4A38080000C020B200220073602082007200236020C0C010B200428021821080240024020022004460D0020042802082201200236020C200220013602080C010B02400240024020042802142201450D00200441146A21070C010B20042802102201450D01200441106A21070B0340200721092001220241146A2107200228021422010D00200241106A2107200228021022010D000B200941003602000C010B410021020B2008450D00024002402004200428021C22074102744194A68080006A2201280200470D002001200236020020020D01410041002802E8A3808000417E200777713602E8A38080000C020B20084110411420082802102004461B6A20023602002002450D010B20022008360218024020042802102201450D0020022001360210200120023602180B20042802142201450D0020022001360214200120023602180B200620006A2100200420066A220428020421010B20042001417E71360204200520006A2000360200200520004101723602040240200041FF014B0D002000417871418CA48080006A21020240024041002802E4A3808000220141012000410376742200710D00410020012000723602E4A3808000200221000C010B200228020821000B2000200536020C200220053602082005200236020C200520003602080C010B411F21020240200041FFFFFF074B0D002000412620004108766722026B7641017120024101746B413E6A21020B2005200236021C2005420037021020024102744194A68080006A2101024041002802E8A3808000220741012002742204710D0020012005360200410020072004723602E8A380800020052001360218200520053602082005200536020C0C010B20004100411920024101766B2002411F461B7421022001280200210702400340200722012802044178712000460D012002411D76210720024101742102200120074104716A41106A220428020022070D000B20042005360200200520013602182005200536020C200520053602080C010B20012802082202200536020C20012005360208200541003602182005200136020C200520023602080B200341086A0B + - Index: 14 + Locals: [] + Body: 2000108F808080000B + - Index: 15 + Locals: + - Type: I32 + Count: 7 + Body: 02402000450D00200041786A22012000417C6A280200220241787122006A2103024020024101710D002002410271450D012001200128020022046B220141002802F4A3808000490D01200420006A21000240024002400240200141002802F8A3808000460D00200128020C21020240200441FF014B0D00200220012802082205470D02410041002802E4A3808000417E200441037677713602E4A38080000C050B20012802182106024020022001460D0020012802082204200236020C200220043602080C040B0240024020012802142204450D00200141146A21050C010B20012802102204450D03200141106A21050B0340200521072004220241146A2105200228021422040D00200241106A2105200228021022040D000B200741003602000C030B200328020422024103714103470D0320032002417E71360204410020003602ECA380800020032000360200200120004101723602040F0B200220053602082005200236020C0C020B410021020B2006450D00024002402001200128021C22054102744194A68080006A2204280200470D002004200236020020020D01410041002802E8A3808000417E200577713602E8A38080000C020B20064110411420062802102001461B6A20023602002002450D010B20022006360218024020012802102204450D0020022004360210200420023602180B20012802142204450D0020022004360214200420023602180B200120034F0D0020032802042204410171450D000240024002400240024020044102710D000240200341002802FCA3808000470D00410020013602FCA3808000410041002802F0A380800020006A22003602F0A380800020012000410172360204200141002802F8A3808000470D06410041003602ECA3808000410041003602F8A38080000F0B0240200341002802F8A3808000470D00410020013602F8A3808000410041002802ECA380800020006A22003602ECA380800020012000410172360204200120006A20003602000F0B200441787120006A2100200328020C21020240200441FF014B0D000240200220032802082205470D00410041002802E4A3808000417E200441037677713602E4A38080000C050B200220053602082005200236020C0C040B20032802182106024020022003460D0020032802082204200236020C200220043602080C030B0240024020032802142204450D00200341146A21050C010B20032802102204450D02200341106A21050B0340200521072004220241146A2105200228021422040D00200241106A2105200228021022040D000B200741003602000C020B20032004417E71360204200120006A2000360200200120004101723602040C030B410021020B2006450D00024002402003200328021C22054102744194A68080006A2204280200470D002004200236020020020D01410041002802E8A3808000417E200577713602E8A38080000C020B20064110411420062802102003461B6A20023602002002450D010B20022006360218024020032802102204450D0020022004360210200420023602180B20032802142204450D0020022004360214200420023602180B200120006A200036020020012000410172360204200141002802F8A3808000470D00410020003602ECA38080000F0B0240200041FF014B0D002000417871418CA48080006A21020240024041002802E4A3808000220441012000410376742200710D00410020042000723602E4A3808000200221000C010B200228020821000B2000200136020C200220013602082001200236020C200120003602080F0B411F21020240200041FFFFFF074B0D002000412620004108766722026B7641017120024101746B413E6A21020B2001200236021C2001420037021020024102744194A68080006A2103024002400240024041002802E8A3808000220441012002742205710D00410020042005723602E8A38080004108210041182102200321050C010B20004100411920024101766B2002411F461B742102200328020021050340200522042802044178712000460D022002411D76210520024101742102200420054104716A41106A220328020022050D000B4108210041182102200421050B20012104200121070C010B20042802082205200136020C41082102200441086A210341002107411821000B20032001360200200120026A20053602002001200436020C200120006A200736020041004100280284A4808000417F6A2201417F20011B360284A48080000B0B + - Index: 16 + Locals: + - Type: I32 + Count: 1 + - Type: I64 + Count: 1 + Body: 0240024020000D00410021020C010B2000AD2001AD7E2203A72102200120007241808004490D00417F20022003422088A74100471B21020B02402002108C808080002200450D002000417C6A2D0000410371450D00200041002002109A808080001A0B20000B + - Index: 17 + Locals: [] + Body: 2000109580808000000B + - Index: 18 + Locals: + - Type: I32 + Count: 3 + Body: 23808080800041106B220024808080800002400240024002400240200041086A2000410C6A1094808080000D00200028020841016A2201450D01200028020C108B808080002202450D02200141041090808080002201450D03200120021093808080000D04200028020820011087808080002101200041106A24808080800020010F0B41C700109180808000000B41C600109180808000000B41C600109180808000000B2002108E8080800041C600109180808000000B2002108E808080002001108E8080800041C700109180808000000B + - Index: 19 + Locals: [] + Body: 2000200110808080800041FFFF03710B + - Index: 20 + Locals: [] + Body: 2000200110818080800041FFFF03710B + - Index: 21 + Locals: [] + Body: 2000108280808000000B + - Index: 22 + Locals: [] + Body: 000B + - Index: 23 + Locals: [] + Body: 024020000D003F004110740F0B0240200041FFFF03710D002000417F4C0D000240200041107640002200417F470D00410041303602E0A3808000417F0F0B20004110740F0B109680808000000B + - Index: 24 + Locals: [] + Body: 0B + - Index: 25 + Locals: [] + Body: 1098808080001098808080000B + - Index: 26 + Locals: + - Type: I32 + Count: 3 + - Type: I64 + Count: 1 + Body: 024020024121490D00200020012002FC0B0020000F0B02402002450D00200020013A0000200020026A2203417F6A20013A000020024103490D00200020013A0002200020013A00012003417D6A20013A00002003417E6A20013A000020024107490D00200020013A00032003417C6A20013A000020024109490D002000410020006B41037122046A2205200141FF017141818284086C22033602002005200220046B413C7122016A2202417C6A200336020020014109490D002005200336020820052003360204200241786A2003360200200241746A200336020020014119490D002005200336021820052003360214200520033602102005200336020C200241706A20033602002002416C6A2003360200200241686A2003360200200241646A20033602002001200541047141187222026B22014120490D002003AD4281808080107E2106200520026A2102034020022006370318200220063703102002200637030820022006370300200241206A2102200141606A2201411F4B0D000B0B20000B + - Type: DATA + Segments: + - SectionOffset: 8 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4096 + Content: 10000000480000008000000000000000430001005C0000006400000000000000010000005A0000000700000000000000510000003C000000480000000100000094000000000000000200000051000000200000002E0000000200000088000000010000000200000073696D706C6500000000000000000000F0FFFFFF50004100540053000300 + - SectionOffset: 148 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4232 + Content: 001000001D110000000000000010000000020000301000000000000000100000000200004C10000000000000 + - SectionOffset: 198 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4276 + Content: 5CFFFFFF + - SectionOffset: 208 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4280 + Content: 48FFFFFF + - SectionOffset: 218 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4284 + Content: 74FFFFFF8CFFFFFF + - SectionOffset: 232 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4292 + Content: 640000000000000004000C0000000000620000000000000000000C00000000003E0000000000000000000C0001000000000000003E0000001E000000 + - SectionOffset: 298 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4352 + Content: '' + - SectionOffset: 304 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4352 + Content: '220000002400000001000000080000000800000008000000' + - SectionOffset: 334 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4376 + Content: '' + - SectionOffset: 340 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4376 + Content: '41007400' + - SectionOffset: 350 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4380 + Content: 426933325F000129FFFFFF0024733673696D706C65315050000001F9FEFFFF00 + - SectionOffset: 388 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4412 + Content: '' + - SectionOffset: 394 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4412 + Content: '' + - SectionOffset: 400 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4412 + Content: '' + - SectionOffset: 406 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4412 + Content: '' + - SectionOffset: 412 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4412 + Content: '' + - SectionOffset: 418 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4412 + Content: '' + - SectionOffset: 424 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4412 + Content: '0300000000000000' + - SectionOffset: 438 + InitFlags: 0 + Offset: + Opcode: I32_CONST + Value: 4420 + Content: F94D3CBDE6014046B3FF38670353FD4E + - Type: CUSTOM + Name: .swift1_autolink_entries + Payload: '' + - Type: CUSTOM + Name: name + FunctionNames: + - Index: 0 + Name: __imported_wasi_snapshot_preview1_args_get + - Index: 1 + Name: __imported_wasi_snapshot_preview1_args_sizes_get + - Index: 2 + Name: __imported_wasi_snapshot_preview1_proc_exit + - Index: 3 + Name: __wasm_call_ctors + - Index: 4 + Name: 'signature_mismatch:swift_addNewDSOImage' + - Index: 5 + Name: _start + - Index: 6 + Name: 'swift_image_constructor()' + - Index: 7 + Name: main + - Index: 8 + Name: '$s6simple1SV1tAA1TVvg' + - Index: 9 + Name: '$s6simple1TVMa' + - Index: 10 + Name: '$s6simple1SVMa' + - Index: 11 + Name: malloc + - Index: 12 + Name: dlmalloc + - Index: 13 + Name: prepend_alloc + - Index: 14 + Name: free + - Index: 15 + Name: dlfree + - Index: 16 + Name: calloc + - Index: 17 + Name: _Exit + - Index: 18 + Name: __main_void + - Index: 19 + Name: __wasi_args_get + - Index: 20 + Name: __wasi_args_sizes_get + - Index: 21 + Name: __wasi_proc_exit + - Index: 22 + Name: abort + - Index: 23 + Name: sbrk + - Index: 24 + Name: dummy + - Index: 25 + Name: __wasm_call_dtors + - Index: 26 + Name: memset + GlobalNames: + - Index: 0 + Name: __stack_pointer + - Index: 1 + Name: GOT.data.internal.__memory_base + DataSegmentNames: + - Index: 0 + Name: .rodata + - Index: 1 + Name: .data + - Index: 2 + Name: swift5_protocols + - Index: 3 + Name: swift5_protocol_conformances + - Index: 4 + Name: swift5_type_metadata + - Index: 5 + Name: swift5_fieldmd + - Index: 6 + Name: swift5_builtin + - Index: 7 + Name: swift5_assocty + - Index: 8 + Name: swift5_capture + - Index: 9 + Name: swift5_reflstr + - Index: 10 + Name: swift5_typeref + - Index: 11 + Name: swift5_mpenum + - Index: 12 + Name: swift5_replace + - Index: 13 + Name: swift5_replac2 + - Index: 14 + Name: swift5_accessible_functions + - Index: 15 + Name: swift5_runtime_attributes + - Index: 16 + Name: swift5_tests + - Index: 17 + Name: swift5_entry + - Index: 18 + Name: .swift_modhash + - Type: CUSTOM + Name: producers + Languages: + - Name: C_plus_plus_14 + Version: '' + Tools: + - Name: clang + Version: '17.0.0 (https://github.com/swiftlang/llvm-project.git b9d3d72e441c70ab8c463d615e36db1df685151b)' + - Type: CUSTOM + Name: target_features + Features: + - Prefix: USED + Name: bulk-memory + - Prefix: USED + Name: multivalue + - Prefix: USED + Name: mutable-globals + - Prefix: USED + Name: reference-types + - Prefix: USED + Name: sign-ext +... diff --git a/test/Reflection/wasm.test b/test/Reflection/wasm.test new file mode 100644 index 0000000000000..98c904795dcc6 --- /dev/null +++ b/test/Reflection/wasm.test @@ -0,0 +1,28 @@ +# RUN: %yaml2obj %S/Inputs/wasm.yaml -o %t.wasm +# RUN: %target-swift-reflection-dump --arch=wasi --no-objc-interop %t.wasm | %FileCheck %s +# +# CHECK: FIELDS +# CHECK: t: +# CHECK: ASSOCIATED TYPES +# CHECK: - : simple.P +# CHECK: typealias A = Builtin.Int32 +# CHECK: Builtin.Int32 +# CHECK: (builtin Builtin.Int32) +# +# simple.swift +# protocol P { associatedtype A } +# struct T {} +# struct S : P { +# typealias A = Builtin.Int32 +# let t: T +# } +# sys.c +# void swift_addNewDSOImage() {} +# +# compiled for -target wasm32-unknown-wasip1 +# obj2yaml simple.o -o simple.o.yaml +# (replace UNDEFINED symbol with a definition) +# obj2yaml simple.o.yaml -o simple-mod.o +# swiftc simple-mod.o sys.o -o simple.wasm +# yaml2obj simple.wasm -o simple-mod.o +# diff --git a/test/lit.cfg b/test/lit.cfg index 8cac70321fcce..54f36dab837c7 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -347,6 +347,7 @@ config.llvm_dis = inferSwiftBinary('llvm-dis') config.llvm_nm = inferSwiftBinary('llvm-nm') config.llvm_readtapi = inferSwiftBinary('llvm-readtapi') config.llvm_size = inferSwiftBinary('llvm-size') +config.yaml2obj = inferSwiftBinary('yaml2obj') config.sourcekitd_test = inferSwiftBinary('sourcekitd-test') config.complete_test = inferSwiftBinary('complete-test') config.swift_api_digester = inferSwiftBinary('swift-api-digester') @@ -747,6 +748,7 @@ config.substitutions.append( ('%llvm-dis', config.llvm_dis) ) config.substitutions.append( ('%llvm-nm', config.llvm_nm) ) config.substitutions.append( ('%llvm-readtapi', config.llvm_readtapi) ) config.substitutions.append( ('%llvm-size', config.llvm_size) ) +config.substitutions.append( ('%yaml2obj', config.yaml2obj) ) config.substitutions.append( ('%swift-demangle-yamldump', config.swift_demangle_yamldump) ) config.substitutions.append( ('%swift-demangle', config.swift_demangle) ) config.substitutions.append( ('%Benchmark_O', config.benchmark_o) ) diff --git a/tools/SourceKit/lib/Support/ImmutableTextBuffer.cpp b/tools/SourceKit/lib/Support/ImmutableTextBuffer.cpp index 81a4623b1a93b..0ebf2619ba200 100644 --- a/tools/SourceKit/lib/Support/ImmutableTextBuffer.cpp +++ b/tools/SourceKit/lib/Support/ImmutableTextBuffer.cpp @@ -11,13 +11,13 @@ //===----------------------------------------------------------------------===// #include "SourceKit/Support/ImmutableTextBuffer.h" -#include "clang/Rewrite/Core/RewriteRope.h" +#include "llvm/ADT/RewriteRope.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" using namespace SourceKit; using namespace llvm; -using clang::RewriteRope; +using llvm::RewriteRope; void ImmutableTextUpdate::anchor() {} diff --git a/tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp b/tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp index 39d06a12a279f..f17962bfce1eb 100644 --- a/tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp +++ b/tools/SourceKit/tools/sourcekitd-test/TestOptions.cpp @@ -35,13 +35,13 @@ enum Opt { #undef OPTION }; -// Create prefix string literals used in Options.td. -#define PREFIX(NAME, VALUE) \ - constexpr llvm::StringLiteral NAME##_init[] = VALUE; \ - constexpr llvm::ArrayRef NAME( \ - NAME##_init, std::size(NAME##_init) - 1); +#define OPTTABLE_STR_TABLE_CODE #include "Options.inc" -#undef PREFIX +#undef OPTTABLE_STR_TABLE_CODE + +#define OPTTABLE_PREFIXES_TABLE_CODE +#include "Options.inc" +#undef OPTTABLE_PREFIXES_TABLE_CODE // Create table mapping all options defined in Options.td. static const llvm::opt::OptTable::Info InfoTable[] = { @@ -53,7 +53,8 @@ static const llvm::opt::OptTable::Info InfoTable[] = { // Create OptTable class for parsing actual command line arguments class TestOptTable : public llvm::opt::GenericOptTable { public: - TestOptTable() : GenericOptTable(InfoTable) {} + TestOptTable() + : GenericOptTable(OptionStrTable, OptionPrefixesTable, InfoTable) {} }; } // end anonymous namespace diff --git a/tools/swift-ide-test/swift-ide-test.cpp b/tools/swift-ide-test/swift-ide-test.cpp index dba714047b1dc..1361ec48e8ea4 100644 --- a/tools/swift-ide-test/swift-ide-test.cpp +++ b/tools/swift-ide-test/swift-ide-test.cpp @@ -55,7 +55,7 @@ #include "swift/Markup/Markup.h" #include "swift/Parse/ParseVersion.h" #include "swift/Sema/IDETypeChecking.h" -#include "clang/Rewrite/Core/RewriteBuffer.h" +#include "llvm/ADT/RewriteBuffer.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/Statistic.h" #include "llvm/Support/CommandLine.h" @@ -2273,7 +2273,7 @@ static int doDumpImporterLookupTables(const CompilerInvocation &InitInvok, class StructureAnnotator : public ide::SyntaxModelWalker { SourceManager &SM; unsigned BufferID; - clang::RewriteBuffer RewriteBuf; + llvm::RewriteBuffer RewriteBuf; std::vector NodeStack; CharSourceRange LastPoppedNodeRange; diff --git a/tools/swift-reflection-dump/swift-reflection-dump.cpp b/tools/swift-reflection-dump/swift-reflection-dump.cpp index dba4352311f20..100af2eb203c7 100644 --- a/tools/swift-reflection-dump/swift-reflection-dump.cpp +++ b/tools/swift-reflection-dump/swift-reflection-dump.cpp @@ -79,11 +79,13 @@ static llvm::cl::opt llvm::cl::desc("Architecture to inspect in the binary"), llvm::cl::Required); -#if SWIFT_OBJC_INTEROP static llvm::cl::opt DisableObjCInterop( "no-objc-interop", - llvm::cl::desc("Disable Objective-C interoperability support")); + llvm::cl::desc("Disable Objective-C interoperability support" +#if SWIFT_OBJC_INTEROP + " (not supported)" #endif + )); } // end namespace options static int doDumpReflectionSections(ArrayRef BinaryFilenames, diff --git a/utils/build.ps1 b/utils/build.ps1 index bc2d8ba443fb0..5cf7ae145932f 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -2041,7 +2041,7 @@ function Build-BuildTools([Hashtable] $Platform) { -Platform $Platform ` -UseMSVCCompilers $(if ($UseHostToolchain) { @("ASM_MASM", "C", "CXX") } else { @("") }) ` -UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("ASM", "C", "CXX") }) ` - -BuildTargets llvm-tblgen,clang-tblgen,clang-pseudo-gen,clang-tidy-confusable-chars-gen,lldb-tblgen,llvm-config,swift-def-to-strings-converter,swift-serialize-diagnostics,swift-compatibility-symbols ` + -BuildTargets llvm-tblgen,clang-tblgen,clang-tidy-confusable-chars-gen,lldb-tblgen,llvm-config,swift-def-to-strings-converter,swift-serialize-diagnostics,swift-compatibility-symbols ` -Defines @{ CMAKE_CROSSCOMPILING = "NO"; CLANG_ENABLE_LIBXML2 = "NO"; diff --git a/utils/build_swift/build_swift/defaults.py b/utils/build_swift/build_swift/defaults.py index 25ce03135ef4f..07d0fbc228b6f 100644 --- a/utils/build_swift/build_swift/defaults.py +++ b/utils/build_swift/build_swift/defaults.py @@ -48,7 +48,7 @@ COMPILER_VENDOR = 'none' SWIFT_USER_VISIBLE_VERSION = Version('6.3') -CLANG_USER_VISIBLE_VERSION = Version('17.0.0') +CLANG_USER_VISIBLE_VERSION = Version('21.0.0') SWIFT_ANALYZE_CODE_COVERAGE = 'false' DARWIN_XCRUN_TOOLCHAIN = 'default' diff --git a/utils/swift_build_support/swift_build_support/products/llvm.py b/utils/swift_build_support/swift_build_support/products/llvm.py index 15a9a236f4167..7b484a4b71588 100644 --- a/utils/swift_build_support/swift_build_support/products/llvm.py +++ b/utils/swift_build_support/swift_build_support/products/llvm.py @@ -446,8 +446,6 @@ def build(self, host_target): 'clang-tidy-confusable-chars-gen') llvm_cmake_options.define('CLANG_TIDY_CONFUSABLE_CHARS_GEN', confusable_chars_gen) - pseudo_gen = os.path.join(host_build_dir, 'bin', 'clang-pseudo-gen') - llvm_cmake_options.define('CLANG_PSEUDO_GEN', pseudo_gen) llvm = os.path.join(host_build_dir, 'llvm') llvm_cmake_options.define('LLVM_NATIVE_BUILD', llvm) diff --git a/utils/update_checkout/update-checkout-config.json b/utils/update_checkout/update-checkout-config.json index 8e920661871f1..838fe3286e031 100644 --- a/utils/update_checkout/update-checkout-config.json +++ b/utils/update_checkout/update-checkout-config.json @@ -129,10 +129,10 @@ "default-branch-scheme": "main", "branch-schemes": { "main": { - "aliases": ["swift/main", "main", "stable/20240723"], + "aliases": ["swift/main", "main", "stable/21.x"], "repos": { - "llvm-project": "stable/20240723", - "swift-llvm-bindings": "stable/20240723", + "llvm-project": "stable/21.x", + "swift-llvm-bindings": "stable/21.x", "swift": "main", "cmark": "gfm", "llbuild": "main", @@ -557,7 +557,7 @@ } }, "rebranch": { - "aliases": ["rebranch", "stable/21.x", "llvm.org/main"], + "aliases": ["rebranch", "llvm.org/main"], "repos": { "llvm-project": "stable/21.x", "swift-llvm-bindings": "stable/21.x",