diff --git a/.ci/metrics/metrics.py b/.ci/metrics/metrics.py index d219c9e55169e..354b5058100e7 100644 --- a/.ci/metrics/metrics.py +++ b/.ci/metrics/metrics.py @@ -24,6 +24,7 @@ class JobMetrics: status: int created_at_ns: int workflow_id: int + workflow_name: str @dataclass @@ -199,6 +200,7 @@ def get_per_workflow_metrics( job_result, created_at_ns, workflow_run.id, + workflow_run.name, ) ) @@ -278,7 +280,7 @@ def main(): for workflow_metric in reversed(current_metrics): if isinstance(workflow_metric, JobMetrics): workflows_to_track[ - workflow_metric.job_name + workflow_metric.workflow_name ] = workflow_metric.workflow_id time.sleep(SCRAPE_INTERVAL_SECONDS) diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp index 76fa2d916f0e8..509fce3a38471 100644 --- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp @@ -179,15 +179,15 @@ static bool checkOverrideByDerivedMethod(const CXXMethodDecl *BaseMD, bool VirtualNearMissCheck::isPossibleToBeOverridden( const CXXMethodDecl *BaseMD) { - auto Iter = PossibleMap.find(BaseMD); - if (Iter != PossibleMap.end()) + auto [Iter, Inserted] = PossibleMap.try_emplace(BaseMD); + if (!Inserted) return Iter->second; bool IsPossible = !BaseMD->isImplicit() && !isa(BaseMD) && !isa(BaseMD) && BaseMD->isVirtual() && !BaseMD->isOverloadedOperator() && !isa(BaseMD); - PossibleMap[BaseMD] = IsPossible; + Iter->second = IsPossible; return IsPossible; } diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp index 6a467910521f5..3d3a79d8eaf21 100644 --- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp @@ -199,10 +199,10 @@ void IncludeModernizePPCallbacks::InclusionDirective( // 2. Insert `using namespace std;` to the beginning of TU. // 3. Do nothing and let the user deal with the migration himself. SourceLocation DiagLoc = FilenameRange.getBegin(); - if (CStyledHeaderToCxx.count(FileName) != 0) { - IncludesToBeProcessed.emplace_back( - IncludeMarker{CStyledHeaderToCxx[FileName], FileName, - FilenameRange.getAsRange(), DiagLoc}); + if (auto It = CStyledHeaderToCxx.find(FileName); + It != CStyledHeaderToCxx.end()) { + IncludesToBeProcessed.emplace_back(IncludeMarker{ + It->second, FileName, FilenameRange.getAsRange(), DiagLoc}); } else if (DeleteHeaders.count(FileName) != 0) { IncludesToBeProcessed.emplace_back( // NOLINTNEXTLINE(modernize-use-emplace) - false-positive diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index efaacdf18d50a..6272f32fa845a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -270,6 +270,10 @@ Code Completion Static Analyzer --------------- +- Clang currently support extending lifetime of object bound to + reference members of aggregates in CFG and ExprEngine, that are + created from default member initializer. + New features ^^^^^^^^^^^^ diff --git a/clang/include/clang/AST/Redeclarable.h b/clang/include/clang/AST/Redeclarable.h index ee21f11e5f707..68516c66aaf65 100644 --- a/clang/include/clang/AST/Redeclarable.h +++ b/clang/include/clang/AST/Redeclarable.h @@ -114,8 +114,6 @@ class Redeclarable { bool isFirst() const { return isa(Link) || - // FIXME: 'template' is required on the next line due to an - // apparent clang bug. isa(cast(Link)); } diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index c4f0fc55b4a38..f10af8f5bd6b2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12626,6 +12626,9 @@ def err_hlsl_pointers_unsupported : Error< "%select{pointers|references}0 are unsupported in HLSL">; def err_hlsl_missing_resource_class : Error<"HLSL resource needs to have [[hlsl::resource_class()]] attribute">; def err_hlsl_attribute_needs_intangible_type: Error<"attribute %0 can be used only on HLSL intangible type %1">; +def err_hlsl_incorrect_num_initializers: Error< + "too %select{few|many}0 initializers in list for type %1 " + "(expected %2 but found %3)">; def err_hlsl_operator_unsupported : Error< "the '%select{&|*|->}0' operator is unsupported in HLSL">; diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index c9266ea50e4bf..4f4bbe95476ee 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -26,6 +26,8 @@ namespace clang { class AttributeCommonInfo; class IdentifierInfo; +class InitializedEntity; +class InitializationKind; class ParsedAttr; class Scope; class VarDecl; @@ -149,6 +151,9 @@ class SemaHLSL : public SemaBase { QualType getInoutParameterType(QualType Ty); + bool TransformInitList(const InitializedEntity &Entity, + const InitializationKind &Kind, InitListExpr *Init); + private: // HLSL resource type attributes need to be processed all at once. // This is a list to collect them. diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 079e39a9fb678..ad291d0948b57 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -751,9 +751,6 @@ class ASTWriter : public ASTDeserializationListener, /// Get the unique number used to refer to the given macro. serialization::MacroID getMacroRef(MacroInfo *MI, const IdentifierInfo *Name); - /// Determine the ID of an already-emitted macro. - serialization::MacroID getMacroID(MacroInfo *MI); - uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name); /// Emit a reference to a type. diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index cf39209819ade..59c236c9da8c8 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -2707,7 +2707,8 @@ bool Compiler::VisitMaterializeTemporaryExpr( // For everyhing else, use local variables. if (SubExprT) { - unsigned LocalIndex = allocateLocalPrimitive(E, *SubExprT, /*IsConst=*/true, + bool IsConst = SubExpr->getType().isConstQualified(); + unsigned LocalIndex = allocateLocalPrimitive(E, *SubExprT, IsConst, /*IsExtended=*/true); if (!this->visit(SubExpr)) return false; @@ -3028,7 +3029,7 @@ bool Compiler::VisitCXXConstructExpr(const CXXConstructExpr *E) { size_t NumElems = CAT->getZExtSize(); const Function *Func = getFunction(E->getConstructor()); - if (!Func || !Func->isConstexpr()) + if (!Func) return false; // FIXME(perf): We're calling the constructor once per array element here, diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h index 96c82a18913e0..01fa4b198de67 100644 --- a/clang/lib/AST/ByteCode/Descriptor.h +++ b/clang/lib/AST/ByteCode/Descriptor.h @@ -274,6 +274,7 @@ struct Descriptor final { void dump() const; void dump(llvm::raw_ostream &OS) const; + void dumpFull(unsigned Offset = 0, unsigned Indent = 0) const; }; /// Bitfield tracking the initialisation status of elements of primitive arrays. diff --git a/clang/lib/AST/ByteCode/Disasm.cpp b/clang/lib/AST/ByteCode/Disasm.cpp index 92a169a37c365..85fc30482b003 100644 --- a/clang/lib/AST/ByteCode/Disasm.cpp +++ b/clang/lib/AST/ByteCode/Disasm.cpp @@ -251,6 +251,38 @@ LLVM_DUMP_METHOD void Descriptor::dump(llvm::raw_ostream &OS) const { OS << " dummy"; } +/// Dump descriptor, including all valid offsets. +LLVM_DUMP_METHOD void Descriptor::dumpFull(unsigned Offset, + unsigned Indent) const { + unsigned Spaces = Indent * 2; + llvm::raw_ostream &OS = llvm::errs(); + OS.indent(Spaces); + dump(OS); + OS << '\n'; + OS.indent(Spaces) << "Metadata: " << getMetadataSize() << " bytes\n"; + OS.indent(Spaces) << "Size: " << getSize() << " bytes\n"; + OS.indent(Spaces) << "AllocSize: " << getAllocSize() << " bytes\n"; + Offset += getMetadataSize(); + if (isCompositeArray()) { + OS.indent(Spaces) << "Elements: " << getNumElems() << '\n'; + unsigned FO = Offset; + for (unsigned I = 0; I != getNumElems(); ++I) { + FO += sizeof(InlineDescriptor); + assert(ElemDesc->getMetadataSize() == 0); + OS.indent(Spaces) << "Element " << I << " offset: " << FO << '\n'; + ElemDesc->dumpFull(FO, Indent + 1); + + FO += ElemDesc->getAllocSize(); + } + } else if (isRecord()) { + ElemRecord->dump(OS, Indent + 1, Offset); + } else if (isPrimitive()) { + } else { + } + + OS << '\n'; +} + LLVM_DUMP_METHOD void InlineDescriptor::dump(llvm::raw_ostream &OS) const { { ColorScope SC(OS, true, {llvm::raw_ostream::BLUE, true}); diff --git a/clang/lib/AST/ByteCode/DynamicAllocator.cpp b/clang/lib/AST/ByteCode/DynamicAllocator.cpp index 819fbdb8b070b..3ef8c2e1f3e7c 100644 --- a/clang/lib/AST/ByteCode/DynamicAllocator.cpp +++ b/clang/lib/AST/ByteCode/DynamicAllocator.cpp @@ -54,6 +54,7 @@ Block *DynamicAllocator::allocate(const Expr *Source, PrimType T, Block *DynamicAllocator::allocate(const Descriptor *ElementDesc, size_t NumElements, unsigned EvalID, Form AllocForm) { + assert(ElementDesc->getMetadataSize() == 0); // Create a new descriptor for an array of the specified size and // element type. const Descriptor *D = allocateDescriptor( @@ -72,6 +73,7 @@ Block *DynamicAllocator::allocate(const Descriptor *D, unsigned EvalID, auto *B = new (Memory.get()) Block(EvalID, D, /*isStatic=*/false); B->invokeCtor(); + assert(D->getMetadataSize() == sizeof(InlineDescriptor)); InlineDescriptor *ID = reinterpret_cast(B->rawData()); ID->Desc = D; ID->IsActive = true; diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 5cc371c7ee495..73cc107b7dbff 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -2896,9 +2896,7 @@ inline bool Alloc(InterpState &S, CodePtr OpPC, const Descriptor *Desc) { Block *B = Allocator.allocate(Desc, S.Ctx.getEvalID(), DynamicAllocator::Form::NonArray); assert(B); - S.Stk.push(B); - return true; } @@ -2923,8 +2921,7 @@ inline bool AllocN(InterpState &S, CodePtr OpPC, PrimType T, const Expr *Source, Allocator.allocate(Source, T, static_cast(NumElements), S.Ctx.getEvalID(), DynamicAllocator::Form::Array); assert(B); - S.Stk.push(B, sizeof(InlineDescriptor)); - + S.Stk.push(B); return true; } @@ -2950,9 +2947,7 @@ inline bool AllocCN(InterpState &S, CodePtr OpPC, const Descriptor *ElementDesc, Allocator.allocate(ElementDesc, static_cast(NumElements), S.Ctx.getEvalID(), DynamicAllocator::Form::Array); assert(B); - - S.Stk.push(B, sizeof(InlineDescriptor)); - + S.Stk.push(B); return true; } diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 55ac41736344d..b964906fb6594 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -1655,27 +1655,27 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC, return false; } + bool IsArray = NumElems.ugt(1); std::optional ElemT = S.getContext().classify(ElemType); DynamicAllocator &Allocator = S.getAllocator(); if (ElemT) { - if (NumElems.ule(1)) { - const Descriptor *Desc = - S.P.createDescriptor(NewCall, *ElemT, Descriptor::InlineDescMD, - /*IsConst=*/false, /*IsTemporary=*/false, - /*IsMutable=*/false); - Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(), + if (IsArray) { + Block *B = Allocator.allocate(NewCall, *ElemT, NumElems.getZExtValue(), + S.Ctx.getEvalID(), DynamicAllocator::Form::Operator); assert(B); - - S.Stk.push(B); + S.Stk.push(Pointer(B).atIndex(0)); return true; } - assert(NumElems.ugt(1)); - Block *B = - Allocator.allocate(NewCall, *ElemT, NumElems.getZExtValue(), - S.Ctx.getEvalID(), DynamicAllocator::Form::Operator); + const Descriptor *Desc = + S.P.createDescriptor(NewCall, *ElemT, Descriptor::InlineDescMD, + /*IsConst=*/false, /*IsTemporary=*/false, + /*IsMutable=*/false); + Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(), + DynamicAllocator::Form::Operator); assert(B); + S.Stk.push(B); return true; } @@ -1683,21 +1683,22 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC, assert(!ElemT); // Structs etc. const Descriptor *Desc = S.P.createDescriptor( - NewCall, ElemType.getTypePtr(), Descriptor::InlineDescMD, + NewCall, ElemType.getTypePtr(), + IsArray ? std::nullopt : Descriptor::InlineDescMD, /*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false, /*Init=*/nullptr); - if (NumElems.ule(1)) { - Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(), - DynamicAllocator::Form::Operator); + if (IsArray) { + Block *B = + Allocator.allocate(Desc, NumElems.getZExtValue(), S.Ctx.getEvalID(), + DynamicAllocator::Form::Operator); assert(B); - S.Stk.push(B); + S.Stk.push(Pointer(B).atIndex(0)); return true; } - Block *B = - Allocator.allocate(Desc, NumElems.getZExtValue(), S.Ctx.getEvalID(), - DynamicAllocator::Form::Operator); + Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(), + DynamicAllocator::Form::Operator); assert(B); S.Stk.push(B); return true; diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp index 833c9ef88d770..0754e259b7cb3 100644 --- a/clang/lib/AST/ByteCode/Program.cpp +++ b/clang/lib/AST/ByteCode/Program.cpp @@ -432,8 +432,8 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty, return allocateDescriptor(D, *T, MDSize, IsTemporary, Descriptor::UnknownSize{}); } else { - const Descriptor *Desc = createDescriptor(D, ElemTy.getTypePtr(), - MDSize, IsConst, IsTemporary); + const Descriptor *Desc = createDescriptor( + D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary); if (!Desc) return nullptr; return allocateDescriptor(D, Desc, MDSize, IsTemporary, diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index e394e0515e599..1aa48f0026335 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -1462,6 +1462,18 @@ void CXXRecordDecl::addedMember(Decl *D) { if (Using->getDeclName().getCXXOverloadedOperator() == OO_Equal) data().HasInheritedAssignment = true; } + + // HLSL: All user-defined data types are aggregates and use aggregate + // initialization, meanwhile most, but not all built-in types behave like + // aggregates. Resource types, and some other HLSL types that wrap handles + // don't behave like aggregates. We can identify these as different because we + // implicitly define "special" member functions, which aren't spellable in + // HLSL. This all _needs_ to change in the future. There are two + // relevant HLSL feature proposals that will depend on this changing: + // * 0005-strict-initializer-lists.md + // * https://github.com/microsoft/hlsl-specs/pull/325 + if (getLangOpts().HLSL) + data().Aggregate = data().UserDeclaredSpecialMembers == 0; } bool CXXRecordDecl::isLiteral() const { diff --git a/clang/lib/AST/ExternalASTMerger.cpp b/clang/lib/AST/ExternalASTMerger.cpp index 257e8338dedef..1c903b5104bf4 100644 --- a/clang/lib/AST/ExternalASTMerger.cpp +++ b/clang/lib/AST/ExternalASTMerger.cpp @@ -206,16 +206,14 @@ class LazyASTImporter : public ASTImporter { << "\n"; Source FromDC( cast(From)->getPrimaryContext()); - if (FromOrigins.count(FromDC) && - Parent.HasImporterForOrigin(*FromOrigins.at(FromDC).AST)) { + if (auto It = FromOrigins.find(FromDC); + It != FromOrigins.end() && + Parent.HasImporterForOrigin(*It->second.AST)) { if (LoggingEnabled) - logs() << "(ExternalASTMerger*)" << (void*)&Parent - << " forced origin (DeclContext*)" - << (void*)FromOrigins.at(FromDC).DC - << ", (ASTContext*)" - << (void*)FromOrigins.at(FromDC).AST - << "\n"; - Parent.ForceRecordOrigin(ToDC, FromOrigins.at(FromDC)); + logs() << "(ExternalASTMerger*)" << (void *)&Parent + << " forced origin (DeclContext*)" << (void *)It->second.DC + << ", (ASTContext*)" << (void *)It->second.AST << "\n"; + Parent.ForceRecordOrigin(ToDC, It->second); } else { if (LoggingEnabled) logs() << "(ExternalASTMerger*)" << (void*)&Parent diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp index e62e71bf5a514..580613b2618fb 100644 --- a/clang/lib/AST/ParentMap.cpp +++ b/clang/lib/AST/ParentMap.cpp @@ -13,6 +13,7 @@ #include "clang/AST/ParentMap.h" #include "clang/AST/Decl.h" #include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" #include "clang/AST/StmtObjC.h" #include "llvm/ADT/DenseMap.h" @@ -103,6 +104,22 @@ static void BuildParentMap(MapTy& M, Stmt* S, BuildParentMap(M, SubStmt, OVMode); } break; + case Stmt::CXXDefaultArgExprClass: + if (auto *Arg = dyn_cast(S)) { + if (Arg->hasRewrittenInit()) { + M[Arg->getExpr()] = S; + BuildParentMap(M, Arg->getExpr(), OVMode); + } + } + break; + case Stmt::CXXDefaultInitExprClass: + if (auto *Init = dyn_cast(S)) { + if (Init->hasRewrittenInit()) { + M[Init->getExpr()] = S; + BuildParentMap(M, Init->getExpr(), OVMode); + } + } + break; default: for (Stmt *SubStmt : S->children()) { if (SubStmt) { diff --git a/clang/lib/AST/VTableBuilder.cpp b/clang/lib/AST/VTableBuilder.cpp index 19d76df99dbe3..18893b996b5d6 100644 --- a/clang/lib/AST/VTableBuilder.cpp +++ b/clang/lib/AST/VTableBuilder.cpp @@ -2115,8 +2115,8 @@ void ItaniumVTableBuilder::dumpLayout(raw_ostream &Out) { // Dump the next address point. uint64_t NextIndex = Index + 1; - if (AddressPointsByIndex.count(NextIndex)) { - if (AddressPointsByIndex.count(NextIndex) == 1) { + if (unsigned Count = AddressPointsByIndex.count(NextIndex)) { + if (Count == 1) { const BaseSubobject &Base = AddressPointsByIndex.find(NextIndex)->second; diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 3e144395cffc6..c82dbc42fb9d8 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -556,6 +556,10 @@ class CFGBuilder { private: // Visitors to walk an AST and construct the CFG. + CFGBlock *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Default, + AddStmtChoice asc); + CFGBlock *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Default, + AddStmtChoice asc); CFGBlock *VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc); CFGBlock *VisitAddrLabelExpr(AddrLabelExpr *A, AddStmtChoice asc); CFGBlock *VisitAttributedStmt(AttributedStmt *A, AddStmtChoice asc); @@ -2263,16 +2267,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc, asc, ExternallyDestructed); case Stmt::CXXDefaultArgExprClass: + return VisitCXXDefaultArgExpr(cast(S), asc); + case Stmt::CXXDefaultInitExprClass: - // FIXME: The expression inside a CXXDefaultArgExpr is owned by the - // called function's declaration, not by the caller. If we simply add - // this expression to the CFG, we could end up with the same Expr - // appearing multiple times (PR13385). - // - // It's likewise possible for multiple CXXDefaultInitExprs for the same - // expression to be used in the same function (through aggregate - // initialization). - return VisitStmt(S, asc); + return VisitCXXDefaultInitExpr(cast(S), asc); case Stmt::CXXBindTemporaryExprClass: return VisitCXXBindTemporaryExpr(cast(S), asc); @@ -2442,6 +2440,44 @@ CFGBlock *CFGBuilder::VisitChildren(Stmt *S) { return B; } +CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg, + AddStmtChoice asc) { + if (Arg->hasRewrittenInit()) { + if (asc.alwaysAdd(*this, Arg)) { + autoCreateBlock(); + appendStmt(Block, Arg); + } + return VisitStmt(Arg->getExpr()->IgnoreParens(), asc); + } + + // We can't add the default argument if it's not rewritten because the + // expression inside a CXXDefaultArgExpr is owned by the called function's + // declaration, not by the caller, we could end up with the same expression + // appearing multiple times. + return VisitStmt(Arg, asc); +} + +CFGBlock *CFGBuilder::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Init, + AddStmtChoice asc) { + if (Init->hasRewrittenInit()) { + if (asc.alwaysAdd(*this, Init)) { + autoCreateBlock(); + appendStmt(Block, Init); + } + + // Unlike CXXDefaultArgExpr::getExpr stripped off the top level FullExpr and + // ConstantExpr, CXXDefaultInitExpr::getExpr does not do this, so we don't + // need to ignore ParenExprs, because the top level will not be a ParenExpr. + return VisitStmt(Init->getExpr(), asc); + } + + // We can't add the default initializer if it's not rewritten because multiple + // CXXDefaultInitExprs for the same sub-expression to be used in the same + // function (through aggregate initialization). we could end up with the same + // expression appearing multiple times. + return VisitStmt(Init, asc); +} + CFGBlock *CFGBuilder::VisitInitListExpr(InitListExpr *ILE, AddStmtChoice asc) { if (asc.alwaysAdd(*this, ILE)) { autoCreateBlock(); diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp index dd81c8e0a3d54..3b1f716f8dea1 100644 --- a/clang/lib/Analysis/ReachableCode.cpp +++ b/clang/lib/Analysis/ReachableCode.cpp @@ -454,11 +454,12 @@ bool DeadCodeScan::isDeadCodeRoot(const clang::CFGBlock *Block) { return isDeadRoot; } -// Check if the given `DeadStmt` is a coroutine statement and is a substmt of -// the coroutine statement. `Block` is the CFGBlock containing the `DeadStmt`. -static bool isInCoroutineStmt(const Stmt *DeadStmt, const CFGBlock *Block) { +// Check if the given `DeadStmt` is one of target statements or is a sub-stmt of +// them. `Block` is the CFGBlock containing the `DeadStmt`. +template +static bool isDeadStmtInOneOf(const Stmt *DeadStmt, const CFGBlock *Block) { // The coroutine statement, co_return, co_await, or co_yield. - const Stmt *CoroStmt = nullptr; + const Stmt *TargetStmt = nullptr; // Find the first coroutine statement after the DeadStmt in the block. bool AfterDeadStmt = false; for (CFGBlock::const_iterator I = Block->begin(), E = Block->end(); I != E; @@ -467,32 +468,27 @@ static bool isInCoroutineStmt(const Stmt *DeadStmt, const CFGBlock *Block) { const Stmt *S = CS->getStmt(); if (S == DeadStmt) AfterDeadStmt = true; - if (AfterDeadStmt && - // For simplicity, we only check simple coroutine statements. - (llvm::isa(S) || llvm::isa(S))) { - CoroStmt = S; + if (AfterDeadStmt && llvm::isa(S)) { + TargetStmt = S; break; } } - if (!CoroStmt) + if (!TargetStmt) return false; struct Checker : DynamicRecursiveASTVisitor { const Stmt *DeadStmt; - bool CoroutineSubStmt = false; - Checker(const Stmt *S) : DeadStmt(S) { - // Statements captured in the CFG can be implicit. - ShouldVisitImplicitCode = true; - } + bool IsSubStmtOfTargetStmt = false; + Checker(const Stmt *S) : DeadStmt(S) { ShouldVisitImplicitCode = true; } bool VisitStmt(Stmt *S) override { if (S == DeadStmt) - CoroutineSubStmt = true; + IsSubStmtOfTargetStmt = true; return true; } }; Checker checker(DeadStmt); - checker.TraverseStmt(const_cast(CoroStmt)); - return checker.CoroutineSubStmt; + checker.TraverseStmt(const_cast(TargetStmt)); + return checker.IsSubStmtOfTargetStmt; } static bool isValidDeadStmt(const Stmt *S, const clang::CFGBlock *Block) { @@ -503,7 +499,12 @@ static bool isValidDeadStmt(const Stmt *S, const clang::CFGBlock *Block) { // Coroutine statements are never considered dead statements, because removing // them may change the function semantic if it is the only coroutine statement // of the coroutine. - return !isInCoroutineStmt(S, Block); + // + // If the dead stmt is a sub-stmt of CXXDefaultInitExpr and CXXDefaultArgExpr, + // we would rather expect to find CXXDefaultInitExpr and CXXDefaultArgExpr as + // a valid dead stmt. + return !isDeadStmtInOneOf(S, Block); } const Stmt *DeadCodeScan::findDeadCode(const clang::CFGBlock *Block) { diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 0b0ffd2db853f..191912ca7d800 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -5551,6 +5551,12 @@ CodeGenFunction::getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e) { return EmitAnyExpr(e->getSourceExpr()); } +bool CodeGenFunction::isOpaqueValueEmitted(const OpaqueValueExpr *E) { + if (OpaqueValueMapping::shouldBindAsLValue(E)) + return OpaqueLValues.contains(E); + return OpaqueRValues.contains(E); +} + RValue CodeGenFunction::EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc) { diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index d25d0f2c2133c..625ca363d9019 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "CGCXXABI.h" +#include "CGHLSLRuntime.h" #include "CGObjCRuntime.h" #include "CGRecordLayout.h" #include "CodeGenFunction.h" @@ -1776,6 +1777,18 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr( } #endif + // HLSL initialization lists in the AST are an expansion which can contain + // side-effecting expressions wrapped in opaque value expressions. To properly + // emit these we need to emit the opaque values before we emit the argument + // expressions themselves. This is a little hacky, but it prevents us needing + // to do a bigger AST-level change for a language feature that we need + // deprecate in the near future. See related HLSL language proposals: + // * 0005-strict-initializer-lists.md + // * https://github.com/microsoft/hlsl-specs/pull/325 + if (CGF.getLangOpts().HLSL && isa(ExprToVisit)) + CGF.CGM.getHLSLRuntime().emitInitListOpaqueValues( + CGF, cast(ExprToVisit)); + AggValueSlot Dest = EnsureSlot(ExprToVisit->getType()); LValue DestLV = CGF.MakeAddrLValue(Dest.getAddress(), ExprToVisit->getType()); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 03ddc87d8d3df..856d8b1b2948d 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -14,9 +14,11 @@ #include "CGHLSLRuntime.h" #include "CGDebugInfo.h" +#include "CodeGenFunction.h" #include "CodeGenModule.h" #include "TargetInfo.h" #include "clang/AST/Decl.h" +#include "clang/AST/RecursiveASTVisitor.h" #include "clang/Basic/TargetOptions.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/LLVMContext.h" @@ -617,3 +619,33 @@ llvm::Instruction *CGHLSLRuntime::getConvergenceToken(BasicBlock &BB) { llvm_unreachable("Convergence token should have been emitted."); return nullptr; } + +class OpaqueValueVisitor : public RecursiveASTVisitor { +public: + llvm::SmallPtrSet OVEs; + OpaqueValueVisitor() {} + + bool VisitOpaqueValueExpr(OpaqueValueExpr *E) { + OVEs.insert(E); + return true; + } +}; + +void CGHLSLRuntime::emitInitListOpaqueValues(CodeGenFunction &CGF, + InitListExpr *E) { + + typedef CodeGenFunction::OpaqueValueMappingData OpaqueValueMappingData; + OpaqueValueVisitor Visitor; + Visitor.TraverseStmt(E); + for (auto *OVE : Visitor.OVEs) { + if (CGF.isOpaqueValueEmitted(OVE)) + continue; + if (OpaqueValueMappingData::shouldBindAsLValue(OVE)) { + LValue LV = CGF.EmitLValue(OVE->getSourceExpr()); + OpaqueValueMappingData::bind(CGF, OVE, LV); + } else { + RValue RV = CGF.EmitAnyExpr(OVE->getSourceExpr()); + OpaqueValueMappingData::bind(CGF, OVE, RV); + } + } +} diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index 032b2dee82f21..8767a2ddceb96 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -55,6 +55,7 @@ class StructType; namespace clang { class VarDecl; class ParmVarDecl; +class InitListExpr; class HLSLBufferDecl; class HLSLResourceBindingAttr; class Type; @@ -65,6 +66,7 @@ class FunctionDecl; namespace CodeGen { class CodeGenModule; +class CodeGenFunction; class CGHLSLRuntime { public: @@ -161,6 +163,8 @@ class CGHLSLRuntime { llvm::Instruction *getConvergenceToken(llvm::BasicBlock &BB); + void emitInitListOpaqueValues(CodeGenFunction &CGF, InitListExpr *E); + private: void addBufferResourceAnnotation(llvm::GlobalVariable *GV, llvm::hlsl::ResourceClass RC, diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 64cd8a3ac55e2..8c5362bcc33c4 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -3011,6 +3011,10 @@ class CodeGenFunction : public CodeGenTypeCache { /// otherwise create one. RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e); + /// isOpaqueValueEmitted - Return true if the opaque value expression has + /// already been emitted. + bool isOpaqueValueEmitted(const OpaqueValueExpr *E); + /// Get the index of the current ArrayInitLoopExpr, if any. llvm::Value *getArrayInitIndex() { return ArrayInitIndex; } diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp index a6d859f0ebfec..62206c5fb3c59 100644 --- a/clang/lib/Driver/ToolChains/FreeBSD.cpp +++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp @@ -452,12 +452,13 @@ void FreeBSD::addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, void FreeBSD::AddCXXStdlibLibArgs(const ArgList &Args, ArgStringList &CmdArgs) const { + Generic_ELF::AddCXXStdlibLibArgs(Args, CmdArgs); unsigned Major = getTriple().getOSMajorVersion(); - bool Profiling = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14; - - CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++"); - if (Args.hasArg(options::OPT_fexperimental_library)) - CmdArgs.push_back("-lc++experimental"); + bool SuffixedLib = Args.hasArg(options::OPT_pg) && Major != 0 && Major < 14; + if (SuffixedLib && GetCXXStdlibType(Args) == CST_Libcxx) + std::replace_if( + CmdArgs.begin(), CmdArgs.end(), + [](const char *S) { return StringRef(S) == "-lc++"; }, "-lc++_p"); } void FreeBSD::AddCudaIncludeArgs(const ArgList &DriverArgs, diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index b3540f39e6f69..069fd40e2834c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1313,7 +1313,7 @@ class AnnotatingParser { switch (bool IsIf = false; Tok->Tok.getKind()) { case tok::plus: case tok::minus: - if (!Tok->Previous && Line.MustBeDeclaration) + if (!Tok->getPreviousNonComment() && Line.MustBeDeclaration) Tok->setType(TT_ObjCMethodSpecifier); break; case tok::colon: diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 4e040183f2f0a..3a24d72d83e27 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -510,7 +510,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) { break; do { NextTok = Tokens->getNextToken(); - } while (NextTok->NewlinesBefore == 0 && NextTok->isNot(tok::eof)); + } while (!NextTok->HasUnescapedNewline && NextTok->isNot(tok::eof)); while (NextTok->is(tok::comment)) NextTok = Tokens->getNextToken(); diff --git a/clang/lib/Headers/amxavx512intrin.h b/clang/lib/Headers/amxavx512intrin.h index a158983482d5b..bbde44fc265b3 100644 --- a/clang/lib/Headers/amxavx512intrin.h +++ b/clang/lib/Headers/amxavx512intrin.h @@ -228,7 +228,7 @@ /// dst.byte[i] := a.row[row_index].byte[row_chunk+i] /// ENDFOR /// \endcode -#define _tile_movrow(a, b) __builtin_ia32_tilemovrow(a, b) +#define _tile_movrow(a, b) ((__m512i)__builtin_ia32_tilemovrow(a, b)) /// This is internal intrinsic. C/C++ user should avoid calling it directly. diff --git a/clang/lib/Headers/shaintrin.h b/clang/lib/Headers/shaintrin.h index 232e1fa298230..e21d3bded7660 100644 --- a/clang/lib/Headers/shaintrin.h +++ b/clang/lib/Headers/shaintrin.h @@ -47,8 +47,9 @@ /// An immediate value where bits [1:0] select among four possible /// combining functions and rounding constants (not specified here). /// \returns A 128-bit vector of [4 x i32] containing the updated SHA-1 state. -#define _mm_sha1rnds4_epu32(V1, V2, M) \ - __builtin_ia32_sha1rnds4((__v4si)(__m128i)(V1), (__v4si)(__m128i)(V2), (M)) +#define _mm_sha1rnds4_epu32(V1, V2, M) \ + ((__m128i)__builtin_ia32_sha1rnds4((__v4si)(__m128i)(V1), \ + (__v4si)(__m128i)(V2), (M))) /// Calculates the SHA-1 state variable E from the SHA-1 state variables in /// the 128-bit vector of [4 x i32] in \a __X, adds that to the next set of diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp index 1e54b413dc59c..0a5a1bcc74865 100644 --- a/clang/lib/Index/USRGeneration.cpp +++ b/clang/lib/Index/USRGeneration.cpp @@ -859,16 +859,12 @@ void USRGenerator::VisitType(QualType T) { } // If we have already seen this (non-built-in) type, use a substitution - // encoding. - llvm::DenseMap::iterator Substitution - = TypeSubstitutions.find(T.getTypePtr()); - if (Substitution != TypeSubstitutions.end()) { + // encoding. Otherwise, record this as a substitution. + auto [Substitution, Inserted] = + TypeSubstitutions.try_emplace(T.getTypePtr(), TypeSubstitutions.size()); + if (!Inserted) { Out << 'S' << Substitution->second << '_'; return; - } else { - // Record this as a substitution. - unsigned Number = TypeSubstitutions.size(); - TypeSubstitutions[T.getTypePtr()] = Number; } if (const PointerType *PT = T->getAs()) { diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 66c233de4ef30..aae61f612a4bc 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -11679,8 +11679,12 @@ static void AnalyzeImplicitConversions( // Propagate whether we are in a C++ list initialization expression. // If so, we do not issue warnings for implicit int-float conversion // precision loss, because C++11 narrowing already handles it. - bool IsListInit = Item.IsListInit || - (isa(OrigE) && S.getLangOpts().CPlusPlus); + // + // HLSL's initialization lists are special, so they shouldn't observe the C++ + // behavior here. + bool IsListInit = + Item.IsListInit || (isa(OrigE) && + S.getLangOpts().CPlusPlus && !S.getLangOpts().HLSL); if (E->isTypeDependent() || E->isValueDependent()) return; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 98c245cdea78f..362df485a025c 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -16014,7 +16014,8 @@ static void diagnoseImplicitlyRetainedSelf(Sema &S) { llvm::DenseMap EscapeInfo; auto IsOrNestedInEscapingBlock = [&](const BlockDecl *BD) { - if (auto It = EscapeInfo.find(BD); It != EscapeInfo.end()) + auto [It, Inserted] = EscapeInfo.try_emplace(BD); + if (!Inserted) return It->second; bool R = false; @@ -16027,7 +16028,7 @@ static void diagnoseImplicitlyRetainedSelf(Sema &S) { CurBD = CurBD->getParent()->getInnermostBlockDecl(); } while (CurBD); - return EscapeInfo[BD] = R; + return It->second = R; }; // If the location where 'self' is implicitly retained is inside a escaping diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 3cd4010740d19..5817632b61dbd 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5570,8 +5570,10 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc, /*SkipImmediateInvocations=*/NestedDefaultChecking)) return ExprError(); + Expr *RewrittenExpr = (Init == Param->getDefaultArg() ? nullptr : Init); return CXXDefaultArgExpr::Create(Context, InitializationContext->Loc, Param, - Init, InitializationContext->Context); + RewrittenExpr, + InitializationContext->Context); } static FieldDecl *FindFieldDeclInstantiationPattern(const ASTContext &Ctx, @@ -5689,10 +5691,11 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) { return ExprError(); } Init = Res.get(); - + Expr *RewrittenInit = + (Init == Field->getInClassInitializer() ? nullptr : Init); return CXXDefaultInitExpr::Create(Context, InitializationContext->Loc, Field, InitializationContext->Context, - Init); + RewrittenInit); } // DR1351: diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 9a60054a6169e..957c3a0888438 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -2589,17 +2589,20 @@ static void BuildFlattenedTypeList(QualType BaseTy, continue; } if (const auto *RT = dyn_cast(T)) { - const RecordDecl *RD = RT->getDecl(); - if (RD->isUnion()) { + const CXXRecordDecl *RD = RT->getAsCXXRecordDecl(); + assert(RD && "HLSL record types should all be CXXRecordDecls!"); + + if (RD->isStandardLayout()) + RD = RD->getStandardLayoutBaseWithFields(); + + // For types that we shouldn't decompose (unions and non-aggregates), just + // add the type itself to the list. + if (RD->isUnion() || !RD->isAggregate()) { List.push_back(T); continue; } - const CXXRecordDecl *CXXD = dyn_cast(RD); llvm::SmallVector FieldTypes; - if (CXXD && CXXD->isStandardLayout()) - RD = CXXD->getStandardLayoutBaseWithFields(); - for (const auto *FD : RD->fields()) FieldTypes.push_back(FD->getType()); // Reverse the newly added sub-range. @@ -2608,9 +2611,9 @@ static void BuildFlattenedTypeList(QualType BaseTy, // If this wasn't a standard layout type we may also have some base // classes to deal with. - if (CXXD && !CXXD->isStandardLayout()) { + if (!RD->isStandardLayout()) { FieldTypes.clear(); - for (const auto &Base : CXXD->bases()) + for (const auto &Base : RD->bases()) FieldTypes.push_back(Base.getType()); std::reverse(FieldTypes.begin(), FieldTypes.end()); WorkList.insert(WorkList.end(), FieldTypes.begin(), FieldTypes.end()); @@ -3056,3 +3059,193 @@ void SemaHLSL::processExplicitBindingsOnDecl(VarDecl *VD) { } } } + +static bool CastInitializer(Sema &S, ASTContext &Ctx, Expr *E, + llvm::SmallVectorImpl &List, + llvm::SmallVectorImpl &DestTypes) { + if (List.size() >= DestTypes.size()) { + List.push_back(E); + // This is odd, but it isn't technically a failure due to conversion, we + // handle mismatched counts of arguments differently. + return true; + } + InitializedEntity Entity = InitializedEntity::InitializeParameter( + Ctx, DestTypes[List.size()], false); + ExprResult Res = S.PerformCopyInitialization(Entity, E->getBeginLoc(), E); + if (Res.isInvalid()) + return false; + Expr *Init = Res.get(); + List.push_back(Init); + return true; +} + +static bool BuildInitializerList(Sema &S, ASTContext &Ctx, Expr *E, + llvm::SmallVectorImpl &List, + llvm::SmallVectorImpl &DestTypes) { + // If this is an initialization list, traverse the sub initializers. + if (auto *Init = dyn_cast(E)) { + for (auto *SubInit : Init->inits()) + if (!BuildInitializerList(S, Ctx, SubInit, List, DestTypes)) + return false; + return true; + } + + // If this is a scalar type, just enqueue the expression. + QualType Ty = E->getType(); + + if (Ty->isScalarType() || (Ty->isRecordType() && !Ty->isAggregateType())) + return CastInitializer(S, Ctx, E, List, DestTypes); + + if (auto *VecTy = Ty->getAs()) { + uint64_t Size = VecTy->getNumElements(); + + QualType SizeTy = Ctx.getSizeType(); + uint64_t SizeTySize = Ctx.getTypeSize(SizeTy); + for (uint64_t I = 0; I < Size; ++I) { + auto *Idx = IntegerLiteral::Create(Ctx, llvm::APInt(SizeTySize, I), + SizeTy, SourceLocation()); + + ExprResult ElExpr = S.CreateBuiltinArraySubscriptExpr( + E, E->getBeginLoc(), Idx, E->getEndLoc()); + if (ElExpr.isInvalid()) + return false; + if (!CastInitializer(S, Ctx, ElExpr.get(), List, DestTypes)) + return false; + } + return true; + } + + if (auto *ArrTy = dyn_cast(Ty.getTypePtr())) { + uint64_t Size = ArrTy->getZExtSize(); + QualType SizeTy = Ctx.getSizeType(); + uint64_t SizeTySize = Ctx.getTypeSize(SizeTy); + for (uint64_t I = 0; I < Size; ++I) { + auto *Idx = IntegerLiteral::Create(Ctx, llvm::APInt(SizeTySize, I), + SizeTy, SourceLocation()); + ExprResult ElExpr = S.CreateBuiltinArraySubscriptExpr( + E, E->getBeginLoc(), Idx, E->getEndLoc()); + if (ElExpr.isInvalid()) + return false; + if (!BuildInitializerList(S, Ctx, ElExpr.get(), List, DestTypes)) + return false; + } + return true; + } + + if (auto *RTy = Ty->getAs()) { + llvm::SmallVector RecordTypes; + RecordTypes.push_back(RTy); + while (RecordTypes.back()->getAsCXXRecordDecl()->getNumBases()) { + CXXRecordDecl *D = RecordTypes.back()->getAsCXXRecordDecl(); + assert(D->getNumBases() == 1 && + "HLSL doesn't support multiple inheritance"); + RecordTypes.push_back(D->bases_begin()->getType()->getAs()); + } + while (!RecordTypes.empty()) { + const RecordType *RT = RecordTypes.back(); + RecordTypes.pop_back(); + for (auto *FD : RT->getDecl()->fields()) { + DeclAccessPair Found = DeclAccessPair::make(FD, FD->getAccess()); + DeclarationNameInfo NameInfo(FD->getDeclName(), E->getBeginLoc()); + ExprResult Res = S.BuildFieldReferenceExpr( + E, false, E->getBeginLoc(), CXXScopeSpec(), FD, Found, NameInfo); + if (Res.isInvalid()) + return false; + if (!BuildInitializerList(S, Ctx, Res.get(), List, DestTypes)) + return false; + } + } + } + return true; +} + +static Expr *GenerateInitLists(ASTContext &Ctx, QualType Ty, + llvm::SmallVectorImpl::iterator &It) { + if (Ty->isScalarType() || (Ty->isRecordType() && !Ty->isAggregateType())) { + return *(It++); + } + llvm::SmallVector Inits; + assert(!isa(Ty) && "Matrix types not yet supported in HLSL"); + Ty = Ty.getDesugaredType(Ctx); + if (Ty->isVectorType() || Ty->isConstantArrayType()) { + QualType ElTy; + uint64_t Size = 0; + if (auto *ATy = Ty->getAs()) { + ElTy = ATy->getElementType(); + Size = ATy->getNumElements(); + } else { + auto *VTy = cast(Ty.getTypePtr()); + ElTy = VTy->getElementType(); + Size = VTy->getZExtSize(); + } + for (uint64_t I = 0; I < Size; ++I) + Inits.push_back(GenerateInitLists(Ctx, ElTy, It)); + } + if (auto *RTy = Ty->getAs()) { + llvm::SmallVector RecordTypes; + RecordTypes.push_back(RTy); + while (RecordTypes.back()->getAsCXXRecordDecl()->getNumBases()) { + CXXRecordDecl *D = RecordTypes.back()->getAsCXXRecordDecl(); + assert(D->getNumBases() == 1 && + "HLSL doesn't support multiple inheritance"); + RecordTypes.push_back(D->bases_begin()->getType()->getAs()); + } + while (!RecordTypes.empty()) { + const RecordType *RT = RecordTypes.back(); + RecordTypes.pop_back(); + for (auto *FD : RT->getDecl()->fields()) { + Inits.push_back(GenerateInitLists(Ctx, FD->getType(), It)); + } + } + } + auto *NewInit = new (Ctx) InitListExpr(Ctx, Inits.front()->getBeginLoc(), + Inits, Inits.back()->getEndLoc()); + NewInit->setType(Ty); + return NewInit; +} + +bool SemaHLSL::TransformInitList(const InitializedEntity &Entity, + const InitializationKind &Kind, + InitListExpr *Init) { + // If the initializer is a scalar, just return it. + if (Init->getType()->isScalarType()) + return true; + ASTContext &Ctx = SemaRef.getASTContext(); + llvm::SmallVector DestTypes; + // An initializer list might be attempting to initialize a reference or + // rvalue-reference. When checking the initializer we should look through the + // reference. + QualType InitTy = Entity.getType().getNonReferenceType(); + BuildFlattenedTypeList(InitTy, DestTypes); + + llvm::SmallVector ArgExprs; + for (unsigned I = 0; I < Init->getNumInits(); ++I) { + Expr *E = Init->getInit(I); + if (E->HasSideEffects(Ctx)) { + QualType Ty = E->getType(); + if (Ty->isRecordType()) + E = new (Ctx) MaterializeTemporaryExpr(Ty, E, E->isLValue()); + E = new (Ctx) OpaqueValueExpr(E->getBeginLoc(), Ty, E->getValueKind(), + E->getObjectKind(), E); + Init->setInit(I, E); + } + if (!BuildInitializerList(SemaRef, Ctx, E, ArgExprs, DestTypes)) + return false; + } + + if (DestTypes.size() != ArgExprs.size()) { + int TooManyOrFew = ArgExprs.size() > DestTypes.size() ? 1 : 0; + SemaRef.Diag(Init->getBeginLoc(), diag::err_hlsl_incorrect_num_initializers) + << TooManyOrFew << InitTy << DestTypes.size() << ArgExprs.size(); + return false; + } + + auto It = ArgExprs.begin(); + // GenerateInitLists will always return an InitListExpr here, because the + // scalar case is handled above. + auto *NewInit = cast(GenerateInitLists(Ctx, InitTy, It)); + Init->resizeInits(Ctx, NewInit->getNumInits()); + for (unsigned I = 0; I < NewInit->getNumInits(); ++I) + Init->updateInit(Ctx, I, NewInit->getInit(I)); + return true; +} diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 18090eb1c9e9a..6a76e6d74a4b0 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -26,6 +26,7 @@ #include "clang/Sema/Initialization.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/Ownership.h" +#include "clang/Sema/SemaHLSL.h" #include "clang/Sema/SemaObjC.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/FoldingSet.h" @@ -4787,6 +4788,10 @@ static void TryListInitialization(Sema &S, bool TreatUnavailableAsInvalid) { QualType DestType = Entity.getType(); + if (S.getLangOpts().HLSL && + !S.HLSL().TransformInitList(Entity, Kind, InitList)) + return; + // C++ doesn't allow scalar initialization with more than one argument. // But C99 complex numbers are scalars and it makes sense there. if (S.getLangOpts().CPlusPlus && DestType->isScalarType() && diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index fc1e3f7d58f4d..73e979927b4f3 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -13672,7 +13672,7 @@ TreeTransform::TransformDesignatedInitExpr(DesignatedInitExpr *E) { Desig.AddDesignator( Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc())); - ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D); + ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D); ArrayExprs.push_back(Index.get()); continue; } diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 903a165ee75c6..64791300fe722 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -6666,14 +6666,6 @@ MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { return ID; } -MacroID ASTWriter::getMacroID(MacroInfo *MI) { - if (!MI || MI->isBuiltinMacro()) - return 0; - - assert(MacroIDs.contains(MI) && "Macro not emitted!"); - return MacroIDs[MI]; -} - uint32_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { return IdentMacroDirectivesOffsetMap.lookup(Name); } diff --git a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp index 109faacf1726a..f56e9192d1d66 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ArrayBoundChecker.cpp @@ -323,7 +323,7 @@ compareValueToThreshold(ProgramStateRef State, NonLoc Value, NonLoc Threshold, // we want to ensure that assumptions coming from this precondition and // assumptions coming from regular C/C++ operator calls are represented by // constraints on the same symbolic expression. A solution that would - // evaluate these "mathematical" compariosns through a separate pathway would + // evaluate these "mathematical" comparisons through a separate pathway would // be a step backwards in this sense. const BinaryOperatorKind OpKind = CheckEquality ? BO_EQ : BO_LT; @@ -394,14 +394,13 @@ static bool tryDividePair(std::optional &Val1, return false; const bool Val1HasRemainder = Val1 && *Val1 % Divisor; const bool Val2HasRemainder = Val2 && *Val2 % Divisor; - if (!Val1HasRemainder && !Val2HasRemainder) { - if (Val1) - *Val1 /= Divisor; - if (Val2) - *Val2 /= Divisor; - return true; - } - return false; + if (Val1HasRemainder || Val2HasRemainder) + return false; + if (Val1) + *Val1 /= Divisor; + if (Val2) + *Val2 /= Divisor; + return true; } static Messages getExceedsMsgs(ASTContext &ACtx, const SubRegion *Region, diff --git a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp index c9df15ceb3b40..2a22e8e10efb0 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp @@ -274,7 +274,13 @@ class FindStackRegionsSymbolVisitor final : public SymbolVisitor { void SaveIfEscapes(const MemRegion *MR) { const StackSpaceRegion *SSR = MR->getMemorySpace()->getAs(); - if (SSR && SSR->getStackFrame() == PoppedStackFrame) + + if (!SSR) + return; + + const StackFrameContext *CapturedSFC = SSR->getStackFrame(); + if (CapturedSFC == PoppedStackFrame || + PoppedStackFrame->isParentOf(CapturedSFC)) EscapingStackRegions.push_back(MR); } diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp index 4ffdac5ca4873..9527993d0edeb 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp @@ -267,6 +267,8 @@ class UncountedLambdaCapturesChecker auto OpCode = OpCE->getOperator(); if (OpCode == OO_Star || OpCode == OO_Amp) { auto *Callee = OpCE->getDirectCallee(); + if (!Callee) + return false; auto clsName = safeGetName(Callee->getParent()); if (!isRefType(clsName) || !OpCE->getNumArgs()) return false; @@ -276,9 +278,10 @@ class UncountedLambdaCapturesChecker } if (auto *UO = dyn_cast(Arg)) { auto OpCode = UO->getOpcode(); - if (OpCode == UO_Deref || OpCode == UO_AddrOf) + if (OpCode == UO_Deref || OpCode == UO_AddrOf) { Arg = UO->getSubExpr()->IgnoreParenCasts(); - continue; + continue; + } } break; } while (Arg); diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 69cf2dd6fc14e..d93952264a606 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1991,33 +1991,45 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, ExplodedNodeSet Tmp; StmtNodeBuilder Bldr2(PreVisit, Tmp, *currBldrCtx); - const Expr *ArgE; - if (const auto *DefE = dyn_cast(S)) + bool HasRebuiltInit = false; + const Expr *ArgE = nullptr; + if (const auto *DefE = dyn_cast(S)) { ArgE = DefE->getExpr(); - else if (const auto *DefE = dyn_cast(S)) + HasRebuiltInit = DefE->hasRewrittenInit(); + } else if (const auto *DefE = dyn_cast(S)) { ArgE = DefE->getExpr(); - else + HasRebuiltInit = DefE->hasRewrittenInit(); + } else llvm_unreachable("unknown constant wrapper kind"); - bool IsTemporary = false; - if (const auto *MTE = dyn_cast(ArgE)) { - ArgE = MTE->getSubExpr(); - IsTemporary = true; - } + if (HasRebuiltInit) { + for (auto *N : PreVisit) { + ProgramStateRef state = N->getState(); + const LocationContext *LCtx = N->getLocationContext(); + state = state->BindExpr(S, LCtx, state->getSVal(ArgE, LCtx)); + Bldr2.generateNode(S, N, state); + } + } else { + // If it's not rewritten, the contents of these expressions are not + // actually part of the current function, so we fall back to constant + // evaluation. + bool IsTemporary = false; + if (const auto *MTE = dyn_cast(ArgE)) { + ArgE = MTE->getSubExpr(); + IsTemporary = true; + } + + std::optional ConstantVal = svalBuilder.getConstantVal(ArgE); + const LocationContext *LCtx = Pred->getLocationContext(); + for (auto *I : PreVisit) { + ProgramStateRef State = I->getState(); + State = State->BindExpr(S, LCtx, ConstantVal.value_or(UnknownVal())); + if (IsTemporary) + State = createTemporaryRegionIfNeeded(State, LCtx, cast(S), + cast(S)); - std::optional ConstantVal = svalBuilder.getConstantVal(ArgE); - if (!ConstantVal) - ConstantVal = UnknownVal(); - - const LocationContext *LCtx = Pred->getLocationContext(); - for (const auto I : PreVisit) { - ProgramStateRef State = I->getState(); - State = State->BindExpr(S, LCtx, *ConstantVal); - if (IsTemporary) - State = createTemporaryRegionIfNeeded(State, LCtx, - cast(S), - cast(S)); - Bldr2.generateNode(S, I, State); + Bldr2.generateNode(S, I, State); + } } getCheckerManager().runCheckersForPostStmt(Dst, Tmp, S, *this); diff --git a/clang/test/AST/ByteCode/libcxx/allocate-arrays.cpp b/clang/test/AST/ByteCode/libcxx/allocate-arrays.cpp new file mode 100644 index 0000000000000..f1e5af6cab2aa --- /dev/null +++ b/clang/test/AST/ByteCode/libcxx/allocate-arrays.cpp @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -std=c++2c -fexperimental-new-constant-interpreter -verify=expected,both %s +// RUN: %clang_cc1 -std=c++2c -verify=ref,both %s + + +/// This example used to cause an invalid read because allocating +/// an array needs to return a pointer to the first element, +/// not to the array. + +namespace std { + using size_t = decltype(sizeof(0)); + + template + class allocator { + public: + typedef size_t size_type; + typedef _Tp value_type; + constexpr _Tp *allocate(size_t __n) { + return static_cast<_Tp *>(::operator new(__n * sizeof(_Tp))); + } + }; +} + +void *operator new(std::size_t, void *p) { return p; } +void* operator new[] (std::size_t, void* p) {return p;} + +namespace std { + template + class initializer_list { + const _Ep *__begin_; + __SIZE_TYPE__ __size_; + + public: + typedef _Ep value_type; + typedef const _Ep &reference; + constexpr __SIZE_TYPE__ size() const noexcept { return __size_; } + constexpr const _Ep *begin() const noexcept { return __begin_; } + constexpr const _Ep *end() const noexcept { return __begin_ + __size_; } + }; +} + +template +class vector { +public: + constexpr vector(std::initializer_list Ts) { + A = B = std::allocator{}.allocate(Ts.size()); // both-note {{heap allocation performed here}} + + new (A) T(*Ts.begin()); + } +private: + T *A = nullptr; + T *B = nullptr; +}; + +constexpr vector> ints = {{3}, {4}}; // both-error {{must be initialized by a constant expression}} \ + // both-note {{pointer to}} diff --git a/clang/test/AST/ByteCode/libcxx/non-const-local-temporary.cpp b/clang/test/AST/ByteCode/libcxx/non-const-local-temporary.cpp new file mode 100644 index 0000000000000..11d4b5383dbf5 --- /dev/null +++ b/clang/test/AST/ByteCode/libcxx/non-const-local-temporary.cpp @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -std=c++2c -fexperimental-new-constant-interpreter -verify=expected,both %s +// RUN: %clang_cc1 -std=c++2c -verify=ref,both %s + +// both-no-diagnostics + +namespace std { +template struct integral_constant { + static const int value = __v; +}; +using size_t = decltype(sizeof(int)); +template +concept __weakly_equality_comparable_with = requires(_Tp __t) { __t; }; +template struct tuple_element; +template struct tuple_size; +template +concept input_or_output_iterator = requires(_Ip __i) { __i; }; +template +concept sentinel_for = __weakly_equality_comparable_with<_Sp, _Ip>; +namespace ranges { +enum subrange_kind { unsized }; +template _Sent, + subrange_kind = unsized> +struct subrange { + _Iter __begin_; + _Sent __end_; + constexpr _Sent end() { return __end_; } +}; +template +constexpr auto get(subrange<_Iter, _Sent, _Kind> __subrange) { + return __subrange.end(); +} +} // namespace ranges +template +struct tuple_size> + : integral_constant {}; +template +struct tuple_element<0, ranges::subrange<_Ip, _Sp, _Kp>> { + using type = _Ip; +}; +template +struct tuple_element<1, ranges::subrange<_Ip, _Sp, _Kp>> { + using type = _Sp; +}; +} // namespace std +constexpr bool test() { + int a[1]; + auto r = std::ranges::subrange(a, a); + auto [first, last] = r; + last = a; + return true; +} +static_assert(test()); + diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index 31f066b37858d..e9850d27666e5 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -865,7 +865,6 @@ constexpr unsigned short ssmall = SS(100)[42]; constexpr auto Ss = SS()[0]; - namespace IncompleteArray { struct A { int b = 10; @@ -908,8 +907,19 @@ namespace IncompleteArray { return c; } static_assert(test4() == 12); +} +namespace NonConstexprArrayCtor { + struct S { + S() {} // both-note 2{{declared here}} + }; + constexpr bool test() { // both-error {{never produces a constant expression}} + auto s = new S[1]; // both-note 2{{non-constexpr constructor}} + return true; + } + static_assert(test()); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} } #else diff --git a/clang/test/AST/ast-dump-recovery.cpp b/clang/test/AST/ast-dump-recovery.cpp index b59fa3778192f..fa6d747556dd8 100644 --- a/clang/test/AST/ast-dump-recovery.cpp +++ b/clang/test/AST/ast-dump-recovery.cpp @@ -507,7 +507,7 @@ union U { // CHECK-NEXT: `-DeclStmt {{.*}} // CHECK-NEXT: `-VarDecl {{.*}} g 'U':'GH112560::U' listinit // CHECK-NEXT: `-InitListExpr {{.*}} 'U':'GH112560::U' contains-errors field Field {{.*}} 'f' 'int' -// CHECK-NEXT: `-CXXDefaultInitExpr {{.*}} 'int' contains-errors has rewritten init +// CHECK-NEXT: `-CXXDefaultInitExpr {{.*}} 'int' contains-errors // CHECK-NEXT: `-RecoveryExpr {{.*}} 'int' contains-errors // DISABLED-NOT: -RecoveryExpr {{.*}} contains-errors void foo() { diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp new file mode 100644 index 0000000000000..840433db5133a --- /dev/null +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures-decl-protects-this-crash.cpp @@ -0,0 +1,38 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.UncountedLambdaCapturesChecker -verify %s + +struct Foo { + int x; + int y; + Foo(int x, int y) : x(x) , y(y) { } +}; + +template +struct Baz { + void ref() const; + void deref() const; + Foo operator*(); + bool operator!(); +}; + +inline Foo operator*(const Foo& a, const Foo& b); + +Baz someFunction(); +template void bar(CallbackType callback) { + auto baz = someFunction(); + callback(baz); +} + +struct Obj { + void ref() const; + void deref() const; + + void foo(Foo foo) { + bar([this](auto baz) { + // expected-warning@-1{{Captured raw-pointer 'this' to ref-counted type or CheckedPtr-capable type is unsafe [webkit.UncountedLambdaCapturesChecker]}} + bar([this, foo = *baz, foo2 = !baz](auto&&) { + // expected-warning@-1{{Captured raw-pointer 'this' to ref-counted type or CheckedPtr-capable type is unsafe [webkit.UncountedLambdaCapturesChecker]}} + someFunction(); + }); + }); + } +}; diff --git a/clang/test/Analysis/lifetime-extended-regions.cpp b/clang/test/Analysis/lifetime-extended-regions.cpp index 4458ad294af7c..02a1210d9af92 100644 --- a/clang/test/Analysis/lifetime-extended-regions.cpp +++ b/clang/test/Analysis/lifetime-extended-regions.cpp @@ -121,11 +121,10 @@ void aggregateWithReferences() { clang_analyzer_dump(viaReference.rx); // expected-warning-re {{&lifetime_extended_object{int, viaReference, S{{[0-9]+}}} }} clang_analyzer_dump(viaReference.ry); // expected-warning-re {{&lifetime_extended_object{Composite, viaReference, S{{[0-9]+}}} }} - // FIXME: clang currently support extending lifetime of object bound to reference members of aggregates, - // that are created from default member initializer. But CFG and ExprEngine need to be updated to address this change. - // The following expect warning: {{&lifetime_extended_object{Composite, defaultInitExtended, S{{[0-9]+}}} }} + // The lifetime of object bound to reference members of aggregates, + // that are created from default member initializer was extended. RefAggregate defaultInitExtended{i}; - clang_analyzer_dump(defaultInitExtended.ry); // expected-warning {{Unknown }} + clang_analyzer_dump(defaultInitExtended.ry); // expected-warning-re {{&lifetime_extended_object{Composite, defaultInitExtended, S{{[0-9]+}}} }} } void lambda() { diff --git a/clang/test/Analysis/stack-addr-ps.cpp b/clang/test/Analysis/stack-addr-ps.cpp index bf988d0a16959..2e509f358b49f 100644 --- a/clang/test/Analysis/stack-addr-ps.cpp +++ b/clang/test/Analysis/stack-addr-ps.cpp @@ -982,6 +982,51 @@ int& ret_local_field_ref() { } } //namespace return_address_of_true_positives +namespace return_from_child_block_scope { +struct S { + int *p; +}; + +S return_child_stack_context() { + S s; + { + int a = 1; + s = (S){ &a }; + } + return s; // expected-warning {{Address of stack memory associated with local variable 'a' returned to caller}} +} + +S return_child_stack_context_field() { + S s; + { + int a = 1; + s.p = &a; + } + return s; // expected-warning {{Address of stack memory associated with local variable 'a' returned to caller}} +} + +// The below are reproducers from Issue #123459 +template +struct T { + V* q{}; + T() = default; + T(T&& rhs) { q = rhs.q; rhs.q = nullptr;} + T& operator=(T&& rhs) { q = rhs.q; rhs.q = nullptr;} + void push_back(const V& v) { if (q == nullptr) q = new V(v); } + ~T() { delete q; } +}; + +T f() { + T t; + { + int a = 1; + t.push_back({ &a }); + } + return t; // expected-warning {{Address of stack memory associated with local variable 'a' returned to caller}} +} + +} // namespace return_from_child_block_scope + namespace true_negatives_return_expressions { struct Container { int *x; }; diff --git a/clang/test/Analysis/stackaddrleak.c b/clang/test/Analysis/stackaddrleak.c index f8101525401b0..95175996e8274 100644 --- a/clang/test/Analysis/stackaddrleak.c +++ b/clang/test/Analysis/stackaddrleak.c @@ -68,3 +68,25 @@ int *g_no_lifetime_bound() { int i = 0; return f_no_lifetime_bound(&i); // no-warning } + +struct child_stack_context_s { + int *p; +}; + +struct child_stack_context_s return_child_stack_context() { + struct child_stack_context_s s; + { + int a = 1; + s = (struct child_stack_context_s){ &a }; + } + return s; // expected-warning {{Address of stack memory associated with local variable 'a' returned to caller}} +} + +struct child_stack_context_s return_child_stack_context_field() { + struct child_stack_context_s s; + { + int a = 1; + s.p = &a; + } + return s; // expected-warning {{Address of stack memory associated with local variable 'a' returned to caller}} +} diff --git a/clang/test/CodeGen/X86/amxavx512-builtins.c b/clang/test/CodeGen/X86/amxavx512-builtins.c index 0f203349b1d1e..d60929994901a 100644 --- a/clang/test/CodeGen/X86/amxavx512-builtins.c +++ b/clang/test/CodeGen/X86/amxavx512-builtins.c @@ -1,5 +1,5 @@ // RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +amx-tile -target-feature +amx-avx512 \ -// RUN: -target-feature +avx10.2-512 -emit-llvm -o - -Wall -Werror -pedantic -Wno-gnu-statement-expression | FileCheck %s +// RUN: -target-feature +avx10.2-512 -emit-llvm -o - -Wall -Werror -pedantic -Wno-gnu-statement-expression -flax-vector-conversions=none | FileCheck %s #include #include diff --git a/clang/test/CodeGen/X86/sha-builtins.c b/clang/test/CodeGen/X86/sha-builtins.c index ede1a6bf7b1f3..44cab43dad9f7 100644 --- a/clang/test/CodeGen/X86/sha-builtins.c +++ b/clang/test/CodeGen/X86/sha-builtins.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +sha -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +sha -emit-llvm -flax-vector-conversions=none -o - | FileCheck %s #include diff --git a/clang/test/CodeGenHLSL/ArrayTemporary.hlsl b/clang/test/CodeGenHLSL/ArrayTemporary.hlsl index e5db7eac37a42..91a283554459d 100644 --- a/clang/test/CodeGenHLSL/ArrayTemporary.hlsl +++ b/clang/test/CodeGenHLSL/ArrayTemporary.hlsl @@ -1,3 +1,4 @@ + // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s void fn(float x[2]) { } @@ -27,7 +28,7 @@ void fn2(Obj O[4]) { } // CHECK: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[Tmp]], ptr align 4 [[Arr]], i32 32, i1 false) // CHECK: call void {{.*}}fn2{{.*}}(ptr noundef byval([4 x %struct.Obj]) align 4 [[Tmp]]) void call2() { - Obj Arr[4] = {}; + Obj Arr[4] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}}; fn2(Arr); } diff --git a/clang/test/CodeGenHLSL/BasicFeatures/InitLists.hlsl b/clang/test/CodeGenHLSL/BasicFeatures/InitLists.hlsl new file mode 100644 index 0000000000000..a0590162c7087 --- /dev/null +++ b/clang/test/CodeGenHLSL/BasicFeatures/InitLists.hlsl @@ -0,0 +1,963 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -disable-llvm-passes -emit-llvm -finclude-default-header -o - %s | FileCheck %s + +struct TwoFloats { + float X, Y; +}; + +struct TwoInts { + int Z, W; +}; + +struct Doggo { + int4 LegState; + int TailState; + float HairCount; + float4 EarDirection[2]; +}; + +struct AnimalBits { + int Legs[4]; + uint State; + int64_t Counter; + float4 LeftDir; + float4 RightDir; +}; + +struct Kitteh { + int4 Legs; + int TailState; + float HairCount; + float4 Claws[2]; +}; + +struct Zoo { + Doggo Dogs[2]; + Kitteh Cats[4]; +}; + +struct FourFloats : TwoFloats { + float Z, W; +}; + +struct SlicyBits { + int Z : 8; + int W : 8; +}; + +// Case 1: Extraneous braces get ignored in literal instantiation. +// CHECK-LABEL: define void @_Z5case1v( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOFLOATS:%.*]]) align 4 [[AGG_RESULT:%.*]]) #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[AGG_RESULT]], ptr align 4 @__const._Z5case1v.TF1, i32 8, i1 false) +// CHECK-NEXT: ret void +// +TwoFloats case1() { + TwoFloats TF1 = {{{1.0, 2}}}; + return TF1; +} + +// Case 2: Valid C/C++ initializer is handled appropriately. +// CHECK-LABEL: define void @_Z5case2v( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOFLOATS:%.*]]) align 4 [[AGG_RESULT:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[AGG_RESULT]], ptr align 4 @__const._Z5case2v.TF2, i32 8, i1 false) +// CHECK-NEXT: ret void +// +TwoFloats case2() { + TwoFloats TF2 = {1, 2}; + return TF2; +} + +// Case 3: Simple initialization with conversion of an argument. +// CHECK-LABEL: define void @_Z5case3i( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOFLOATS:%.*]]) align 4 [[AGG_RESULT:%.*]], i32 noundef [[VAL:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[VAL_ADDR:%.*]] = alloca i32, align 4 +// CHECK-NEXT: store i32 [[VAL]], ptr [[VAL_ADDR]], align 4 +// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[VAL_ADDR]], align 4 +// CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[TMP0]] to float +// CHECK-NEXT: store float [[CONV]], ptr [[X]], align 4 +// CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: store float 2.000000e+00, ptr [[Y]], align 4 +// CHECK-NEXT: ret void +// +TwoFloats case3(int Val) { + TwoFloats TF3 = {Val, 2}; + return TF3; +} + +// Case 4: Initialization from a scalarized vector into a structure with element +// conversions. +// CHECK-LABEL: define void @_Z5case4Dv2_i( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOFLOATS:%.*]]) align 4 [[AGG_RESULT:%.*]], <2 x i32> noundef [[TWOVALS:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[TWOVALS_ADDR:%.*]] = alloca <2 x i32>, align 8 +// CHECK-NEXT: store <2 x i32> [[TWOVALS]], ptr [[TWOVALS_ADDR]], align 8 +// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load <2 x i32>, ptr [[TWOVALS_ADDR]], align 8 +// CHECK-NEXT: [[VECEXT:%.*]] = extractelement <2 x i32> [[TMP0]], i64 0 +// CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[VECEXT]] to float +// CHECK-NEXT: store float [[CONV]], ptr [[X]], align 4 +// CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[TMP1:%.*]] = load <2 x i32>, ptr [[TWOVALS_ADDR]], align 8 +// CHECK-NEXT: [[VECEXT1:%.*]] = extractelement <2 x i32> [[TMP1]], i64 1 +// CHECK-NEXT: [[CONV2:%.*]] = sitofp i32 [[VECEXT1]] to float +// CHECK-NEXT: store float [[CONV2]], ptr [[Y]], align 4 +// CHECK-NEXT: ret void +// +TwoFloats case4(int2 TwoVals) { + TwoFloats TF4 = {TwoVals}; + return TF4; +} + +// Case 5: Initialization from a scalarized vector of matching type. +// CHECK-LABEL: define void @_Z5case5Dv2_i( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOINTS:%.*]]) align 4 [[AGG_RESULT:%.*]], <2 x i32> noundef [[TWOVALS:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[TWOVALS_ADDR:%.*]] = alloca <2 x i32>, align 8 +// CHECK-NEXT: store <2 x i32> [[TWOVALS]], ptr [[TWOVALS_ADDR]], align 8 +// CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load <2 x i32>, ptr [[TWOVALS_ADDR]], align 8 +// CHECK-NEXT: [[VECEXT:%.*]] = extractelement <2 x i32> [[TMP0]], i64 0 +// CHECK-NEXT: store i32 [[VECEXT]], ptr [[Z]], align 4 +// CHECK-NEXT: [[W:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[TMP1:%.*]] = load <2 x i32>, ptr [[TWOVALS_ADDR]], align 8 +// CHECK-NEXT: [[VECEXT1:%.*]] = extractelement <2 x i32> [[TMP1]], i64 1 +// CHECK-NEXT: store i32 [[VECEXT1]], ptr [[W]], align 4 +// CHECK-NEXT: ret void +// +TwoInts case5(int2 TwoVals) { + TwoInts TI1 = {TwoVals}; + return TI1; +} + +// Case 6: Initialization from a scalarized structure of different type with +// different element types. +// CHECK-LABEL: define void @_Z5case69TwoFloats( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOINTS:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef byval([[STRUCT_TWOFLOATS:%.*]]) align 4 [[TF4:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF4]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load float, ptr [[X]], align 4 +// CHECK-NEXT: [[CONV:%.*]] = fptosi float [[TMP0]] to i32 +// CHECK-NEXT: store i32 [[CONV]], ptr [[Z]], align 4 +// CHECK-NEXT: [[W:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF4]], i32 0, i32 1 +// CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[Y]], align 4 +// CHECK-NEXT: [[CONV1:%.*]] = fptosi float [[TMP1]] to i32 +// CHECK-NEXT: store i32 [[CONV1]], ptr [[W]], align 4 +// CHECK-NEXT: ret void +// +TwoInts case6(TwoFloats TF4) { + TwoInts TI2 = {TF4}; + return TI2; +} + +// Case 7: Initialization of a complex structure, with bogus braces and element +// conversions from a collection of scalar values, and structures. +// CHECK-LABEL: define void @_Z5case77TwoIntsS_i9TwoFloatsS0_S0_S0_( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_DOGGO:%.*]]) align 16 [[AGG_RESULT:%.*]], ptr noundef byval([[STRUCT_TWOINTS:%.*]]) align 4 [[TI1:%.*]], ptr noundef byval([[STRUCT_TWOINTS]]) align 4 [[TI2:%.*]], i32 noundef [[VAL:%.*]], ptr noundef byval([[STRUCT_TWOFLOATS:%.*]]) align 4 [[TF1:%.*]], ptr noundef byval([[STRUCT_TWOFLOATS]]) align 4 [[TF2:%.*]], ptr noundef byval([[STRUCT_TWOFLOATS]]) align 4 [[TF3:%.*]], ptr noundef byval([[STRUCT_TWOFLOATS]]) align 4 [[TF4:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[VAL_ADDR:%.*]] = alloca i32, align 4 +// CHECK-NEXT: store i32 [[VAL]], ptr [[VAL_ADDR]], align 4 +// CHECK-NEXT: [[LEGSTATE:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[TI1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Z]], align 4 +// CHECK-NEXT: [[VECINIT:%.*]] = insertelement <4 x i32> poison, i32 [[TMP0]], i32 0 +// CHECK-NEXT: [[W:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[TI1]], i32 0, i32 1 +// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[W]], align 4 +// CHECK-NEXT: [[VECINIT1:%.*]] = insertelement <4 x i32> [[VECINIT]], i32 [[TMP1]], i32 1 +// CHECK-NEXT: [[Z2:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[TI2]], i32 0, i32 0 +// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[Z2]], align 4 +// CHECK-NEXT: [[VECINIT3:%.*]] = insertelement <4 x i32> [[VECINIT1]], i32 [[TMP2]], i32 2 +// CHECK-NEXT: [[W4:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[TI2]], i32 0, i32 1 +// CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[W4]], align 4 +// CHECK-NEXT: [[VECINIT5:%.*]] = insertelement <4 x i32> [[VECINIT3]], i32 [[TMP3]], i32 3 +// CHECK-NEXT: store <4 x i32> [[VECINIT5]], ptr [[LEGSTATE]], align 16 +// CHECK-NEXT: [[TAILSTATE:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[VAL_ADDR]], align 4 +// CHECK-NEXT: store i32 [[TMP4]], ptr [[TAILSTATE]], align 16 +// CHECK-NEXT: [[HAIRCOUNT:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[AGG_RESULT]], i32 0, i32 2 +// CHECK-NEXT: [[TMP5:%.*]] = load i32, ptr [[VAL_ADDR]], align 4 +// CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[TMP5]] to float +// CHECK-NEXT: store float [[CONV]], ptr [[HAIRCOUNT]], align 4 +// CHECK-NEXT: [[EARDIRECTION:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[AGG_RESULT]], i32 0, i32 3 +// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP6:%.*]] = load float, ptr [[X]], align 4 +// CHECK-NEXT: [[VECINIT6:%.*]] = insertelement <4 x float> poison, float [[TMP6]], i32 0 +// CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF1]], i32 0, i32 1 +// CHECK-NEXT: [[TMP7:%.*]] = load float, ptr [[Y]], align 4 +// CHECK-NEXT: [[VECINIT7:%.*]] = insertelement <4 x float> [[VECINIT6]], float [[TMP7]], i32 1 +// CHECK-NEXT: [[X8:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF2]], i32 0, i32 0 +// CHECK-NEXT: [[TMP8:%.*]] = load float, ptr [[X8]], align 4 +// CHECK-NEXT: [[VECINIT9:%.*]] = insertelement <4 x float> [[VECINIT7]], float [[TMP8]], i32 2 +// CHECK-NEXT: [[Y10:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF2]], i32 0, i32 1 +// CHECK-NEXT: [[TMP9:%.*]] = load float, ptr [[Y10]], align 4 +// CHECK-NEXT: [[VECINIT11:%.*]] = insertelement <4 x float> [[VECINIT9]], float [[TMP9]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT11]], ptr [[EARDIRECTION]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT:%.*]] = getelementptr inbounds <4 x float>, ptr [[EARDIRECTION]], i32 1 +// CHECK-NEXT: [[X12:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF3]], i32 0, i32 0 +// CHECK-NEXT: [[TMP10:%.*]] = load float, ptr [[X12]], align 4 +// CHECK-NEXT: [[VECINIT13:%.*]] = insertelement <4 x float> poison, float [[TMP10]], i32 0 +// CHECK-NEXT: [[Y14:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF3]], i32 0, i32 1 +// CHECK-NEXT: [[TMP11:%.*]] = load float, ptr [[Y14]], align 4 +// CHECK-NEXT: [[VECINIT15:%.*]] = insertelement <4 x float> [[VECINIT13]], float [[TMP11]], i32 1 +// CHECK-NEXT: [[X16:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF4]], i32 0, i32 0 +// CHECK-NEXT: [[TMP12:%.*]] = load float, ptr [[X16]], align 4 +// CHECK-NEXT: [[VECINIT17:%.*]] = insertelement <4 x float> [[VECINIT15]], float [[TMP12]], i32 2 +// CHECK-NEXT: [[Y18:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF4]], i32 0, i32 1 +// CHECK-NEXT: [[TMP13:%.*]] = load float, ptr [[Y18]], align 4 +// CHECK-NEXT: [[VECINIT19:%.*]] = insertelement <4 x float> [[VECINIT17]], float [[TMP13]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT19]], ptr [[ARRAYINIT_ELEMENT]], align 16 +// CHECK-NEXT: ret void +// +Doggo case7(TwoInts TI1, TwoInts TI2, int Val, TwoFloats TF1, TwoFloats TF2, + TwoFloats TF3, TwoFloats TF4) { + Doggo D1 = {TI1, TI2, {Val, Val}, {{TF1, TF2}, {TF3, TF4}}}; + return D1; +} + +// Case 8: Initialization of a structure from a different structure with +// significantly different element types and grouping. +// CHECK-LABEL: define void @_Z5case85Doggo( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_ANIMALBITS:%.*]]) align 16 [[AGG_RESULT:%.*]], ptr noundef byval([[STRUCT_DOGGO:%.*]]) align 16 [[D1:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[LEGS:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[LEGSTATE:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load <4 x i32>, ptr [[LEGSTATE]], align 16 +// CHECK-NEXT: [[VECEXT:%.*]] = extractelement <4 x i32> [[TMP0]], i64 0 +// CHECK-NEXT: store i32 [[VECEXT]], ptr [[LEGS]], align 4 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT:%.*]] = getelementptr inbounds i32, ptr [[LEGS]], i32 1 +// CHECK-NEXT: [[LEGSTATE1:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP1:%.*]] = load <4 x i32>, ptr [[LEGSTATE1]], align 16 +// CHECK-NEXT: [[VECEXT2:%.*]] = extractelement <4 x i32> [[TMP1]], i64 1 +// CHECK-NEXT: store i32 [[VECEXT2]], ptr [[ARRAYINIT_ELEMENT]], align 4 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT3:%.*]] = getelementptr inbounds i32, ptr [[LEGS]], i32 2 +// CHECK-NEXT: [[LEGSTATE4:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP2:%.*]] = load <4 x i32>, ptr [[LEGSTATE4]], align 16 +// CHECK-NEXT: [[VECEXT5:%.*]] = extractelement <4 x i32> [[TMP2]], i64 2 +// CHECK-NEXT: store i32 [[VECEXT5]], ptr [[ARRAYINIT_ELEMENT3]], align 4 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT6:%.*]] = getelementptr inbounds i32, ptr [[LEGS]], i32 3 +// CHECK-NEXT: [[LEGSTATE7:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP3:%.*]] = load <4 x i32>, ptr [[LEGSTATE7]], align 16 +// CHECK-NEXT: [[VECEXT8:%.*]] = extractelement <4 x i32> [[TMP3]], i64 3 +// CHECK-NEXT: store i32 [[VECEXT8]], ptr [[ARRAYINIT_ELEMENT6]], align 4 +// CHECK-NEXT: [[STATE:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[TAILSTATE:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 1 +// CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[TAILSTATE]], align 16 +// CHECK-NEXT: store i32 [[TMP4]], ptr [[STATE]], align 16 +// CHECK-NEXT: [[COUNTER:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[AGG_RESULT]], i32 0, i32 2 +// CHECK-NEXT: [[HAIRCOUNT:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 2 +// CHECK-NEXT: [[TMP5:%.*]] = load float, ptr [[HAIRCOUNT]], align 4 +// CHECK-NEXT: [[CONV:%.*]] = fptosi float [[TMP5]] to i64 +// CHECK-NEXT: store i64 [[CONV]], ptr [[COUNTER]], align 8 +// CHECK-NEXT: [[LEFTDIR:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[AGG_RESULT]], i32 0, i32 3 +// CHECK-NEXT: [[EARDIRECTION:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION]], i32 0, i32 0 +// CHECK-NEXT: [[TMP6:%.*]] = load <4 x float>, ptr [[ARRAYIDX]], align 16 +// CHECK-NEXT: [[VECEXT9:%.*]] = extractelement <4 x float> [[TMP6]], i64 0 +// CHECK-NEXT: [[VECINIT:%.*]] = insertelement <4 x float> poison, float [[VECEXT9]], i32 0 +// CHECK-NEXT: [[EARDIRECTION10:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX11:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION10]], i32 0, i32 0 +// CHECK-NEXT: [[TMP7:%.*]] = load <4 x float>, ptr [[ARRAYIDX11]], align 16 +// CHECK-NEXT: [[VECEXT12:%.*]] = extractelement <4 x float> [[TMP7]], i64 1 +// CHECK-NEXT: [[VECINIT13:%.*]] = insertelement <4 x float> [[VECINIT]], float [[VECEXT12]], i32 1 +// CHECK-NEXT: [[EARDIRECTION14:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX15:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION14]], i32 0, i32 0 +// CHECK-NEXT: [[TMP8:%.*]] = load <4 x float>, ptr [[ARRAYIDX15]], align 16 +// CHECK-NEXT: [[VECEXT16:%.*]] = extractelement <4 x float> [[TMP8]], i64 2 +// CHECK-NEXT: [[VECINIT17:%.*]] = insertelement <4 x float> [[VECINIT13]], float [[VECEXT16]], i32 2 +// CHECK-NEXT: [[EARDIRECTION18:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX19:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION18]], i32 0, i32 0 +// CHECK-NEXT: [[TMP9:%.*]] = load <4 x float>, ptr [[ARRAYIDX19]], align 16 +// CHECK-NEXT: [[VECEXT20:%.*]] = extractelement <4 x float> [[TMP9]], i64 3 +// CHECK-NEXT: [[VECINIT21:%.*]] = insertelement <4 x float> [[VECINIT17]], float [[VECEXT20]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT21]], ptr [[LEFTDIR]], align 16 +// CHECK-NEXT: [[RIGHTDIR:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[AGG_RESULT]], i32 0, i32 4 +// CHECK-NEXT: [[EARDIRECTION22:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX23:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION22]], i32 0, i32 1 +// CHECK-NEXT: [[TMP10:%.*]] = load <4 x float>, ptr [[ARRAYIDX23]], align 16 +// CHECK-NEXT: [[VECEXT24:%.*]] = extractelement <4 x float> [[TMP10]], i64 0 +// CHECK-NEXT: [[VECINIT25:%.*]] = insertelement <4 x float> poison, float [[VECEXT24]], i32 0 +// CHECK-NEXT: [[EARDIRECTION26:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX27:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION26]], i32 0, i32 1 +// CHECK-NEXT: [[TMP11:%.*]] = load <4 x float>, ptr [[ARRAYIDX27]], align 16 +// CHECK-NEXT: [[VECEXT28:%.*]] = extractelement <4 x float> [[TMP11]], i64 1 +// CHECK-NEXT: [[VECINIT29:%.*]] = insertelement <4 x float> [[VECINIT25]], float [[VECEXT28]], i32 1 +// CHECK-NEXT: [[EARDIRECTION30:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX31:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION30]], i32 0, i32 1 +// CHECK-NEXT: [[TMP12:%.*]] = load <4 x float>, ptr [[ARRAYIDX31]], align 16 +// CHECK-NEXT: [[VECEXT32:%.*]] = extractelement <4 x float> [[TMP12]], i64 2 +// CHECK-NEXT: [[VECINIT33:%.*]] = insertelement <4 x float> [[VECINIT29]], float [[VECEXT32]], i32 2 +// CHECK-NEXT: [[EARDIRECTION34:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX35:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION34]], i32 0, i32 1 +// CHECK-NEXT: [[TMP13:%.*]] = load <4 x float>, ptr [[ARRAYIDX35]], align 16 +// CHECK-NEXT: [[VECEXT36:%.*]] = extractelement <4 x float> [[TMP13]], i64 3 +// CHECK-NEXT: [[VECINIT37:%.*]] = insertelement <4 x float> [[VECINIT33]], float [[VECEXT36]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT37]], ptr [[RIGHTDIR]], align 16 +// CHECK-NEXT: ret void +// +AnimalBits case8(Doggo D1) { + AnimalBits A1 = {D1}; + return A1; +} + +// Case 9: Everything everywhere all at once... Initializing mismatched +// structures from different layouts, different component groupings, with no +// top-level bracing separation. +// CHECK-LABEL: define void @_Z5case95Doggo10AnimalBits( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_ZOO:%.*]]) align 16 [[AGG_RESULT:%.*]], ptr noundef byval([[STRUCT_DOGGO:%.*]]) align 16 [[D1:%.*]], ptr noundef byval([[STRUCT_ANIMALBITS:%.*]]) align 16 [[A1:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[DOGS:%.*]] = getelementptr inbounds nuw [[STRUCT_ZOO]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[LEGSTATE:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[DOGS]], i32 0, i32 0 +// CHECK-NEXT: [[LEGSTATE1:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load <4 x i32>, ptr [[LEGSTATE1]], align 16 +// CHECK-NEXT: [[VECEXT:%.*]] = extractelement <4 x i32> [[TMP0]], i64 0 +// CHECK-NEXT: [[VECINIT:%.*]] = insertelement <4 x i32> poison, i32 [[VECEXT]], i32 0 +// CHECK-NEXT: [[LEGSTATE2:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP1:%.*]] = load <4 x i32>, ptr [[LEGSTATE2]], align 16 +// CHECK-NEXT: [[VECEXT3:%.*]] = extractelement <4 x i32> [[TMP1]], i64 1 +// CHECK-NEXT: [[VECINIT4:%.*]] = insertelement <4 x i32> [[VECINIT]], i32 [[VECEXT3]], i32 1 +// CHECK-NEXT: [[LEGSTATE5:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP2:%.*]] = load <4 x i32>, ptr [[LEGSTATE5]], align 16 +// CHECK-NEXT: [[VECEXT6:%.*]] = extractelement <4 x i32> [[TMP2]], i64 2 +// CHECK-NEXT: [[VECINIT7:%.*]] = insertelement <4 x i32> [[VECINIT4]], i32 [[VECEXT6]], i32 2 +// CHECK-NEXT: [[LEGSTATE8:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP3:%.*]] = load <4 x i32>, ptr [[LEGSTATE8]], align 16 +// CHECK-NEXT: [[VECEXT9:%.*]] = extractelement <4 x i32> [[TMP3]], i64 3 +// CHECK-NEXT: [[VECINIT10:%.*]] = insertelement <4 x i32> [[VECINIT7]], i32 [[VECEXT9]], i32 3 +// CHECK-NEXT: store <4 x i32> [[VECINIT10]], ptr [[LEGSTATE]], align 16 +// CHECK-NEXT: [[TAILSTATE:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[DOGS]], i32 0, i32 1 +// CHECK-NEXT: [[TAILSTATE11:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 1 +// CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[TAILSTATE11]], align 16 +// CHECK-NEXT: store i32 [[TMP4]], ptr [[TAILSTATE]], align 16 +// CHECK-NEXT: [[HAIRCOUNT:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[DOGS]], i32 0, i32 2 +// CHECK-NEXT: [[HAIRCOUNT12:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 2 +// CHECK-NEXT: [[TMP5:%.*]] = load float, ptr [[HAIRCOUNT12]], align 4 +// CHECK-NEXT: store float [[TMP5]], ptr [[HAIRCOUNT]], align 4 +// CHECK-NEXT: [[EARDIRECTION:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[DOGS]], i32 0, i32 3 +// CHECK-NEXT: [[EARDIRECTION13:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION13]], i32 0, i32 0 +// CHECK-NEXT: [[TMP6:%.*]] = load <4 x float>, ptr [[ARRAYIDX]], align 16 +// CHECK-NEXT: [[VECEXT14:%.*]] = extractelement <4 x float> [[TMP6]], i64 0 +// CHECK-NEXT: [[VECINIT15:%.*]] = insertelement <4 x float> poison, float [[VECEXT14]], i32 0 +// CHECK-NEXT: [[EARDIRECTION16:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX17:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION16]], i32 0, i32 0 +// CHECK-NEXT: [[TMP7:%.*]] = load <4 x float>, ptr [[ARRAYIDX17]], align 16 +// CHECK-NEXT: [[VECEXT18:%.*]] = extractelement <4 x float> [[TMP7]], i64 1 +// CHECK-NEXT: [[VECINIT19:%.*]] = insertelement <4 x float> [[VECINIT15]], float [[VECEXT18]], i32 1 +// CHECK-NEXT: [[EARDIRECTION20:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX21:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION20]], i32 0, i32 0 +// CHECK-NEXT: [[TMP8:%.*]] = load <4 x float>, ptr [[ARRAYIDX21]], align 16 +// CHECK-NEXT: [[VECEXT22:%.*]] = extractelement <4 x float> [[TMP8]], i64 2 +// CHECK-NEXT: [[VECINIT23:%.*]] = insertelement <4 x float> [[VECINIT19]], float [[VECEXT22]], i32 2 +// CHECK-NEXT: [[EARDIRECTION24:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX25:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION24]], i32 0, i32 0 +// CHECK-NEXT: [[TMP9:%.*]] = load <4 x float>, ptr [[ARRAYIDX25]], align 16 +// CHECK-NEXT: [[VECEXT26:%.*]] = extractelement <4 x float> [[TMP9]], i64 3 +// CHECK-NEXT: [[VECINIT27:%.*]] = insertelement <4 x float> [[VECINIT23]], float [[VECEXT26]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT27]], ptr [[EARDIRECTION]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT:%.*]] = getelementptr inbounds <4 x float>, ptr [[EARDIRECTION]], i32 1 +// CHECK-NEXT: [[EARDIRECTION28:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX29:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION28]], i32 0, i32 1 +// CHECK-NEXT: [[TMP10:%.*]] = load <4 x float>, ptr [[ARRAYIDX29]], align 16 +// CHECK-NEXT: [[VECEXT30:%.*]] = extractelement <4 x float> [[TMP10]], i64 0 +// CHECK-NEXT: [[VECINIT31:%.*]] = insertelement <4 x float> poison, float [[VECEXT30]], i32 0 +// CHECK-NEXT: [[EARDIRECTION32:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX33:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION32]], i32 0, i32 1 +// CHECK-NEXT: [[TMP11:%.*]] = load <4 x float>, ptr [[ARRAYIDX33]], align 16 +// CHECK-NEXT: [[VECEXT34:%.*]] = extractelement <4 x float> [[TMP11]], i64 1 +// CHECK-NEXT: [[VECINIT35:%.*]] = insertelement <4 x float> [[VECINIT31]], float [[VECEXT34]], i32 1 +// CHECK-NEXT: [[EARDIRECTION36:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX37:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION36]], i32 0, i32 1 +// CHECK-NEXT: [[TMP12:%.*]] = load <4 x float>, ptr [[ARRAYIDX37]], align 16 +// CHECK-NEXT: [[VECEXT38:%.*]] = extractelement <4 x float> [[TMP12]], i64 2 +// CHECK-NEXT: [[VECINIT39:%.*]] = insertelement <4 x float> [[VECINIT35]], float [[VECEXT38]], i32 2 +// CHECK-NEXT: [[EARDIRECTION40:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX41:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION40]], i32 0, i32 1 +// CHECK-NEXT: [[TMP13:%.*]] = load <4 x float>, ptr [[ARRAYIDX41]], align 16 +// CHECK-NEXT: [[VECEXT42:%.*]] = extractelement <4 x float> [[TMP13]], i64 3 +// CHECK-NEXT: [[VECINIT43:%.*]] = insertelement <4 x float> [[VECINIT39]], float [[VECEXT42]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT43]], ptr [[ARRAYINIT_ELEMENT]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT44:%.*]] = getelementptr inbounds [[STRUCT_DOGGO]], ptr [[DOGS]], i32 1 +// CHECK-NEXT: [[LEGSTATE45:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[ARRAYINIT_ELEMENT44]], i32 0, i32 0 +// CHECK-NEXT: [[LEGS:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX46:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS]], i32 0, i32 0 +// CHECK-NEXT: [[TMP14:%.*]] = load i32, ptr [[ARRAYIDX46]], align 16 +// CHECK-NEXT: [[VECINIT47:%.*]] = insertelement <4 x i32> poison, i32 [[TMP14]], i32 0 +// CHECK-NEXT: [[LEGS48:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX49:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS48]], i32 0, i32 1 +// CHECK-NEXT: [[TMP15:%.*]] = load i32, ptr [[ARRAYIDX49]], align 4 +// CHECK-NEXT: [[VECINIT50:%.*]] = insertelement <4 x i32> [[VECINIT47]], i32 [[TMP15]], i32 1 +// CHECK-NEXT: [[LEGS51:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX52:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS51]], i32 0, i32 2 +// CHECK-NEXT: [[TMP16:%.*]] = load i32, ptr [[ARRAYIDX52]], align 8 +// CHECK-NEXT: [[VECINIT53:%.*]] = insertelement <4 x i32> [[VECINIT50]], i32 [[TMP16]], i32 2 +// CHECK-NEXT: [[LEGS54:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX55:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS54]], i32 0, i32 3 +// CHECK-NEXT: [[TMP17:%.*]] = load i32, ptr [[ARRAYIDX55]], align 4 +// CHECK-NEXT: [[VECINIT56:%.*]] = insertelement <4 x i32> [[VECINIT53]], i32 [[TMP17]], i32 3 +// CHECK-NEXT: store <4 x i32> [[VECINIT56]], ptr [[LEGSTATE45]], align 16 +// CHECK-NEXT: [[TAILSTATE57:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[ARRAYINIT_ELEMENT44]], i32 0, i32 1 +// CHECK-NEXT: [[STATE:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 1 +// CHECK-NEXT: [[TMP18:%.*]] = load i32, ptr [[STATE]], align 16 +// CHECK-NEXT: store i32 [[TMP18]], ptr [[TAILSTATE57]], align 16 +// CHECK-NEXT: [[HAIRCOUNT58:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[ARRAYINIT_ELEMENT44]], i32 0, i32 2 +// CHECK-NEXT: [[COUNTER:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 2 +// CHECK-NEXT: [[TMP19:%.*]] = load i64, ptr [[COUNTER]], align 8 +// CHECK-NEXT: [[CONV:%.*]] = sitofp i64 [[TMP19]] to float +// CHECK-NEXT: store float [[CONV]], ptr [[HAIRCOUNT58]], align 4 +// CHECK-NEXT: [[EARDIRECTION59:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[ARRAYINIT_ELEMENT44]], i32 0, i32 3 +// CHECK-NEXT: [[LEFTDIR:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP20:%.*]] = load <4 x float>, ptr [[LEFTDIR]], align 16 +// CHECK-NEXT: [[VECEXT60:%.*]] = extractelement <4 x float> [[TMP20]], i64 0 +// CHECK-NEXT: [[VECINIT61:%.*]] = insertelement <4 x float> poison, float [[VECEXT60]], i32 0 +// CHECK-NEXT: [[LEFTDIR62:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP21:%.*]] = load <4 x float>, ptr [[LEFTDIR62]], align 16 +// CHECK-NEXT: [[VECEXT63:%.*]] = extractelement <4 x float> [[TMP21]], i64 1 +// CHECK-NEXT: [[VECINIT64:%.*]] = insertelement <4 x float> [[VECINIT61]], float [[VECEXT63]], i32 1 +// CHECK-NEXT: [[LEFTDIR65:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP22:%.*]] = load <4 x float>, ptr [[LEFTDIR65]], align 16 +// CHECK-NEXT: [[VECEXT66:%.*]] = extractelement <4 x float> [[TMP22]], i64 2 +// CHECK-NEXT: [[VECINIT67:%.*]] = insertelement <4 x float> [[VECINIT64]], float [[VECEXT66]], i32 2 +// CHECK-NEXT: [[LEFTDIR68:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP23:%.*]] = load <4 x float>, ptr [[LEFTDIR68]], align 16 +// CHECK-NEXT: [[VECEXT69:%.*]] = extractelement <4 x float> [[TMP23]], i64 3 +// CHECK-NEXT: [[VECINIT70:%.*]] = insertelement <4 x float> [[VECINIT67]], float [[VECEXT69]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT70]], ptr [[EARDIRECTION59]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT71:%.*]] = getelementptr inbounds <4 x float>, ptr [[EARDIRECTION59]], i32 1 +// CHECK-NEXT: [[RIGHTDIR:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP24:%.*]] = load <4 x float>, ptr [[RIGHTDIR]], align 16 +// CHECK-NEXT: [[VECEXT72:%.*]] = extractelement <4 x float> [[TMP24]], i64 0 +// CHECK-NEXT: [[VECINIT73:%.*]] = insertelement <4 x float> poison, float [[VECEXT72]], i32 0 +// CHECK-NEXT: [[RIGHTDIR74:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP25:%.*]] = load <4 x float>, ptr [[RIGHTDIR74]], align 16 +// CHECK-NEXT: [[VECEXT75:%.*]] = extractelement <4 x float> [[TMP25]], i64 1 +// CHECK-NEXT: [[VECINIT76:%.*]] = insertelement <4 x float> [[VECINIT73]], float [[VECEXT75]], i32 1 +// CHECK-NEXT: [[RIGHTDIR77:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP26:%.*]] = load <4 x float>, ptr [[RIGHTDIR77]], align 16 +// CHECK-NEXT: [[VECEXT78:%.*]] = extractelement <4 x float> [[TMP26]], i64 2 +// CHECK-NEXT: [[VECINIT79:%.*]] = insertelement <4 x float> [[VECINIT76]], float [[VECEXT78]], i32 2 +// CHECK-NEXT: [[RIGHTDIR80:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP27:%.*]] = load <4 x float>, ptr [[RIGHTDIR80]], align 16 +// CHECK-NEXT: [[VECEXT81:%.*]] = extractelement <4 x float> [[TMP27]], i64 3 +// CHECK-NEXT: [[VECINIT82:%.*]] = insertelement <4 x float> [[VECINIT79]], float [[VECEXT81]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT82]], ptr [[ARRAYINIT_ELEMENT71]], align 16 +// CHECK-NEXT: [[CATS:%.*]] = getelementptr inbounds nuw [[STRUCT_ZOO]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[LEGS83:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH:%.*]], ptr [[CATS]], i32 0, i32 0 +// CHECK-NEXT: [[LEGSTATE84:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP28:%.*]] = load <4 x i32>, ptr [[LEGSTATE84]], align 16 +// CHECK-NEXT: [[VECEXT85:%.*]] = extractelement <4 x i32> [[TMP28]], i64 0 +// CHECK-NEXT: [[VECINIT86:%.*]] = insertelement <4 x i32> poison, i32 [[VECEXT85]], i32 0 +// CHECK-NEXT: [[LEGSTATE87:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP29:%.*]] = load <4 x i32>, ptr [[LEGSTATE87]], align 16 +// CHECK-NEXT: [[VECEXT88:%.*]] = extractelement <4 x i32> [[TMP29]], i64 1 +// CHECK-NEXT: [[VECINIT89:%.*]] = insertelement <4 x i32> [[VECINIT86]], i32 [[VECEXT88]], i32 1 +// CHECK-NEXT: [[LEGSTATE90:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP30:%.*]] = load <4 x i32>, ptr [[LEGSTATE90]], align 16 +// CHECK-NEXT: [[VECEXT91:%.*]] = extractelement <4 x i32> [[TMP30]], i64 2 +// CHECK-NEXT: [[VECINIT92:%.*]] = insertelement <4 x i32> [[VECINIT89]], i32 [[VECEXT91]], i32 2 +// CHECK-NEXT: [[LEGSTATE93:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP31:%.*]] = load <4 x i32>, ptr [[LEGSTATE93]], align 16 +// CHECK-NEXT: [[VECEXT94:%.*]] = extractelement <4 x i32> [[TMP31]], i64 3 +// CHECK-NEXT: [[VECINIT95:%.*]] = insertelement <4 x i32> [[VECINIT92]], i32 [[VECEXT94]], i32 3 +// CHECK-NEXT: store <4 x i32> [[VECINIT95]], ptr [[LEGS83]], align 16 +// CHECK-NEXT: [[TAILSTATE96:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[CATS]], i32 0, i32 1 +// CHECK-NEXT: [[TAILSTATE97:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 1 +// CHECK-NEXT: [[TMP32:%.*]] = load i32, ptr [[TAILSTATE97]], align 16 +// CHECK-NEXT: store i32 [[TMP32]], ptr [[TAILSTATE96]], align 16 +// CHECK-NEXT: [[HAIRCOUNT98:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[CATS]], i32 0, i32 2 +// CHECK-NEXT: [[HAIRCOUNT99:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 2 +// CHECK-NEXT: [[TMP33:%.*]] = load float, ptr [[HAIRCOUNT99]], align 4 +// CHECK-NEXT: store float [[TMP33]], ptr [[HAIRCOUNT98]], align 4 +// CHECK-NEXT: [[CLAWS:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[CATS]], i32 0, i32 3 +// CHECK-NEXT: [[EARDIRECTION100:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX101:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION100]], i32 0, i32 0 +// CHECK-NEXT: [[TMP34:%.*]] = load <4 x float>, ptr [[ARRAYIDX101]], align 16 +// CHECK-NEXT: [[VECEXT102:%.*]] = extractelement <4 x float> [[TMP34]], i64 0 +// CHECK-NEXT: [[VECINIT103:%.*]] = insertelement <4 x float> poison, float [[VECEXT102]], i32 0 +// CHECK-NEXT: [[EARDIRECTION104:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX105:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION104]], i32 0, i32 0 +// CHECK-NEXT: [[TMP35:%.*]] = load <4 x float>, ptr [[ARRAYIDX105]], align 16 +// CHECK-NEXT: [[VECEXT106:%.*]] = extractelement <4 x float> [[TMP35]], i64 1 +// CHECK-NEXT: [[VECINIT107:%.*]] = insertelement <4 x float> [[VECINIT103]], float [[VECEXT106]], i32 1 +// CHECK-NEXT: [[EARDIRECTION108:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX109:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION108]], i32 0, i32 0 +// CHECK-NEXT: [[TMP36:%.*]] = load <4 x float>, ptr [[ARRAYIDX109]], align 16 +// CHECK-NEXT: [[VECEXT110:%.*]] = extractelement <4 x float> [[TMP36]], i64 2 +// CHECK-NEXT: [[VECINIT111:%.*]] = insertelement <4 x float> [[VECINIT107]], float [[VECEXT110]], i32 2 +// CHECK-NEXT: [[EARDIRECTION112:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX113:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION112]], i32 0, i32 0 +// CHECK-NEXT: [[TMP37:%.*]] = load <4 x float>, ptr [[ARRAYIDX113]], align 16 +// CHECK-NEXT: [[VECEXT114:%.*]] = extractelement <4 x float> [[TMP37]], i64 3 +// CHECK-NEXT: [[VECINIT115:%.*]] = insertelement <4 x float> [[VECINIT111]], float [[VECEXT114]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT115]], ptr [[CLAWS]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT116:%.*]] = getelementptr inbounds <4 x float>, ptr [[CLAWS]], i32 1 +// CHECK-NEXT: [[EARDIRECTION117:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX118:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION117]], i32 0, i32 1 +// CHECK-NEXT: [[TMP38:%.*]] = load <4 x float>, ptr [[ARRAYIDX118]], align 16 +// CHECK-NEXT: [[VECEXT119:%.*]] = extractelement <4 x float> [[TMP38]], i64 0 +// CHECK-NEXT: [[VECINIT120:%.*]] = insertelement <4 x float> poison, float [[VECEXT119]], i32 0 +// CHECK-NEXT: [[EARDIRECTION121:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX122:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION121]], i32 0, i32 1 +// CHECK-NEXT: [[TMP39:%.*]] = load <4 x float>, ptr [[ARRAYIDX122]], align 16 +// CHECK-NEXT: [[VECEXT123:%.*]] = extractelement <4 x float> [[TMP39]], i64 1 +// CHECK-NEXT: [[VECINIT124:%.*]] = insertelement <4 x float> [[VECINIT120]], float [[VECEXT123]], i32 1 +// CHECK-NEXT: [[EARDIRECTION125:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX126:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION125]], i32 0, i32 1 +// CHECK-NEXT: [[TMP40:%.*]] = load <4 x float>, ptr [[ARRAYIDX126]], align 16 +// CHECK-NEXT: [[VECEXT127:%.*]] = extractelement <4 x float> [[TMP40]], i64 2 +// CHECK-NEXT: [[VECINIT128:%.*]] = insertelement <4 x float> [[VECINIT124]], float [[VECEXT127]], i32 2 +// CHECK-NEXT: [[EARDIRECTION129:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX130:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION129]], i32 0, i32 1 +// CHECK-NEXT: [[TMP41:%.*]] = load <4 x float>, ptr [[ARRAYIDX130]], align 16 +// CHECK-NEXT: [[VECEXT131:%.*]] = extractelement <4 x float> [[TMP41]], i64 3 +// CHECK-NEXT: [[VECINIT132:%.*]] = insertelement <4 x float> [[VECINIT128]], float [[VECEXT131]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT132]], ptr [[ARRAYINIT_ELEMENT116]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT133:%.*]] = getelementptr inbounds [[STRUCT_KITTEH]], ptr [[CATS]], i32 1 +// CHECK-NEXT: [[LEGS134:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT133]], i32 0, i32 0 +// CHECK-NEXT: [[LEGS135:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX136:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS135]], i32 0, i32 0 +// CHECK-NEXT: [[TMP42:%.*]] = load i32, ptr [[ARRAYIDX136]], align 16 +// CHECK-NEXT: [[VECINIT137:%.*]] = insertelement <4 x i32> poison, i32 [[TMP42]], i32 0 +// CHECK-NEXT: [[LEGS138:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX139:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS138]], i32 0, i32 1 +// CHECK-NEXT: [[TMP43:%.*]] = load i32, ptr [[ARRAYIDX139]], align 4 +// CHECK-NEXT: [[VECINIT140:%.*]] = insertelement <4 x i32> [[VECINIT137]], i32 [[TMP43]], i32 1 +// CHECK-NEXT: [[LEGS141:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX142:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS141]], i32 0, i32 2 +// CHECK-NEXT: [[TMP44:%.*]] = load i32, ptr [[ARRAYIDX142]], align 8 +// CHECK-NEXT: [[VECINIT143:%.*]] = insertelement <4 x i32> [[VECINIT140]], i32 [[TMP44]], i32 2 +// CHECK-NEXT: [[LEGS144:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX145:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS144]], i32 0, i32 3 +// CHECK-NEXT: [[TMP45:%.*]] = load i32, ptr [[ARRAYIDX145]], align 4 +// CHECK-NEXT: [[VECINIT146:%.*]] = insertelement <4 x i32> [[VECINIT143]], i32 [[TMP45]], i32 3 +// CHECK-NEXT: store <4 x i32> [[VECINIT146]], ptr [[LEGS134]], align 16 +// CHECK-NEXT: [[TAILSTATE147:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT133]], i32 0, i32 1 +// CHECK-NEXT: [[STATE148:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 1 +// CHECK-NEXT: [[TMP46:%.*]] = load i32, ptr [[STATE148]], align 16 +// CHECK-NEXT: store i32 [[TMP46]], ptr [[TAILSTATE147]], align 16 +// CHECK-NEXT: [[HAIRCOUNT149:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT133]], i32 0, i32 2 +// CHECK-NEXT: [[COUNTER150:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 2 +// CHECK-NEXT: [[TMP47:%.*]] = load i64, ptr [[COUNTER150]], align 8 +// CHECK-NEXT: [[CONV151:%.*]] = sitofp i64 [[TMP47]] to float +// CHECK-NEXT: store float [[CONV151]], ptr [[HAIRCOUNT149]], align 4 +// CHECK-NEXT: [[CLAWS152:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT133]], i32 0, i32 3 +// CHECK-NEXT: [[LEFTDIR153:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP48:%.*]] = load <4 x float>, ptr [[LEFTDIR153]], align 16 +// CHECK-NEXT: [[VECEXT154:%.*]] = extractelement <4 x float> [[TMP48]], i64 0 +// CHECK-NEXT: [[VECINIT155:%.*]] = insertelement <4 x float> poison, float [[VECEXT154]], i32 0 +// CHECK-NEXT: [[LEFTDIR156:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP49:%.*]] = load <4 x float>, ptr [[LEFTDIR156]], align 16 +// CHECK-NEXT: [[VECEXT157:%.*]] = extractelement <4 x float> [[TMP49]], i64 1 +// CHECK-NEXT: [[VECINIT158:%.*]] = insertelement <4 x float> [[VECINIT155]], float [[VECEXT157]], i32 1 +// CHECK-NEXT: [[LEFTDIR159:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP50:%.*]] = load <4 x float>, ptr [[LEFTDIR159]], align 16 +// CHECK-NEXT: [[VECEXT160:%.*]] = extractelement <4 x float> [[TMP50]], i64 2 +// CHECK-NEXT: [[VECINIT161:%.*]] = insertelement <4 x float> [[VECINIT158]], float [[VECEXT160]], i32 2 +// CHECK-NEXT: [[LEFTDIR162:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP51:%.*]] = load <4 x float>, ptr [[LEFTDIR162]], align 16 +// CHECK-NEXT: [[VECEXT163:%.*]] = extractelement <4 x float> [[TMP51]], i64 3 +// CHECK-NEXT: [[VECINIT164:%.*]] = insertelement <4 x float> [[VECINIT161]], float [[VECEXT163]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT164]], ptr [[CLAWS152]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT165:%.*]] = getelementptr inbounds <4 x float>, ptr [[CLAWS152]], i32 1 +// CHECK-NEXT: [[RIGHTDIR166:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP52:%.*]] = load <4 x float>, ptr [[RIGHTDIR166]], align 16 +// CHECK-NEXT: [[VECEXT167:%.*]] = extractelement <4 x float> [[TMP52]], i64 0 +// CHECK-NEXT: [[VECINIT168:%.*]] = insertelement <4 x float> poison, float [[VECEXT167]], i32 0 +// CHECK-NEXT: [[RIGHTDIR169:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP53:%.*]] = load <4 x float>, ptr [[RIGHTDIR169]], align 16 +// CHECK-NEXT: [[VECEXT170:%.*]] = extractelement <4 x float> [[TMP53]], i64 1 +// CHECK-NEXT: [[VECINIT171:%.*]] = insertelement <4 x float> [[VECINIT168]], float [[VECEXT170]], i32 1 +// CHECK-NEXT: [[RIGHTDIR172:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP54:%.*]] = load <4 x float>, ptr [[RIGHTDIR172]], align 16 +// CHECK-NEXT: [[VECEXT173:%.*]] = extractelement <4 x float> [[TMP54]], i64 2 +// CHECK-NEXT: [[VECINIT174:%.*]] = insertelement <4 x float> [[VECINIT171]], float [[VECEXT173]], i32 2 +// CHECK-NEXT: [[RIGHTDIR175:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP55:%.*]] = load <4 x float>, ptr [[RIGHTDIR175]], align 16 +// CHECK-NEXT: [[VECEXT176:%.*]] = extractelement <4 x float> [[TMP55]], i64 3 +// CHECK-NEXT: [[VECINIT177:%.*]] = insertelement <4 x float> [[VECINIT174]], float [[VECEXT176]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT177]], ptr [[ARRAYINIT_ELEMENT165]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT178:%.*]] = getelementptr inbounds [[STRUCT_KITTEH]], ptr [[CATS]], i32 2 +// CHECK-NEXT: [[LEGS179:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT178]], i32 0, i32 0 +// CHECK-NEXT: [[LEGSTATE180:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP56:%.*]] = load <4 x i32>, ptr [[LEGSTATE180]], align 16 +// CHECK-NEXT: [[VECEXT181:%.*]] = extractelement <4 x i32> [[TMP56]], i64 0 +// CHECK-NEXT: [[VECINIT182:%.*]] = insertelement <4 x i32> poison, i32 [[VECEXT181]], i32 0 +// CHECK-NEXT: [[LEGSTATE183:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP57:%.*]] = load <4 x i32>, ptr [[LEGSTATE183]], align 16 +// CHECK-NEXT: [[VECEXT184:%.*]] = extractelement <4 x i32> [[TMP57]], i64 1 +// CHECK-NEXT: [[VECINIT185:%.*]] = insertelement <4 x i32> [[VECINIT182]], i32 [[VECEXT184]], i32 1 +// CHECK-NEXT: [[LEGSTATE186:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP58:%.*]] = load <4 x i32>, ptr [[LEGSTATE186]], align 16 +// CHECK-NEXT: [[VECEXT187:%.*]] = extractelement <4 x i32> [[TMP58]], i64 2 +// CHECK-NEXT: [[VECINIT188:%.*]] = insertelement <4 x i32> [[VECINIT185]], i32 [[VECEXT187]], i32 2 +// CHECK-NEXT: [[LEGSTATE189:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP59:%.*]] = load <4 x i32>, ptr [[LEGSTATE189]], align 16 +// CHECK-NEXT: [[VECEXT190:%.*]] = extractelement <4 x i32> [[TMP59]], i64 3 +// CHECK-NEXT: [[VECINIT191:%.*]] = insertelement <4 x i32> [[VECINIT188]], i32 [[VECEXT190]], i32 3 +// CHECK-NEXT: store <4 x i32> [[VECINIT191]], ptr [[LEGS179]], align 16 +// CHECK-NEXT: [[TAILSTATE192:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT178]], i32 0, i32 1 +// CHECK-NEXT: [[TAILSTATE193:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 1 +// CHECK-NEXT: [[TMP60:%.*]] = load i32, ptr [[TAILSTATE193]], align 16 +// CHECK-NEXT: store i32 [[TMP60]], ptr [[TAILSTATE192]], align 16 +// CHECK-NEXT: [[HAIRCOUNT194:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT178]], i32 0, i32 2 +// CHECK-NEXT: [[HAIRCOUNT195:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 2 +// CHECK-NEXT: [[TMP61:%.*]] = load float, ptr [[HAIRCOUNT195]], align 4 +// CHECK-NEXT: store float [[TMP61]], ptr [[HAIRCOUNT194]], align 4 +// CHECK-NEXT: [[CLAWS196:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT178]], i32 0, i32 3 +// CHECK-NEXT: [[EARDIRECTION197:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX198:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION197]], i32 0, i32 0 +// CHECK-NEXT: [[TMP62:%.*]] = load <4 x float>, ptr [[ARRAYIDX198]], align 16 +// CHECK-NEXT: [[VECEXT199:%.*]] = extractelement <4 x float> [[TMP62]], i64 0 +// CHECK-NEXT: [[VECINIT200:%.*]] = insertelement <4 x float> poison, float [[VECEXT199]], i32 0 +// CHECK-NEXT: [[EARDIRECTION201:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX202:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION201]], i32 0, i32 0 +// CHECK-NEXT: [[TMP63:%.*]] = load <4 x float>, ptr [[ARRAYIDX202]], align 16 +// CHECK-NEXT: [[VECEXT203:%.*]] = extractelement <4 x float> [[TMP63]], i64 1 +// CHECK-NEXT: [[VECINIT204:%.*]] = insertelement <4 x float> [[VECINIT200]], float [[VECEXT203]], i32 1 +// CHECK-NEXT: [[EARDIRECTION205:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX206:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION205]], i32 0, i32 0 +// CHECK-NEXT: [[TMP64:%.*]] = load <4 x float>, ptr [[ARRAYIDX206]], align 16 +// CHECK-NEXT: [[VECEXT207:%.*]] = extractelement <4 x float> [[TMP64]], i64 2 +// CHECK-NEXT: [[VECINIT208:%.*]] = insertelement <4 x float> [[VECINIT204]], float [[VECEXT207]], i32 2 +// CHECK-NEXT: [[EARDIRECTION209:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX210:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION209]], i32 0, i32 0 +// CHECK-NEXT: [[TMP65:%.*]] = load <4 x float>, ptr [[ARRAYIDX210]], align 16 +// CHECK-NEXT: [[VECEXT211:%.*]] = extractelement <4 x float> [[TMP65]], i64 3 +// CHECK-NEXT: [[VECINIT212:%.*]] = insertelement <4 x float> [[VECINIT208]], float [[VECEXT211]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT212]], ptr [[CLAWS196]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT213:%.*]] = getelementptr inbounds <4 x float>, ptr [[CLAWS196]], i32 1 +// CHECK-NEXT: [[EARDIRECTION214:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX215:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION214]], i32 0, i32 1 +// CHECK-NEXT: [[TMP66:%.*]] = load <4 x float>, ptr [[ARRAYIDX215]], align 16 +// CHECK-NEXT: [[VECEXT216:%.*]] = extractelement <4 x float> [[TMP66]], i64 0 +// CHECK-NEXT: [[VECINIT217:%.*]] = insertelement <4 x float> poison, float [[VECEXT216]], i32 0 +// CHECK-NEXT: [[EARDIRECTION218:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX219:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION218]], i32 0, i32 1 +// CHECK-NEXT: [[TMP67:%.*]] = load <4 x float>, ptr [[ARRAYIDX219]], align 16 +// CHECK-NEXT: [[VECEXT220:%.*]] = extractelement <4 x float> [[TMP67]], i64 1 +// CHECK-NEXT: [[VECINIT221:%.*]] = insertelement <4 x float> [[VECINIT217]], float [[VECEXT220]], i32 1 +// CHECK-NEXT: [[EARDIRECTION222:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX223:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION222]], i32 0, i32 1 +// CHECK-NEXT: [[TMP68:%.*]] = load <4 x float>, ptr [[ARRAYIDX223]], align 16 +// CHECK-NEXT: [[VECEXT224:%.*]] = extractelement <4 x float> [[TMP68]], i64 2 +// CHECK-NEXT: [[VECINIT225:%.*]] = insertelement <4 x float> [[VECINIT221]], float [[VECEXT224]], i32 2 +// CHECK-NEXT: [[EARDIRECTION226:%.*]] = getelementptr inbounds nuw [[STRUCT_DOGGO]], ptr [[D1]], i32 0, i32 3 +// CHECK-NEXT: [[ARRAYIDX227:%.*]] = getelementptr inbounds nuw [2 x <4 x float>], ptr [[EARDIRECTION226]], i32 0, i32 1 +// CHECK-NEXT: [[TMP69:%.*]] = load <4 x float>, ptr [[ARRAYIDX227]], align 16 +// CHECK-NEXT: [[VECEXT228:%.*]] = extractelement <4 x float> [[TMP69]], i64 3 +// CHECK-NEXT: [[VECINIT229:%.*]] = insertelement <4 x float> [[VECINIT225]], float [[VECEXT228]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT229]], ptr [[ARRAYINIT_ELEMENT213]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT230:%.*]] = getelementptr inbounds [[STRUCT_KITTEH]], ptr [[CATS]], i32 3 +// CHECK-NEXT: [[LEGS231:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT230]], i32 0, i32 0 +// CHECK-NEXT: [[LEGS232:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX233:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS232]], i32 0, i32 0 +// CHECK-NEXT: [[TMP70:%.*]] = load i32, ptr [[ARRAYIDX233]], align 16 +// CHECK-NEXT: [[VECINIT234:%.*]] = insertelement <4 x i32> poison, i32 [[TMP70]], i32 0 +// CHECK-NEXT: [[LEGS235:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX236:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS235]], i32 0, i32 1 +// CHECK-NEXT: [[TMP71:%.*]] = load i32, ptr [[ARRAYIDX236]], align 4 +// CHECK-NEXT: [[VECINIT237:%.*]] = insertelement <4 x i32> [[VECINIT234]], i32 [[TMP71]], i32 1 +// CHECK-NEXT: [[LEGS238:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX239:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS238]], i32 0, i32 2 +// CHECK-NEXT: [[TMP72:%.*]] = load i32, ptr [[ARRAYIDX239]], align 8 +// CHECK-NEXT: [[VECINIT240:%.*]] = insertelement <4 x i32> [[VECINIT237]], i32 [[TMP72]], i32 2 +// CHECK-NEXT: [[LEGS241:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 0 +// CHECK-NEXT: [[ARRAYIDX242:%.*]] = getelementptr inbounds nuw [4 x i32], ptr [[LEGS241]], i32 0, i32 3 +// CHECK-NEXT: [[TMP73:%.*]] = load i32, ptr [[ARRAYIDX242]], align 4 +// CHECK-NEXT: [[VECINIT243:%.*]] = insertelement <4 x i32> [[VECINIT240]], i32 [[TMP73]], i32 3 +// CHECK-NEXT: store <4 x i32> [[VECINIT243]], ptr [[LEGS231]], align 16 +// CHECK-NEXT: [[TAILSTATE244:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT230]], i32 0, i32 1 +// CHECK-NEXT: [[STATE245:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 1 +// CHECK-NEXT: [[TMP74:%.*]] = load i32, ptr [[STATE245]], align 16 +// CHECK-NEXT: store i32 [[TMP74]], ptr [[TAILSTATE244]], align 16 +// CHECK-NEXT: [[HAIRCOUNT246:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT230]], i32 0, i32 2 +// CHECK-NEXT: [[COUNTER247:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 2 +// CHECK-NEXT: [[TMP75:%.*]] = load i64, ptr [[COUNTER247]], align 8 +// CHECK-NEXT: [[CONV248:%.*]] = sitofp i64 [[TMP75]] to float +// CHECK-NEXT: store float [[CONV248]], ptr [[HAIRCOUNT246]], align 4 +// CHECK-NEXT: [[CLAWS249:%.*]] = getelementptr inbounds nuw [[STRUCT_KITTEH]], ptr [[ARRAYINIT_ELEMENT230]], i32 0, i32 3 +// CHECK-NEXT: [[LEFTDIR250:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP76:%.*]] = load <4 x float>, ptr [[LEFTDIR250]], align 16 +// CHECK-NEXT: [[VECEXT251:%.*]] = extractelement <4 x float> [[TMP76]], i64 0 +// CHECK-NEXT: [[VECINIT252:%.*]] = insertelement <4 x float> poison, float [[VECEXT251]], i32 0 +// CHECK-NEXT: [[LEFTDIR253:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP77:%.*]] = load <4 x float>, ptr [[LEFTDIR253]], align 16 +// CHECK-NEXT: [[VECEXT254:%.*]] = extractelement <4 x float> [[TMP77]], i64 1 +// CHECK-NEXT: [[VECINIT255:%.*]] = insertelement <4 x float> [[VECINIT252]], float [[VECEXT254]], i32 1 +// CHECK-NEXT: [[LEFTDIR256:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP78:%.*]] = load <4 x float>, ptr [[LEFTDIR256]], align 16 +// CHECK-NEXT: [[VECEXT257:%.*]] = extractelement <4 x float> [[TMP78]], i64 2 +// CHECK-NEXT: [[VECINIT258:%.*]] = insertelement <4 x float> [[VECINIT255]], float [[VECEXT257]], i32 2 +// CHECK-NEXT: [[LEFTDIR259:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 3 +// CHECK-NEXT: [[TMP79:%.*]] = load <4 x float>, ptr [[LEFTDIR259]], align 16 +// CHECK-NEXT: [[VECEXT260:%.*]] = extractelement <4 x float> [[TMP79]], i64 3 +// CHECK-NEXT: [[VECINIT261:%.*]] = insertelement <4 x float> [[VECINIT258]], float [[VECEXT260]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT261]], ptr [[CLAWS249]], align 16 +// CHECK-NEXT: [[ARRAYINIT_ELEMENT262:%.*]] = getelementptr inbounds <4 x float>, ptr [[CLAWS249]], i32 1 +// CHECK-NEXT: [[RIGHTDIR263:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP80:%.*]] = load <4 x float>, ptr [[RIGHTDIR263]], align 16 +// CHECK-NEXT: [[VECEXT264:%.*]] = extractelement <4 x float> [[TMP80]], i64 0 +// CHECK-NEXT: [[VECINIT265:%.*]] = insertelement <4 x float> poison, float [[VECEXT264]], i32 0 +// CHECK-NEXT: [[RIGHTDIR266:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP81:%.*]] = load <4 x float>, ptr [[RIGHTDIR266]], align 16 +// CHECK-NEXT: [[VECEXT267:%.*]] = extractelement <4 x float> [[TMP81]], i64 1 +// CHECK-NEXT: [[VECINIT268:%.*]] = insertelement <4 x float> [[VECINIT265]], float [[VECEXT267]], i32 1 +// CHECK-NEXT: [[RIGHTDIR269:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP82:%.*]] = load <4 x float>, ptr [[RIGHTDIR269]], align 16 +// CHECK-NEXT: [[VECEXT270:%.*]] = extractelement <4 x float> [[TMP82]], i64 2 +// CHECK-NEXT: [[VECINIT271:%.*]] = insertelement <4 x float> [[VECINIT268]], float [[VECEXT270]], i32 2 +// CHECK-NEXT: [[RIGHTDIR272:%.*]] = getelementptr inbounds nuw [[STRUCT_ANIMALBITS]], ptr [[A1]], i32 0, i32 4 +// CHECK-NEXT: [[TMP83:%.*]] = load <4 x float>, ptr [[RIGHTDIR272]], align 16 +// CHECK-NEXT: [[VECEXT273:%.*]] = extractelement <4 x float> [[TMP83]], i64 3 +// CHECK-NEXT: [[VECINIT274:%.*]] = insertelement <4 x float> [[VECINIT271]], float [[VECEXT273]], i32 3 +// CHECK-NEXT: store <4 x float> [[VECINIT274]], ptr [[ARRAYINIT_ELEMENT262]], align 16 +// CHECK-NEXT: ret void +// +Zoo case9(Doggo D1, AnimalBits A1) { + Zoo Z1 = {D1, A1, D1, A1, D1, A1}; + return Z1; +} + +// Case 10: Initialize an object with a base class from two objects. +// CHECK-LABEL: define void @_Z6case109TwoFloatsS_( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_FOURFLOATS:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef byval([[STRUCT_TWOFLOATS:%.*]]) align 4 [[TF1:%.*]], ptr noundef byval([[STRUCT_TWOFLOATS]]) align 4 [[TF2:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[X1:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF1]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load float, ptr [[X1]], align 4 +// CHECK-NEXT: store float [[TMP0]], ptr [[X]], align 4 +// CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[Y2:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF1]], i32 0, i32 1 +// CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[Y2]], align 4 +// CHECK-NEXT: store float [[TMP1]], ptr [[Y]], align 4 +// CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds nuw [[STRUCT_FOURFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[X3:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF2]], i32 0, i32 0 +// CHECK-NEXT: [[TMP2:%.*]] = load float, ptr [[X3]], align 4 +// CHECK-NEXT: store float [[TMP2]], ptr [[Z]], align 4 +// CHECK-NEXT: [[W:%.*]] = getelementptr inbounds nuw [[STRUCT_FOURFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 2 +// CHECK-NEXT: [[Y4:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[TF2]], i32 0, i32 1 +// CHECK-NEXT: [[TMP3:%.*]] = load float, ptr [[Y4]], align 4 +// CHECK-NEXT: store float [[TMP3]], ptr [[W]], align 4 +// CHECK-NEXT: ret void +// +FourFloats case10(TwoFloats TF1, TwoFloats TF2) { + FourFloats FF1 = {TF1, TF2}; + return FF1; +} + +// Case 11: Initialize an object with a base class from a vector splat. +// CHECK-LABEL: define void @_Z6case11f( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_FOURFLOATS:%.*]]) align 4 [[AGG_RESULT:%.*]], float noundef nofpclass(nan inf) [[F:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[F_ADDR:%.*]] = alloca float, align 4 +// CHECK-NEXT: [[REF_TMP:%.*]] = alloca <4 x float>, align 16 +// CHECK-NEXT: [[REF_TMP1:%.*]] = alloca <4 x float>, align 16 +// CHECK-NEXT: [[REF_TMP4:%.*]] = alloca <4 x float>, align 16 +// CHECK-NEXT: [[REF_TMP7:%.*]] = alloca <4 x float>, align 16 +// CHECK-NEXT: store float [[F]], ptr [[F_ADDR]], align 4 +// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS:%.*]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load float, ptr [[F_ADDR]], align 4 +// CHECK-NEXT: [[CAST_SPLAT:%.*]] = insertelement <1 x float> poison, float [[TMP0]], i64 0 +// CHECK-NEXT: [[TMP1:%.*]] = shufflevector <1 x float> [[CAST_SPLAT]], <1 x float> poison, <4 x i32> zeroinitializer +// CHECK-NEXT: store <4 x float> [[TMP1]], ptr [[REF_TMP]], align 16 +// CHECK-NEXT: [[TMP2:%.*]] = load <4 x float>, ptr [[REF_TMP]], align 16 +// CHECK-NEXT: [[VECEXT:%.*]] = extractelement <4 x float> [[TMP2]], i64 0 +// CHECK-NEXT: store float [[VECEXT]], ptr [[X]], align 4 +// CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[TMP3:%.*]] = load float, ptr [[F_ADDR]], align 4 +// CHECK-NEXT: [[CAST_SPLAT2:%.*]] = insertelement <1 x float> poison, float [[TMP3]], i64 0 +// CHECK-NEXT: [[TMP4:%.*]] = shufflevector <1 x float> [[CAST_SPLAT2]], <1 x float> poison, <4 x i32> zeroinitializer +// CHECK-NEXT: store <4 x float> [[TMP4]], ptr [[REF_TMP1]], align 16 +// CHECK-NEXT: [[TMP5:%.*]] = load <4 x float>, ptr [[REF_TMP1]], align 16 +// CHECK-NEXT: [[VECEXT3:%.*]] = extractelement <4 x float> [[TMP5]], i64 1 +// CHECK-NEXT: store float [[VECEXT3]], ptr [[Y]], align 4 +// CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds nuw [[STRUCT_FOURFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[TMP6:%.*]] = load float, ptr [[F_ADDR]], align 4 +// CHECK-NEXT: [[CAST_SPLAT5:%.*]] = insertelement <1 x float> poison, float [[TMP6]], i64 0 +// CHECK-NEXT: [[TMP7:%.*]] = shufflevector <1 x float> [[CAST_SPLAT5]], <1 x float> poison, <4 x i32> zeroinitializer +// CHECK-NEXT: store <4 x float> [[TMP7]], ptr [[REF_TMP4]], align 16 +// CHECK-NEXT: [[TMP8:%.*]] = load <4 x float>, ptr [[REF_TMP4]], align 16 +// CHECK-NEXT: [[VECEXT6:%.*]] = extractelement <4 x float> [[TMP8]], i64 2 +// CHECK-NEXT: store float [[VECEXT6]], ptr [[Z]], align 4 +// CHECK-NEXT: [[W:%.*]] = getelementptr inbounds nuw [[STRUCT_FOURFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 2 +// CHECK-NEXT: [[TMP9:%.*]] = load float, ptr [[F_ADDR]], align 4 +// CHECK-NEXT: [[CAST_SPLAT8:%.*]] = insertelement <1 x float> poison, float [[TMP9]], i64 0 +// CHECK-NEXT: [[TMP10:%.*]] = shufflevector <1 x float> [[CAST_SPLAT8]], <1 x float> poison, <4 x i32> zeroinitializer +// CHECK-NEXT: store <4 x float> [[TMP10]], ptr [[REF_TMP7]], align 16 +// CHECK-NEXT: [[TMP11:%.*]] = load <4 x float>, ptr [[REF_TMP7]], align 16 +// CHECK-NEXT: [[VECEXT9:%.*]] = extractelement <4 x float> [[TMP11]], i64 3 +// CHECK-NEXT: store float [[VECEXT9]], ptr [[W]], align 4 +// CHECK-NEXT: ret void +// +FourFloats case11(float F) { + FourFloats FF1 = {F.xxxx}; + return FF1; +} + +// Case 12: Initialize bitfield from two integers. +// CHECK-LABEL: define void @_Z6case12ii( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_SLICYBITS:%.*]]) align 4 [[AGG_RESULT:%.*]], i32 noundef [[I:%.*]], i32 noundef [[J:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[I_ADDR:%.*]] = alloca i32, align 4 +// CHECK-NEXT: [[J_ADDR:%.*]] = alloca i32, align 4 +// CHECK-NEXT: store i32 [[I]], ptr [[I_ADDR]], align 4 +// CHECK-NEXT: store i32 [[J]], ptr [[J_ADDR]], align 4 +// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[I_ADDR]], align 4 +// CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[TMP0]] to i16 +// CHECK-NEXT: [[BF_LOAD:%.*]] = load i16, ptr [[AGG_RESULT]], align 4 +// CHECK-NEXT: [[BF_VALUE:%.*]] = and i16 [[TMP1]], 255 +// CHECK-NEXT: [[BF_CLEAR:%.*]] = and i16 [[BF_LOAD]], -256 +// CHECK-NEXT: [[BF_SET:%.*]] = or i16 [[BF_CLEAR]], [[BF_VALUE]] +// CHECK-NEXT: store i16 [[BF_SET]], ptr [[AGG_RESULT]], align 4 +// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[J_ADDR]], align 4 +// CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[TMP2]] to i16 +// CHECK-NEXT: [[BF_LOAD1:%.*]] = load i16, ptr [[AGG_RESULT]], align 4 +// CHECK-NEXT: [[BF_VALUE2:%.*]] = and i16 [[TMP3]], 255 +// CHECK-NEXT: [[BF_SHL:%.*]] = shl i16 [[BF_VALUE2]], 8 +// CHECK-NEXT: [[BF_CLEAR3:%.*]] = and i16 [[BF_LOAD1]], 255 +// CHECK-NEXT: [[BF_SET4:%.*]] = or i16 [[BF_CLEAR3]], [[BF_SHL]] +// CHECK-NEXT: store i16 [[BF_SET4]], ptr [[AGG_RESULT]], align 4 +// CHECK-NEXT: ret void +// +SlicyBits case12(int I, int J) { + SlicyBits SB = {I, J}; + return SB; +} + +// Case 13: Initialize bitfield from a struct of two ints. +// CHECK-LABEL: define void @_Z6case137TwoInts( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_SLICYBITS:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef byval([[STRUCT_TWOINTS:%.*]]) align 4 [[TI:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[TI]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[Z]], align 4 +// CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[TMP0]] to i16 +// CHECK-NEXT: [[BF_LOAD:%.*]] = load i16, ptr [[AGG_RESULT]], align 4 +// CHECK-NEXT: [[BF_VALUE:%.*]] = and i16 [[TMP1]], 255 +// CHECK-NEXT: [[BF_CLEAR:%.*]] = and i16 [[BF_LOAD]], -256 +// CHECK-NEXT: [[BF_SET:%.*]] = or i16 [[BF_CLEAR]], [[BF_VALUE]] +// CHECK-NEXT: store i16 [[BF_SET]], ptr [[AGG_RESULT]], align 4 +// CHECK-NEXT: [[W:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[TI]], i32 0, i32 1 +// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[W]], align 4 +// CHECK-NEXT: [[TMP3:%.*]] = trunc i32 [[TMP2]] to i16 +// CHECK-NEXT: [[BF_LOAD1:%.*]] = load i16, ptr [[AGG_RESULT]], align 4 +// CHECK-NEXT: [[BF_VALUE2:%.*]] = and i16 [[TMP3]], 255 +// CHECK-NEXT: [[BF_SHL:%.*]] = shl i16 [[BF_VALUE2]], 8 +// CHECK-NEXT: [[BF_CLEAR3:%.*]] = and i16 [[BF_LOAD1]], 255 +// CHECK-NEXT: [[BF_SET4:%.*]] = or i16 [[BF_CLEAR3]], [[BF_SHL]] +// CHECK-NEXT: store i16 [[BF_SET4]], ptr [[AGG_RESULT]], align 4 +// CHECK-NEXT: ret void +// +SlicyBits case13(TwoInts TI) { + SlicyBits SB = {TI}; + return SB; +} + +// Case 14: Initialize struct of ints from struct with bitfields. +// CHECK-LABEL: define void @_Z6case149SlicyBits( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOINTS:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef byval([[STRUCT_SLICYBITS:%.*]]) align 4 [[SB:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[BF_LOAD:%.*]] = load i16, ptr [[SB]], align 4 +// CHECK-NEXT: [[BF_SHL:%.*]] = shl i16 [[BF_LOAD]], 8 +// CHECK-NEXT: [[BF_ASHR:%.*]] = ashr i16 [[BF_SHL]], 8 +// CHECK-NEXT: [[BF_CAST:%.*]] = sext i16 [[BF_ASHR]] to i32 +// CHECK-NEXT: store i32 [[BF_CAST]], ptr [[Z]], align 4 +// CHECK-NEXT: [[W:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOINTS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[BF_LOAD1:%.*]] = load i16, ptr [[SB]], align 4 +// CHECK-NEXT: [[BF_ASHR2:%.*]] = ashr i16 [[BF_LOAD1]], 8 +// CHECK-NEXT: [[BF_CAST3:%.*]] = sext i16 [[BF_ASHR2]] to i32 +// CHECK-NEXT: store i32 [[BF_CAST3]], ptr [[W]], align 4 +// CHECK-NEXT: ret void +// +TwoInts case14(SlicyBits SB) { + TwoInts TI = {SB}; + return TI; +} + +// Case 15: Initialize struct of floats from struct with bitfields. +// CHECK-LABEL: define void @_Z6case159SlicyBits( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOFLOATS:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef byval([[STRUCT_SLICYBITS:%.*]]) align 4 [[SB:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[X:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[BF_LOAD:%.*]] = load i16, ptr [[SB]], align 4 +// CHECK-NEXT: [[BF_SHL:%.*]] = shl i16 [[BF_LOAD]], 8 +// CHECK-NEXT: [[BF_ASHR:%.*]] = ashr i16 [[BF_SHL]], 8 +// CHECK-NEXT: [[BF_CAST:%.*]] = sext i16 [[BF_ASHR]] to i32 +// CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[BF_CAST]] to float +// CHECK-NEXT: store float [[CONV]], ptr [[X]], align 4 +// CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[BF_LOAD1:%.*]] = load i16, ptr [[SB]], align 4 +// CHECK-NEXT: [[BF_ASHR2:%.*]] = ashr i16 [[BF_LOAD1]], 8 +// CHECK-NEXT: [[BF_CAST3:%.*]] = sext i16 [[BF_ASHR2]] to i32 +// CHECK-NEXT: [[CONV4:%.*]] = sitofp i32 [[BF_CAST3]] to float +// CHECK-NEXT: store float [[CONV4]], ptr [[Y]], align 4 +// CHECK-NEXT: ret void +// +TwoFloats case15(SlicyBits SB) { + TwoFloats TI = {SB}; + return TI; +} + +// Case 16: Side-effecting initialization list arguments. The important thing +// here is that case16 only has _one_ call to makeTwo. +// CHECK-LABEL: define void @_Z7makeTwoRf( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_TWOFLOATS:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noalias noundef nonnull align 4 dereferenceable(4) [[X:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 4 +// CHECK-NEXT: store ptr [[X]], ptr [[X_ADDR]], align 4 +// CHECK-NEXT: [[X1:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[X_ADDR]], align 4 +// CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[TMP0]], align 4 +// CHECK-NEXT: store float [[TMP1]], ptr [[X1]], align 4 +// CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[TMP2:%.*]] = load ptr, ptr [[X_ADDR]], align 4 +// CHECK-NEXT: [[TMP3:%.*]] = load float, ptr [[TMP2]], align 4 +// CHECK-NEXT: [[MUL:%.*]] = fmul reassoc nnan ninf nsz arcp afn float [[TMP3]], 1.500000e+00 +// CHECK-NEXT: store float [[MUL]], ptr [[Y]], align 4 +// CHECK-NEXT: [[TMP4:%.*]] = load ptr, ptr [[X_ADDR]], align 4 +// CHECK-NEXT: [[TMP5:%.*]] = load float, ptr [[TMP4]], align 4 +// CHECK-NEXT: [[MUL2:%.*]] = fmul reassoc nnan ninf nsz arcp afn float [[TMP5]], 2.000000e+00 +// CHECK-NEXT: store float [[MUL2]], ptr [[TMP4]], align 4 +// CHECK-NEXT: ret void +// +TwoFloats makeTwo(inout float X) { + TwoFloats TF = {X, X*1.5}; + X *= 2; + return TF; +} + +// CHECK-LABEL: define void @_Z6case16v( +// CHECK-SAME: ptr dead_on_unwind noalias writable sret([[STRUCT_FOURFLOATS:%.*]]) align 4 [[AGG_RESULT:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[X:%.*]] = alloca float, align 4 +// CHECK-NEXT: [[REF_TMP:%.*]] = alloca [[STRUCT_TWOFLOATS:%.*]], align 4 +// CHECK-NEXT: [[TMP:%.*]] = alloca float, align 4 +// CHECK-NEXT: store float 0.000000e+00, ptr [[X]], align 4 +// CHECK-NEXT: [[TMP0:%.*]] = load float, ptr [[X]], align 4 +// CHECK-NEXT: store float [[TMP0]], ptr [[TMP]], align 4 +// CHECK-NEXT: call void @_Z7makeTwoRf(ptr dead_on_unwind writable sret([[STRUCT_TWOFLOATS]]) align 4 [[REF_TMP]], ptr noalias noundef nonnull align 4 dereferenceable(4) [[TMP]]) #[[ATTR2:[0-9]+]] +// CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[TMP]], align 4 +// CHECK-NEXT: store float [[TMP1]], ptr [[X]], align 4 +// CHECK-NEXT: [[X1:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 0 +// CHECK-NEXT: store float 0.000000e+00, ptr [[X1]], align 4 +// CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[X2:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[REF_TMP]], i32 0, i32 0 +// CHECK-NEXT: [[TMP2:%.*]] = load float, ptr [[X2]], align 4 +// CHECK-NEXT: store float [[TMP2]], ptr [[Y]], align 4 +// CHECK-NEXT: [[Z:%.*]] = getelementptr inbounds nuw [[STRUCT_FOURFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 1 +// CHECK-NEXT: [[Y3:%.*]] = getelementptr inbounds nuw [[STRUCT_TWOFLOATS]], ptr [[REF_TMP]], i32 0, i32 1 +// CHECK-NEXT: [[TMP3:%.*]] = load float, ptr [[Y3]], align 4 +// CHECK-NEXT: store float [[TMP3]], ptr [[Z]], align 4 +// CHECK-NEXT: [[W:%.*]] = getelementptr inbounds nuw [[STRUCT_FOURFLOATS]], ptr [[AGG_RESULT]], i32 0, i32 2 +// CHECK-NEXT: store float 3.000000e+00, ptr [[W]], align 4 +// CHECK-NEXT: ret void +// +FourFloats case16() { + float X = 0; + FourFloats FF = {0, makeTwo(X), 3}; + return FF; +} diff --git a/clang/test/Driver/experimental-library-flag.cpp b/clang/test/Driver/experimental-library-flag.cpp index db6a90b50f255..62b007516897e 100644 --- a/clang/test/Driver/experimental-library-flag.cpp +++ b/clang/test/Driver/experimental-library-flag.cpp @@ -9,6 +9,11 @@ // RUN: %clangxx -fexperimental-library -stdlib=libstdc++ -### %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIBSTDCXX %s // RUN: %clangxx -fexperimental-library -stdlib=libc++ -nostdlib++ -### %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-NOSTDLIB %s +/// The FreeBSD driver did not support -stdlib=libstdc++ previously, check that it does the right thing here. +// RUN: %clangxx --target=x86_64-unknown-freebsd -fexperimental-library -stdlib=libc++ -### %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIBCXX %s +// RUN: %clangxx --target=x86_64-unknown-freebsd -fexperimental-library -stdlib=libstdc++ -### %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIBSTDCXX %s +// RUN: %clangxx --target=x86_64-unknown-freebsd -fexperimental-library -stdlib=libc++ -nostdlib++ -### %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-NOSTDLIB %s + // -fexperimental-library must be passed to CC1. // CHECK: -fexperimental-library diff --git a/clang/test/Driver/freebsd.cpp b/clang/test/Driver/freebsd.cpp index dc8c98d3c3cb7..e2f76cd013f7f 100644 --- a/clang/test/Driver/freebsd.cpp +++ b/clang/test/Driver/freebsd.cpp @@ -1,15 +1,19 @@ -// RUN: %clangxx %s -### -o %t.o --target=amd64-unknown-freebsd -stdlib=platform 2>&1 \ +// RUN: %clangxx %s -### --target=amd64-unknown-freebsd -stdlib=platform 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-DEFAULT %s -// RUN: %clangxx %s -### -o %t.o --target=amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-TEN %s +// RUN: %clangxx %s -### --target=amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-DEFAULT %s +// RUN: %clangxx %s -### --target=amd64-unknown-freebsd -stdlib=libc++ 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-DEFAULT %s +// RUN: %clangxx %s -### --target=amd64-unknown-freebsd -stdlib=libstdc++ 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-STDLIBCXX %s // CHECK-DEFAULT: "-lc++" "-lm" -// CHECK-TEN: "-lc++" "-lm" +// CHECK-STDLIBCXX: "-lstdc++" "-lm" -// RUN: %clangxx %s -### -pg -o %t.o --target=amd64-unknown-freebsd -stdlib=platform 2>&1 \ +// RUN: %clangxx %s -### -pg --target=amd64-unknown-freebsd -stdlib=platform 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-PG-DEFAULT %s -// RUN: %clangxx %s -### -pg -o %t.o --target=amd64-unknown-freebsd14.0 -stdlib=platform 2>&1 \ +// RUN: %clangxx %s -### -pg --target=amd64-unknown-freebsd14.0 -stdlib=platform 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-PG-FOURTEEN %s -// RUN: %clangxx %s -### -pg -o %t.o --target=amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \ +// RUN: %clangxx %s -### -pg --target=amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-PG-TEN %s // CHECK-PG-DEFAULT: "-lc++" "-lm" // CHECK-PG-FOURTEEN: "-lc++" "-lm" diff --git a/clang/test/Driver/print-supported-extensions-riscv.c b/clang/test/Driver/print-supported-extensions-riscv.c index 3443ff0b69de9..49c5bfca2716f 100644 --- a/clang/test/Driver/print-supported-extensions-riscv.c +++ b/clang/test/Driver/print-supported-extensions-riscv.c @@ -182,6 +182,7 @@ // CHECK-NEXT: xwchc 2.2 'Xwchc' (WCH/QingKe additional compressed opcodes) // CHECK-EMPTY: // CHECK-NEXT: Experimental extensions +// CHECK-NEXT: p 0.14 'P' ('Base P' (Packed SIMD)) // CHECK-NEXT: zicfilp 1.0 'Zicfilp' (Landing pad) // CHECK-NEXT: zicfiss 1.0 'Zicfiss' (Shadow stack) // CHECK-NEXT: zalasr 0.1 'Zalasr' (Load-Acquire and Store-Release Instructions) diff --git a/clang/test/SemaCXX/cxx2c-placeholder-vars.cpp b/clang/test/SemaCXX/cxx2c-placeholder-vars.cpp index 8e428c0ef0427..37824c16f4f05 100644 --- a/clang/test/SemaCXX/cxx2c-placeholder-vars.cpp +++ b/clang/test/SemaCXX/cxx2c-placeholder-vars.cpp @@ -274,16 +274,16 @@ void f() { // CHECK: ClassTemplateSpecializationDecl {{.*}} struct A definition // CHECK: CXXConstructorDecl {{.*}} implicit used constexpr A 'void () noexcept' // CHECK-NEXT: CXXCtorInitializer Field {{.*}} '_' 'int' -// CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' has rewritten init +// CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1 // CHECK-NEXT: CXXCtorInitializer Field {{.*}} '_' 'int' -// CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' has rewritten init +// CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2 // CHECK-NEXT: CXXCtorInitializer Field {{.*}} 'a' 'int' -// CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' has rewritten init +// CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3 // CHECK-NEXT: CXXCtorInitializer Field {{.*}} '_' 'int' -// CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' has rewritten init +// CHECK-NEXT: CXXDefaultInitExpr {{.*}} 'int' // CHECK-NEXT: IntegerLiteral {{.*}} 'int' 4 // CHECK-NEXT: CompoundStmt {{.*}} diff --git a/clang/test/SemaCXX/warn-unreachable.cpp b/clang/test/SemaCXX/warn-unreachable.cpp index e6f5bc5ef8e12..c96f26e196451 100644 --- a/clang/test/SemaCXX/warn-unreachable.cpp +++ b/clang/test/SemaCXX/warn-unreachable.cpp @@ -414,3 +414,78 @@ void tautological_compare(bool x, int y) { calledFun(); } + +namespace test_rebuilt_default_arg { +struct A { + explicit A(int = __builtin_LINE()); +}; + +int h(int a) { + return 3; + A(); // expected-warning {{will never be executed}} +} + +struct Temp { + Temp(); + ~Temp(); +}; + +struct B { + explicit B(const Temp &t = Temp()); +}; +int f(int a) { + return 3; + B(); // expected-warning {{will never be executed}} +} +} // namespace test_rebuilt_default_arg +namespace test_rebuilt_default_init { + +struct A { + A(); + ~A(); +}; + +struct B { + const A &t = A(); +}; +int f(int a) { + return 3; + A{}; // expected-warning {{will never be executed}} +} +} // namespace test_rebuilt_default_init + +// This issue reported by the comments in https://github.com/llvm/llvm-project/pull/117437. +// All block-level expressions should have already been IgnoreParens()ed. +namespace gh117437_ignore_parens_in_default_arg { + class Location { + public: + static Location Current(int = __builtin_LINE()); + }; + class DOMMatrix; + class BasicMember { + public: + BasicMember(DOMMatrix *); + }; + template using Member = BasicMember; + class ExceptionState { + public: + ExceptionState &ReturnThis(); + ExceptionState(Location); + }; + class NonThrowableExceptionState : public ExceptionState { + public: + NonThrowableExceptionState(Location location = Location::Current()) + : ExceptionState(location) {} + }; + class DOMMatrix { + public: + static DOMMatrix * + Create(int *, ExceptionState & = (NonThrowableExceptionState().ReturnThis())); + }; + class CSSMatrixComponent { + int CSSMatrixComponent_matrix; + CSSMatrixComponent() + : matrix_(DOMMatrix::Create(&CSSMatrixComponent_matrix)) {} + Member matrix_; + }; +} // namespace gh117437_ignore_parens_in_default_arg diff --git a/clang/test/SemaHLSL/ArrayTemporary.hlsl b/clang/test/SemaHLSL/ArrayTemporary.hlsl index 0266a198e7ec9..3d713a89adf3b 100644 --- a/clang/test/SemaHLSL/ArrayTemporary.hlsl +++ b/clang/test/SemaHLSL/ArrayTemporary.hlsl @@ -25,7 +25,7 @@ void fn2(Obj O[4]) { } // CHECK-NEXT: ImplicitCastExpr {{.*}} 'Obj[4]' void call2() { - Obj Arr[4] = {}; + Obj Arr[4] = {0, 0, 0, 0, 0, 0, 0, 0}; fn2(Arr); } diff --git a/clang/test/SemaHLSL/Language/ElementwiseCast-errors.hlsl b/clang/test/SemaHLSL/Language/ElementwiseCast-errors.hlsl index b7085bc69547b..9417249383469 100644 --- a/clang/test/SemaHLSL/Language/ElementwiseCast-errors.hlsl +++ b/clang/test/SemaHLSL/Language/ElementwiseCast-errors.hlsl @@ -43,7 +43,9 @@ export void cantCast4() { int2 A = {1,2}; R r = R(A); // expected-error@-1 {{no matching conversion for functional-style cast from 'int2' (aka 'vector') to 'R'}} - R r2 = {1, 2}; + R r2; + r2.A = 1; + r2.F = 2.0; int2 B = (int2)r2; // expected-error@-1 {{cannot convert 'R' to 'int2' (aka 'vector') without a conversion operator}} } diff --git a/clang/test/SemaHLSL/Language/InitListAST.hlsl b/clang/test/SemaHLSL/Language/InitListAST.hlsl new file mode 100644 index 0000000000000..d58582f9029fe --- /dev/null +++ b/clang/test/SemaHLSL/Language/InitListAST.hlsl @@ -0,0 +1,983 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -disable-llvm-passes -finclude-default-header -ast-dump -ast-dump-filter=case %s | FileCheck %s + +struct TwoFloats { + float X, Y; +}; + +struct TwoInts { + int Z, W; +}; + +struct Doggo { + int4 LegState; + int TailState; + float HairCount; + float4 EarDirection[2]; +}; + +struct AnimalBits { + int Legs[4]; + uint State; + int64_t Counter; + float4 LeftDir; + float4 RightDir; +}; + +struct Kitteh { + int4 Legs; + int TailState; + float HairCount; + float4 Claws[2]; +}; + +struct Zoo { + Doggo Dogs[2]; + Kitteh Cats[4]; +}; + +struct FourFloats : TwoFloats { + float Z, W; +}; + +struct SlicyBits { + int Z : 8; + int W : 8; +}; + +// Case 1: Extraneous braces get ignored in literal instantiation. +// CHECK-LABEL: Dumping case1 +// CHECK: VarDecl {{.*}} used TF1 'TwoFloats' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'TwoFloats' +// CHECK-NEXT: FloatingLiteral {{.*}} 'float' 1.000000e+00 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2 +TwoFloats case1() { + TwoFloats TF1 = {{{1.0, 2}}}; + return TF1; +} + +// Case 2: Valid C/C++ initializer is handled appropriately. +//CHECK-LABEL: Dumping case2 +//CHECK: VarDecl {{.*}} used TF2 'TwoFloats' nrvo cinit +//CHECK-NEXT: InitListExpr {{.*}} 'TwoFloats' +//CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +//CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1 +//CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +//CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2 +TwoFloats case2() { + TwoFloats TF2 = {1, 2}; + return TF2; +} + +// Case 3: Simple initialization with conversion of an argument. +// CHECK-LABEL: Dumping case3 +// CHECK: VarDecl {{.*}} used TF3 'TwoFloats' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'Val' 'int' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2 +TwoFloats case3(int Val) { + TwoFloats TF3 = {Val, 2}; + return TF3; +} + +// Case 4: Initialization from a scalarized vector into a structure with element +// conversions. +// CHECK-LABEL: Dumping case4 +// CHECK: VarDecl {{.*}} used TF4 'TwoFloats' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ImplicitCastExpr {{.*}}'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: DeclRefExpr {{.*}} 'int2':'vector' lvalue ParmVar {{.*}} 'TwoVals' 'int2':'vector' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: DeclRefExpr {{.*}} 'int2':'vector' lvalue ParmVar {{.*}} 'TwoVals' 'int2':'vector' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +TwoFloats case4(int2 TwoVals) { + TwoFloats TF4 = {TwoVals}; + return TF4; +} + +// Case 5: Initialization from a scalarized vector of matching type. +// CHECK-LABEL: Dumping case5 +// CHECK: VarDecl {{.*}} used TI1 'TwoInts' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'TwoInts' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: DeclRefExpr {{.*}} 'int2':'vector' lvalue ParmVar {{.*}} 'TwoVals' 'int2':'vector' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: DeclRefExpr {{.*}} 'int2':'vector' lvalue ParmVar {{.*}} 'TwoVals' 'int2':'vector' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +TwoInts case5(int2 TwoVals) { + TwoInts TI1 = {TwoVals}; + return TI1; +} + +// Case 6: Initialization from a scalarized structure of different type with +// different element types. +// CHECK-LABEL: Dumping case6 +// CHECK: VarDecl {{.*}} used TI2 'TwoInts' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'TwoInts' +// CHECK-NEXT: ImplicitCastExpr {{.*}}'int' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .X {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF4' 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .Y {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF4' 'TwoFloats' +TwoInts case6(TwoFloats TF4) { + TwoInts TI2 = {TF4}; + return TI2; +} + +// Case 7: Initialization of a complex structure, with bogus braces and element +// conversions from a collection of scalar values, and structures. +// CHECK-LABEL: Dumping case7 +// CHECK: VarDecl {{.*}} used D1 'Doggo' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'Doggo' +// CHECK-NEXT: InitListExpr {{.*}} 'int4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue .Z {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoInts' lvalue ParmVar {{.*}} 'TI1' 'TwoInts' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue .W {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoInts' lvalue ParmVar {{.*}} 'TI1' 'TwoInts' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue .Z {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoInts' lvalue ParmVar {{.*}} 'TI2' 'TwoInts' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue .W {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoInts' lvalue ParmVar {{.*}} 'TI2' 'TwoInts' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'Val' 'int' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'Val' 'int' +// CHECK-NEXT: InitListExpr {{.*}} 'float4[2]' +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .X {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF1' 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .Y {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF1' 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .X {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF2' 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .Y {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF2' 'TwoFloats' +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .X {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF3' 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .Y {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF3' 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .X {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF4' 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .Y {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF4' 'TwoFloats' +Doggo case7(TwoInts TI1, TwoInts TI2, int Val, TwoFloats TF1, TwoFloats TF2, + TwoFloats TF3, TwoFloats TF4) { + Doggo D1 = {TI1, TI2, {Val, Val}, {{TF1, TF2}, {TF3, TF4}}}; + return D1; +} + +// Case 8: Initialization of a structure from a different structure with +// significantly different element types and grouping. +// CHECK-LABEL: Dumping case8 +// CHECK: VarDecl {{.*}} used A1 'AnimalBits' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'AnimalBits' +// CHECK-NEXT: InitListExpr {{.*}} 'int[4]' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue .TailState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'long' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .HairCount {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +AnimalBits case8(Doggo D1) { + AnimalBits A1 = {D1}; + return A1; +} + +// Case 9: Everything everywhere all at once... Initializing mismatched +// structures from different layouts, different component groupings, with no +// top-level bracing separation. +// CHECK-LABEL: Dumping case9 +// CHECK: VarDecl {{.*}} used Z1 'Zoo' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'Zoo' +// CHECK-NEXT: InitListExpr {{.*}} 'Doggo[2]' +// CHECK-NEXT: InitListExpr {{.*}} 'Doggo' +// CHECK-NEXT: InitListExpr {{.*}} 'int4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue .TailState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .HairCount {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: InitListExpr {{.*}} 'float4[2]' +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'Doggo' +// CHECK-NEXT: InitListExpr {{.*}} 'int4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint':'unsigned int' +// CHECK-NEXT: MemberExpr {{.*}} 'uint':'unsigned int' lvalue .State {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int64_t':'long' +// CHECK-NEXT: MemberExpr {{.*}} 'int64_t':'long' lvalue .Counter {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: InitListExpr {{.*}} 'float4[2]' +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'Kitteh[4]' +// CHECK-NEXT: InitListExpr {{.*}} 'Kitteh' +// CHECK-NEXT: InitListExpr {{.*}} 'int4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue .TailState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .HairCount {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: InitListExpr {{.*}} 'float4[2]' +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'Kitteh' +// CHECK-NEXT: InitListExpr {{.*}} 'int4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint':'unsigned int' +// CHECK-NEXT: MemberExpr {{.*}} 'uint':'unsigned int' lvalue .State {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int64_t':'long' +// CHECK-NEXT: MemberExpr {{.*}} 'int64_t':'long' lvalue .Counter {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: InitListExpr {{.*}} 'float4[2]' +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'Kitteh' +// CHECK-NEXT: InitListExpr {{.*}} 'int4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'int4':'vector' lvalue .LegState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue .TailState {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .HairCount {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: InitListExpr {{.*}} 'float4[2]' +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float4':'vector' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float4 *' +// CHECK-NEXT: MemberExpr {{.*}} 'float4[2]' lvalue .EarDirection {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'Doggo' lvalue ParmVar {{.*}} 'D1' 'Doggo' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'Kitteh' +// CHECK-NEXT: InitListExpr {{.*}} 'int4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'int' lvalue +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int *' +// CHECK-NEXT: MemberExpr {{.*}} 'int[4]' lvalue .Legs {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'uint':'unsigned int' +// CHECK-NEXT: MemberExpr {{.*}} 'uint':'unsigned int' lvalue .State {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int64_t':'long' +// CHECK-NEXT: MemberExpr {{.*}} 'int64_t':'long' lvalue .Counter {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: InitListExpr {{.*}} 'float4[2]' +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .LeftDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +// CHECK-NEXT: InitListExpr {{.*}} 'float4':'vector' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' lvalue vectorcomponent +// CHECK-NEXT: MemberExpr {{.*}} 'float4':'vector' lvalue .RightDir {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'AnimalBits' lvalue ParmVar {{.*}} 'A1' 'AnimalBits' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +Zoo case9(Doggo D1, AnimalBits A1) { + Zoo Z1 = {D1, A1, D1, A1, D1, A1}; + return Z1; +} + +// Case 10: Initialize an object with a base class from two objects. +// CHECK-LABEL: Dumping case10 +// CHECK: | `-VarDecl {{.*}} used FF1 'FourFloats' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'FourFloats' +// CHECK-NEXT: InitListExpr {{.*}} 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .X {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF1' 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .Y {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF1' 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .X {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF2' 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' lvalue .Y {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoFloats' lvalue ParmVar {{.*}} 'TF2' 'TwoFloats' +FourFloats case10(TwoFloats TF1, TwoFloats TF2) { + FourFloats FF1 = {TF1, TF2}; + return FF1; +} + +// Case 11: Initialize an object with a base class from a vector splat. +// CHECK-LABEL: Dumping case11 +// CHECK: VarDecl {{.*}} used FF1 'FourFloats' nrvo cinit +// CHECK-NEXT: ExprWithCleanups {{.*}} 'FourFloats' +// CHECK-NEXT: InitListExpr {{.*}} 'FourFloats' +// CHECK-NEXT: InitListExpr {{.*}} 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' xvalue vectorcomponent +// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'vector' xvalue +// CHECK-NEXT: ExtVectorElementExpr {{.*}} 'vector' xxxx +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector' lvalue +// CHECK-NEXT: DeclRefExpr {{.*}} 'float' lvalue ParmVar {{.*}} 'F' 'float' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' xvalue vectorcomponent +// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'vector' xvalue +// CHECK-NEXT: ExtVectorElementExpr {{.*}} 'vector' xxxx +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector' lvalue +// CHECK-NEXT: DeclRefExpr {{.*}} 'float' lvalue ParmVar {{.*}} 'F' 'float' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 1 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' xvalue vectorcomponent +// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'vector' xvalue +// CHECK-NEXT: ExtVectorElementExpr {{.*}} 'vector' xxxx +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector' lvalue +// CHECK-NEXT: DeclRefExpr {{.*}} 'float' lvalue ParmVar {{.*}} 'F' 'float' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 2 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ArraySubscriptExpr {{.*}} 'float' xvalue vectorcomponent +// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'vector' xvalue +// CHECK-NEXT: ExtVectorElementExpr {{.*}} 'vector' xxxx +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector' lvalue +// CHECK-NEXT: DeclRefExpr {{.*}} 'float' lvalue ParmVar {{.*}} 'F' 'float' +// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned long' 3 +FourFloats case11(float F) { + FourFloats FF1 = {F.xxxx}; + return FF1; +} + +// Case 12: Initialize bitfield from two integers. +// CHECK-LABEL: Dumping case12 +// CHECK: VarDecl {{.*}} used SB 'SlicyBits' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'SlicyBits' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'I' 'int' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'J' 'int' +SlicyBits case12(int I, int J) { + SlicyBits SB = {I, J}; + return SB; +} + +// Case 13: Initialize bitfield from a struct of two ints. +// CHECK-LABEL: Dumping case13 +// CHECK: VarDecl {{.*}} used SB 'SlicyBits' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'SlicyBits' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue .Z {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoInts' lvalue ParmVar {{.*}} 'TI' 'TwoInts' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue .W {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'TwoInts' lvalue ParmVar {{.*}} 'TI' 'TwoInts' +SlicyBits case13(TwoInts TI) { + SlicyBits SB = {TI}; + return SB; +} + +// Case 14: Initialize struct of ints from struct with bitfields. +// CHECK-LABEL: Dumping case14 +// CHECK: VarDecl {{.*}} used TI 'TwoInts' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'TwoInts' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue bitfield .Z {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'SlicyBits' lvalue ParmVar {{.*}} 'SB' 'SlicyBits' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue bitfield .W {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'SlicyBits' lvalue ParmVar {{.*}} 'SB' 'SlicyBits' +TwoInts case14(SlicyBits SB) { + TwoInts TI = {SB}; + return TI; +} + +// Case 15: Initialize struct of floats from struct with bitfields. +// CHECK-LABEL: Dumping case15 +// CHECK: VarDecl {{.*}} used TI 'TwoFloats' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue bitfield .Z {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'SlicyBits' lvalue ParmVar {{.*}} 'SB' 'SlicyBits' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' +// CHECK-NEXT: MemberExpr {{.*}} 'int' lvalue bitfield .W {{.*}} +// CHECK-NEXT: DeclRefExpr {{.*}} 'SlicyBits' lvalue ParmVar {{.*}} 'SB' 'SlicyBits' +TwoFloats case15(SlicyBits SB) { + TwoFloats TI = {SB}; + return TI; +} + +// Case 16: Side-effecting initialization list arguments. The important thing +// here is that case16 only has _one_ call to makeTwo. +TwoFloats makeTwo(inout float X) { + TwoFloats TF = {X, X*1.5}; + X *= 2; + return TF; +} + +// CHECK-LABEL: Dumping case16 +// CHECK: VarDecl {{.*}} used FF 'FourFloats' nrvo cinit +// CHECK-NEXT: InitListExpr {{.*}} 'FourFloats' +// CHECK-NEXT: InitListExpr {{.*}} 'TwoFloats' +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0 +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float' +// CHECK-NEXT: MemberExpr {{.*}} 'float' xvalue .X {{.*}} +// CHECK-NEXT: OpaqueValueExpr [[OVEArg:0x[0-9A-Fa-f]+]] {{.*}} 'TwoFloats' xvalue +// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'TwoFloats' xvalue +// CHECK-NEXT: CallExpr {{.*}} 'TwoFloats' + +// I don't care about the call here, just skip ahead to the next argument, and +// verify that we match the same OpaqueValueExpr. + +// CHECK: MemberExpr {{.*}} 'float' xvalue .Y {{.*}} +// CHECK-NEXT: OpaqueValueExpr [[OVEArg]] {{.*}} 'TwoFloats' xvalue +// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'TwoFloats' xvalue +// CHECK-NEXT: CallExpr {{.*}} 'TwoFloats' +FourFloats case16() { + float X = 0; + FourFloats FF = {0, makeTwo(X), 3}; + return FF; +} diff --git a/clang/test/SemaHLSL/Language/InitLists.hlsl b/clang/test/SemaHLSL/Language/InitLists.hlsl new file mode 100644 index 0000000000000..3607dfd8aedbc --- /dev/null +++ b/clang/test/SemaHLSL/Language/InitLists.hlsl @@ -0,0 +1,126 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -finclude-default-header -verify -Wdouble-promotion -Wconversion %s + +struct TwoFloats { + float X, Y; +}; + +struct TwoInts { + int Z, W; +}; + +struct Doggo { + int4 LegState; + int TailState; + float HairCount; + float4 EarDirection[2]; +}; + +struct AnimalBits { + int Legs[4]; + uint State; + int64_t Counter; + float4 LeftDir; + float4 RightDir; +}; + +struct Kitteh { + int4 Legs; + int TailState; + float HairCount; + float4 Claws[2]; +}; + +struct Zoo { + Doggo Dogs[2]; + Kitteh Cats[4]; +}; + +struct FourFloats : TwoFloats { + float Z, W; +}; + +struct SlicyBits { + int Z : 8; + int W : 8; +}; + +struct ContainsResource { // #ContainsResource + int X; + RWBuffer B; +}; + +struct ContainsResourceInverted { + RWBuffer B; + int X; +}; + +void fn() { + TwoFloats TF1 = {{{1.0, 2}}}; + TwoFloats TF2 = {1,2}; + int Val = 1; + TwoFloats TF3 = {Val, 2}; // expected-warning{{implicit conversion from 'int' to 'float' may lose precision}} + int2 TwoVals = 1.xx; + int2 Something = 1.xxx; // expected-warning{{implicit conversion truncates vector: 'vector' (vector of 3 'int' values) to 'vector' (vector of 2 'int' values)}} + TwoFloats TF4 = {TwoVals}; // expected-warning{{implicit conversion from 'int' to 'float' may lose precision}} expected-warning{{implicit conversion from 'int' to 'float' may lose precision}} + + TwoInts TI1 = {TwoVals}; + TwoInts TI2 = {TF4}; // expected-warning{{implicit conversion turns floating-point number into integer: 'float' to 'int'}} expected-warning{{implicit conversion turns floating-point number into integer: 'float' to 'int'}} + + Doggo D1 = {TI1, TI2, {Val, Val}, {{TF1, TF2}, {TF3, TF4}}}; // expected-warning{{implicit conversion from 'int' to 'float' may lose precision}} + AnimalBits A1 = {D1}; // expected-warning{{implicit conversion turns floating-point number into integer: 'float' to 'long'}} expected-warning{{implicit conversion changes signedness: 'int' to 'unsigned int'}} + + Zoo Z1 = {D1, A1, D1, A1, D1, A1}; // #insanity + + // expected-warning@#insanity{{implicit conversion from 'int64_t' (aka 'long') to 'float' may lose precision}} + // expected-warning@#insanity{{implicit conversion changes signedness: 'uint' (aka 'unsigned int') to 'int'}} + // expected-warning@#insanity{{implicit conversion from 'int64_t' (aka 'long') to 'float' may lose precision}} + // expected-warning@#insanity{{implicit conversion changes signedness: 'uint' (aka 'unsigned int') to 'int'}} + // expected-warning@#insanity{{implicit conversion from 'int64_t' (aka 'long') to 'float' may lose precision}} + // expected-warning@#insanity{{implicit conversion changes signedness: 'uint' (aka 'unsigned int') to 'int'}} +} + +void fn2() { + TwoFloats TF2 = {1,2}; + FourFloats FF1 = {TF2, TF2}; + FourFloats FF2 = {1,2,3,4}; + FourFloats FF3 = {1.xxx, 2}; + + SlicyBits SB1 = {1,2}; + TwoInts TI1 = {SB1}; + SlicyBits SB2 = {TI1}; +} + +void Errs() { + TwoFloats F1 = {}; // expected-error{{too few initializers in list for type 'TwoFloats' (expected 2 but found 0)}} + TwoFloats F2 = {1}; // expected-error{{too few initializers in list for type 'TwoFloats' (expected 2 but found 1)}} + TwoFloats F3 = {1,2,3}; // expected-error{{too many initializers in list for type 'TwoFloats' (expected 2 but found 3)}} + + int2 Something = {1.xxx}; // expected-error{{too many initializers in list for type 'int2' (aka 'vector') (expected 2 but found 3)}} +} + +struct R { + int A; + union { // #anon + float F; + int4 G; + }; +}; + +// expected-note@#anon{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to}} +// expected-note@#anon{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to}} + +void Err2(RWBuffer B) { + ContainsResource RS1 = {1, B}; + ContainsResource RS2 = (1.xx); // expected-error{{no viable conversion from 'vector' (vector of 2 'int' values) to 'ContainsResource'}} + ContainsResource RS3 = {B, 1}; // expected-error{{no viable conversion from 'RWBuffer' (aka 'RWBuffer>') to 'int'}} + ContainsResourceInverted IR = {RS1}; // expected-error{{no viable conversion from 'int' to 'hlsl::RWBuffer>'}} + + R r = {1,2}; // expected-error{{no viable conversion from 'int' to 'R::(anonymous union at}} +} + +// expected-note@#ContainsResource{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'vector' (vector of 2 'int' values) to 'const ContainsResource &' for 1st argument}} +// expected-note@#ContainsResource{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'vector' (vector of 2 'int' values) to 'ContainsResource &&' for 1st argument}} + +// These notes refer to the RWBuffer constructors that do not have source locations +// expected-note@*{{candidate constructor (the implicit copy constructor) not viable}} +// expected-note@*{{candidate constructor (the implicit move constructor) not viable}} diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp index e78763faad73e..7db8f3e27d704 100644 --- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp +++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp @@ -1060,8 +1060,9 @@ Expected getSymbolsFromBitcode(MemoryBufferRef Buffer, OffloadKind Kind, if (Sym.isFormatSpecific() || !Sym.isGlobal()) continue; - bool NewSymbol = Syms.count(Sym.getName()) == 0; - auto OldSym = NewSymbol ? Sym_None : Syms[Sym.getName()]; + auto It = Syms.find(Sym.getName()); + bool NewSymbol = It == Syms.end(); + auto OldSym = NewSymbol ? Sym_None : It->second; // We will extract if it defines a currenlty undefined non-weak // symbol. diff --git a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp index c6d5b31ab512c..49cb0d70f492b 100644 --- a/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp +++ b/clang/tools/clang-offload-packager/ClangOffloadPackager.cpp @@ -70,10 +70,9 @@ static DenseMap getImageArguments(StringRef Image, DenseMap Args; for (StringRef Arg : llvm::split(Image, ",")) { auto [Key, Value] = Arg.split("="); - if (Args.count(Key)) - Args[Key] = Saver.save(Args[Key] + "," + Value); - else - Args[Key] = Value; + auto [It, Inserted] = Args.try_emplace(Key, Value); + if (!Inserted) + It->second = Saver.save(It->second + "," + Value); } return Args; diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp index 9b6f0c396d4db..f7f73db62045c 100644 --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -567,6 +567,13 @@ TEST_F(FormatTestObjC, FormatObjCMethodDeclarations) { " error:(NSError **)theError {\n" "}"); verifyFormat("+ (instancetype)new;"); + + verifyFormat("/*\n" + " */\n" + "- (void)foo;", + "/*\n" + " */- (void)foo;"); + Style.ColumnLimit = 60; verifyFormat("- (instancetype)initXxxxxx:(id)x\n" " y:(id)y\n" diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 5ab0867490122..1d0870c818acc 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1849,6 +1849,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsObjCMethodExpr) { EXPECT_TOKEN(Tokens[15], tok::greater, TT_BinaryOperator); } +TEST_F(TokenAnnotatorTest, UnderstandsObjCMethodDecl) { + auto Tokens = annotate("/**/ - (void)foo;"); + ASSERT_EQ(Tokens.size(), 8u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::minus, TT_ObjCMethodSpecifier); + EXPECT_TOKEN(Tokens[5], tok::identifier, TT_SelectorName); +} + TEST_F(TokenAnnotatorTest, UnderstandsLambdas) { auto Tokens = annotate("[]() constexpr {}"); ASSERT_EQ(Tokens.size(), 8u) << Tokens; @@ -3512,6 +3519,19 @@ TEST_F(TokenAnnotatorTest, BraceKind) { EXPECT_BRACE_KIND(Tokens[11], BK_Block); EXPECT_BRACE_KIND(Tokens[12], BK_Block); + Tokens = annotate("class foo {\n" + " foo() {}\n" + "#if defined(_MSC_VER__clang____GNUC__FOO_) || \\\n" + " (defined(__GNUC__) && defined(FOO))\n" + " foo() {}\n" + "#endif\n" + "};"); + ASSERT_EQ(Tokens.size(), 36u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_FunctionLBrace); + EXPECT_BRACE_KIND(Tokens[7], BK_Block); + EXPECT_TOKEN(Tokens[26], tok::identifier, TT_CtorDtorDeclName); + EXPECT_TOKEN(Tokens[27], tok::l_paren, TT_FunctionDeclarationLParen); + Tokens = annotate("a = class extends goog.a {};", getGoogleStyle(FormatStyle::LK_JavaScript)); ASSERT_EQ(Tokens.size(), 11u) << Tokens; diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html index 0fc3b1d314698..2d5b96b47fe2d 100755 --- a/clang/www/cxx_status.html +++ b/clang/www/cxx_status.html @@ -251,6 +251,42 @@

C++2c implementation status

P3176R1 Clang 20 + + + Trivial unions + P3074R7 + No + + + Partial program correctness + P1494R5 + No + + + Contracts + P2900R14 + No + + + Defang and deprecate memory_order::consume + P3475R2 + No + + + Concept and variable-template template-parameters + P2841R7 + No + + + Trivial Relocatability + P2786R13 + No + + +
#embed
+ P1967R14 + No + diff --git a/flang-rt/.clang-format b/flang-rt/.clang-format new file mode 100644 index 0000000000000..23f4c5ae2dcf2 --- /dev/null +++ b/flang-rt/.clang-format @@ -0,0 +1,25 @@ +--- +# See: https://clang.llvm.org/docs/ClangFormatStyleOptions.html +BasedOnStyle: LLVM +AlignAfterOpenBracket: DontAlign +AlignEscapedNewlines: DontAlign +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignOperands: false +AlignTrailingComments: false +IncludeCategories: + - Regex: '^<' + Priority: 6 + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 5 + - Regex: '^"flang/' # Headers shared with Flang + Priority: 4 + - Regex: '^"flang-rt/' # Public Flang-RT headers + Priority: 3 + - Regex: '^[^/]*$' # Private headers from same library + Priority: 1 + - Regex: '.*' # Private headers from sibling libraries + Priority: 2 +... + +# vim:set filetype=yaml: diff --git a/flang-rt/.clang-tidy b/flang-rt/.clang-tidy new file mode 100644 index 0000000000000..ee3a0ab2201bf --- /dev/null +++ b/flang-rt/.clang-tidy @@ -0,0 +1,2 @@ +Checks: '-llvm-include-order,readability-braces-around-statements,-readability-identifier-naming,-clang-diagnostic-*' +InheritParentConfig: true diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt new file mode 100644 index 0000000000000..df35e24ec28a7 --- /dev/null +++ b/flang-rt/CMakeLists.txt @@ -0,0 +1,261 @@ +#===-- CMakeLists.txt ------------------------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# +# +# Build instructions for the flang-rt library. This is file is intended to be +# included using the LLVM_ENABLE_RUNTIMES mechanism. +# +#===------------------------------------------------------------------------===# + +if (NOT LLVM_RUNTIMES_BUILD) + message(FATAL_ERROR "Use this CMakeLists.txt from LLVM's runtimes build system. + Example: + cmake /runtimes -DLLVM_ENABLE_RUNTIMES=flang-rt + ") +endif () + +set(LLVM_SUBPROJECT_TITLE "Flang-RT") +set(FLANG_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(FLANG_RT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") +set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang") + +# CMake 3.24 is the first version of CMake that directly recognizes Flang. +# LLVM's requirement is only CMake 3.20, teach CMake 3.20-3.23 how to use Flang. +if (CMAKE_VERSION VERSION_LESS "3.24") + cmake_path(GET CMAKE_Fortran_COMPILER STEM _Fortran_COMPILER_STEM) + if (_Fortran_COMPILER_STEM STREQUAL "flang-new" OR _Fortran_COMPILER_STEM STREQUAL "flang") + include(CMakeForceCompiler) + CMAKE_FORCE_Fortran_COMPILER("${CMAKE_Fortran_COMPILER}" "LLVMFlang") + + set(CMAKE_Fortran_COMPILER_ID "LLVMFlang") + set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}") + + set(CMAKE_Fortran_SUBMODULE_SEP "-") + set(CMAKE_Fortran_SUBMODULE_EXT ".mod") + + set(CMAKE_Fortran_PREPROCESS_SOURCE + " -cpp -E > ") + + set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form") + set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form") + + set(CMAKE_Fortran_MODDIR_FLAG "-module-dir") + + set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_ON "-cpp") + set(CMAKE_Fortran_COMPILE_OPTIONS_PREPROCESS_OFF "-nocpp") + set(CMAKE_Fortran_POSTPROCESS_FLAG "-ffixed-line-length-72") + + set(CMAKE_Fortran_COMPILE_OPTIONS_TARGET "--target=") + + set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,") + set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",") + endif () +endif () +enable_language(Fortran) + + +list(APPEND CMAKE_MODULE_PATH + "${FLANG_RT_SOURCE_DIR}/cmake/modules" + "${FLANG_SOURCE_DIR}/cmake/modules" + ) +include(AddFlangRT) +include(GetToolchainDirs) +include(FlangCommon) +include(HandleCompilerRT) +include(ExtendPath) + + +############################ +# Build Mode Introspection # +############################ + +# Determine whether we are in the runtimes/runtimes-bins directory of a +# bootstrap build. +set(LLVM_TREE_AVAILABLE OFF) +if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSION) + set(LLVM_TREE_AVAILABLE ON) +endif() + +# Path to LLVM development tools (FileCheck, llvm-lit, not, ...) +set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin") + +# Determine build and install paths. +# The build path is absolute, but the install dir is relative, CMake's install +# command has to apply CMAKE_INSTALL_PREFIX itself. +get_toolchain_library_subdir(toolchain_lib_subdir) +if (LLVM_TREE_AVAILABLE) + # In a bootstrap build emit the libraries into a default search path in the + # build directory of the just-built compiler. This allows using the + # just-built compiler without specifying paths to runtime libraries. + # + # Despite Clang in the name, get_clang_resource_dir does not depend on Clang + # being added to the build. Flang uses the same resource dir as clang. + include(GetClangResourceDir) + get_clang_resource_dir(FLANG_RT_OUTPUT_RESOURCE_DIR PREFIX "${LLVM_LIBRARY_OUTPUT_INTDIR}/..") + get_clang_resource_dir(FLANG_RT_INSTALL_RESOURCE_PATH) + + extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" "${toolchain_lib_subdir}") +else () + # In a standalone runtimes build, do not write into LLVM_BINARY_DIR. It may be + # read-only and/or shared by multiple runtimes with different build + # configurations (e.g. Debug/Release). Use the runtime's own lib dir like any + # non-toolchain library. + # For the install prefix, still use the resource dir assuming that Flang will + # be installed there using the same prefix. This is to not have a difference + # between bootstrap and standalone runtimes builds. + set(FLANG_RT_OUTPUT_RESOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}") + set(FLANG_RT_INSTALL_RESOURCE_PATH "lib${LLVM_LIBDIR_SUFFIX}/clang/${LLVM_VERSION_MAJOR}") + + extend_path(FLANG_RT_OUTPUT_RESOURCE_LIB_DIR "${FLANG_RT_OUTPUT_RESOURCE_DIR}" "lib${LLVM_LIBDIR_SUFFIX}") +endif () +extend_path(FLANG_RT_INSTALL_RESOURCE_LIB_PATH "${FLANG_RT_INSTALL_RESOURCE_PATH}" "${toolchain_lib_subdir}") +cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_DIR) +cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_PATH) +cmake_path(NORMAL_PATH FLANG_RT_OUTPUT_RESOURCE_LIB_DIR) +cmake_path(NORMAL_PATH FLANG_RT_INSTALL_RESOURCE_LIB_PATH) + + +################# +# Build Options # +################# + +# Important: flang-rt user options must be prefixed with "FLANG_RT_". Variables +# with this prefix will be forwarded in bootstrap builds. + +option(FLANG_RT_INCLUDE_TESTS "Generate build targets for the flang-rt unit and regression-tests." "${LLVM_INCLUDE_TESTS}") + + +set(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT "" CACHE STRING "Compile Flang-RT with GPU support (CUDA or OpenMP)") +set_property(CACHE FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT PROPERTY STRINGS + "" + CUDA + OpenMP + ) +if (NOT FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT) + # Support for GPUs disabled +elseif (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA") + # Support for CUDA + set(FLANG_RT_LIBCUDACXX_PATH "" CACHE PATH "Path to libcu++ package installation") + option(FLANG_RT_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS "Do not compile global variables' definitions when producing PTX library" OFF) +elseif (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "OpenMP") + # Support for OpenMP offloading + set(FLANG_RT_DEVICE_ARCHITECTURES "all" CACHE STRING + "List of OpenMP device architectures to be used to compile the Fortran runtime (e.g. 'gfx1103;sm_90')" + ) + + if (FLANG_RT_DEVICE_ARCHITECTURES STREQUAL "all") + # TODO: support auto detection on the build system. + set(all_amdgpu_architectures + "gfx700;gfx701;gfx801;gfx803;gfx900;gfx902;gfx906" + "gfx908;gfx90a;gfx90c;gfx940;gfx1010;gfx1030" + "gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036" + "gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151" + "gfx1152;gfx1153") + set(all_nvptx_architectures + "sm_35;sm_37;sm_50;sm_52;sm_53;sm_60;sm_61;sm_62" + "sm_70;sm_72;sm_75;sm_80;sm_86;sm_89;sm_90") + set(all_gpu_architectures + "${all_amdgpu_architectures};${all_nvptx_architectures}") + set(FLANG_RT_DEVICE_ARCHITECTURES ${all_gpu_architectures}) + endif() + list(REMOVE_DUPLICATES FLANG_RT_DEVICE_ARCHITECTURES) +else () + message(FATAL_ERROR "Invalid value '${FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT}' for FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT; must be empty, 'CUDA', or 'OpenMP'") +endif () + + +option(FLANG_RT_INCLUDE_CUF "Build the CUDA Fortran runtime (libflang_rt.cuda.a)" OFF) +if (FLANG_RT_INCLUDE_CUF) + find_package(CUDAToolkit REQUIRED) +endif() + + +######################## +# System Introspection # +######################## + +include(CheckCXXSymbolExists) +include(CheckCXXSourceCompiles) +check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R) +# Can't use symbol exists here as the function is overloaded in C++ +check_cxx_source_compiles( + "#include + int main() { + char buf[4096]; + return strerror_s(buf, 4096, 0); + } + " + HAVE_DECL_STRERROR_S) + + +# Search for clang_rt.builtins library. Need in addition to msvcrt. +if (WIN32) + find_compiler_rt_library(builtins FLANG_RT_BUILTINS_LIBRARY) +endif () + + +# Check whether the compiler can undefine a macro using the "-U" flag. +# Aternatively, we could use +# CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU" +# but some older versions of CMake don't define it for GCC itself. +check_cxx_compiler_flag("-UTESTFLAG" FLANG_RT_SUPPORTS_UNDEFINE_FLAG) + +# Check whether -fno-lto is supported. +check_cxx_compiler_flag(-fno-lto FLANG_RT_HAS_FNO_LTO_FLAG) + + +# function checks +find_package(Backtrace) +set(HAVE_BACKTRACE ${Backtrace_FOUND}) +set(BACKTRACE_HEADER ${Backtrace_HEADER}) + + +##################### +# Build Preparation # +##################### + +if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT AND FLANG_RT_INCLUDE_TESTS) + # If Fortran runtime is built as CUDA library, the linking + # of targets that link flang-rt must be done + # with CUDA_RESOLVE_DEVICE_SYMBOLS. + # CUDA language must be enabled for CUDA_RESOLVE_DEVICE_SYMBOLS + # to take effect. + enable_language(CUDA) +endif() + + +# C++17 is required for flang-rt; user or other runtimes may override this. +# GTest included later also requires C++17. +set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") +set(CMAKE_CXX_STANDARD_REQUIRED YES) + + +configure_file(cmake/config.h.cmake.in config.h) + + +# The bootstrap build will create a phony target with the same as the top-level +# directory ("flang-rt") and delegate it to the runtimes build dir. +# AddFlangRT will add all non-EXCLUDE_FROM_ALL targets to it. +add_custom_target(flang-rt) + + +################### +# Build Artifacts # +################### + +add_subdirectory(lib) + +if (LLVM_INCLUDE_EXAMPLES) + add_subdirectory(examples) +endif () + +if (FLANG_RT_INCLUDE_TESTS) + add_subdirectory(unittests) + add_subdirectory(test) +else () + add_custom_target(check-flang-rt) +endif() diff --git a/flang-rt/CODE_OWNERS.TXT b/flang-rt/CODE_OWNERS.TXT new file mode 100644 index 0000000000000..649243aa1e8fe --- /dev/null +++ b/flang-rt/CODE_OWNERS.TXT @@ -0,0 +1,14 @@ +This file is a list of the people responsible for ensuring that patches for a +particular part of Flang are reviewed, either by themself or by someone else. +They are also the gatekeepers for their part of Flang, with the final word on +what goes in or not. + +The list is sorted by surname and formatted to allow easy grepping and +beautification by scripts. The fields are: name (N), email (E), web-address +(W), PGP key ID and fingerprint (P), description (D), snail-mail address +(S) and (I) IRC handle. Each entry should contain at least the (N), (E) and +(D) fields. + +N: Steve Scalpone +E: sscalpone@nvidia.com +D: Anything not covered by others diff --git a/flang-rt/LICENSE.TXT b/flang-rt/LICENSE.TXT new file mode 100644 index 0000000000000..53bb2e7fbc764 --- /dev/null +++ b/flang-rt/LICENSE.TXT @@ -0,0 +1,234 @@ +============================================================================== +The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: +============================================================================== + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +---- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. + +============================================================================== +Software from third parties included in the LLVM Project: +============================================================================== +The LLVM Project contains third party software which is under different license +terms. All such code will be identified clearly using at least one of two +mechanisms: +1) It will be in a separate directory tree with its own `LICENSE.txt` or + `LICENSE` file at the top containing the specific license and restrictions + which apply to that software, or +2) It will contain specific license and restriction terms at the top of every + file. diff --git a/flang-rt/README.md b/flang-rt/README.md new file mode 100644 index 0000000000000..aba64e2453872 --- /dev/null +++ b/flang-rt/README.md @@ -0,0 +1,188 @@ + + +# Fortran Runtime (Flang-RT) + +Flang-RT is the runtime library for code emitted by the Flang compiler +(https://flang.llvm.org). + + +## Getting Started + +There are two build modes for the Flang-RT. The bootstrap build, also +called the in-tree build, and the runtime-only build, also called the +out-of-tree build. +Not to be confused with the terms +[in-source and out-of-source](https://cmake.org/cmake/help/latest/manual/cmake.1.html#introduction-to-cmake-buildsystems) +builds as defined by CMake. In an in-source build, the source directory and the +build directory are identical, whereas with an out-of-source build the +build artifacts are stored somewhere else, possibly in a subdirectory of the +source directory. LLVM does not support in-source builds. + + +### Requirements + +Requirements: + * [Same as LLVM](https://llvm.org/docs/GettingStarted.html#requirements). + + +### Bootstrapping Runtimes Build + +The bootstrapping build will first build Clang and Flang, then use these +compilers to compile Flang-RT. CMake will create a secondary build tree +configured to use these just-built compilers. The secondary build will reuse +the same build options (Flags, Debug/Release, ...) as the primary build. +It will also ensure that once built, Flang-RT is found by Flang from either +the build- or install-prefix. To enable, add `flang-rt` to +`LLVM_ENABLE_RUNTIMES`: + +```bash +cmake -S /llvm \ + -GNinja \ + -DLLVM_ENABLE_PROJECTS="clang;flang" \ + -DLLVM_ENABLE_RUNTIMES=flang-rt \ + ... +``` + +It is recommended to enable building OpenMP alongside Flang and Flang-RT +as well. This will build `omp_lib.mod` required to use OpenMP from Fortran. +Building Compiler-RT may also be required, particularly on platforms that do +not provide all C-ABI functionality (such as Windows). + +```bash +cmake -S /llvm \ + -GNinja \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_ENABLE_PROJECTS="clang;flang;openmp" \ + -DLLVM_ENABLE_RUNTIMES="compiler-rt;flang-rt" \ + ... +``` + +By default, the enabled runtimes will only be built for the host platform +(`-DLLVM_RUNTIME_TARGETS=default`). To add additional targets to support +cross-compilation via `flang --target=`, add more triples to +`LLVM_RUNTIME_TARGETS`, such as +`-DLLVM_RUNTIME_TARGETS="default;aarch64-linux-gnu"`. + +After configuration, build, test, and install the runtime(s) via + +```shell +$ ninja flang-rt +$ ninja check-flang-rt +$ ninja install +``` + + +### Standalone Runtimes Build + +Instead of building Clang and Flang from scratch, the standalone Runtime build +uses CMake's environment introspection to find a C, C++, and Fortran compiler. +The compiler to be used can be controlled using CMake's standard mechanisms such +as `CMAKE_CXX_COMPILER`, `CMAKE_CXX_COMPILER`, and `CMAKE_Fortran_COMPILER`. +`CMAKE_Fortran_COMPILER` must be `flang` built from the same Git commit as +Flang-RT to ensure they are using the same ABI. The C and C++ compiler +can be any compiler supporting the same ABI. + +In addition to the compiler, the build be able to find LLVM development tools +such as `lit` and `FileCheck` that are not found in an LLVM's install +directory. Use `CMAKE_BINARY_DIR` to point to directory where LLVM has +been built. A simple build configuration might look like the following: + +```bash +cmake -S /runtimes \ + -GNinja \ + -DLLVM_BINARY_DIR= \ + -DCMAKE_Fortran_COMPILER=/bin/flang \ + -DCMAKE_Fortran_COMPILER_WORKS=yes \ + -DLLVM_ENABLE_RUNTIMES=flang-rt \ + ... +``` + +The `CMAKE_Fortran_COMPILER_WORKS` parameter must be set because otherwise CMake +will test whether the Fortran compiler can compile and link programs which will +obviously fail without a runtime library available yet. + +Building Flang-RT for cross-compilation triple, the target triple can +be selected using `LLVM_DEFAULT_TARGET_TRIPLE` AND `LLVM_RUNTIMES_TARGET`. +Of course, Flang-RT can be built multiple times with different build +configurations, but have to be located manually when using with the Flang +driver using the `-L` option. + +After configuration, build, test, and install the runtime via + +```shell +$ ninja +$ ninja check-flang-rt +$ ninja install +``` + + +## Configuration Option Reference + +Flang-RT has the followign configuration options. This is in +addition to the build options the LLVM_ENABLE_RUNTIMES mechanism and +CMake itself provide. + + * `FLANG_RT_INCLUDE_TESTS` (boolean; default: `ON`) + + When `OFF`, does not add any tests and unittests. The `check-flang-rt` + build target will do nothing. + + * `FLANG_RUNTIME_F128_MATH_LIB` (default: `""`) + + Determines the implementation of `REAL(16)` math functions. If set to + `libquadmath`, uses `quadmath.h` and `-lquadmath` typically distributed with + gcc. If empty, disables `REAL(16)` support. For any other value, introspects + the compiler for `__float128` or 128-bit `long double` support. + [More details](docs/Real16MathSupport.md). + + * `FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT` (values: `"CUDA"`,`"OpenMP"`, `""` default: `""`) + + When set to `CUDA`, builds Flang-RT with experimental support for GPU + accelerators using CUDA. `CMAKE_CUDA_COMPILER` must be set if not + automatically detected by CMake. `nvcc` as well as `clang` are supported. + + When set to `OpenMP`, builds Flang-RT with experimental support for + GPU accelerators using OpenMP offloading. Only Clang is supported for + `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER`. + + * `FLANG_RT_INCLUDE_CUF` (bool, default: `OFF`) + + Compiles the `libflang_rt.cuda_.a/.so` library. This is + independent of `FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA` and only + requires a + [CUDA Toolkit installation](https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html) + (no `CMAKE_CUDA_COMPILER`). + + +### Experimental CUDA Support + +With `-DFLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA`, the following +additional configuration options become available. + + * `FLANG_RT_LIBCUDACXX_PATH` (path, default: `""`) + + Path to libcu++ package installation. + + * `FLANG_RT_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS` (boolean, default: `OFF`) + + Do not compile global variables' definitions when producing PTX library. + Default is `OFF`, meaning global variable definitions are compiled by + default. + + +### Experimental OpenMP Offload Support + +With `-DFLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=OpenMP`, the following +additional configuration options become available. + + * `FLANG_RT_DEVICE_ARCHITECTURES` (default: `"all"`) + + A list of device architectures that Flang-RT is going to support. + If `"all"` uses a pre-defined list of architectures. Same purpose as + `LIBOMPTARGET_DEVICE_ARCHITECTURES` from liboffload. diff --git a/flang/runtime/config.h.cmake b/flang-rt/cmake/config.h.cmake.in similarity index 54% rename from flang/runtime/config.h.cmake rename to flang-rt/cmake/config.h.cmake.in index a2271be77b8c6..84c234d86bae6 100644 --- a/flang/runtime/config.h.cmake +++ b/flang-rt/cmake/config.h.cmake.in @@ -1,3 +1,11 @@ +/*===-- cmake/config.cmake.in ---------------------------------------*- 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 + * + *===----------------------------------------------------------------------===*/ + #ifndef FORTRAN_RUNTIME_CONFIG_H #define FORTRAN_RUNTIME_CONFIG_H diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake new file mode 100644 index 0000000000000..630aeb3c65005 --- /dev/null +++ b/flang-rt/cmake/modules/AddFlangRT.cmake @@ -0,0 +1,199 @@ +#===-- cmake/modules/AddFlangRT.cmake --------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +# Builds a library with common options for Flang-RT. +# +# Usage: +# +# add_flangrt_library(name sources ... +# SHARED +# Build a dynamic (.so/.dll) library +# STATIC +# Build a static (.a/.lib) library +# OBJECT +# Create only object files without static/dynamic library +# INSTALL_WITH_TOOLCHAIN +# Install library into Clang's resource directory so it can be found by the +# Flang driver during compilation, including tests +# EXCLUDE_FROM_ALL +# Do not build library by default; typically used for libraries needed for +# testing only, no install +# LINK_TO_LLVM +# Library requires include path and linking to LLVM's Support component +# ADDITIONAL_HEADERS +# May specify header files for IDE generators. +# INCLUDE_DIRECTORIES +# Additional target_include_directories for all added targets +# LINK_LIBRARIES +# Additional target_link_libraries for all added targets +# TARGET_PROPERTIES +# Set target properties of all added targets +# ) +function (add_flangrt_library name) + set(options STATIC SHARED OBJECT INSTALL_WITH_TOOLCHAIN EXCLUDE_FROM_ALL LINK_TO_LLVM) + set(multiValueArgs ADDITIONAL_HEADERS INCLUDE_DIRECTORIES LINK_LIBRARIES TARGET_PROPERTIES) + cmake_parse_arguments(ARG + "${options}" + "" + "${multiValueArgs}" + ${ARGN}) + + if (ARG_INSTALL_WITH_TOOLCHAIN AND ARG_EXCLUDE_FROM_ALL) + message(SEND_ERROR "add_flangrt_library(${name} ...): + INSTALL_WITH_TOOLCHAIN and EXCLUDE_FROM_ALL are in conflict. When + installing an artifact it must have been built first in the 'all' target. + ") + endif () + + # Forward libtype to add_library + set(extra_args "") + if (ARG_SHARED) + list(APPEND extra_args SHARED) + endif () + if (ARG_STATIC) + list(APPEND extra_args STATIC) + endif () + if (ARG_OBJECT) + list(APPEND extra_args OBJECT) + endif () + if (ARG_EXCLUDE_FROM_ALL) + list(APPEND extra_args EXCLUDE_FROM_ALL) + endif () + + # Also add header files to IDEs to list as part of the library. + set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON) + + add_library(${name} ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS}) + + if (ARG_INSTALL_WITH_TOOLCHAIN) + set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Toolchain Libraries") + elseif (ARG_OBJECT) + set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Object Libraries") + else () + set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Libraries") + endif () + + # Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else. + target_compile_features(${name} PRIVATE cxx_std_17) + + # Use compiler-specific options to disable exceptions and RTTI. + if (LLVM_COMPILER_IS_GCC_COMPATIBLE) + target_compile_options(${name} PRIVATE + $<$:-fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables> + ) + elseif (MSVC) + target_compile_options(${name} PRIVATE + $<$:/EHs-c- /GR-> + ) + elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL") + target_compile_options(${name} PRIVATE + $<$:-qnoeh -qnortti> + ) + endif () + + # Also for CUDA source when compiling with FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA + if (CMAKE_CUDA_COMPILER_ID MATCHES "NVIDIA") + # Assuming gcc as host compiler. + target_compile_options(${name} PRIVATE + $<$:--no-exceptions -Xcompiler -fno-rtti -Xcompiler -fno-unwind-tables -Xcompiler -fno-asynchronous-unwind-tables> + ) + else () + # Assuming a clang-compatible CUDA compiler. + target_compile_options(${name} PRIVATE + $<$:-fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables> + ) + endif () + + # Flang-RT's public headers + target_include_directories(${name} PUBLIC "${FLANG_RT_SOURCE_DIR}/include") + + # For ISO_Fortran_binding.h to be found by the runtime itself (Accessed as #include "flang/ISO_Fortran_binding.h") + # User applications can use #include + target_include_directories(${name} PUBLIC "${FLANG_SOURCE_DIR}/include") + + # For Flang-RT's configured config.h to be found + target_include_directories(${name} PRIVATE "${FLANG_RT_BINARY_DIR}") + + # Disable libstdc++/libc++ assertions, even in an LLVM_ENABLE_ASSERTIONS + # build, to avoid an unwanted dependency on libstdc++/libc++.so. + if (FLANG_RT_SUPPORTS_UNDEFINE_FLAG) + target_compile_options(${name} PUBLIC -U_GLIBCXX_ASSERTIONS) + target_compile_options(${name} PUBLIC -U_LIBCPP_ENABLE_ASSERTIONS) + endif () + + # When building the flang runtime if LTO is enabled the archive file + # contains LLVM IR rather than object code. Currently flang is not + # LTO aware so cannot link this file to compiled Fortran code. + if (FLANG_RT_HAS_FNO_LTO_FLAG) + target_compile_options(${name} PRIVATE -fno-lto) + endif () + + # Flang/Clang (including clang-cl) -compiled programs targeting the MSVC ABI + # should only depend on msvcrt/ucrt. LLVM still emits libgcc/compiler-rt + # functions in some cases like 128-bit integer math (__udivti3, __modti3, + # __fixsfti, __floattidf, ...) that msvc does not support. We are injecting a + # dependency to Compiler-RT's builtin library where these are implemented. + if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if (FLANG_RT_BUILTINS_LIBRARY) + target_compile_options(${name} PRIVATE "$<$:-Xclang>" "$<$:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>") + endif () + endif () + if (MSVC AND CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang") + if (FLANG_RT_BUILTINS_LIBRARY) + target_compile_options(${name} PRIVATE "$<$:-Xflang>" "$<$:--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}>") + else () + message(WARNING "Did not find libclang_rt.builtins.lib. + LLVM may emit builtins that are not implemented in msvcrt/ucrt and + instead falls back to builtins from Compiler-RT. Linking with ${name} + may result in a linker error.") + endif () + endif () + + # Non-GTest unittests depend on LLVMSupport + if (ARG_LINK_TO_LLVM) + if (LLVM_LINK_LLVM_DYLIB) + set(llvm_libs LLVM) + else() + llvm_map_components_to_libnames(llvm_libs Support) + endif() + target_link_libraries(${name} PUBLIC ${llvm_libs}) + target_include_directories(${name} PUBLIC ${LLVM_INCLUDE_DIRS}) + endif () + + if (ARG_INCLUDE_DIRECTORIES) + target_include_directories(${name} ${ARG_INCLUDE_DIRECTORIES}) + endif () + + if (ARG_LINK_LIBRARIES) + target_link_libraries(${name} PUBLIC ${ARG_LINK_LIBRARIES}) + endif () + + # If this is part of the toolchain, put it into the compiler's resource + # directory. Otherwise it is part of testing and is not installed at all. + # TODO: Consider multi-configuration builds (MSVC_IDE, "Ninja Multi-Config") + if (ARG_INSTALL_WITH_TOOLCHAIN) + set_target_properties(${name} + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_LIB_DIR}" + ) + + install(TARGETS ${name} + ARCHIVE DESTINATION "${FLANG_RT_INSTALL_RESOURCE_LIB_PATH}" + ) + endif () + + if (ARG_TARGET_PROPERTIES) + set_target_properties(${name} PROPERTIES ${ARG_TARGET_PROPERTIES}) + endif () + + # flang-rt should build all the Flang-RT targets that are built in an + # 'all' build. + if (NOT ARG_EXCLUDE_FROM_ALL) + add_dependencies(flang-rt ${name}) + endif () +endfunction (add_flangrt_library) diff --git a/flang-rt/cmake/modules/AddFlangRTOffload.cmake b/flang-rt/cmake/modules/AddFlangRTOffload.cmake new file mode 100644 index 0000000000000..4e4bd60c63545 --- /dev/null +++ b/flang-rt/cmake/modules/AddFlangRTOffload.cmake @@ -0,0 +1,100 @@ +#===-- cmake/modules/AddFlangRTOffload.cmake -------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +macro(enable_cuda_compilation name files) + if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA") + enable_language(CUDA) + + set_target_properties(${name} + PROPERTIES + CUDA_SEPARABLE_COMPILATION ON + ) + + # Treat all supported sources as CUDA files. + set_source_files_properties(${files} PROPERTIES LANGUAGE CUDA) + set(CUDA_COMPILE_OPTIONS) + if ("${CMAKE_CUDA_COMPILER_ID}" MATCHES "Clang") + # Allow varargs. + set(CUDA_COMPILE_OPTIONS + -Xclang -fcuda-allow-variadic-functions + ) + endif() + if ("${CMAKE_CUDA_COMPILER_ID}" MATCHES "NVIDIA") + set(CUDA_COMPILE_OPTIONS + --expt-relaxed-constexpr + # Disable these warnings: + # 'long double' is treated as 'double' in device code + -Xcudafe --diag_suppress=20208 + -Xcudafe --display_error_number + ) + endif() + set_source_files_properties(${files} PROPERTIES COMPILE_OPTIONS + "${CUDA_COMPILE_OPTIONS}") + + # Create a .a library consisting of CUDA PTX. + # This is different from a regular static library. The CUDA_PTX_COMPILATION + # property can only be applied to object libraries and create *.ptx files + # instead of *.o files. The .a will consist of those *.ptx files only. + add_flangrt_library(obj.${name}PTX OBJECT ${files}) + set_property(TARGET obj.${name}PTX PROPERTY CUDA_PTX_COMPILATION ON) + add_flangrt_library(${name}PTX STATIC "$") + + # Apply configuration options + if (FLANG_RT_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS) + target_compile_definitions(obj.${name}PTX + PRIVATE FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS + ) + endif() + + # When using libcudacxx headers files, we have to use them + # for all files of Flang-RT. + if (EXISTS "${FLANG_RT_LIBCUDACXX_PATH}/include") + foreach (tgt IN ITEMS "${name}" "obj.${name}PTX") + target_include_directories(${tgt} AFTER PRIVATE "${FLANG_RT_LIBCUDACXX_PATH}/include") + target_compile_definitions(${tgt} PRIVATE RT_USE_LIBCUDACXX=1) + endforeach () + endif () + endif() +endmacro() + +macro(enable_omp_offload_compilation name files) + if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "OpenMP") + # OpenMP offload build only works with Clang compiler currently. + + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND + "${CMAKE_C_COMPILER_ID}" MATCHES "Clang") + + string(REPLACE ";" "," compile_for_architectures + "${FLANG_RT_DEVICE_ARCHITECTURES}" + ) + + set(OMP_COMPILE_OPTIONS + -fopenmp + -fvisibility=hidden + -fopenmp-cuda-mode + --offload-arch=${compile_for_architectures} + # Force LTO for the device part. + -foffload-lto + ) + set_source_files_properties(${files} PROPERTIES COMPILE_OPTIONS + "${OMP_COMPILE_OPTIONS}" + ) + target_link_options(${name} PUBLIC ${OMP_COMPILE_OPTIONS}) + + # Enable "declare target" in the source code. + set_source_files_properties(${files} + PROPERTIES COMPILE_DEFINITIONS OMP_OFFLOAD_BUILD + ) + else() + message(FATAL_ERROR + "Flang-rt build with OpenMP offload is not supported for these compilers:\n" + "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}\n" + "CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}") + endif() + endif() +endmacro() diff --git a/flang-rt/cmake/modules/GetToolchainDirs.cmake b/flang-rt/cmake/modules/GetToolchainDirs.cmake new file mode 100644 index 0000000000000..426a5e8e801f3 --- /dev/null +++ b/flang-rt/cmake/modules/GetToolchainDirs.cmake @@ -0,0 +1,125 @@ +#===-- cmake/modules/GetToolchainDirs.cmake --------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + + +# Determine the subdirectory relative to Clang's resource dir/sysroot where to +# install target-specific libraries, to be found by Clang/Flang driver. This was +# adapted from Compiler-RT's mechanism to find the path for +# libclang_rt.builtins.a. +# +# Compiler-RT has two mechanisms for the path (simplified): +# +# * LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=1: lib/${oslibname}/libclang_rt.builtins-${arch}.a +# * LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=0: lib/${triple}/libclang_rt.builtins.a +# +# LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON is the newer scheme, but the old one is +# currently still used for some platforms such as Windows. Clang looks for which +# of the files exist before passing the path to the linker. Hence, the +# directories have to match what Clang is looking for, which is done in +# ToolChain::getArchSpecificLibPaths(..), ToolChain::getRuntimePath(), +# ToolChain::getCompilerRTPath(), and ToolChain::getCompilerRT(..), not entirely +# consistent between these functions, Compiler-RT's CMake code, and overrides +# in different toolchains. +# +# For Fortran, Flang always assumes the library name libflang_rt.a without +# architecture suffix. Hence, we always use the second scheme even as if +# LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON, even if it actually set to OFF. It as +# added unconditionally to the library search path by +# ToolChain::getArchSpecificLibPaths(...). +function (get_toolchain_library_subdir outvar) + if (NOT APPLE) + set(outval "lib") + else () + # Required to be "darwin" for MachO toolchain. + get_toolchain_os_dirname(os_dirname) + set(outval "lib/${os_dirname}") + endif () + + get_toolchain_arch_dirname(arch_dirname) + set(outval "lib/${arch_dirname}") + + set(${outvar} "${outval}" PARENT_SCOPE) +endfunction () + + +# Corresponds to Clang's ToolChain::getOSLibName(). Adapted from Compiler-RT. +function (get_toolchain_os_dirname outvar) + if (ANDROID) + # The CMAKE_SYSTEM_NAME for Android is "Android", but the OS is Linux and the + # driver will search for libraries in the "linux" directory. + set(outval "linux") + else () + string(TOLOWER "${CMAKE_SYSTEM_NAME}" outval) + endif () + set(${outvar} "${outval}" PARENT_SCOPE) +endfunction () + + +# Corresponds to Clang's ToolChain::getRuntimePath(). Adapted from Compiler-RT. +function (get_toolchain_arch_dirname outvar) + string(REPLACE "-" ";" triple_list ${LLVM_TARGET_TRIPLE}) + list(GET triple_list 0 arch) + + if("${arch}" MATCHES "^i.86$") + # Android uses i686, but that's remapped at a later stage. + set(arch "i386") + endif() + + string(FIND ${LLVM_TARGET_TRIPLE} "-" dash_index) + string(SUBSTRING ${LLVM_TARGET_TRIPLE} ${dash_index} -1 triple_suffix) + string(SUBSTRING ${LLVM_TARGET_TRIPLE} 0 ${dash_index} triple_cpu) + set(arch "${triple_cpu}") + if("${arch}" MATCHES "^i.86$") + # Android uses i686, but that's remapped at a later stage. + set(arch "i386") + endif() + + if(ANDROID AND ${arch} STREQUAL "i386") + set(target "i686${triple_suffix}") + elseif(${arch} STREQUAL "amd64") + set(target "x86_64${triple_suffix}") + elseif(${arch} STREQUAL "sparc64") + set(target "sparcv9${triple_suffix}") + elseif("${arch}" MATCHES "mips64|mips64el") + string(REGEX REPLACE "-gnu.*" "-gnuabi64" triple_suffix_gnu "${triple_suffix}") + string(REGEX REPLACE "mipsisa32" "mipsisa64" triple_cpu_mips "${triple_cpu}") + string(REGEX REPLACE "^mips$" "mips64" triple_cpu_mips "${triple_cpu_mips}") + string(REGEX REPLACE "^mipsel$" "mips64el" triple_cpu_mips "${triple_cpu_mips}") + set(target "${triple_cpu_mips}${triple_suffix_gnu}") + elseif("${arch}" MATCHES "mips|mipsel") + string(REGEX REPLACE "-gnuabi.*" "-gnu" triple_suffix_gnu "${triple_suffix}") + string(REGEX REPLACE "mipsisa64" "mipsisa32" triple_cpu_mips "${triple_cpu}") + string(REGEX REPLACE "mips64" "mips" triple_cpu_mips "${triple_cpu_mips}") + set(target "${triple_cpu_mips}${triple_suffix_gnu}") + elseif("${arch}" MATCHES "^arm") + # FIXME: Handle arch other than arm, armhf, armv6m + if (${arch} STREQUAL "armhf") + # If we are building for hard float but our ABI is soft float. + if ("${triple_suffix}" MATCHES ".*eabi$") + # Change "eabi" -> "eabihf" + set(triple_suffix "${triple_suffix}hf") + endif() + # ABI is already set in the triple, don't repeat it in the architecture. + set(arch "arm") + else () + # If we are building for soft float, but the triple's ABI is hard float. + if ("${triple_suffix}" MATCHES ".*eabihf$") + # Change "eabihf" -> "eabi" + string(REGEX REPLACE "hf$" "" triple_suffix "${triple_suffix}") + endif() + endif() + set(target "${arch}${triple_suffix}") + elseif("${arch}" MATCHES "^amdgcn") + set(target "amdgcn-amd-amdhsa") + elseif("${arch}" MATCHES "^nvptx") + set(target "nvptx64-nvidia-cuda") + else() + set(target "${arch}${triple_suffix}") + endif() + set(${outvar} "${target}" PARENT_SCOPE) +endfunction() diff --git a/flang-rt/examples/CMakeLists.txt b/flang-rt/examples/CMakeLists.txt new file mode 100644 index 0000000000000..f45a95d18b641 --- /dev/null +++ b/flang-rt/examples/CMakeLists.txt @@ -0,0 +1,9 @@ +#===-- examples/CMakeLists.txt ---------------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +add_subdirectory(ExternalHelloWorld) diff --git a/flang-rt/examples/ExternalHelloWorld/CMakeLists.txt b/flang-rt/examples/ExternalHelloWorld/CMakeLists.txt new file mode 100644 index 0000000000000..4fd04f8f2769a --- /dev/null +++ b/flang-rt/examples/ExternalHelloWorld/CMakeLists.txt @@ -0,0 +1,17 @@ +#===-- examples/ExternalHelloWorld/CMakeLists.txt --------------------------===# +# +# 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 test is not run by default as it requires input. +add_llvm_example(external-hello-world + external-hello.cpp +) + +target_link_libraries(external-hello-world + PRIVATE + flang_rt.runtime + ) diff --git a/flang/examples/ExternalHelloWorld/external-hello.cpp b/flang-rt/examples/ExternalHelloWorld/external-hello.cpp similarity index 80% rename from flang/examples/ExternalHelloWorld/external-hello.cpp rename to flang-rt/examples/ExternalHelloWorld/external-hello.cpp index 4991bf9eba999..7c8a12476295c 100644 --- a/flang/examples/ExternalHelloWorld/external-hello.cpp +++ b/flang-rt/examples/ExternalHelloWorld/external-hello.cpp @@ -1,3 +1,11 @@ +//===-- examples/ExternalHelloWorld/external-hello.cpp ----------*- 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 +// +//===----------------------------------------------------------------------===// + #include "flang/Runtime/io-api.h" #include "flang/Runtime/main.h" #include "flang/Runtime/stop.h" diff --git a/flang/include/flang/Runtime/allocator-registry.h b/flang-rt/include/flang-rt/runtime/allocator-registry.h similarity index 87% rename from flang/include/flang/Runtime/allocator-registry.h rename to flang-rt/include/flang-rt/runtime/allocator-registry.h index 29302c5d825bc..1a59ec8b1ef5b 100644 --- a/flang/include/flang/Runtime/allocator-registry.h +++ b/flang-rt/include/flang-rt/runtime/allocator-registry.h @@ -1,4 +1,4 @@ -//===-- runtime/allocator-registry.h ----------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/allocator-registry.h -----------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_ -#define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_ +#ifndef FLANG_RT_RUNTIME_ALLOCATOR_REGISTRY_H_ +#define FLANG_RT_RUNTIME_ALLOCATOR_REGISTRY_H_ #include "flang/Common/api-attrs.h" #include "flang/Runtime/allocator-registry-consts.h" @@ -55,4 +55,4 @@ RT_OFFLOAD_VAR_GROUP_END } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_ +#endif // FLANG_RT_RUNTIME_ALLOCATOR_REGISTRY_H_ diff --git a/flang/include/flang/Runtime/array-constructor.h b/flang-rt/include/flang-rt/runtime/array-constructor.h similarity index 89% rename from flang/include/flang/Runtime/array-constructor.h rename to flang-rt/include/flang-rt/runtime/array-constructor.h index 2f6aaae17c650..9c037177161c0 100644 --- a/flang/include/flang/Runtime/array-constructor.h +++ b/flang-rt/include/flang-rt/runtime/array-constructor.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/array-constructor.h ---------------*- C++ -*-===// +//===-- include/flang-rt/runtime/array-constructor.h ------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,11 +9,11 @@ // External APIs to create temporary storage for array constructors when their // final extents or length parameters cannot be pre-computed. -#ifndef FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_ -#define FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_ +#ifndef FLANG_RT_RUNTIME_ARRAY_CONSTRUCTOR_H_ +#define FLANG_RT_RUNTIME_ARRAY_CONSTRUCTOR_H_ +#include "descriptor.h" #include "flang/Runtime/array-constructor-consts.h" -#include "flang/Runtime/descriptor.h" #include "flang/Runtime/entry-names.h" #include @@ -54,4 +54,4 @@ static_assert(alignof(Fortran::runtime::ArrayConstructorVector) <= "MaxArrayConstructorVectorAlignInBytes"); } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_ +#endif // FLANG_RT_RUNTIME_ARRAY_CONSTRUCTOR_H_ diff --git a/flang/runtime/assign-impl.h b/flang-rt/include/flang-rt/runtime/assign-impl.h similarity index 85% rename from flang/runtime/assign-impl.h rename to flang-rt/include/flang-rt/runtime/assign-impl.h index aaa320ef7f959..cc931f6713cd8 100644 --- a/flang/runtime/assign-impl.h +++ b/flang-rt/include/flang-rt/runtime/assign-impl.h @@ -1,4 +1,4 @@ -//===-- runtime/assign-impl.h -----------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/assign-impl.h ------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_ASSIGN_IMPL_H_ -#define FORTRAN_RUNTIME_ASSIGN_IMPL_H_ +#ifndef FLANG_RT_RUNTIME_ASSIGN_IMPL_H_ +#define FLANG_RT_RUNTIME_ASSIGN_IMPL_H_ #include "flang/Runtime/freestanding-tools.h" @@ -28,4 +28,4 @@ RT_API_ATTRS void DoFromSourceAssign(Descriptor &, const Descriptor &, #endif } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_ASSIGN_IMPL_H_ +#endif // FLANG_RT_RUNTIME_ASSIGN_IMPL_H_ diff --git a/flang/runtime/buffer.h b/flang-rt/include/flang-rt/runtime/buffer.h similarity index 97% rename from flang/runtime/buffer.h rename to flang-rt/include/flang-rt/runtime/buffer.h index 41a1abb1b2d90..b5a9ce9e35e91 100644 --- a/flang/runtime/buffer.h +++ b/flang-rt/include/flang-rt/runtime/buffer.h @@ -1,4 +1,4 @@ -//===-- runtime/buffer.h ----------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/buffer.h -----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,12 +8,12 @@ // External file buffering -#ifndef FORTRAN_RUNTIME_BUFFER_H_ -#define FORTRAN_RUNTIME_BUFFER_H_ +#ifndef FLANG_RT_RUNTIME_BUFFER_H_ +#define FLANG_RT_RUNTIME_BUFFER_H_ #include "io-error.h" +#include "memory.h" #include "flang/Runtime/freestanding-tools.h" -#include "flang/Runtime/memory.h" #include #include #include @@ -221,4 +221,4 @@ template class FileFrame { bool dirty_{false}; }; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_BUFFER_H_ +#endif // FLANG_RT_RUNTIME_BUFFER_H_ diff --git a/flang/runtime/connection.h b/flang-rt/include/flang-rt/runtime/connection.h similarity index 96% rename from flang/runtime/connection.h rename to flang-rt/include/flang-rt/runtime/connection.h index 6f1ea90a160e5..03d9658e7067b 100644 --- a/flang/runtime/connection.h +++ b/flang-rt/include/flang-rt/runtime/connection.h @@ -1,4 +1,4 @@ -//===-- runtime/connection.h ------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/connection.h -------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,8 +8,8 @@ // Fortran I/O connection state (abstracted over internal & external units) -#ifndef FORTRAN_RUNTIME_IO_CONNECTION_H_ -#define FORTRAN_RUNTIME_IO_CONNECTION_H_ +#ifndef FLANG_RT_RUNTIME_CONNECTION_H_ +#define FLANG_RT_RUNTIME_CONNECTION_H_ #include "format.h" #include "flang/Common/optional.h" @@ -124,4 +124,4 @@ class SavedPosition { }; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_IO_CONNECTION_H_ +#endif // FLANG_RT_RUNTIME_CONNECTION_H_ diff --git a/flang/runtime/derived.h b/flang-rt/include/flang-rt/runtime/derived.h similarity index 90% rename from flang/runtime/derived.h rename to flang-rt/include/flang-rt/runtime/derived.h index f5a1e219b848c..ac6962c57168c 100644 --- a/flang/runtime/derived.h +++ b/flang-rt/include/flang-rt/runtime/derived.h @@ -1,4 +1,4 @@ -//===-- runtime/derived.h -------------------------------------------------===// +//===-- include/flang-rt/runtime/derived.h ----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,8 +8,8 @@ // Internal runtime utilities for derived type operations. -#ifndef FORTRAN_RUNTIME_DERIVED_H_ -#define FORTRAN_RUNTIME_DERIVED_H_ +#ifndef FLANG_RT_RUNTIME_DERIVED_H_ +#define FLANG_RT_RUNTIME_DERIVED_H_ #include "flang/Common/api-attrs.h" @@ -48,4 +48,4 @@ RT_API_ATTRS void Destroy(const Descriptor &, bool finalize, RT_API_ATTRS bool HasDynamicComponent(const Descriptor &); } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_DERIVED_H_ +#endif // FLANG_RT_RUNTIME_DERIVED_H_ diff --git a/flang/include/flang/Runtime/descriptor.h b/flang-rt/include/flang-rt/runtime/descriptor.h similarity index 98% rename from flang/include/flang/Runtime/descriptor.h rename to flang-rt/include/flang-rt/runtime/descriptor.h index 628ac8c927a51..19e1a0bf6a1dd 100644 --- a/flang/include/flang/Runtime/descriptor.h +++ b/flang-rt/include/flang-rt/runtime/descriptor.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/descriptor.h ----------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/descriptor.h -------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_DESCRIPTOR_H_ -#define FORTRAN_RUNTIME_DESCRIPTOR_H_ +#ifndef FLANG_RT_RUNTIME_DESCRIPTOR_H_ +#define FLANG_RT_RUNTIME_DESCRIPTOR_H_ // Defines data structures used during execution of a Fortran program // to implement nontrivial dummy arguments, pointers, allocatables, @@ -18,10 +18,10 @@ // User C code is welcome to depend on that ISO_Fortran_binding.h file, // but should never reference this internal header. +#include "memory.h" +#include "type-code.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" #include "flang/Runtime/descriptor-consts.h" -#include "flang/Runtime/memory.h" -#include "flang/Runtime/type-code.h" #include #include #include @@ -482,4 +482,4 @@ class alignas(Descriptor) StaticDescriptor { }; } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_DESCRIPTOR_H_ +#endif // FLANG_RT_RUNTIME_DESCRIPTOR_H_ diff --git a/flang/runtime/emit-encoded.h b/flang-rt/include/flang-rt/runtime/emit-encoded.h similarity index 94% rename from flang/runtime/emit-encoded.h rename to flang-rt/include/flang-rt/runtime/emit-encoded.h index 4b5e390078835..d99f56b29558e 100644 --- a/flang/runtime/emit-encoded.h +++ b/flang-rt/include/flang-rt/runtime/emit-encoded.h @@ -1,4 +1,4 @@ -//===-- runtime/emit-encoded.h ----------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/emit-encoded.h -----------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,8 +8,8 @@ // Templates for emitting CHARACTER values with conversion -#ifndef FORTRAN_RUNTIME_EMIT_ENCODED_H_ -#define FORTRAN_RUNTIME_EMIT_ENCODED_H_ +#ifndef FLANG_RT_RUNTIME_EMIT_ENCODED_H_ +#define FLANG_RT_RUNTIME_EMIT_ENCODED_H_ #include "connection.h" #include "environment.h" @@ -114,4 +114,4 @@ RT_API_ATTRS bool EmitRepeated(CONTEXT &to, char ch, std::size_t n) { } } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_EMIT_ENCODED_H_ +#endif // FLANG_RT_RUNTIME_EMIT_ENCODED_H_ diff --git a/flang/runtime/environment.h b/flang-rt/include/flang-rt/runtime/environment.h similarity index 91% rename from flang/runtime/environment.h rename to flang-rt/include/flang-rt/runtime/environment.h index 500aa925a625b..142add432b5f7 100644 --- a/flang/runtime/environment.h +++ b/flang-rt/include/flang-rt/runtime/environment.h @@ -1,4 +1,4 @@ -//===-- runtime/environment.h -----------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/environment.h ------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_ENVIRONMENT_H_ -#define FORTRAN_RUNTIME_ENVIRONMENT_H_ +#ifndef FLANG_RT_RUNTIME_ENVIRONMENT_H_ +#define FLANG_RT_RUNTIME_ENVIRONMENT_H_ #include "flang/Common/optional.h" #include "flang/Decimal/decimal.h" @@ -67,4 +67,4 @@ RT_OFFLOAD_VAR_GROUP_END } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_ENVIRONMENT_H_ +#endif // FLANG_RT_RUNTIME_ENVIRONMENT_H_ diff --git a/flang/runtime/file.h b/flang-rt/include/flang-rt/runtime/file.h similarity index 95% rename from flang/runtime/file.h rename to flang-rt/include/flang-rt/runtime/file.h index c06acbb9904cc..3bba29722b3b8 100644 --- a/flang/runtime/file.h +++ b/flang-rt/include/flang-rt/runtime/file.h @@ -1,4 +1,4 @@ -//===-- runtime/file.h ------------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/file.h -------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,12 +8,12 @@ // Raw system I/O wrappers -#ifndef FORTRAN_RUNTIME_FILE_H_ -#define FORTRAN_RUNTIME_FILE_H_ +#ifndef FLANG_RT_RUNTIME_FILE_H_ +#define FLANG_RT_RUNTIME_FILE_H_ #include "io-error.h" +#include "memory.h" #include "flang/Common/optional.h" -#include "flang/Runtime/memory.h" #include namespace Fortran::runtime::io { @@ -113,4 +113,4 @@ RT_API_ATTRS bool MayWrite(const char *path); RT_API_ATTRS bool MayReadAndWrite(const char *path); RT_API_ATTRS std::int64_t SizeInBytes(const char *path); } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_FILE_H_ +#endif // FLANG_RT_RUNTIME_FILE_H_ diff --git a/flang/runtime/format-implementation.h b/flang-rt/include/flang-rt/runtime/format-implementation.h similarity index 98% rename from flang/runtime/format-implementation.h rename to flang-rt/include/flang-rt/runtime/format-implementation.h index 46204ca927c13..8f4eb1161dd14 100644 --- a/flang/runtime/format-implementation.h +++ b/flang-rt/include/flang-rt/runtime/format-implementation.h @@ -1,4 +1,4 @@ -//===-- runtime/format-implementation.h -------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/format-implementation.h --------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,8 +8,8 @@ // Implements out-of-line member functions of template class FormatControl -#ifndef FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_ -#define FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_ +#ifndef FLANG_RT_RUNTIME_FORMAT_IMPLEMENTATION_H_ +#define FLANG_RT_RUNTIME_FORMAT_IMPLEMENTATION_H_ #include "emit-encoded.h" #include "format.h" @@ -601,4 +601,4 @@ RT_API_ATTRS void FormatControl::Finish(Context &context) { } } } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_FORMAT_IMPLEMENTATION_H_ +#endif // FLANG_RT_RUNTIME_FORMAT_IMPLEMENTATION_H_ diff --git a/flang/runtime/format.h b/flang-rt/include/flang-rt/runtime/format.h similarity index 97% rename from flang/runtime/format.h rename to flang-rt/include/flang-rt/runtime/format.h index 815bf70685e64..b169d63fa4999 100644 --- a/flang/runtime/format.h +++ b/flang-rt/include/flang-rt/runtime/format.h @@ -1,4 +1,4 @@ -//===-- runtime/format.h ----------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/format.h -----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,8 +8,8 @@ // FORMAT string processing -#ifndef FORTRAN_RUNTIME_FORMAT_H_ -#define FORTRAN_RUNTIME_FORMAT_H_ +#ifndef FLANG_RT_RUNTIME_FORMAT_H_ +#define FLANG_RT_RUNTIME_FORMAT_H_ #include "environment.h" #include "io-error.h" @@ -201,4 +201,4 @@ template class FormatControl { Iteration stack_[maxMaxHeight]; }; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_FORMAT_H_ +#endif // FLANG_RT_RUNTIME_FORMAT_H_ diff --git a/flang/runtime/internal-unit.h b/flang-rt/include/flang-rt/runtime/internal-unit.h similarity index 89% rename from flang/runtime/internal-unit.h rename to flang-rt/include/flang-rt/runtime/internal-unit.h index a0ee6353eeda3..429d3489e0112 100644 --- a/flang/runtime/internal-unit.h +++ b/flang-rt/include/flang-rt/runtime/internal-unit.h @@ -1,4 +1,4 @@ -//===-- runtime/internal-unit.h ---------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/internal-unit.h ----------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,11 +8,11 @@ // Fortran internal I/O "units" -#ifndef FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_ -#define FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_ +#ifndef FLANG_RT_RUNTIME_INTERNAL_UNIT_H_ +#define FLANG_RT_RUNTIME_INTERNAL_UNIT_H_ #include "connection.h" -#include "flang/Runtime/descriptor.h" +#include "descriptor.h" #include #include @@ -56,4 +56,4 @@ template class InternalDescriptorUnit : public ConnectionState { extern template class InternalDescriptorUnit; extern template class InternalDescriptorUnit; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_IO_INTERNAL_UNIT_H_ +#endif // FLANG_RT_RUNTIME_INTERNAL_UNIT_H_ diff --git a/flang/runtime/io-error.h b/flang-rt/include/flang-rt/runtime/io-error.h similarity index 92% rename from flang/runtime/io-error.h rename to flang-rt/include/flang-rt/runtime/io-error.h index 39a343c8e0a51..1cef6a208f374 100644 --- a/flang/runtime/io-error.h +++ b/flang-rt/include/flang-rt/runtime/io-error.h @@ -1,4 +1,4 @@ -//===-- runtime/io-error.h --------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/io-error.h ---------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -12,12 +12,12 @@ // IOSTAT error codes are raw errno values augmented with values for // Fortran-specific errors. -#ifndef FORTRAN_RUNTIME_IO_ERROR_H_ -#define FORTRAN_RUNTIME_IO_ERROR_H_ +#ifndef FLANG_RT_RUNTIME_IO_ERROR_H_ +#define FLANG_RT_RUNTIME_IO_ERROR_H_ +#include "memory.h" #include "terminator.h" #include "flang/Runtime/iostat.h" -#include "flang/Runtime/memory.h" #include namespace Fortran::runtime::io { @@ -80,4 +80,4 @@ class IoErrorHandler : public Terminator { }; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_IO_ERROR_H_ +#endif // FLANG_RT_RUNTIME_IO_ERROR_H_ diff --git a/flang/runtime/io-stmt.h b/flang-rt/include/flang-rt/runtime/io-stmt.h similarity index 99% rename from flang/runtime/io-stmt.h rename to flang-rt/include/flang-rt/runtime/io-stmt.h index 1f1419b249e5e..a364ddfd9b3c7 100644 --- a/flang/runtime/io-stmt.h +++ b/flang-rt/include/flang-rt/runtime/io-stmt.h @@ -1,4 +1,4 @@ -//===-- runtime/io-stmt.h ---------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/io-stmt.h ----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,10 +8,11 @@ // Representations of the state of an I/O statement in progress -#ifndef FORTRAN_RUNTIME_IO_STMT_H_ -#define FORTRAN_RUNTIME_IO_STMT_H_ +#ifndef FLANG_RT_RUNTIME_IO_STMT_H_ +#define FLANG_RT_RUNTIME_IO_STMT_H_ #include "connection.h" +#include "descriptor.h" #include "file.h" #include "format.h" #include "internal-unit.h" @@ -19,7 +20,6 @@ #include "flang/Common/optional.h" #include "flang/Common/reference-wrapper.h" #include "flang/Common/visit.h" -#include "flang/Runtime/descriptor.h" #include "flang/Runtime/io-api.h" #include #include @@ -791,4 +791,4 @@ class ErroneousIoStatementState : public IoStatementBase { }; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_IO_STMT_H_ +#endif // FLANG_RT_RUNTIME_IO_STMT_H_ diff --git a/flang/runtime/lock.h b/flang-rt/include/flang-rt/runtime/lock.h similarity index 94% rename from flang/runtime/lock.h rename to flang-rt/include/flang-rt/runtime/lock.h index 46ca28703a45b..7c88534245733 100644 --- a/flang/runtime/lock.h +++ b/flang-rt/include/flang-rt/runtime/lock.h @@ -1,4 +1,4 @@ -//===-- runtime/lock.h ------------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/lock.h -------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,8 +8,8 @@ // Wraps a mutex -#ifndef FORTRAN_RUNTIME_LOCK_H_ -#define FORTRAN_RUNTIME_LOCK_H_ +#ifndef FLANG_RT_RUNTIME_LOCK_H_ +#define FLANG_RT_RUNTIME_LOCK_H_ #include "terminator.h" #include "tools.h" @@ -113,4 +113,4 @@ class CriticalSection { }; } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_LOCK_H_ +#endif // FLANG_RT_RUNTIME_LOCK_H_ diff --git a/flang/include/flang/Runtime/memory.h b/flang-rt/include/flang-rt/runtime/memory.h similarity index 96% rename from flang/include/flang/Runtime/memory.h rename to flang-rt/include/flang-rt/runtime/memory.h index 98412a989f890..93b477afa9814 100644 --- a/flang/include/flang/Runtime/memory.h +++ b/flang-rt/include/flang-rt/runtime/memory.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/memory.h --------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/memory.h -----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,8 +9,8 @@ // Thin wrapper around malloc()/free() to isolate the dependency, // ease porting, and provide an owning pointer. -#ifndef FORTRAN_RUNTIME_MEMORY_H_ -#define FORTRAN_RUNTIME_MEMORY_H_ +#ifndef FLANG_RT_RUNTIME_MEMORY_H_ +#define FLANG_RT_RUNTIME_MEMORY_H_ #include "flang/Common/api-attrs.h" #include @@ -170,4 +170,4 @@ template struct Allocator { }; } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_MEMORY_H_ +#endif // FLANG_RT_RUNTIME_MEMORY_H_ diff --git a/flang/runtime/namelist.h b/flang-rt/include/flang-rt/runtime/namelist.h similarity index 91% rename from flang/runtime/namelist.h rename to flang-rt/include/flang-rt/runtime/namelist.h index 25216a75e9367..17d7bf310cc96 100644 --- a/flang/runtime/namelist.h +++ b/flang-rt/include/flang-rt/runtime/namelist.h @@ -1,4 +1,4 @@ -//===-- runtime/namelist.h --------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/namelist.h ---------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,8 +8,8 @@ // Defines the data structure used for NAMELIST I/O -#ifndef FORTRAN_RUNTIME_NAMELIST_H_ -#define FORTRAN_RUNTIME_NAMELIST_H_ +#ifndef FLANG_RT_RUNTIME_NAMELIST_H_ +#define FLANG_RT_RUNTIME_NAMELIST_H_ #include "non-tbp-dio.h" #include "flang/Common/api-attrs.h" @@ -51,4 +51,4 @@ class NamelistGroup { RT_API_ATTRS bool IsNamelistNameOrSlash(IoStatementState &); } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_NAMELIST_H_ +#endif // FLANG_RT_RUNTIME_NAMELIST_H_ diff --git a/flang/runtime/non-tbp-dio.h b/flang-rt/include/flang-rt/runtime/non-tbp-dio.h similarity index 91% rename from flang/runtime/non-tbp-dio.h rename to flang-rt/include/flang-rt/runtime/non-tbp-dio.h index 8429d790fea57..2bbbfa7f97f79 100644 --- a/flang/runtime/non-tbp-dio.h +++ b/flang-rt/include/flang-rt/runtime/non-tbp-dio.h @@ -1,4 +1,4 @@ -//===-- flang/runtime/non-tbp-dio.h -----------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/non-tbp-dio.h ------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -19,8 +19,8 @@ // a containing scope has become inaccessible in a nested scope due // to the use of "IMPORT, NONE" or "IMPORT, ONLY:". -#ifndef FORTRAN_RUNTIME_NON_TBP_DIO_H_ -#define FORTRAN_RUNTIME_NON_TBP_DIO_H_ +#ifndef FLANG_RT_RUNTIME_NON_TBP_DIO_H_ +#define FLANG_RT_RUNTIME_NON_TBP_DIO_H_ #include "flang/Common/Fortran-consts.h" #include "flang/Common/api-attrs.h" @@ -53,4 +53,4 @@ struct NonTbpDefinedIoTable { }; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_NON_TBP_DIO_H_ +#endif // FLANG_RT_RUNTIME_NON_TBP_DIO_H_ diff --git a/flang/runtime/numeric-templates.h b/flang-rt/include/flang-rt/runtime/numeric-templates.h similarity index 98% rename from flang/runtime/numeric-templates.h rename to flang-rt/include/flang-rt/runtime/numeric-templates.h index fbb371bffc27a..1253d56f3c0fd 100644 --- a/flang/runtime/numeric-templates.h +++ b/flang-rt/include/flang-rt/runtime/numeric-templates.h @@ -1,4 +1,4 @@ -//===-- runtime/numeric-templates.h -----------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/numeric-templates.h ------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -15,8 +15,8 @@ // for the data type corresponding to CppTypeFor // on the target. -#ifndef FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_ -#define FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_ +#ifndef FLANG_RT_RUNTIME_NUMERIC_TEMPLATES_H_ +#define FLANG_RT_RUNTIME_NUMERIC_TEMPLATES_H_ #include "terminator.h" #include "tools.h" @@ -368,4 +368,4 @@ template inline RT_API_ATTRS T ErfcScaled(T arg) { } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_NUMERIC_TEMPLATES_H_ +#endif // FLANG_RT_RUNTIME_NUMERIC_TEMPLATES_H_ diff --git a/flang/runtime/random-templates.h b/flang-rt/include/flang-rt/runtime/random-templates.h similarity index 93% rename from flang/runtime/random-templates.h rename to flang-rt/include/flang-rt/runtime/random-templates.h index 3885941704d4a..895c5ad4fc8bb 100644 --- a/flang/runtime/random-templates.h +++ b/flang-rt/include/flang-rt/runtime/random-templates.h @@ -1,4 +1,4 @@ -//===-- runtime/random-templates.h ------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/random-templates.h -------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,13 +6,13 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_ -#define FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_ +#ifndef FLANG_RT_RUNTIME_RANDOM_TEMPLATES_H_ +#define FLANG_RT_RUNTIME_RANDOM_TEMPLATES_H_ +#include "descriptor.h" #include "lock.h" #include "numeric-templates.h" #include "flang/Common/optional.h" -#include "flang/Runtime/descriptor.h" #include #include @@ -108,4 +108,4 @@ inline void GenerateUnsigned(const Descriptor &harvest) { } // namespace Fortran::runtime::random -#endif // FORTRAN_RUNTIME_RANDOM_TEMPLATES_H_ +#endif // FLANG_RT_RUNTIME_RANDOM_TEMPLATES_H_ diff --git a/flang/runtime/reduction-templates.h b/flang-rt/include/flang-rt/runtime/reduction-templates.h similarity index 98% rename from flang/runtime/reduction-templates.h rename to flang-rt/include/flang-rt/runtime/reduction-templates.h index b20b03655c3d0..8c6f838b8dadf 100644 --- a/flang/runtime/reduction-templates.h +++ b/flang-rt/include/flang-rt/runtime/reduction-templates.h @@ -1,4 +1,4 @@ -//===-- runtime/reduction-templates.h ---------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/reduction-templates.h ----------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -18,14 +18,14 @@ // * Character-valued reductions (MAXVAL & MINVAL) return arbitrary // length results, dynamically allocated in a caller-supplied descriptor -#ifndef FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_ -#define FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_ +#ifndef FLANG_RT_RUNTIME_REDUCTION_TEMPLATES_H_ +#define FLANG_RT_RUNTIME_REDUCTION_TEMPLATES_H_ +#include "descriptor.h" #include "numeric-templates.h" #include "terminator.h" #include "tools.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include namespace Fortran::runtime { @@ -416,4 +416,4 @@ template struct Norm2Helper { }; } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_REDUCTION_TEMPLATES_H_ +#endif // FLANG_RT_RUNTIME_REDUCTION_TEMPLATES_H_ diff --git a/flang/runtime/stat.h b/flang-rt/include/flang-rt/runtime/stat.h similarity index 93% rename from flang/runtime/stat.h rename to flang-rt/include/flang-rt/runtime/stat.h index 572cb6d10b489..070d0bf8673fb 100644 --- a/flang/runtime/stat.h +++ b/flang-rt/include/flang-rt/runtime/stat.h @@ -1,4 +1,4 @@ -//===-- runtime/stat.h ------------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/stat.h -------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,8 +9,8 @@ // Defines the values returned by the runtime for STAT= specifiers // on executable statements. -#ifndef FORTRAN_RUNTIME_STAT_H_ -#define FORTRAN_RUNTIME_STAT_H_ +#ifndef FLANG_RT_RUNTIME_STAT_H_ +#define FLANG_RT_RUNTIME_STAT_H_ #include "flang/Common/ISO_Fortran_binding_wrapper.h" #include "flang/Common/api-attrs.h" #include "flang/Runtime/magic-numbers.h" @@ -60,4 +60,4 @@ RT_API_ATTRS int ToErrmsg(const Descriptor *errmsg, int stat); // returns stat RT_API_ATTRS int ReturnError(Terminator &, int stat, const Descriptor *errmsg = nullptr, bool hasStat = false); } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_STAT_H +#endif // FLANG_RT_RUNTIME_STAT_H_ diff --git a/flang/runtime/terminator.h b/flang-rt/include/flang-rt/runtime/terminator.h similarity index 95% rename from flang/runtime/terminator.h rename to flang-rt/include/flang-rt/runtime/terminator.h index 609f059d6e092..4815f0674c849 100644 --- a/flang/runtime/terminator.h +++ b/flang-rt/include/flang-rt/runtime/terminator.h @@ -1,4 +1,4 @@ -//===-- runtime/terminator.h ------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/terminator.h -------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,8 +8,8 @@ // Termination of the image -#ifndef FORTRAN_RUNTIME_TERMINATOR_H_ -#define FORTRAN_RUNTIME_TERMINATOR_H_ +#ifndef FLANG_RT_RUNTIME_TERMINATOR_H_ +#define FLANG_RT_RUNTIME_TERMINATOR_H_ #include "flang/Common/api-attrs.h" #include @@ -121,4 +121,4 @@ namespace Fortran::runtime::io { RT_API_ATTRS void FlushOutputOnCrash(const Terminator &); } -#endif // FORTRAN_RUNTIME_TERMINATOR_H_ +#endif // FLANG_RT_RUNTIME_TERMINATOR_H_ diff --git a/flang/runtime/tools.h b/flang-rt/include/flang-rt/runtime/tools.h similarity index 98% rename from flang/runtime/tools.h rename to flang-rt/include/flang-rt/runtime/tools.h index 75544098d47ab..91a026bf2ac14 100644 --- a/flang/runtime/tools.h +++ b/flang-rt/include/flang-rt/runtime/tools.h @@ -1,4 +1,4 @@ -//===-- runtime/tools.h -----------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/tools.h ------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,16 +6,16 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_TOOLS_H_ -#define FORTRAN_RUNTIME_TOOLS_H_ +#ifndef FLANG_RT_RUNTIME_TOOLS_H_ +#define FLANG_RT_RUNTIME_TOOLS_H_ +#include "descriptor.h" +#include "memory.h" #include "stat.h" #include "terminator.h" #include "flang/Common/optional.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include "flang/Runtime/freestanding-tools.h" -#include "flang/Runtime/memory.h" #include #include #include @@ -348,7 +348,7 @@ inline RT_API_ATTRS RESULT ApplyFloatingPointKind( if constexpr (HasCppTypeFor) { // If FUNC implemenation relies on FP math functions, // then we should not be here. The compiler should have - // generated a call to an entry in flang_rt.quadmath + // generated a call to an entry in the libflang_rt.quadmath // library. if constexpr (!NEEDSMATH) { return FUNC<16>{}(std::forward(x)...); @@ -570,4 +570,4 @@ RT_API_ATTRS void CreatePartialReductionResult(Descriptor &result, const char *intrinsic, TypeCode); } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_TOOLS_H_ +#endif // FLANG_RT_RUNTIME_TOOLS_H_ diff --git a/flang/include/flang/Runtime/type-code.h b/flang-rt/include/flang-rt/runtime/type-code.h similarity index 93% rename from flang/include/flang/Runtime/type-code.h rename to flang-rt/include/flang-rt/runtime/type-code.h index ae854ed2145e4..9416a2816fd43 100644 --- a/flang/include/flang/Runtime/type-code.h +++ b/flang-rt/include/flang-rt/runtime/type-code.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/type-code.h -----------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/type-code.h --------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_TYPE_CODE_H_ -#define FORTRAN_RUNTIME_TYPE_CODE_H_ +#ifndef FLANG_RT_RUNTIME_TYPE_CODE_H_ +#define FLANG_RT_RUNTIME_TYPE_CODE_H_ #include "flang/Common/Fortran-consts.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" @@ -75,4 +75,4 @@ class TypeCode { ISO::CFI_type_t raw_{CFI_type_other}; }; } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_TYPE_CODE_H_ +#endif // FLANG_RT_RUNTIME_TYPE_CODE_H_ diff --git a/flang/runtime/type-info.h b/flang-rt/include/flang-rt/runtime/type-info.h similarity index 98% rename from flang/runtime/type-info.h rename to flang-rt/include/flang-rt/runtime/type-info.h index 32403b1db5169..9891fcecdcb25 100644 --- a/flang/runtime/type-info.h +++ b/flang-rt/include/flang-rt/runtime/type-info.h @@ -1,4 +1,4 @@ -//===-- runtime/type-info.h -------------------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/type-info.h --------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,17 +6,17 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_TYPE_INFO_H_ -#define FORTRAN_RUNTIME_TYPE_INFO_H_ +#ifndef FLANG_RT_RUNTIME_TYPE_INFO_H_ +#define FLANG_RT_RUNTIME_TYPE_INFO_H_ // A C++ perspective of the derived type description schemata in // flang/module/__fortran_type_info.f90. +#include "descriptor.h" #include "terminator.h" #include "flang/Common/Fortran-consts.h" #include "flang/Common/bit-population-count.h" #include "flang/Common/optional.h" -#include "flang/Runtime/descriptor.h" #include #include @@ -321,4 +321,4 @@ class DerivedType { }; } // namespace Fortran::runtime::typeInfo -#endif // FORTRAN_RUNTIME_TYPE_INFO_H_ +#endif // FLANG_RT_RUNTIME_TYPE_INFO_H_ diff --git a/flang/runtime/utf.h b/flang-rt/include/flang-rt/runtime/utf.h similarity index 94% rename from flang/runtime/utf.h rename to flang-rt/include/flang-rt/runtime/utf.h index 10c2d61484217..b5add823124fc 100644 --- a/flang/runtime/utf.h +++ b/flang-rt/include/flang-rt/runtime/utf.h @@ -1,4 +1,4 @@ -//===-- runtime/utf.h -----------------------------------------------------===// +//===-- include/flang-rt/runtime/utf.h --------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -38,8 +38,8 @@ // standard maximum. However, we support extended forms up to 32 bits so that // CHARACTER(KIND=4) can be abused to hold arbitrary 32-bit data. -#ifndef FORTRAN_RUNTIME_UTF_H_ -#define FORTRAN_RUNTIME_UTF_H_ +#ifndef FLANG_RT_RUNTIME_UTF_H_ +#define FLANG_RT_RUNTIME_UTF_H_ #include "flang/Common/optional.h" #include @@ -70,4 +70,4 @@ RT_API_ATTRS Fortran::common::optional DecodeUTF8(const char *); RT_API_ATTRS std::size_t EncodeUTF8(char *, char32_t); } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_UTF_H_ +#endif // FLANG_RT_RUNTIME_UTF_H_ diff --git a/flang-rt/lib/CMakeLists.txt b/flang-rt/lib/CMakeLists.txt new file mode 100644 index 0000000000000..aee51dcc9fa24 --- /dev/null +++ b/flang-rt/lib/CMakeLists.txt @@ -0,0 +1,17 @@ +#===-- lib/CMakeLists.txt --------------------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +add_subdirectory(quadmath) +add_subdirectory(runtime) +if (FLANG_RT_INCLUDE_CUF) + add_subdirectory(cuda) +endif() + +if (FLANG_RT_INCLUDE_TESTS) + add_subdirectory(Testing) +endif () diff --git a/flang-rt/lib/Testing/CMakeLists.txt b/flang-rt/lib/Testing/CMakeLists.txt new file mode 100644 index 0000000000000..19c20ad44c025 --- /dev/null +++ b/flang-rt/lib/Testing/CMakeLists.txt @@ -0,0 +1,20 @@ +#===-- lib/Testing/CMakeLists.txt ------------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +set(public_headers "") +file(GLOB_RECURSE public_headers + "${FLANG_SOURCE_DIR}/lib/Testing/*.h" +) + +add_flangrt_library(NonGTestTesting EXCLUDE_FROM_ALL LINK_TO_LLVM + ${FLANG_SOURCE_DIR}/lib/Testing/testing.cpp + ${FLANG_SOURCE_DIR}/lib/Testing/fp-testing.cpp + + ADDITIONAL_HEADERS + ${public_headers} + ) diff --git a/flang-rt/lib/cuda/CMakeLists.txt b/flang-rt/lib/cuda/CMakeLists.txt new file mode 100644 index 0000000000000..d5ca354c1029f --- /dev/null +++ b/flang-rt/lib/cuda/CMakeLists.txt @@ -0,0 +1,34 @@ +#===-- lib/cuda/CMakeLists.txt ---------------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + + +add_flangrt_library(flang_rt.cuda STATIC + allocatable.cpp + allocator.cpp + descriptor.cpp + init.cpp + kernel.cpp + memmove-function.cpp + memory.cpp + registration.cpp + + # libflang_rt.runtime depends on a certain version of CUDA. To be able to have + # multiple build of this library with different CUDA version, the version is + # added to the library name. + TARGET_PROPERTIES + OUTPUT_NAME "flang_rt.cuda_${CUDAToolkit_VERSION_MAJOR}" + + INCLUDE_DIRECTORIES + PRIVATE ${CUDAToolkit_INCLUDE_DIRS} +) + +target_link_libraries(flang_rt.cuda + PUBLIC + flang_rt.runtime + CUDA::cudart_static +) diff --git a/flang/runtime/CUDA/allocatable.cpp b/flang-rt/lib/cuda/allocatable.cpp similarity index 94% rename from flang/runtime/CUDA/allocatable.cpp rename to flang-rt/lib/cuda/allocatable.cpp index 6df3b06793b3e..b773e802c90ff 100644 --- a/flang/runtime/CUDA/allocatable.cpp +++ b/flang-rt/lib/cuda/allocatable.cpp @@ -1,4 +1,4 @@ -//===-- runtime/CUDA/allocatable.cpp --------------------------------------===// +//===-- lib/cuda/allocatable.cpp --------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,9 +7,10 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/CUDA/allocatable.h" -#include "../assign-impl.h" -#include "../stat.h" -#include "../terminator.h" +#include "flang-rt/runtime/assign-impl.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/common.h" #include "flang/Runtime/CUDA/descriptor.h" #include "flang/Runtime/CUDA/memmove-function.h" diff --git a/flang/runtime/CUDA/allocator.cpp b/flang-rt/lib/cuda/allocator.cpp similarity index 86% rename from flang/runtime/CUDA/allocator.cpp rename to flang-rt/lib/cuda/allocator.cpp index 368c1124ef70a..4199bf04b33f0 100644 --- a/flang/runtime/CUDA/allocator.cpp +++ b/flang-rt/lib/cuda/allocator.cpp @@ -1,4 +1,4 @@ -//===-- runtime/CUDA/allocator.cpp ----------------------------------------===// +//===-- lib/cuda/allocator.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,13 +7,13 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/CUDA/allocator.h" -#include "../derived.h" -#include "../stat.h" -#include "../terminator.h" -#include "../type-info.h" +#include "flang-rt/runtime/allocator-registry.h" +#include "flang-rt/runtime/derived.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/type-info.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" #include "flang/Runtime/CUDA/common.h" -#include "flang/Runtime/allocator-registry.h" #include "flang/Support/Fortran.h" #include "cuda_runtime.h" diff --git a/flang/runtime/CUDA/descriptor.cpp b/flang-rt/lib/cuda/descriptor.cpp similarity index 91% rename from flang/runtime/CUDA/descriptor.cpp rename to flang-rt/lib/cuda/descriptor.cpp index 947eeb66aa3d6..d44ab2e45d2a8 100644 --- a/flang/runtime/CUDA/descriptor.cpp +++ b/flang-rt/lib/cuda/descriptor.cpp @@ -1,4 +1,4 @@ -//===-- runtime/CUDA/descriptor.cpp ---------------------------------------===// +//===-- lib/cuda/descriptor.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,10 +7,10 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/CUDA/descriptor.h" -#include "../terminator.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/allocator.h" #include "flang/Runtime/CUDA/common.h" -#include "flang/Runtime/descriptor.h" #include "cuda_runtime.h" diff --git a/flang/runtime/CUDA/init.cpp b/flang-rt/lib/cuda/init.cpp similarity index 81% rename from flang/runtime/CUDA/init.cpp rename to flang-rt/lib/cuda/init.cpp index 2bffce842b952..d79bffc32424d 100644 --- a/flang/runtime/CUDA/init.cpp +++ b/flang-rt/lib/cuda/init.cpp @@ -1,4 +1,4 @@ -//===-- runtime/CUDA/init.cpp ---------------------------------------------===// +//===-- lib/cuda/init.cpp ---------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/CUDA/init.h" -#include "../environment.h" -#include "../terminator.h" +#include "flang-rt/runtime/environment.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/common.h" #include "cuda_runtime.h" diff --git a/flang/runtime/CUDA/kernel.cpp b/flang-rt/lib/cuda/kernel.cpp similarity index 98% rename from flang/runtime/CUDA/kernel.cpp rename to flang-rt/lib/cuda/kernel.cpp index 02d89fb8423a5..75eb639817b9a 100644 --- a/flang/runtime/CUDA/kernel.cpp +++ b/flang-rt/lib/cuda/kernel.cpp @@ -1,4 +1,4 @@ -//===-- runtime/CUDA/kernel.cpp -------------------------------------------===// +//===-- lib/cuda/kernel.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/CUDA/kernel.h" -#include "../terminator.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/common.h" #include "cuda_runtime.h" diff --git a/flang/runtime/CUDA/memmove-function.cpp b/flang-rt/lib/cuda/memmove-function.cpp similarity index 90% rename from flang/runtime/CUDA/memmove-function.cpp rename to flang-rt/lib/cuda/memmove-function.cpp index 3ba9fa7e0f7f7..a7eb0cf1a3e7a 100644 --- a/flang/runtime/CUDA/memmove-function.cpp +++ b/flang-rt/lib/cuda/memmove-function.cpp @@ -1,4 +1,4 @@ -//===-- runtime/CUDA/memmove-function.cpp ---------------------------------===// +//===-- lib/cuda/memmove-function.cpp ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/CUDA/memmove-function.h" -#include "../terminator.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/common.h" #include "cuda_runtime.h" diff --git a/flang/runtime/CUDA/memory.cpp b/flang-rt/lib/cuda/memory.cpp similarity index 96% rename from flang/runtime/CUDA/memory.cpp rename to flang-rt/lib/cuda/memory.cpp index 0bbb493d2db91..7ead0dd35e1d9 100644 --- a/flang/runtime/CUDA/memory.cpp +++ b/flang-rt/lib/cuda/memory.cpp @@ -1,4 +1,4 @@ -//===-- runtime/CUDA/memory.cpp -------------------------------------------===// +//===-- lib/cuda/memory.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/CUDA/memory.h" -#include "../assign-impl.h" -#include "../terminator.h" +#include "flang-rt/runtime/assign-impl.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/common.h" #include "flang/Runtime/CUDA/descriptor.h" #include "flang/Runtime/CUDA/memmove-function.h" diff --git a/flang/runtime/CUDA/pointer.cpp b/flang-rt/lib/cuda/pointer.cpp similarity index 92% rename from flang/runtime/CUDA/pointer.cpp rename to flang-rt/lib/cuda/pointer.cpp index d3ebe97b4e4ac..c2559ecb9a6f2 100644 --- a/flang/runtime/CUDA/pointer.cpp +++ b/flang-rt/lib/cuda/pointer.cpp @@ -1,4 +1,4 @@ -//===-- runtime/CUDA/pointer.cpp ------------------------------------------===// +//===-- lib/cuda/pointer.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,9 +7,10 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/CUDA/pointer.h" -#include "../assign-impl.h" -#include "../stat.h" -#include "../terminator.h" +#include "flang-rt/runtime/assign-impl.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/descriptor.h" #include "flang/Runtime/CUDA/memmove-function.h" #include "flang/Runtime/pointer.h" diff --git a/flang/runtime/CUDA/registration.cpp b/flang-rt/lib/cuda/registration.cpp similarity index 92% rename from flang/runtime/CUDA/registration.cpp rename to flang-rt/lib/cuda/registration.cpp index b7b6ef389bffb..60b0e491b6ffd 100644 --- a/flang/runtime/CUDA/registration.cpp +++ b/flang-rt/lib/cuda/registration.cpp @@ -1,4 +1,4 @@ -//===-- runtime/CUDA/registration.cpp -------------------------------------===// +//===-- lib/cuda/registration.cpp -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/CUDA/registration.h" -#include "../terminator.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/common.h" #include "cuda_runtime.h" diff --git a/flang-rt/lib/quadmath/CMakeLists.txt b/flang-rt/lib/quadmath/CMakeLists.txt new file mode 100644 index 0000000000000..4f113216b42c8 --- /dev/null +++ b/flang-rt/lib/quadmath/CMakeLists.txt @@ -0,0 +1,136 @@ +#===-- lib/quadmath/CMakeLists.txt -----------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +# FortranFloat128 implements IEEE-754 128-bit float math functions. +# It is a thin wapper and it currently relies on third-party +# libraries available for the target. +# It is distributed as a static library only. +# Fortran programs/libraries that end up linking any of the provided +# will have a dependency on the third-party library that is being +# used for building this libflang_rt.quadmath library. + +include(CheckLibraryExists) +include(CheckIncludeFile) + +set(sources + acos.cpp + acosh.cpp + asin.cpp + asinh.cpp + atan.cpp + atan2.cpp + atanh.cpp + ceil.cpp + complex-math.c + cos.cpp + cosh.cpp + erf.cpp + erfc.cpp + exp.cpp + exponent.cpp + floor.cpp + fma.cpp + fraction.cpp + hypot.cpp + j0.cpp + j1.cpp + jn.cpp + lgamma.cpp + llround.cpp + log.cpp + log10.cpp + lround.cpp + mod-real.cpp + modulo-real.cpp + nearest.cpp + nearbyint.cpp + norm2.cpp + pow.cpp + random.cpp + remainder.cpp + round.cpp + rrspacing.cpp + scale.cpp + set-exponent.cpp + sin.cpp + sinh.cpp + spacing.cpp + sqrt.cpp + tan.cpp + tanh.cpp + tgamma.cpp + trunc.cpp + y0.cpp + y1.cpp + yn.cpp + ) + +include_directories(AFTER "${CMAKE_CURRENT_SOURCE_DIR}/..") +add_library(FortranFloat128MathILib INTERFACE) +target_include_directories(FortranFloat128MathILib INTERFACE + $ + ) + +if (FLANG_RUNTIME_F128_MATH_LIB) + if (${FLANG_RUNTIME_F128_MATH_LIB} STREQUAL "libquadmath") + check_include_file(quadmath.h FOUND_QUADMATH_HEADER) + if(FOUND_QUADMATH_HEADER) + add_compile_definitions(HAS_QUADMATHLIB) + else() + message(FATAL_ERROR + "FLANG_RUNTIME_F128_MATH_LIB setting requires quadmath.h " + "to be available: ${FLANG_RUNTIME_F128_MATH_LIB}" + ) + endif() + else() + message(FATAL_ERROR + "Unsupported third-party library for Fortran F128 math runtime: " + "${FLANG_RUNTIME_F128_MATH_LIB}" + ) + endif() + + if (WIN32) + # Do not create a flang_rt.quadmath library under Windows, the Flang + # driver never links it. Instead, add the sources to flang_rt.runtime. + target_sources(FortranFloat128MathILib INTERFACE ${sources}) + target_compile_definitions(FortranFloat128MathILib INTERFACE HAS_QUADMATHLIB) + else () + add_flangrt_library(flang_rt.quadmath STATIC INSTALL_WITH_TOOLCHAIN + ${sources}) + target_include_directories(flang_rt.quadmath PRIVATE + "${FLANG_RT_SOURCE_DIR}/lib/flang_rt" + ) + endif () +elseif (HAVE_LDBL_MANT_DIG_113) + # We can use 'long double' versions from libc. + check_library_exists(m sinl "" FOUND_LIBM) + if (FOUND_LIBM) + target_compile_definitions(FortranFloat128MathILib INTERFACE + HAS_LIBM + ) + target_include_directories(FortranFloat128MathILib INTERFACE + "${FLANG_RT_SOURCE_DIR}/lib/flang_rt" + ) + target_sources(FortranFloat128MathILib INTERFACE ${sources}) + else() + message(FATAL_ERROR "Flang-RT cannot build without libm") + endif() +else() + # We can use '__float128' version from libc, if it has them. + check_library_exists(m sinf128 "" FOUND_LIBMF128) + if (FOUND_LIBMF128) + target_compile_definitions(FortranFloat128MathILib INTERFACE + HAS_LIBMF128 + ) + target_include_directories(FortranFloat128MathILib INTERFACE + "${FLANG_RT_SOURCE_DIR}/lib/flang_rt" + ) + # Enable this, when math-entries.h and complex-math.h is ready. + # target_sources(FortranFloat128MathILib INTERFACE ${sources}) + endif() +endif() diff --git a/flang/runtime/Float128Math/acos.cpp b/flang-rt/lib/quadmath/acos.cpp similarity index 87% rename from flang/runtime/Float128Math/acos.cpp rename to flang-rt/lib/quadmath/acos.cpp index d9b4950aa1e35..d094121f0f678 100644 --- a/flang/runtime/Float128Math/acos.cpp +++ b/flang-rt/lib/quadmath/acos.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/acos.cpp -------------------------------------===// +//===-- lib/quadmath/acos.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/acosh.cpp b/flang-rt/lib/quadmath/acosh.cpp similarity index 87% rename from flang/runtime/Float128Math/acosh.cpp rename to flang-rt/lib/quadmath/acosh.cpp index c572673ef55e6..968aa489d15a2 100644 --- a/flang/runtime/Float128Math/acosh.cpp +++ b/flang-rt/lib/quadmath/acosh.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/acosh.cpp ------------------------------------===// +//===-- lib/quadmath/acosh.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/asin.cpp b/flang-rt/lib/quadmath/asin.cpp similarity index 87% rename from flang/runtime/Float128Math/asin.cpp rename to flang-rt/lib/quadmath/asin.cpp index 57b6ffd967360..c3345cd3d748a 100644 --- a/flang/runtime/Float128Math/asin.cpp +++ b/flang-rt/lib/quadmath/asin.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/asin.cpp -------------------------------------===// +//===-- lib/quadmath/asin.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/asinh.cpp b/flang-rt/lib/quadmath/asinh.cpp similarity index 87% rename from flang/runtime/Float128Math/asinh.cpp rename to flang-rt/lib/quadmath/asinh.cpp index 03dded722b254..1023b678b6131 100644 --- a/flang/runtime/Float128Math/asinh.cpp +++ b/flang-rt/lib/quadmath/asinh.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/asinh.cpp ------------------------------------===// +//===-- lib/quadmath/asinh.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/atan.cpp b/flang-rt/lib/quadmath/atan.cpp similarity index 87% rename from flang/runtime/Float128Math/atan.cpp rename to flang-rt/lib/quadmath/atan.cpp index 19c86cae8867b..6379df3275c03 100644 --- a/flang/runtime/Float128Math/atan.cpp +++ b/flang-rt/lib/quadmath/atan.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/atan.cpp -------------------------------------===// +//===-- lib/quadmath/atan.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/atan2.cpp b/flang-rt/lib/quadmath/atan2.cpp similarity index 88% rename from flang/runtime/Float128Math/atan2.cpp rename to flang-rt/lib/quadmath/atan2.cpp index 09d666ae14304..7527b224cb3a5 100644 --- a/flang/runtime/Float128Math/atan2.cpp +++ b/flang-rt/lib/quadmath/atan2.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/atan2.cpp ------------------------------------===// +//===-- lib/quadmath/atan2.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/atanh.cpp b/flang-rt/lib/quadmath/atanh.cpp similarity index 87% rename from flang/runtime/Float128Math/atanh.cpp rename to flang-rt/lib/quadmath/atanh.cpp index 442d9beafae47..c7455fcb7ca67 100644 --- a/flang/runtime/Float128Math/atanh.cpp +++ b/flang-rt/lib/quadmath/atanh.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/atanh.cpp ------------------------------------===// +//===-- lib/quadmath/atanh.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/ceil.cpp b/flang-rt/lib/quadmath/ceil.cpp similarity index 87% rename from flang/runtime/Float128Math/ceil.cpp rename to flang-rt/lib/quadmath/ceil.cpp index 48e20b2b41577..03a98bedfdc03 100644 --- a/flang/runtime/Float128Math/ceil.cpp +++ b/flang-rt/lib/quadmath/ceil.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/ceil.cpp -------------------------------------===// +//===-- lib/quadmath/ceil.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/complex-math.c b/flang-rt/lib/quadmath/complex-math.c similarity index 92% rename from flang/runtime/Float128Math/complex-math.c rename to flang-rt/lib/quadmath/complex-math.c index a7e32f3ef755b..e485fd7eb5dbb 100644 --- a/flang/runtime/Float128Math/complex-math.c +++ b/flang-rt/lib/quadmath/complex-math.c @@ -1,11 +1,10 @@ -/*===-- runtime/Float128Math/complex-math.c -------------------------*- C -*-=== +/*===-- lib/quadmath/complex-math.c ---------------------------------*- 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 * - * ===-----------------------------------------------------------------------=== - */ + *===----------------------------------------------------------------------===*/ #include "complex-math.h" diff --git a/flang/runtime/Float128Math/complex-math.h b/flang-rt/lib/quadmath/complex-math.h similarity index 88% rename from flang/runtime/Float128Math/complex-math.h rename to flang-rt/lib/quadmath/complex-math.h index cf5e980a39b6b..424ed84da4e01 100644 --- a/flang/runtime/Float128Math/complex-math.h +++ b/flang-rt/lib/quadmath/complex-math.h @@ -1,4 +1,4 @@ -/*===-- runtime/Float128Math/complex-math.h -------------------------*- C -*-=== +/*===-- lib/quadmath/complex-math.h ---------------------------------*- C -*-=== * * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. * See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ * *===----------------------------------------------------------------------===*/ -#ifndef FORTRAN_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_ -#define FORTRAN_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_ +#ifndef FLANG_RT_QUADMATH_COMPLEX_MATH_H_ +#define FLANG_RT_QUADMATH_COMPLEX_MATH_H_ #include "flang/Common/float128.h" #include "flang/Runtime/entry-names.h" @@ -59,4 +59,4 @@ #error "Float128Math build with glibc>=2.26 is unsupported yet" #endif -#endif /* FORTRAN_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_ */ +#endif /* FLANG_RT_QUADMATH_COMPLEX_MATH_H_ */ diff --git a/flang/runtime/Float128Math/cos.cpp b/flang-rt/lib/quadmath/cos.cpp similarity index 87% rename from flang/runtime/Float128Math/cos.cpp rename to flang-rt/lib/quadmath/cos.cpp index d1b3e0e736ca3..1116080c53d2a 100644 --- a/flang/runtime/Float128Math/cos.cpp +++ b/flang-rt/lib/quadmath/cos.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/cos.cpp --------------------------------------===// +//===-- lib/quadmath/cos.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/cosh.cpp b/flang-rt/lib/quadmath/cosh.cpp similarity index 87% rename from flang/runtime/Float128Math/cosh.cpp rename to flang-rt/lib/quadmath/cosh.cpp index 9fe5b61d8f95f..dd5978e5e5f08 100644 --- a/flang/runtime/Float128Math/cosh.cpp +++ b/flang-rt/lib/quadmath/cosh.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/cosh.cpp -------------------------------------===// +//===-- lib/quadmath/cosh.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/erf.cpp b/flang-rt/lib/quadmath/erf.cpp similarity index 87% rename from flang/runtime/Float128Math/erf.cpp rename to flang-rt/lib/quadmath/erf.cpp index 2a553bd395e88..0021b7900f6a1 100644 --- a/flang/runtime/Float128Math/erf.cpp +++ b/flang-rt/lib/quadmath/erf.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/erf.cpp --------------------------------------===// +//===-- lib/quadmath/erf.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/erfc.cpp b/flang-rt/lib/quadmath/erfc.cpp similarity index 87% rename from flang/runtime/Float128Math/erfc.cpp rename to flang-rt/lib/quadmath/erfc.cpp index 2435ed2786cb3..5b80fb475b3fc 100644 --- a/flang/runtime/Float128Math/erfc.cpp +++ b/flang-rt/lib/quadmath/erfc.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/erfc.cpp -------------------------------------===// +//===-- lib/quadmath/erfc.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/exp.cpp b/flang-rt/lib/quadmath/exp.cpp similarity index 87% rename from flang/runtime/Float128Math/exp.cpp rename to flang-rt/lib/quadmath/exp.cpp index 5ca87d9dd25d2..94e444c3b00c7 100644 --- a/flang/runtime/Float128Math/exp.cpp +++ b/flang-rt/lib/quadmath/exp.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/exp.cpp --------------------------------------===// +//===-- lib/quadmath/exp.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/exponent.cpp b/flang-rt/lib/quadmath/exponent.cpp similarity index 90% rename from flang/runtime/Float128Math/exponent.cpp rename to flang-rt/lib/quadmath/exponent.cpp index 237cde34e8691..0d2fa6478cca8 100644 --- a/flang/runtime/Float128Math/exponent.cpp +++ b/flang-rt/lib/quadmath/exponent.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/exponent.cpp ---------------------------------===// +//===-- lib/quadmath/exponent.cpp -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/floor.cpp b/flang-rt/lib/quadmath/floor.cpp similarity index 87% rename from flang/runtime/Float128Math/floor.cpp rename to flang-rt/lib/quadmath/floor.cpp index 28f9c7b55dd51..e5dfb33db82ce 100644 --- a/flang/runtime/Float128Math/floor.cpp +++ b/flang-rt/lib/quadmath/floor.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/floor.cpp ------------------------------------===// +//===-- lib/quadmath/floor.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/fma.cpp b/flang-rt/lib/quadmath/fma.cpp similarity index 89% rename from flang/runtime/Float128Math/fma.cpp rename to flang-rt/lib/quadmath/fma.cpp index 87176c25dd604..910303af32339 100644 --- a/flang/runtime/Float128Math/fma.cpp +++ b/flang-rt/lib/quadmath/fma.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/fma.cpp --------------------------------------===// +//===-- lib/quadmath/fma.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/fraction.cpp b/flang-rt/lib/quadmath/fraction.cpp similarity index 87% rename from flang/runtime/Float128Math/fraction.cpp rename to flang-rt/lib/quadmath/fraction.cpp index 45ec12cd77518..a9927666a7b00 100644 --- a/flang/runtime/Float128Math/fraction.cpp +++ b/flang-rt/lib/quadmath/fraction.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/fraction.cpp ---------------------------------===// +//===-- lib/quadmath/fraction.cpp -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/hypot.cpp b/flang-rt/lib/quadmath/hypot.cpp similarity index 88% rename from flang/runtime/Float128Math/hypot.cpp rename to flang-rt/lib/quadmath/hypot.cpp index 03049b06d3a24..3090d0b2aff74 100644 --- a/flang/runtime/Float128Math/hypot.cpp +++ b/flang-rt/lib/quadmath/hypot.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/hypot.cpp ------------------------------------===// +//===-- lib/quadmath/hypot.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/j0.cpp b/flang-rt/lib/quadmath/j0.cpp similarity index 87% rename from flang/runtime/Float128Math/j0.cpp rename to flang-rt/lib/quadmath/j0.cpp index 7207cbe1a92e7..06df1c2aca452 100644 --- a/flang/runtime/Float128Math/j0.cpp +++ b/flang-rt/lib/quadmath/j0.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/j0.cpp ---------------------------------------===// +//===-- lib/quadmath/j0.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/j1.cpp b/flang-rt/lib/quadmath/j1.cpp similarity index 87% rename from flang/runtime/Float128Math/j1.cpp rename to flang-rt/lib/quadmath/j1.cpp index 9e49bcbc32ca4..d8a1f123b95e6 100644 --- a/flang/runtime/Float128Math/j1.cpp +++ b/flang-rt/lib/quadmath/j1.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/j1.cpp ---------------------------------------===// +//===-- lib/quadmath/j1.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/jn.cpp b/flang-rt/lib/quadmath/jn.cpp similarity index 87% rename from flang/runtime/Float128Math/jn.cpp rename to flang-rt/lib/quadmath/jn.cpp index 37e5f428e5e26..a53e305bb8746 100644 --- a/flang/runtime/Float128Math/jn.cpp +++ b/flang-rt/lib/quadmath/jn.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/jn.cpp ---------------------------------------===// +//===-- lib/quadmath/jn.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/lgamma.cpp b/flang-rt/lib/quadmath/lgamma.cpp similarity index 87% rename from flang/runtime/Float128Math/lgamma.cpp rename to flang-rt/lib/quadmath/lgamma.cpp index 54d0dd8083868..b96dff1d0d72a 100644 --- a/flang/runtime/Float128Math/lgamma.cpp +++ b/flang-rt/lib/quadmath/lgamma.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/lgamma.cpp -----------------------------------===// +//===-- lib/quadmath/lgamma.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/llround.cpp b/flang-rt/lib/quadmath/llround.cpp similarity index 87% rename from flang/runtime/Float128Math/llround.cpp rename to flang-rt/lib/quadmath/llround.cpp index f0c53ccdf66fd..8f2913d390431 100644 --- a/flang/runtime/Float128Math/llround.cpp +++ b/flang-rt/lib/quadmath/llround.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/llround.cpp ----------------------------------===// +//===-- lib/quadmath/llround.cpp --------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/log.cpp b/flang-rt/lib/quadmath/log.cpp similarity index 87% rename from flang/runtime/Float128Math/log.cpp rename to flang-rt/lib/quadmath/log.cpp index 28fec1958f10b..0c489c922a3fc 100644 --- a/flang/runtime/Float128Math/log.cpp +++ b/flang-rt/lib/quadmath/log.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/log.cpp --------------------------------------===// +//===-- lib/quadmath/log.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/log10.cpp b/flang-rt/lib/quadmath/log10.cpp similarity index 87% rename from flang/runtime/Float128Math/log10.cpp rename to flang-rt/lib/quadmath/log10.cpp index f844d508f8d3b..a2f222e15a147 100644 --- a/flang/runtime/Float128Math/log10.cpp +++ b/flang-rt/lib/quadmath/log10.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/log10.cpp ------------------------------------===// +//===-- lib/quadmath/log10.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/lround.cpp b/flang-rt/lib/quadmath/lround.cpp similarity index 87% rename from flang/runtime/Float128Math/lround.cpp rename to flang-rt/lib/quadmath/lround.cpp index 8c2d3315c62a7..539ee107a3881 100644 --- a/flang/runtime/Float128Math/lround.cpp +++ b/flang-rt/lib/quadmath/lround.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/lround.cpp -----------------------------------===// +//===-- lib/quadmath/lround.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/math-entries.h b/flang-rt/lib/quadmath/math-entries.h similarity index 96% rename from flang/runtime/Float128Math/math-entries.h rename to flang-rt/lib/quadmath/math-entries.h index a94503fe8e67a..6e47f32cc8a43 100644 --- a/flang/runtime/Float128Math/math-entries.h +++ b/flang-rt/lib/quadmath/math-entries.h @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/math-entries.h ---------------------*- C++ -*-===// +//===-- lib/quadmath/math-entries.h -----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,11 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_ -#define FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_ -#include "terminator.h" -#include "tools.h" +#ifndef FLANG_RT_QUADMATH_MATH_ENTRIES_H_ +#define FLANG_RT_QUADMATH_MATH_ENTRIES_H_ + +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Common/float128.h" #include "flang/Runtime/entry-names.h" #include @@ -231,4 +232,4 @@ DEFINE_SIMPLE_ALIAS(Yn, ynl) } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_ +#endif // FLANG_RT_QUADMATH_MATH_ENTRIES_H_ diff --git a/flang/runtime/Float128Math/mod-real.cpp b/flang-rt/lib/quadmath/mod-real.cpp similarity index 88% rename from flang/runtime/Float128Math/mod-real.cpp rename to flang-rt/lib/quadmath/mod-real.cpp index e831c2df4abc1..0230964e3ddc2 100644 --- a/flang/runtime/Float128Math/mod-real.cpp +++ b/flang-rt/lib/quadmath/mod-real.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/mod-real.cpp ---------------------------------===// +//===-- lib/quadmath/mod-real.cpp -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/modulo-real.cpp b/flang-rt/lib/quadmath/modulo-real.cpp similarity index 89% rename from flang/runtime/Float128Math/modulo-real.cpp rename to flang-rt/lib/quadmath/modulo-real.cpp index 88729da7e3987..0f28747b86985 100644 --- a/flang/runtime/Float128Math/modulo-real.cpp +++ b/flang-rt/lib/quadmath/modulo-real.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/modulo-real.cpp ------------------------------===// +//===-- lib/quadmath/modulo-real.cpp ----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/nearbyint.cpp b/flang-rt/lib/quadmath/nearbyint.cpp similarity index 87% rename from flang/runtime/Float128Math/nearbyint.cpp rename to flang-rt/lib/quadmath/nearbyint.cpp index 9eecb0c5f3e2f..3811fc53d1d82 100644 --- a/flang/runtime/Float128Math/nearbyint.cpp +++ b/flang-rt/lib/quadmath/nearbyint.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/nearbyint.cpp --------------------------------===// +//===-- lib/quadmath/nearbyint.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/nearest.cpp b/flang-rt/lib/quadmath/nearest.cpp similarity index 88% rename from flang/runtime/Float128Math/nearest.cpp rename to flang-rt/lib/quadmath/nearest.cpp index 50f6e7ea75a60..8c1969a7b596c 100644 --- a/flang/runtime/Float128Math/nearest.cpp +++ b/flang-rt/lib/quadmath/nearest.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/nearest.cpp ----------------------------------===// +//===-- lib/quadmath/nearest.cpp --------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/norm2.cpp b/flang-rt/lib/quadmath/norm2.cpp similarity index 89% rename from flang/runtime/Float128Math/norm2.cpp rename to flang-rt/lib/quadmath/norm2.cpp index 18e9c8cc8a2b9..e98f4007737d1 100644 --- a/flang/runtime/Float128Math/norm2.cpp +++ b/flang-rt/lib/quadmath/norm2.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/norm2.cpp ------------------------------------===// +//===-- lib/quadmath/norm2.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,7 +8,7 @@ #include "math-entries.h" #include "numeric-template-specs.h" -#include "reduction-templates.h" +#include "flang-rt/runtime/reduction-templates.h" namespace Fortran::runtime { extern "C" { diff --git a/flang/runtime/Float128Math/numeric-template-specs.h b/flang-rt/lib/quadmath/numeric-template-specs.h similarity index 82% rename from flang/runtime/Float128Math/numeric-template-specs.h rename to flang-rt/lib/quadmath/numeric-template-specs.h index a0a77230c3e9e..e215ad70eca14 100644 --- a/flang/runtime/Float128Math/numeric-template-specs.h +++ b/flang-rt/lib/quadmath/numeric-template-specs.h @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/numeric-template-specs.h -----------*- C++ -*-===// +//===-- lib/quadmath/numeric-template-specs.h -------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,11 +6,11 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_ -#define FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_ +#ifndef FLANG_RT_QUADMATH_NUMERIC_TEMPLATE_SPECS_H_ +#define FLANG_RT_QUADMATH_NUMERIC_TEMPLATE_SPECS_H_ #include "math-entries.h" -#include "numeric-templates.h" +#include "flang-rt/runtime/numeric-templates.h" namespace Fortran::runtime { using F128Type = CppTypeFor; @@ -52,4 +52,4 @@ template <> struct SQRTTy { }; } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_ +#endif // FLANG_RT_QUADMATH_NUMERIC_TEMPLATE_SPECS_H_ diff --git a/flang/runtime/Float128Math/pow.cpp b/flang-rt/lib/quadmath/pow.cpp similarity index 88% rename from flang/runtime/Float128Math/pow.cpp rename to flang-rt/lib/quadmath/pow.cpp index 99aae04c65ecb..29c0536254658 100644 --- a/flang/runtime/Float128Math/pow.cpp +++ b/flang-rt/lib/quadmath/pow.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/pow.cpp --------------------------------------===// +//===-- lib/quadmath/pow.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/random.cpp b/flang-rt/lib/quadmath/random.cpp similarity index 83% rename from flang/runtime/Float128Math/random.cpp rename to flang-rt/lib/quadmath/random.cpp index 93c5c14cee37d..a6d22733ebce4 100644 --- a/flang/runtime/Float128Math/random.cpp +++ b/flang-rt/lib/quadmath/random.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/random.cpp -----------------------------------===// +//===-- lib/quadmath/random.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,7 +8,7 @@ #include "math-entries.h" #include "numeric-template-specs.h" -#include "random-templates.h" +#include "flang-rt/runtime/random-templates.h" using namespace Fortran::runtime::random; extern "C" { diff --git a/flang/runtime/Float128Math/remainder.cpp b/flang-rt/lib/quadmath/remainder.cpp similarity index 88% rename from flang/runtime/Float128Math/remainder.cpp rename to flang-rt/lib/quadmath/remainder.cpp index e5c2793dab71a..4b68cdd6ac9de 100644 --- a/flang/runtime/Float128Math/remainder.cpp +++ b/flang-rt/lib/quadmath/remainder.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/remainder.cpp --------------------------------===// +//===-- lib/quadmath/remainder.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/round.cpp b/flang-rt/lib/quadmath/round.cpp similarity index 89% rename from flang/runtime/Float128Math/round.cpp rename to flang-rt/lib/quadmath/round.cpp index e79ce30536b3b..844338f5e6413 100644 --- a/flang/runtime/Float128Math/round.cpp +++ b/flang-rt/lib/quadmath/round.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/round.cpp ------------------------------------===// +//===-- lib/quadmath/round.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/rrspacing.cpp b/flang-rt/lib/quadmath/rrspacing.cpp similarity index 87% rename from flang/runtime/Float128Math/rrspacing.cpp rename to flang-rt/lib/quadmath/rrspacing.cpp index 04cefc049bbee..e8613f4d7d7e2 100644 --- a/flang/runtime/Float128Math/rrspacing.cpp +++ b/flang-rt/lib/quadmath/rrspacing.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/rrspacing.cpp --------------------------------===// +//===-- lib/quadmath/rrspacing.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/scale.cpp b/flang-rt/lib/quadmath/scale.cpp similarity index 90% rename from flang/runtime/Float128Math/scale.cpp rename to flang-rt/lib/quadmath/scale.cpp index 6b083afbdf4d1..3d919f85a4487 100644 --- a/flang/runtime/Float128Math/scale.cpp +++ b/flang-rt/lib/quadmath/scale.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/scale.cpp ------------------------------------===// +//===-- lib/quadmath/scale.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/set-exponent.cpp b/flang-rt/lib/quadmath/set-exponent.cpp similarity index 88% rename from flang/runtime/Float128Math/set-exponent.cpp rename to flang-rt/lib/quadmath/set-exponent.cpp index 63c5b325085fb..d6b582e7c4f38 100644 --- a/flang/runtime/Float128Math/set-exponent.cpp +++ b/flang-rt/lib/quadmath/set-exponent.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/set-exponent.cpp -----------------------------===// +//===-- lib/quadmath/set-exponent.cpp ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/sin.cpp b/flang-rt/lib/quadmath/sin.cpp similarity index 87% rename from flang/runtime/Float128Math/sin.cpp rename to flang-rt/lib/quadmath/sin.cpp index 99fa3e493e694..dcff2f9ce02ca 100644 --- a/flang/runtime/Float128Math/sin.cpp +++ b/flang-rt/lib/quadmath/sin.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/sin.cpp --------------------------------------===// +//===-- lib/quadmath/sin.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/sinh.cpp b/flang-rt/lib/quadmath/sinh.cpp similarity index 87% rename from flang/runtime/Float128Math/sinh.cpp rename to flang-rt/lib/quadmath/sinh.cpp index b6cd96963612e..3ab7280f705a6 100644 --- a/flang/runtime/Float128Math/sinh.cpp +++ b/flang-rt/lib/quadmath/sinh.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/sinh.cpp -------------------------------------===// +//===-- lib/quadmath/sinh.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/spacing.cpp b/flang-rt/lib/quadmath/spacing.cpp similarity index 87% rename from flang/runtime/Float128Math/spacing.cpp rename to flang-rt/lib/quadmath/spacing.cpp index fc6aa2c4ec2d8..1d7ecdb4852d2 100644 --- a/flang/runtime/Float128Math/spacing.cpp +++ b/flang-rt/lib/quadmath/spacing.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/spacing.cpp ----------------------------------===// +//===-- lib/quadmath/spacing.cpp --------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/sqrt.cpp b/flang-rt/lib/quadmath/sqrt.cpp similarity index 87% rename from flang/runtime/Float128Math/sqrt.cpp rename to flang-rt/lib/quadmath/sqrt.cpp index 871c66e007984..6e0d11a6697f0 100644 --- a/flang/runtime/Float128Math/sqrt.cpp +++ b/flang-rt/lib/quadmath/sqrt.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/sqrt.cpp -------------------------------------===// +//===-- lib/quadmath/sqrt.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/tan.cpp b/flang-rt/lib/quadmath/tan.cpp similarity index 87% rename from flang/runtime/Float128Math/tan.cpp rename to flang-rt/lib/quadmath/tan.cpp index 2d6f448ba8955..6f09b93060228 100644 --- a/flang/runtime/Float128Math/tan.cpp +++ b/flang-rt/lib/quadmath/tan.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/tan.cpp --------------------------------------===// +//===-- lib/quadmath/tan.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/tanh.cpp b/flang-rt/lib/quadmath/tanh.cpp similarity index 87% rename from flang/runtime/Float128Math/tanh.cpp rename to flang-rt/lib/quadmath/tanh.cpp index f6321f4819191..214a18d5c3778 100644 --- a/flang/runtime/Float128Math/tanh.cpp +++ b/flang-rt/lib/quadmath/tanh.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/tanh.cpp -------------------------------------===// +//===-- lib/quadmath/tanh.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/tgamma.cpp b/flang-rt/lib/quadmath/tgamma.cpp similarity index 87% rename from flang/runtime/Float128Math/tgamma.cpp rename to flang-rt/lib/quadmath/tgamma.cpp index 98fd792a63330..2b05a60dcaabb 100644 --- a/flang/runtime/Float128Math/tgamma.cpp +++ b/flang-rt/lib/quadmath/tgamma.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/tgamma.cpp -----------------------------------===// +//===-- lib/quadmath/tgamma.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/trunc.cpp b/flang-rt/lib/quadmath/trunc.cpp similarity index 89% rename from flang/runtime/Float128Math/trunc.cpp rename to flang-rt/lib/quadmath/trunc.cpp index 54fa33176813c..cd7c27b569fc3 100644 --- a/flang/runtime/Float128Math/trunc.cpp +++ b/flang-rt/lib/quadmath/trunc.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/trunc.cpp ------------------------------------===// +//===-- lib/quadmath/trunc.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/y0.cpp b/flang-rt/lib/quadmath/y0.cpp similarity index 87% rename from flang/runtime/Float128Math/y0.cpp rename to flang-rt/lib/quadmath/y0.cpp index 0b3059b4cfe25..9db04277660ad 100644 --- a/flang/runtime/Float128Math/y0.cpp +++ b/flang-rt/lib/quadmath/y0.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/y0.cpp ---------------------------------------===// +//===-- lib/quadmath/y0.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/y1.cpp b/flang-rt/lib/quadmath/y1.cpp similarity index 87% rename from flang/runtime/Float128Math/y1.cpp rename to flang-rt/lib/quadmath/y1.cpp index cb39d87034dc7..92e658195f3d9 100644 --- a/flang/runtime/Float128Math/y1.cpp +++ b/flang-rt/lib/quadmath/y1.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/y1.cpp ---------------------------------------===// +//===-- lib/quadmath/y1.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/Float128Math/yn.cpp b/flang-rt/lib/quadmath/yn.cpp similarity index 87% rename from flang/runtime/Float128Math/yn.cpp rename to flang-rt/lib/quadmath/yn.cpp index bef8f9457df2f..20c0bc9d5218e 100644 --- a/flang/runtime/Float128Math/yn.cpp +++ b/flang-rt/lib/quadmath/yn.cpp @@ -1,4 +1,4 @@ -//===-- runtime/Float128Math/yn.cpp ---------------------------------------===// +//===-- lib/quadmath/yn.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt new file mode 100644 index 0000000000000..0afcbf2783533 --- /dev/null +++ b/flang-rt/lib/runtime/CMakeLists.txt @@ -0,0 +1,215 @@ +#===-- lib/runtime/CMakeLists.txt ------------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +include(AddFlangRTOffload) +# function checks +find_package(Backtrace) +set(HAVE_BACKTRACE ${Backtrace_FOUND}) +set(BACKTRACE_HEADER ${Backtrace_HEADER}) + + +# List of files that are buildable for all devices. +set(supported_sources + ${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp + ${FLANG_SOURCE_DIR}/lib/Decimal/decimal-to-binary.cpp + ISO_Fortran_binding.cpp + allocator-registry.cpp + allocatable.cpp + array-constructor.cpp + assign.cpp + buffer.cpp + character.cpp + connection.cpp + copy.cpp + derived-api.cpp + derived.cpp + descriptor-io.cpp + descriptor.cpp + dot-product.cpp + edit-input.cpp + edit-output.cpp + environment.cpp + external-unit.cpp + extrema.cpp + file.cpp + findloc.cpp + format.cpp + inquiry.cpp + internal-unit.cpp + io-api.cpp + io-api-minimal.cpp + io-error.cpp + io-stmt.cpp + iostat.cpp + matmul-transpose.cpp + matmul.cpp + memory.cpp + misc-intrinsic.cpp + namelist.cpp + non-tbp-dio.cpp + numeric.cpp + pointer.cpp + product.cpp + pseudo-unit.cpp + ragged.cpp + stat.cpp + sum.cpp + support.cpp + terminator.cpp + tools.cpp + transformational.cpp + type-code.cpp + type-info.cpp + unit.cpp + unit-map.cpp + utf.cpp +) + +# List of source not used for GPU offloading. +set(host_sources + ${FLANG_SOURCE_DIR}/module/iso_fortran_env_impl.f90 + command.cpp + complex-powi.cpp + complex-reduction.c + exceptions.cpp + execute.cpp + extensions.cpp + main.cpp + random.cpp + reduce.cpp + reduction.cpp + stop.cpp + temporary-stack.cpp + time-intrinsic.cpp +) + +file(GLOB_RECURSE public_headers + "${FLANG_RT_SOURCE_DIR}/include/flang_rt/*.h" + "${FLANG_SOURCE_DIR}/include/flang/Common/*.h" + ) + +file(GLOB_RECURSE private_headers + "${FLANG_RT_SOURCE_DIR}/lib/flang_rt/*.h" + "${FLANG_SOURCE_DIR}/lib/Common/*.h" + ) + + +# Import changes from flang_rt.quadmath +get_target_property(f128_sources + FortranFloat128MathILib INTERFACE_SOURCES + ) +if (f128_sources) + # The interface may define special macros for Float128Math files, + # so we need to propagate them. + get_target_property(f128_defs + FortranFloat128MathILib INTERFACE_COMPILE_DEFINITIONS + ) + set_property(SOURCE ${f128_sources} + APPEND PROPERTY COMPILE_DEFINITIONS + ${f128_defs} + ) + get_target_property(f128_include_dirs + FortranFloat128MathILib INTERFACE_INCLUDE_DIRECTORIES + ) + set_property(SOURCE ${f128_sources} + APPEND PROPERTY INCLUDE_DIRECTORIES + ${f128_include_dirs} + ) +else () + set(f128_sources "") +endif () + +set(sources ${supported_sources} ${host_sources} ${f128_sources}) + + +if (NOT WIN32) + add_flangrt_library(flang_rt.runtime STATIC + ${sources} + LINK_LIBRARIES ${Backtrace_LIBRARY} + INSTALL_WITH_TOOLCHAIN + ADDITIONAL_HEADERS ${public_headers} ${private_headers} + ) + + enable_cuda_compilation(flang_rt.runtime "${supported_sources}") + enable_omp_offload_compilation(flang_rt.runtime "${supported_sources}") + + # For unittests that depend on flang_rt. Should link to the static version + # of the library. + add_library(flang_rt.runtime.static ALIAS flang_rt.runtime) + add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime) +else() + # Target for building all versions of the runtime + add_custom_target(flang_rt.runtime) + set_target_properties(flang_rt.runtime PROPERTIES FOLDER "Flang-RT/Meta") + + function (add_win_flangrt_runtime libtype suffix msvc_lib) + set(name "flang_rt.runtime.${suffix}") + add_flangrt_library(${name} ${libtype} + ${sources} + ${ARGN} + LINK_LIBRARIES ${Backtrace_LIBRARY} + ADDITIONAL_HEADERS ${public_headers} ${private_headers} + ) + + if (msvc_lib) + set_target_properties(${name} + PROPERTIES + MSVC_RUNTIME_LIBRARY "${msvc_lib}" + ) + endif () + + # Setting an unique Fortran_MODULE_DIRECTORY is required for each variant to + # write a different .mod file. + set_target_properties(${name} + PROPERTIES + Fortran_MODULE_DIRECTORY "module.${suffix}" + ) + + enable_cuda_compilation(${name} "${supported_sources}") + enable_omp_offload_compilation(${name} "${supported_sources}") + add_dependencies(flang_rt.runtime ${name}) + endfunction () + + # Variants of the static flang_rt for different versions of the msvc runtime. + # + # The dynamic/dynamic_dbg variants are not DLLs themselves, only require + # linking to msvcrt(d).dll. + # FIXME: Generating actual runtime DLLs is currently not possible. There are + # two roadblocks: + # + # * Flang emits /DEFAULTLIB:flang_rt.dynamic.lib into + # iso_fortran_env_impl.f90.obj. Because that file is itself part of + # flang_rt.dynamic, this results in a recursive dependency when invoking + # the linker. + # + # * The externally-visible functions must either be annotated with + # __declspec(dllexport), or listed in an exports file. A possible workaround + # is CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS which would also export the internal + # C++ symbols and still requires global data symbols to be annotated + # manually. + add_win_flangrt_runtime(STATIC static MultiThreaded INSTALL_WITH_TOOLCHAIN) + add_win_flangrt_runtime(STATIC static_dbg MultiThreadedDebug INSTALL_WITH_TOOLCHAIN) + add_win_flangrt_runtime(STATIC dynamic MultiThreadedDLL INSTALL_WITH_TOOLCHAIN) + add_win_flangrt_runtime(STATIC dynamic_dbg MultiThreadedDebugDLL INSTALL_WITH_TOOLCHAIN) + + # Unittests link against LLVMSupport which is using CMake's default runtime + # library selection, which is either MultiThreadedDLL or MultiThreadedDebugDLL + # depending on the configuration. They have to match or linking will fail. + if (GENERATOR_IS_MULTI_CONFIG) + # We cannot select an ALIAS library because it may be different + # per configuration. Fallback to CMake's default. + add_win_flangrt_runtime(STATIC unittest "" EXCLUDE_FROM_ALL) + else () + string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) + if (build_type STREQUAL "debug") + add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg) + else () + add_library(flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic) + endif () + endif () +endif() diff --git a/flang/runtime/ISO_Fortran_binding.cpp b/flang-rt/lib/runtime/ISO_Fortran_binding.cpp similarity index 97% rename from flang/runtime/ISO_Fortran_binding.cpp rename to flang-rt/lib/runtime/ISO_Fortran_binding.cpp index 64e239f498230..a5f8b357ae0b8 100644 --- a/flang/runtime/ISO_Fortran_binding.cpp +++ b/flang-rt/lib/runtime/ISO_Fortran_binding.cpp @@ -1,4 +1,4 @@ -//===-- runtime/ISO_Fortran_binding.cpp -----------------------------------===// +//===-- lib/runtime/ISO_Fortran_binding.cpp ---------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,11 +10,11 @@ // as specified in section 18.5.5 of Fortran 2018. #include "ISO_Fortran_util.h" -#include "terminator.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/type-code.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" -#include "flang/Runtime/descriptor.h" #include "flang/Runtime/pointer.h" -#include "flang/Runtime/type-code.h" #include namespace Fortran::ISO { diff --git a/flang/runtime/ISO_Fortran_util.h b/flang-rt/lib/runtime/ISO_Fortran_util.h similarity index 90% rename from flang/runtime/ISO_Fortran_util.h rename to flang-rt/lib/runtime/ISO_Fortran_util.h index aca9aee8c5718..9bbc03eefc490 100644 --- a/flang/runtime/ISO_Fortran_util.h +++ b/flang-rt/lib/runtime/ISO_Fortran_util.h @@ -1,4 +1,4 @@ -//===-- runtime/ISO_Fortran_util.h ------------------------------*- C++ -*-===// +//===-- lib/runtime/ISO_Fortran_util.h --------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,15 +6,15 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_ -#define FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_ +#ifndef FLANG_RT_RUNTIME_ISO_FORTRAN_UTIL_H_ +#define FLANG_RT_RUNTIME_ISO_FORTRAN_UTIL_H_ // Internal utils for establishing CFI_cdesc_t descriptors. -#include "terminator.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/type-code.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" -#include "flang/Runtime/descriptor.h" -#include "flang/Runtime/type-code.h" #include namespace Fortran::ISO { @@ -99,4 +99,4 @@ static inline RT_API_ATTRS void EstablishDescriptor(CFI_cdesc_t *descriptor, } } } // namespace Fortran::ISO -#endif // FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_ +#endif // FLANG_RT_RUNTIME_ISO_FORTRAN_UTIL_H_ diff --git a/flang/runtime/allocatable.cpp b/flang-rt/lib/runtime/allocatable.cpp similarity index 96% rename from flang/runtime/allocatable.cpp rename to flang-rt/lib/runtime/allocatable.cpp index 686114bf86eaf..a51816129199a 100644 --- a/flang/runtime/allocatable.cpp +++ b/flang-rt/lib/runtime/allocatable.cpp @@ -1,4 +1,4 @@ -//===-- runtime/allocatable.cpp -------------------------------------------===// +//===-- lib/runtime/allocatable.cpp -----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,14 +7,14 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/allocatable.h" -#include "assign-impl.h" -#include "derived.h" -#include "stat.h" -#include "terminator.h" -#include "type-info.h" +#include "flang-rt/runtime/assign-impl.h" +#include "flang-rt/runtime/derived.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/type-info.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" #include "flang/Runtime/assign.h" -#include "flang/Runtime/descriptor.h" namespace Fortran::runtime { extern "C" { diff --git a/flang/runtime/allocator-registry.cpp b/flang-rt/lib/runtime/allocator-registry.cpp similarity index 87% rename from flang/runtime/allocator-registry.cpp rename to flang-rt/lib/runtime/allocator-registry.cpp index f5670331d6dbe..f8a8daaf8e748 100644 --- a/flang/runtime/allocator-registry.cpp +++ b/flang-rt/lib/runtime/allocator-registry.cpp @@ -1,4 +1,4 @@ -//===-- runtime/allocator-registry.cpp ------------------------------------===// +//===-- lib/runtime/allocator-registry.cpp ----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/allocator-registry.h" -#include "terminator.h" +#include "flang-rt/runtime/allocator-registry.h" +#include "flang-rt/runtime/terminator.h" namespace Fortran::runtime { diff --git a/flang/runtime/array-constructor.cpp b/flang-rt/lib/runtime/array-constructor.cpp similarity index 96% rename from flang/runtime/array-constructor.cpp rename to flang-rt/lib/runtime/array-constructor.cpp index c6953167f5fb2..7e267e714927f 100644 --- a/flang/runtime/array-constructor.cpp +++ b/flang-rt/lib/runtime/array-constructor.cpp @@ -1,4 +1,4 @@ -//===-- runtime/array-constructor.cpp -------------------------------------===// +//===-- lib/runtime/array-constructor.cpp -----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,14 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/array-constructor.h" -#include "derived.h" -#include "terminator.h" -#include "tools.h" -#include "type-info.h" +#include "flang-rt/runtime/array-constructor.h" +#include "flang-rt/runtime/derived.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" +#include "flang-rt/runtime/type-info.h" #include "flang/Runtime/allocatable.h" #include "flang/Runtime/assign.h" -#include "flang/Runtime/descriptor.h" namespace Fortran::runtime { diff --git a/flang/runtime/assign.cpp b/flang-rt/lib/runtime/assign.cpp similarity index 98% rename from flang/runtime/assign.cpp rename to flang-rt/lib/runtime/assign.cpp index 8f0efaa376c19..a1f3715f278c1 100644 --- a/flang/runtime/assign.cpp +++ b/flang-rt/lib/runtime/assign.cpp @@ -1,4 +1,4 @@ -//===-- runtime/assign.cpp ------------------------------------------------===// +//===-- lib/runtime/assign.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,13 +7,13 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/assign.h" -#include "assign-impl.h" -#include "derived.h" -#include "stat.h" -#include "terminator.h" -#include "tools.h" -#include "type-info.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/assign-impl.h" +#include "flang-rt/runtime/derived.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" +#include "flang-rt/runtime/type-info.h" namespace Fortran::runtime { diff --git a/flang/runtime/buffer.cpp b/flang-rt/lib/runtime/buffer.cpp similarity index 88% rename from flang/runtime/buffer.cpp rename to flang-rt/lib/runtime/buffer.cpp index 7b4869d69c2e5..4cf85e13b6d36 100644 --- a/flang/runtime/buffer.cpp +++ b/flang-rt/lib/runtime/buffer.cpp @@ -1,4 +1,4 @@ -//===-- runtime/buffer.cpp ------------------------------------------------===// +//===-- lib/runtime/buffer.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "buffer.h" +#include "flang-rt/runtime/buffer.h" #include namespace Fortran::runtime::io { diff --git a/flang/runtime/character.cpp b/flang-rt/lib/runtime/character.cpp similarity index 99% rename from flang/runtime/character.cpp rename to flang-rt/lib/runtime/character.cpp index 5049247397eb3..10cf27c37c4d8 100644 --- a/flang/runtime/character.cpp +++ b/flang-rt/lib/runtime/character.cpp @@ -1,4 +1,4 @@ -//===-- runtime/character.cpp ---------------------------------------------===// +//===-- lib/runtime/character.cpp -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,13 +7,13 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/character.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Common/bit-population-count.h" #include "flang/Common/uint128.h" #include "flang/Runtime/character.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include #include diff --git a/flang/runtime/command.cpp b/flang-rt/lib/runtime/command.cpp similarity index 96% rename from flang/runtime/command.cpp rename to flang-rt/lib/runtime/command.cpp index a555e26f96a66..8a5a61ac1ad44 100644 --- a/flang/runtime/command.cpp +++ b/flang-rt/lib/runtime/command.cpp @@ -1,4 +1,4 @@ -//===-- runtime/command.cpp -----------------------------------------------===// +//===-- lib/runtime/command.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/command.h" -#include "environment.h" -#include "stat.h" -#include "terminator.h" -#include "tools.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/environment.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include #include diff --git a/flang/runtime/complex-powi.cpp b/flang-rt/lib/runtime/complex-powi.cpp similarity index 92% rename from flang/runtime/complex-powi.cpp rename to flang-rt/lib/runtime/complex-powi.cpp index 62f73e037b76f..a561d114591cf 100644 --- a/flang/runtime/complex-powi.cpp +++ b/flang-rt/lib/runtime/complex-powi.cpp @@ -1,11 +1,11 @@ -/*===-- flang/runtime/complex-powi.cpp ----------------------------*- 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 - * - * ===-----------------------------------------------------------------------=== - */ +//===-- lib/runtime/complex-powi.cpp ----------------------------*- 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 +// +//===----------------------------------------------------------------------===// + #include "flang/Common/float128.h" #include "flang/Runtime/cpp-type.h" #include "flang/Runtime/entry-names.h" diff --git a/flang/runtime/complex-reduction.c b/flang-rt/lib/runtime/complex-reduction.c similarity index 97% rename from flang/runtime/complex-reduction.c rename to flang-rt/lib/runtime/complex-reduction.c index de1ff3d683084..967f26c05e702 100644 --- a/flang/runtime/complex-reduction.c +++ b/flang-rt/lib/runtime/complex-reduction.c @@ -1,11 +1,10 @@ -/*===-- flang/runtime/complex-reduction.c ---------------------------*- C -*-=== +/*===-- lib/flang_rt/complex-reduction.c ----------------------------*- 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 * - * ===-----------------------------------------------------------------------=== - */ + *===----------------------------------------------------------------------===*/ #include "complex-reduction.h" #include diff --git a/flang/runtime/complex-reduction.h b/flang-rt/lib/runtime/complex-reduction.h similarity index 96% rename from flang/runtime/complex-reduction.h rename to flang-rt/lib/runtime/complex-reduction.h index 5ff2a828fb3ec..44c52fb02fa43 100644 --- a/flang/runtime/complex-reduction.h +++ b/flang-rt/lib/runtime/complex-reduction.h @@ -1,19 +1,18 @@ -/*===-- flang/runtime/complex-reduction.h ---------------------------*- C -*-=== +/*===-- lib/runtime/complex-reduction.h -----------------------------*- 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 * - * ===-----------------------------------------------------------------------=== - */ + *===----------------------------------------------------------------------===*/ /* Wraps the C++-coded complex-valued SUM and PRODUCT reductions with * C-coded wrapper functions returning _Complex values, to avoid problems * with C++ build compilers that don't support C's _Complex. */ -#ifndef FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_ -#define FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_ +#ifndef FLANG_RT_RUNTIME_COMPLEX_REDUCTION_H_ +#define FLANG_RT_RUNTIME_COMPLEX_REDUCTION_H_ #include "flang/Common/float128.h" #include "flang/Runtime/entry-names.h" @@ -156,4 +155,4 @@ void RTNAME(ReduceComplex16DimValue)( REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_value_op)); #endif -#endif // FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_ +#endif // FLANG_RT_RUNTIME_COMPLEX_REDUCTION_H_ diff --git a/flang/runtime/connection.cpp b/flang-rt/lib/runtime/connection.cpp similarity index 90% rename from flang/runtime/connection.cpp rename to flang-rt/lib/runtime/connection.cpp index f24f0e832eb48..2f01dbbb95920 100644 --- a/flang/runtime/connection.cpp +++ b/flang-rt/lib/runtime/connection.cpp @@ -1,4 +1,4 @@ -//===-- runtime/connection.cpp --------------------------------------------===// +//===-- lib/runtime/connection.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "connection.h" -#include "environment.h" -#include "io-stmt.h" +#include "flang-rt/runtime/connection.h" +#include "flang-rt/runtime/environment.h" +#include "flang-rt/runtime/io-stmt.h" #include namespace Fortran::runtime::io { diff --git a/flang/runtime/copy.cpp b/flang-rt/lib/runtime/copy.cpp similarity index 97% rename from flang/runtime/copy.cpp rename to flang-rt/lib/runtime/copy.cpp index b20f68f019498..5956642dd7258 100644 --- a/flang/runtime/copy.cpp +++ b/flang-rt/lib/runtime/copy.cpp @@ -1,4 +1,4 @@ -//===-- runtime/copy.cpp -------------------------------------------------===// +//===-- lib/runtime/copy.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,10 +8,10 @@ #include "copy.h" #include "stack.h" -#include "terminator.h" -#include "type-info.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/type-info.h" #include "flang/Runtime/allocatable.h" -#include "flang/Runtime/descriptor.h" #include namespace Fortran::runtime { diff --git a/flang/runtime/copy.h b/flang-rt/lib/runtime/copy.h similarity index 78% rename from flang/runtime/copy.h rename to flang-rt/lib/runtime/copy.h index 542660530bfb6..836c9d4a1ef89 100644 --- a/flang/runtime/copy.h +++ b/flang-rt/lib/runtime/copy.h @@ -1,4 +1,4 @@ -//===-- runtime/copy.h ------------------------------------------*- C++ -*-===// +//===-- lib/runtime/copy.h --------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,10 +9,10 @@ // Utilities that copy data in a type-aware fashion, allocating & duplicating // allocatable/automatic components of derived types along the way. -#ifndef FORTRAN_RUNTIME_COPY_H_ -#define FORTRAN_RUNTIME_COPY_H_ +#ifndef FLANG_RT_RUNTIME_COPY_H_ +#define FLANG_RT_RUNTIME_COPY_H_ -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" namespace Fortran::runtime { @@ -22,4 +22,4 @@ RT_API_ATTRS void CopyElement(const Descriptor &to, const SubscriptValue toAt[], const Descriptor &from, const SubscriptValue fromAt[], Terminator &); } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_COPY_H_ +#endif // FLANG_RT_RUNTIME_COPY_H_ diff --git a/flang/runtime/derived-api.cpp b/flang-rt/lib/runtime/derived-api.cpp similarity index 95% rename from flang/runtime/derived-api.cpp rename to flang-rt/lib/runtime/derived-api.cpp index c8ffd8e3bb67c..884fa8ee7d095 100644 --- a/flang/runtime/derived-api.cpp +++ b/flang-rt/lib/runtime/derived-api.cpp @@ -1,5 +1,4 @@ -//===-- runtime/derived-api.cpp -//-----------------------------------------------===// +//===-- lib/runtime/derived-api.cpp -----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/derived-api.h" -#include "derived.h" -#include "terminator.h" -#include "tools.h" -#include "type-info.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/derived.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" +#include "flang-rt/runtime/type-info.h" namespace Fortran::runtime { diff --git a/flang/runtime/derived.cpp b/flang-rt/lib/runtime/derived.cpp similarity index 98% rename from flang/runtime/derived.cpp rename to flang-rt/lib/runtime/derived.cpp index 10813c62e5da1..87e4b29d08c28 100644 --- a/flang/runtime/derived.cpp +++ b/flang-rt/lib/runtime/derived.cpp @@ -1,4 +1,4 @@ -//===-- runtime/derived.cpp -----------------------------------------------===// +//===-- lib/runtime/derived.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,12 +6,12 @@ // //===----------------------------------------------------------------------===// -#include "derived.h" -#include "stat.h" -#include "terminator.h" -#include "tools.h" -#include "type-info.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/derived.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" +#include "flang-rt/runtime/type-info.h" namespace Fortran::runtime { diff --git a/flang/runtime/descriptor-io.cpp b/flang-rt/lib/runtime/descriptor-io.cpp similarity index 98% rename from flang/runtime/descriptor-io.cpp rename to flang-rt/lib/runtime/descriptor-io.cpp index 380ad425d925f..3db1455af52fe 100644 --- a/flang/runtime/descriptor-io.cpp +++ b/flang-rt/lib/runtime/descriptor-io.cpp @@ -1,4 +1,4 @@ -//===-- runtime/descriptor-io.cpp -----------------------------------------===// +//===-- lib/runtime/descriptor-io.cpp ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/descriptor-io.h b/flang-rt/lib/runtime/descriptor-io.h similarity index 98% rename from flang/runtime/descriptor-io.h rename to flang-rt/lib/runtime/descriptor-io.h index 1034958bf654a..dd399164325cb 100644 --- a/flang/runtime/descriptor-io.h +++ b/flang-rt/lib/runtime/descriptor-io.h @@ -1,4 +1,4 @@ -//===-- runtime/descriptor-io.h ---------------------------------*- C++ -*-===// +//===-- lib/runtime/descriptor-io.h -----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_DESCRIPTOR_IO_H_ -#define FORTRAN_RUNTIME_DESCRIPTOR_IO_H_ +#ifndef FLANG_RT_RUNTIME_DESCRIPTOR_IO_H_ +#define FLANG_RT_RUNTIME_DESCRIPTOR_IO_H_ // Implementation of I/O data list item transfers based on descriptors. // (All I/O items come through here so that the code is exercised for test; @@ -16,15 +16,15 @@ #include "edit-input.h" #include "edit-output.h" -#include "io-stmt.h" -#include "namelist.h" -#include "terminator.h" -#include "type-info.h" #include "unit.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/io-stmt.h" +#include "flang-rt/runtime/namelist.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/type-info.h" #include "flang/Common/optional.h" #include "flang/Common/uint128.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" namespace Fortran::runtime::io::descr { template @@ -626,4 +626,4 @@ static RT_API_ATTRS bool DescriptorIO(IoStatementState &io, return false; } } // namespace Fortran::runtime::io::descr -#endif // FORTRAN_RUNTIME_DESCRIPTOR_IO_H_ +#endif // FLANG_RT_RUNTIME_DESCRIPTOR_IO_H_ diff --git a/flang/runtime/descriptor.cpp b/flang-rt/lib/runtime/descriptor.cpp similarity index 94% rename from flang/runtime/descriptor.cpp rename to flang-rt/lib/runtime/descriptor.cpp index 32f43e89dc7a3..8241a34a4990c 100644 --- a/flang/runtime/descriptor.cpp +++ b/flang-rt/lib/runtime/descriptor.cpp @@ -1,4 +1,4 @@ -//===-- runtime/descriptor.cpp --------------------------------------------===// +//===-- lib/runtime/descriptor.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,15 +6,15 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" #include "ISO_Fortran_util.h" -#include "derived.h" #include "memory.h" -#include "stat.h" -#include "terminator.h" -#include "tools.h" -#include "type-info.h" -#include "flang/Runtime/allocator-registry.h" +#include "flang-rt/runtime/allocator-registry.h" +#include "flang-rt/runtime/derived.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" +#include "flang-rt/runtime/type-info.h" #include #include #include @@ -141,8 +141,10 @@ RT_API_ATTRS OwningPtr Descriptor::Create( RT_API_ATTRS std::size_t Descriptor::SizeInBytes() const { const DescriptorAddendum *addendum{Addendum()}; - return sizeof *this - sizeof(Dimension) + raw_.rank * sizeof(Dimension) + - (addendum ? addendum->SizeInBytes() : 0); + std::size_t bytes{ sizeof *this - sizeof(Dimension) + raw_.rank * sizeof(Dimension) + + (addendum ? addendum->SizeInBytes() : 0)}; + assert (bytes <= MaxDescriptorSizeInBytes(raw_.rank,addendum) && "Descriptor must fit compiler-allocated space"); + return bytes; } RT_API_ATTRS std::size_t Descriptor::Elements() const { diff --git a/flang/runtime/dot-product.cpp b/flang-rt/lib/runtime/dot-product.cpp similarity index 98% rename from flang/runtime/dot-product.cpp rename to flang-rt/lib/runtime/dot-product.cpp index 712497a3a50ac..20612f1876c15 100644 --- a/flang/runtime/dot-product.cpp +++ b/flang-rt/lib/runtime/dot-product.cpp @@ -1,4 +1,4 @@ -//===-- runtime/dot-product.cpp -------------------------------------------===// +//===-- lib/runtime/dot-product.cpp -----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "float.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Common/float128.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include "flang/Runtime/reduction.h" #include #include diff --git a/flang/runtime/edit-input.cpp b/flang-rt/lib/runtime/edit-input.cpp similarity index 99% rename from flang/runtime/edit-input.cpp rename to flang-rt/lib/runtime/edit-input.cpp index 317f0b676bd21..99a266648f95c 100644 --- a/flang/runtime/edit-input.cpp +++ b/flang-rt/lib/runtime/edit-input.cpp @@ -1,4 +1,4 @@ -//===-- runtime/edit-input.cpp --------------------------------------------===// +//===-- lib/runtime/edit-input.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "edit-input.h" -#include "namelist.h" -#include "utf.h" +#include "flang-rt/runtime/namelist.h" +#include "flang-rt/runtime/utf.h" #include "flang/Common/optional.h" #include "flang/Common/real.h" #include "flang/Common/uint128.h" diff --git a/flang/runtime/edit-input.h b/flang-rt/lib/runtime/edit-input.h similarity index 87% rename from flang/runtime/edit-input.h rename to flang-rt/lib/runtime/edit-input.h index 55a7a45578171..686cd461b3e34 100644 --- a/flang/runtime/edit-input.h +++ b/flang-rt/lib/runtime/edit-input.h @@ -1,4 +1,4 @@ -//===-- runtime/edit-input.h ------------------------------------*- C++ -*-===// +//===-- lib/runtime/edit-input.h --------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,11 +6,11 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_EDIT_INPUT_H_ -#define FORTRAN_RUNTIME_EDIT_INPUT_H_ +#ifndef FLANG_RT_RUNTIME_EDIT_INPUT_H_ +#define FLANG_RT_RUNTIME_EDIT_INPUT_H_ -#include "format.h" -#include "io-stmt.h" +#include "flang-rt/runtime/format.h" +#include "flang-rt/runtime/io-stmt.h" #include "flang/Decimal/decimal.h" namespace Fortran::runtime::io { @@ -50,4 +50,4 @@ extern template RT_API_ATTRS bool EditCharacterInput( IoStatementState &, const DataEdit &, char32_t *, std::size_t); } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_EDIT_INPUT_H_ +#endif // FLANG_RT_RUNTIME_EDIT_INPUT_H_ diff --git a/flang/runtime/edit-output.cpp b/flang-rt/lib/runtime/edit-output.cpp similarity index 99% rename from flang/runtime/edit-output.cpp rename to flang-rt/lib/runtime/edit-output.cpp index 9db9a3d4a511b..36bbc638ff5fc 100644 --- a/flang/runtime/edit-output.cpp +++ b/flang-rt/lib/runtime/edit-output.cpp @@ -1,4 +1,4 @@ -//===-- runtime/edit-output.cpp -------------------------------------------===// +//===-- lib/runtime/edit-output.cpp -----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "edit-output.h" -#include "emit-encoded.h" -#include "utf.h" +#include "flang-rt/runtime/emit-encoded.h" +#include "flang-rt/runtime/utf.h" #include "flang/Common/real.h" #include "flang/Common/uint128.h" #include diff --git a/flang/runtime/edit-output.h b/flang-rt/lib/runtime/edit-output.h similarity index 95% rename from flang/runtime/edit-output.h rename to flang-rt/lib/runtime/edit-output.h index 42cc993f98cc1..51a47405e49e4 100644 --- a/flang/runtime/edit-output.h +++ b/flang-rt/lib/runtime/edit-output.h @@ -1,4 +1,4 @@ -//===-- runtime/edit-output.h -----------------------------------*- C++ -*-===// +//===-- lib/runtime/edit-output.h -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_RUNTIME_EDIT_OUTPUT_H_ -#define FORTRAN_RUNTIME_EDIT_OUTPUT_H_ +#ifndef FLANG_RT_RUNTIME_EDIT_OUTPUT_H_ +#define FLANG_RT_RUNTIME_EDIT_OUTPUT_H_ // Output data editing templates implementing the FORMAT data editing // descriptors E, EN, ES, EX, D, F, and G for REAL data (and COMPLEX @@ -18,8 +18,8 @@ // Drives the same fast binary-to-decimal formatting templates used // in the f18 front-end. -#include "format.h" -#include "io-stmt.h" +#include "flang-rt/runtime/format.h" +#include "flang-rt/runtime/io-stmt.h" #include "flang/Common/uint128.h" #include "flang/Decimal/decimal.h" @@ -138,4 +138,4 @@ extern template class RealOutputEditing<10>; extern template class RealOutputEditing<16>; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_EDIT_OUTPUT_H_ +#endif // FLANG_RT_RUNTIME_EDIT_OUTPUT_H_ diff --git a/flang/runtime/environment-default-list.h b/flang-rt/lib/runtime/environment-default-list.h similarity index 70% rename from flang/runtime/environment-default-list.h rename to flang-rt/lib/runtime/environment-default-list.h index 4da261b10b9a8..76c0955bcce6d 100644 --- a/flang/runtime/environment-default-list.h +++ b/flang-rt/lib/runtime/environment-default-list.h @@ -1,14 +1,13 @@ -/*===-- runtime/environment-default-list.h --------------------------*- C -*-=== +/*===-- lib/flang_rt/environment-default-list.h ---------------------*- 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 * - * ===-----------------------------------------------------------------------=== - */ + *===----------------------------------------------------------------------===*/ -#ifndef FORTRAN_RUNTIME_ENVIRONMENT_DEFAULT_LIST_H_ -#define FORTRAN_RUNTIME_ENVIRONMENT_DEFAULT_LIST_H_ +#ifndef FLANG_RT_ENVIRONMENT_DEFAULT_LIST_H_ +#define FLANG_RT_ENVIRONMENT_DEFAULT_LIST_H_ /* Try to maintain C compatibility to make it easier to both define environment * defaults in non-Fortran main programs as well as pass through the environment @@ -28,4 +27,4 @@ struct EnvironmentDefaultList { const struct EnvironmentDefaultItem *item; }; -#endif /* FORTRAN_RUNTIME_ENVIRONMENT_DEFAULT_LIST_H_ */ +#endif /* FLANG_RT_ENVIRONMENT_DEFAULT_LIST_H_ */ diff --git a/flang/runtime/environment.cpp b/flang-rt/lib/runtime/environment.cpp similarity index 96% rename from flang/runtime/environment.cpp rename to flang-rt/lib/runtime/environment.cpp index 678d8745c9fd7..15380ba148df5 100644 --- a/flang/runtime/environment.cpp +++ b/flang-rt/lib/runtime/environment.cpp @@ -1,4 +1,4 @@ -//===-- runtime/environment.cpp -------------------------------------------===// +//===-- lib/runtime/environment.cpp -----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,10 @@ // //===----------------------------------------------------------------------===// -#include "environment.h" +#include "flang-rt/runtime/environment.h" #include "environment-default-list.h" #include "memory.h" -#include "tools.h" +#include "flang-rt/runtime/tools.h" #include #include #include diff --git a/flang/runtime/exceptions.cpp b/flang-rt/lib/runtime/exceptions.cpp similarity index 97% rename from flang/runtime/exceptions.cpp rename to flang-rt/lib/runtime/exceptions.cpp index 344e7216cfaae..d25a67c8e9cb5 100644 --- a/flang/runtime/exceptions.cpp +++ b/flang-rt/lib/runtime/exceptions.cpp @@ -1,4 +1,4 @@ -//===-- runtime/exceptions.cpp --------------------------------------===// +//===-- lib/runtime/exceptions.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,7 +9,7 @@ // Runtime exception support. #include "flang/Runtime/exceptions.h" -#include "terminator.h" +#include "flang-rt/runtime/terminator.h" #include #if defined(__aarch64__) && defined(__GLIBC__) #include diff --git a/flang/runtime/execute.cpp b/flang-rt/lib/runtime/execute.cpp similarity index 97% rename from flang/runtime/execute.cpp rename to flang-rt/lib/runtime/execute.cpp index c7f8f386d81f4..f180da846a32c 100644 --- a/flang/runtime/execute.cpp +++ b/flang-rt/lib/runtime/execute.cpp @@ -1,4 +1,4 @@ -//===-- runtime/execute.cpp -----------------------------------------------===// +//===-- lib/runtime/execute.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/execute.h" -#include "environment.h" -#include "stat.h" -#include "terminator.h" -#include "tools.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/environment.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include #include #include diff --git a/flang/runtime/extensions.cpp b/flang-rt/lib/runtime/extensions.cpp similarity index 97% rename from flang/runtime/extensions.cpp rename to flang-rt/lib/runtime/extensions.cpp index ac19ba7b31d4c..75195c33a6c21 100644 --- a/flang/runtime/extensions.cpp +++ b/flang-rt/lib/runtime/extensions.cpp @@ -1,4 +1,4 @@ -//===-- runtime/extensions.cpp --------------------------------------------===// +//===-- lib/runtime/extensions.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,10 +10,10 @@ // extensions that will eventually be implemented in Fortran. #include "flang/Runtime/extensions.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Runtime/command.h" -#include "flang/Runtime/descriptor.h" #include "flang/Runtime/entry-names.h" #include "flang/Runtime/io-api.h" #include diff --git a/flang/runtime/external-unit.cpp b/flang-rt/lib/runtime/external-unit.cpp similarity index 98% rename from flang/runtime/external-unit.cpp rename to flang-rt/lib/runtime/external-unit.cpp index d17a92622f844..b8004d6315994 100644 --- a/flang/runtime/external-unit.cpp +++ b/flang-rt/lib/runtime/external-unit.cpp @@ -1,4 +1,4 @@ -//===-- runtime/external-unit.cpp -----------------------------------------===// +//===-- lib/runtime/external-unit.cpp ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,11 +10,11 @@ // //===----------------------------------------------------------------------===// -#include "io-error.h" -#include "lock.h" -#include "tools.h" #include "unit-map.h" #include "unit.h" +#include "flang-rt/runtime/io-error.h" +#include "flang-rt/runtime/lock.h" +#include "flang-rt/runtime/tools.h" // NOTE: the header files above may define OpenMP declare target // variables, so they have to be included unconditionally diff --git a/flang/runtime/extrema.cpp b/flang-rt/lib/runtime/extrema.cpp similarity index 99% rename from flang/runtime/extrema.cpp rename to flang-rt/lib/runtime/extrema.cpp index 7ecdf4b91702e..3d84daa380441 100644 --- a/flang/runtime/extrema.cpp +++ b/flang-rt/lib/runtime/extrema.cpp @@ -1,4 +1,4 @@ -//===-- runtime/extrema.cpp -----------------------------------------------===// +//===-- lib/runtime/extrema.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,7 +10,7 @@ // and shapes and (for MAXLOC & MINLOC) result integer kinds. Also implements // NORM2 using common infrastructure. -#include "reduction-templates.h" +#include "flang-rt/runtime/reduction-templates.h" #include "flang/Common/float128.h" #include "flang/Runtime/character.h" #include "flang/Runtime/reduction.h" diff --git a/flang/runtime/file.cpp b/flang-rt/lib/runtime/file.cpp similarity index 98% rename from flang/runtime/file.cpp rename to flang-rt/lib/runtime/file.cpp index 9e077b8cea44b..16e73db488727 100644 --- a/flang/runtime/file.cpp +++ b/flang-rt/lib/runtime/file.cpp @@ -1,4 +1,4 @@ -//===-- runtime/file.cpp --------------------------------------------------===// +//===-- lib/runtime/file.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,10 @@ // //===----------------------------------------------------------------------===// -#include "file.h" -#include "tools.h" +#include "flang-rt/runtime/file.h" +#include "flang-rt/runtime/memory.h" +#include "flang-rt/runtime/tools.h" #include "flang/Runtime/magic-numbers.h" -#include "flang/Runtime/memory.h" #include #include #include diff --git a/flang/runtime/findloc.cpp b/flang-rt/lib/runtime/findloc.cpp similarity index 99% rename from flang/runtime/findloc.cpp rename to flang-rt/lib/runtime/findloc.cpp index b9b1d7f7ab689..95986aefb86a4 100644 --- a/flang/runtime/findloc.cpp +++ b/flang-rt/lib/runtime/findloc.cpp @@ -1,4 +1,4 @@ -//===-- runtime/findloc.cpp -----------------------------------------------===// +//===-- lib/runtime/findloc.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,7 +9,7 @@ // Implements FINDLOC for all required operand types and shapes and result // integer kinds. -#include "reduction-templates.h" +#include "flang-rt/runtime/reduction-templates.h" #include "flang/Runtime/character.h" #include "flang/Runtime/reduction.h" #include diff --git a/flang/runtime/format.cpp b/flang-rt/lib/runtime/format.cpp similarity index 87% rename from flang/runtime/format.cpp rename to flang-rt/lib/runtime/format.cpp index 433acce4b7373..ee0059f5f0729 100644 --- a/flang/runtime/format.cpp +++ b/flang-rt/lib/runtime/format.cpp @@ -1,4 +1,4 @@ -//===-- runtime/format.cpp ------------------------------------------------===// +//===-- lib/runtime/format.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "format-implementation.h" +#include "flang-rt/runtime/format-implementation.h" namespace Fortran::runtime::io { RT_OFFLOAD_API_GROUP_BEGIN diff --git a/flang/runtime/inquiry.cpp b/flang-rt/lib/runtime/inquiry.cpp similarity index 94% rename from flang/runtime/inquiry.cpp rename to flang-rt/lib/runtime/inquiry.cpp index 9fbcaa96fa3c4..b6a7fce7a1e78 100644 --- a/flang/runtime/inquiry.cpp +++ b/flang-rt/lib/runtime/inquiry.cpp @@ -1,4 +1,4 @@ -//===-- runtime/inquiry.cpp --------------------------------------===// +//===-- lib/runtime/inquiry.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -11,9 +11,9 @@ #include "flang/Runtime/inquiry.h" #include "copy.h" -#include "terminator.h" -#include "tools.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include namespace Fortran::runtime { diff --git a/flang/runtime/internal-unit.cpp b/flang-rt/lib/runtime/internal-unit.cpp similarity index 96% rename from flang/runtime/internal-unit.cpp rename to flang-rt/lib/runtime/internal-unit.cpp index f8f3877efb20e..e344b01e8b34e 100644 --- a/flang/runtime/internal-unit.cpp +++ b/flang-rt/lib/runtime/internal-unit.cpp @@ -1,4 +1,4 @@ -//===-- runtime/internal-unit.cpp -----------------------------------------===// +//===-- lib/runtime/internal-unit.cpp ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "internal-unit.h" -#include "io-error.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/internal-unit.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/io-error.h" #include "flang/Runtime/freestanding-tools.h" #include #include diff --git a/flang/runtime/io-api-common.h b/flang-rt/lib/runtime/io-api-common.h similarity index 92% rename from flang/runtime/io-api-common.h rename to flang-rt/lib/runtime/io-api-common.h index c7b86cab73a52..b91ff9ff16863 100644 --- a/flang/runtime/io-api-common.h +++ b/flang-rt/lib/runtime/io-api-common.h @@ -1,4 +1,4 @@ -//===-- runtime/io-api-common.h ---------------------------------*- C++ -*-===// +//===-- lib/runtime/io-api-common.h -----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,12 +6,12 @@ // //===----------------------------------------------------------------------===// -#ifndef FLANG_RUNTIME_IO_API_COMMON_H_ -#define FLANG_RUNTIME_IO_API_COMMON_H_ +#ifndef FLANG_RT_RUNTIME_IO_API_COMMON_H_ +#define FLANG_RT_RUNTIME_IO_API_COMMON_H_ -#include "io-stmt.h" -#include "terminator.h" #include "unit.h" +#include "flang-rt/runtime/io-stmt.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Common/api-attrs.h" #include "flang/Common/optional.h" #include "flang/Runtime/io-api.h" @@ -94,4 +94,4 @@ RT_API_ATTRS Cookie BeginExternalListIO( } } // namespace Fortran::runtime::io -#endif // FLANG_RUNTIME_IO_API_COMMON_H_ +#endif // FLANG_RT_RUNTIME_IO_API_COMMON_H_ diff --git a/flang/runtime/io-api-minimal.cpp b/flang-rt/lib/runtime/io-api-minimal.cpp similarity index 95% rename from flang/runtime/io-api-minimal.cpp rename to flang-rt/lib/runtime/io-api-minimal.cpp index 68768427be0c2..8d8c9c6070b04 100644 --- a/flang/runtime/io-api-minimal.cpp +++ b/flang-rt/lib/runtime/io-api-minimal.cpp @@ -1,4 +1,4 @@ -//===-- runtime/io-api-minimal.cpp ----------------------------------------===// +//===-- lib/runtime/io-api-minimal.cpp --------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,12 +10,12 @@ // list-directed output (PRINT *) of intrinsic types. #include "edit-output.h" -#include "format.h" #include "io-api-common.h" -#include "io-stmt.h" -#include "terminator.h" -#include "tools.h" #include "unit.h" +#include "flang-rt/runtime/format.h" +#include "flang-rt/runtime/io-stmt.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Runtime/io-api.h" namespace Fortran::runtime::io { diff --git a/flang/runtime/io-api.cpp b/flang-rt/lib/runtime/io-api.cpp similarity index 99% rename from flang/runtime/io-api.cpp rename to flang-rt/lib/runtime/io-api.cpp index dc3f6f87fc21b..0355734c67fcd 100644 --- a/flang/runtime/io-api.cpp +++ b/flang-rt/lib/runtime/io-api.cpp @@ -1,4 +1,4 @@ -//===-- runtime/io-api.cpp ------------------------------------------------===// +//===-- lib/runtime/io-api.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -17,16 +17,16 @@ #include "descriptor-io.h" #include "edit-input.h" #include "edit-output.h" -#include "environment.h" -#include "format.h" #include "io-api-common.h" -#include "io-stmt.h" -#include "terminator.h" -#include "tools.h" #include "unit.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/environment.h" +#include "flang-rt/runtime/format.h" +#include "flang-rt/runtime/io-stmt.h" +#include "flang-rt/runtime/memory.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Common/optional.h" -#include "flang/Runtime/descriptor.h" -#include "flang/Runtime/memory.h" #include #include diff --git a/flang/runtime/io-error.cpp b/flang-rt/lib/runtime/io-error.cpp similarity index 96% rename from flang/runtime/io-error.cpp rename to flang-rt/lib/runtime/io-error.cpp index 37909e8e6dad2..b350fb66fc25b 100644 --- a/flang/runtime/io-error.cpp +++ b/flang-rt/lib/runtime/io-error.cpp @@ -1,4 +1,4 @@ -//===-- runtime/io-error.cpp ----------------------------------------------===// +//===-- lib/runtime/io-error.cpp --------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "io-error.h" +#include "flang-rt/runtime/io-error.h" #include "config.h" -#include "tools.h" +#include "flang-rt/runtime/tools.h" #include "flang/Runtime/magic-numbers.h" #include #include diff --git a/flang/runtime/io-stmt.cpp b/flang-rt/lib/runtime/io-stmt.cpp similarity index 99% rename from flang/runtime/io-stmt.cpp rename to flang-rt/lib/runtime/io-stmt.cpp index f24eb929ce748..b0823ffd9e703 100644 --- a/flang/runtime/io-stmt.cpp +++ b/flang-rt/lib/runtime/io-stmt.cpp @@ -1,4 +1,4 @@ -//===-- runtime/io-stmt.cpp -----------------------------------------------===// +//===-- lib/runtime/io-stmt.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,14 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "io-stmt.h" -#include "connection.h" -#include "emit-encoded.h" -#include "format.h" -#include "tools.h" +#include "flang-rt/runtime/io-stmt.h" #include "unit.h" -#include "utf.h" -#include "flang/Runtime/memory.h" +#include "flang-rt/runtime/connection.h" +#include "flang-rt/runtime/emit-encoded.h" +#include "flang-rt/runtime/format.h" +#include "flang-rt/runtime/memory.h" +#include "flang-rt/runtime/tools.h" +#include "flang-rt/runtime/utf.h" #include #include #include diff --git a/flang/runtime/iostat.cpp b/flang-rt/lib/runtime/iostat.cpp similarity index 98% rename from flang/runtime/iostat.cpp rename to flang-rt/lib/runtime/iostat.cpp index 39e224cb01286..0f8bfb884e544 100644 --- a/flang/runtime/iostat.cpp +++ b/flang-rt/lib/runtime/iostat.cpp @@ -1,4 +1,4 @@ -//===-- runtime/iostat.cpp ------------------------------------------------===// +//===-- lib/runtime/iostat.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/main.cpp b/flang-rt/lib/runtime/main.cpp similarity index 89% rename from flang/runtime/main.cpp rename to flang-rt/lib/runtime/main.cpp index 96454989581b7..b3f066cda3732 100644 --- a/flang/runtime/main.cpp +++ b/flang-rt/lib/runtime/main.cpp @@ -1,4 +1,4 @@ -//===-- runtime/main.cpp --------------------------------------------------===// +//===-- lib/runtime/main.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/main.h" -#include "environment.h" -#include "terminator.h" +#include "flang-rt/runtime/environment.h" +#include "flang-rt/runtime/terminator.h" #include #include #include diff --git a/flang/runtime/matmul-transpose.cpp b/flang-rt/lib/runtime/matmul-transpose.cpp similarity index 98% rename from flang/runtime/matmul-transpose.cpp rename to flang-rt/lib/runtime/matmul-transpose.cpp index bafa05056bebc..e20abbdddcd30 100644 --- a/flang/runtime/matmul-transpose.cpp +++ b/flang-rt/lib/runtime/matmul-transpose.cpp @@ -1,4 +1,4 @@ -//===-- runtime/matmul-transpose.cpp --------------------------------------===// +//===-- lib/runtime/matmul-transpose.cpp ------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -21,12 +21,12 @@ // to use the faster BLAS routines. #include "flang/Runtime/matmul-transpose.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Common/optional.h" #include "flang/Runtime/c-or-cpp.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include namespace { diff --git a/flang/runtime/matmul.cpp b/flang-rt/lib/runtime/matmul.cpp similarity index 98% rename from flang/runtime/matmul.cpp rename to flang-rt/lib/runtime/matmul.cpp index f72601073a600..f14cea922d21e 100644 --- a/flang/runtime/matmul.cpp +++ b/flang-rt/lib/runtime/matmul.cpp @@ -1,4 +1,4 @@ -//===-- runtime/matmul.cpp ------------------------------------------------===// +//===-- lib/runtime/matmul.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -20,12 +20,12 @@ // Places where BLAS routines could be called are marked as TODO items. #include "flang/Runtime/matmul.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Common/optional.h" #include "flang/Runtime/c-or-cpp.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include namespace { diff --git a/flang/runtime/memory.cpp b/flang-rt/lib/runtime/memory.cpp similarity index 85% rename from flang/runtime/memory.cpp rename to flang-rt/lib/runtime/memory.cpp index c7068ad6479a1..79c7e33777569 100644 --- a/flang/runtime/memory.cpp +++ b/flang-rt/lib/runtime/memory.cpp @@ -1,4 +1,4 @@ -//===-- runtime/memory.cpp ------------------------------------------------===// +//===-- lib/runtime/memory.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/memory.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/memory.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Runtime/freestanding-tools.h" #include diff --git a/flang/runtime/misc-intrinsic.cpp b/flang-rt/lib/runtime/misc-intrinsic.cpp similarity index 95% rename from flang/runtime/misc-intrinsic.cpp rename to flang-rt/lib/runtime/misc-intrinsic.cpp index f7d893829fc0d..b7335e9f6799e 100644 --- a/flang/runtime/misc-intrinsic.cpp +++ b/flang-rt/lib/runtime/misc-intrinsic.cpp @@ -1,4 +1,4 @@ -//===-- runtime/misc-intrinsic.cpp ----------------------------------------===// +//===-- lib/runtime/misc-intrinsic.cpp --------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,10 +7,10 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/misc-intrinsic.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Common/optional.h" -#include "flang/Runtime/descriptor.h" #include #include #include diff --git a/flang/runtime/namelist.cpp b/flang-rt/lib/runtime/namelist.cpp similarity index 99% rename from flang/runtime/namelist.cpp rename to flang-rt/lib/runtime/namelist.cpp index af092de70f781..b0cf2180fc6d4 100644 --- a/flang/runtime/namelist.cpp +++ b/flang-rt/lib/runtime/namelist.cpp @@ -1,4 +1,4 @@ -//===-- runtime/namelist.cpp ----------------------------------------------===// +//===-- lib/runtime/namelist.cpp --------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,10 @@ // //===----------------------------------------------------------------------===// -#include "namelist.h" +#include "flang-rt/runtime/namelist.h" #include "descriptor-io.h" -#include "emit-encoded.h" -#include "io-stmt.h" +#include "flang-rt/runtime/emit-encoded.h" +#include "flang-rt/runtime/io-stmt.h" #include "flang/Runtime/io-api.h" #include #include diff --git a/flang/runtime/non-tbp-dio.cpp b/flang-rt/lib/runtime/non-tbp-dio.cpp similarity index 86% rename from flang/runtime/non-tbp-dio.cpp rename to flang-rt/lib/runtime/non-tbp-dio.cpp index 9419adb7631cc..72101b06e0c6e 100644 --- a/flang/runtime/non-tbp-dio.cpp +++ b/flang-rt/lib/runtime/non-tbp-dio.cpp @@ -1,4 +1,4 @@ -//===-- flang/runtime/non-tbp-dio.cpp ---------------------------*- C++ -*-===// +//===-- lib/runtime/non-tbp-dio.cpp -----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "non-tbp-dio.h" -#include "type-info.h" +#include "flang-rt/runtime/non-tbp-dio.h" +#include "flang-rt/runtime/type-info.h" namespace Fortran::runtime::io { diff --git a/flang/runtime/numeric.cpp b/flang-rt/lib/runtime/numeric.cpp similarity index 99% rename from flang/runtime/numeric.cpp rename to flang-rt/lib/runtime/numeric.cpp index 45fb56348fd44..37638765dc650 100644 --- a/flang/runtime/numeric.cpp +++ b/flang-rt/lib/runtime/numeric.cpp @@ -1,4 +1,4 @@ -//===-- runtime/numeric.cpp -----------------------------------------------===// +//===-- lib/runtime/numeric.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/numeric.h" -#include "numeric-templates.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/numeric-templates.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Common/float128.h" #include #include diff --git a/flang/runtime/pointer.cpp b/flang-rt/lib/runtime/pointer.cpp similarity index 96% rename from flang/runtime/pointer.cpp rename to flang-rt/lib/runtime/pointer.cpp index 3b0babe3d852f..ecca86bfe73cd 100644 --- a/flang/runtime/pointer.cpp +++ b/flang-rt/lib/runtime/pointer.cpp @@ -1,4 +1,4 @@ -//===-- runtime/pointer.cpp -----------------------------------------------===// +//===-- lib/runtime/pointer.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,13 +7,13 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/pointer.h" -#include "assign-impl.h" -#include "derived.h" -#include "environment.h" -#include "stat.h" -#include "terminator.h" -#include "tools.h" -#include "type-info.h" +#include "flang-rt/runtime/assign-impl.h" +#include "flang-rt/runtime/derived.h" +#include "flang-rt/runtime/environment.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" +#include "flang-rt/runtime/type-info.h" namespace Fortran::runtime { extern "C" { diff --git a/flang/runtime/product.cpp b/flang-rt/lib/runtime/product.cpp similarity index 98% rename from flang/runtime/product.cpp rename to flang-rt/lib/runtime/product.cpp index 293ffd301ba2e..02fdc2bfcd576 100644 --- a/flang/runtime/product.cpp +++ b/flang-rt/lib/runtime/product.cpp @@ -1,4 +1,4 @@ -//===-- runtime/product.cpp -----------------------------------------------===// +//===-- lib/runtime/product.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,7 +8,7 @@ // Implements PRODUCT for all required operand types and shapes. -#include "reduction-templates.h" +#include "flang-rt/runtime/reduction-templates.h" #include "flang/Common/float128.h" #include "flang/Runtime/reduction.h" #include diff --git a/flang/runtime/pseudo-unit.cpp b/flang-rt/lib/runtime/pseudo-unit.cpp similarity index 97% rename from flang/runtime/pseudo-unit.cpp rename to flang-rt/lib/runtime/pseudo-unit.cpp index 526afd11d916e..7e1f3bc86b294 100644 --- a/flang/runtime/pseudo-unit.cpp +++ b/flang-rt/lib/runtime/pseudo-unit.cpp @@ -1,4 +1,4 @@ -//===-- runtime/pseudo-unit.cpp -------------------------------------------===// +//===-- lib/runtime/pseudo-unit.cpp -----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -11,9 +11,9 @@ // //===----------------------------------------------------------------------===// -#include "io-error.h" -#include "tools.h" #include "unit.h" +#include "flang-rt/runtime/io-error.h" +#include "flang-rt/runtime/tools.h" // NOTE: the header files above may define OpenMP declare target // variables, so they have to be included unconditionally diff --git a/flang/runtime/ragged.cpp b/flang-rt/lib/runtime/ragged.cpp similarity index 96% rename from flang/runtime/ragged.cpp rename to flang-rt/lib/runtime/ragged.cpp index a4d9e541ba531..dddc3ccdfd858 100644 --- a/flang/runtime/ragged.cpp +++ b/flang-rt/lib/runtime/ragged.cpp @@ -1,4 +1,4 @@ -//===-- runtime/ragged.cpp ------------------------------------------------===// +//===-- lib/runtime/ragged.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/ragged.h" -#include "tools.h" +#include "flang-rt/runtime/tools.h" #include namespace Fortran::runtime { diff --git a/flang/runtime/random.cpp b/flang-rt/lib/runtime/random.cpp similarity index 96% rename from flang/runtime/random.cpp rename to flang-rt/lib/runtime/random.cpp index 8f158007a5a65..dc74f2725ed51 100644 --- a/flang/runtime/random.cpp +++ b/flang-rt/lib/runtime/random.cpp @@ -1,4 +1,4 @@ -//===-- runtime/random.cpp ------------------------------------------------===// +//===-- lib/runtime/random.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,14 +10,14 @@ // RANDOM_SEED. #include "flang/Runtime/random.h" -#include "lock.h" -#include "random-templates.h" -#include "terminator.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/lock.h" +#include "flang-rt/runtime/random-templates.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Common/float128.h" #include "flang/Common/leading-zero-bit-count.h" #include "flang/Common/uint128.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include #include #include diff --git a/flang/runtime/reduce.cpp b/flang-rt/lib/runtime/reduce.cpp similarity index 99% rename from flang/runtime/reduce.cpp rename to flang-rt/lib/runtime/reduce.cpp index 6c42c5ef50e4f..3c5e815e32d2b 100644 --- a/flang/runtime/reduce.cpp +++ b/flang-rt/lib/runtime/reduce.cpp @@ -1,4 +1,4 @@ -//===-- runtime/reduce.cpp ------------------------------------------------===// +//===-- lib/runtime/reduce.cpp ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,10 +9,10 @@ // REDUCE() implementation #include "flang/Runtime/reduce.h" -#include "reduction-templates.h" -#include "terminator.h" -#include "tools.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/reduction-templates.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" namespace Fortran::runtime { diff --git a/flang/runtime/reduction.cpp b/flang-rt/lib/runtime/reduction.cpp similarity index 98% rename from flang/runtime/reduction.cpp rename to flang-rt/lib/runtime/reduction.cpp index a8fcde7b3a166..5e45870489479 100644 --- a/flang/runtime/reduction.cpp +++ b/flang-rt/lib/runtime/reduction.cpp @@ -1,4 +1,4 @@ -//===-- runtime/reduction.cpp ---------------------------------------------===// +//===-- lib/runtime/reduction.cpp -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -14,8 +14,8 @@ // NORM2, MAXLOC, MINLOC, MAXVAL, and MINVAL are in extrema.cpp. #include "flang/Runtime/reduction.h" -#include "reduction-templates.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/reduction-templates.h" #include namespace Fortran::runtime { diff --git a/flang/runtime/stack.h b/flang-rt/lib/runtime/stack.h similarity index 93% rename from flang/runtime/stack.h rename to flang-rt/lib/runtime/stack.h index b6e6edb595e9a..38364ff541f16 100644 --- a/flang/runtime/stack.h +++ b/flang-rt/lib/runtime/stack.h @@ -1,4 +1,4 @@ -//===-- runtime/stack.h -----------------------------------------*- C++ -*-===// +//===-- lib/runtime/stack.h -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,11 +10,11 @@ // It is a list based stack with dynamic allocation/deallocation // of the list nodes. -#ifndef FORTRAN_RUNTIME_STACK_H -#define FORTRAN_RUNTIME_STACK_H +#ifndef FLANG_RT_RUNTIME_STACK_H_ +#define FLANG_RT_RUNTIME_STACK_H_ -#include "terminator.h" -#include "flang/Runtime/memory.h" +#include "flang-rt/runtime/memory.h" +#include "flang-rt/runtime/terminator.h" namespace Fortran::runtime { // Storage for the Stack elements of type T. @@ -133,4 +133,4 @@ template class Stack : public StackStorage { Terminator &terminator_; }; } // namespace Fortran::runtime -#endif // FORTRAN_RUNTIME_STACK_H +#endif // FLANG_RT_RUNTIME_STACK_H_ diff --git a/flang/runtime/stat.cpp b/flang-rt/lib/runtime/stat.cpp similarity index 92% rename from flang/runtime/stat.cpp rename to flang-rt/lib/runtime/stat.cpp index 525a4e36cdc77..322b7282b7024 100644 --- a/flang/runtime/stat.cpp +++ b/flang-rt/lib/runtime/stat.cpp @@ -1,4 +1,4 @@ -//===-- runtime/stat.cpp --------------------------------------------------===// +//===-- lib/runtime/stat.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,10 @@ // //===----------------------------------------------------------------------===// -#include "stat.h" -#include "terminator.h" -#include "tools.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/stat.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" namespace Fortran::runtime { RT_OFFLOAD_API_GROUP_BEGIN diff --git a/flang/runtime/stop.cpp b/flang-rt/lib/runtime/stop.cpp similarity index 95% rename from flang/runtime/stop.cpp rename to flang-rt/lib/runtime/stop.cpp index f8c180e0aaffa..1d70a137377aa 100644 --- a/flang/runtime/stop.cpp +++ b/flang-rt/lib/runtime/stop.cpp @@ -1,4 +1,4 @@ -//===-- runtime/stop.cpp --------------------------------------------------===// +//===-- lib/runtime/stop.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,11 +8,11 @@ #include "flang/Runtime/stop.h" #include "config.h" -#include "environment.h" -#include "file.h" -#include "io-error.h" -#include "terminator.h" #include "unit.h" +#include "flang-rt/runtime/environment.h" +#include "flang-rt/runtime/file.h" +#include "flang-rt/runtime/io-error.h" +#include "flang-rt/runtime/terminator.h" #include #include #include diff --git a/flang/runtime/sum.cpp b/flang-rt/lib/runtime/sum.cpp similarity index 98% rename from flang/runtime/sum.cpp rename to flang-rt/lib/runtime/sum.cpp index 3cb7a2b285779..a76e228f18a4e 100644 --- a/flang/runtime/sum.cpp +++ b/flang-rt/lib/runtime/sum.cpp @@ -1,4 +1,4 @@ -//===-- runtime/sum.cpp ---------------------------------------------------===// +//===-- lib/runtime/sum.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -12,7 +12,7 @@ // cancellation on intermediate results by using "Kahan summation" // (basically the same as manual "double-double"). -#include "reduction-templates.h" +#include "flang-rt/runtime/reduction-templates.h" #include "flang/Common/float128.h" #include "flang/Runtime/reduction.h" #include diff --git a/flang/runtime/support.cpp b/flang-rt/lib/runtime/support.cpp similarity index 90% rename from flang/runtime/support.cpp rename to flang-rt/lib/runtime/support.cpp index a607120256d9d..5a2b0c920aa80 100644 --- a/flang/runtime/support.cpp +++ b/flang-rt/lib/runtime/support.cpp @@ -1,4 +1,4 @@ -//===-- runtime/support.cpp -----------------------------------------------===// +//===-- lib/runtime/support.cpp ---------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,8 +8,8 @@ #include "flang/Runtime/support.h" #include "ISO_Fortran_util.h" -#include "type-info.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/type-info.h" namespace Fortran::runtime { extern "C" { diff --git a/flang/runtime/temporary-stack.cpp b/flang-rt/lib/runtime/temporary-stack.cpp similarity index 97% rename from flang/runtime/temporary-stack.cpp rename to flang-rt/lib/runtime/temporary-stack.cpp index 93340266b1b44..ea89d0c17bb6b 100644 --- a/flang/runtime/temporary-stack.cpp +++ b/flang-rt/lib/runtime/temporary-stack.cpp @@ -1,4 +1,4 @@ -//===-- runtime/temporary-stack.cpp ---------------------------------------===// +//===-- lib/runtime/temporary-stack.cpp -------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,11 +10,11 @@ // temporaries. For use in HLFIR lowering. #include "flang/Runtime/temporary-stack.h" -#include "terminator.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/memory.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" #include "flang/Runtime/assign.h" -#include "flang/Runtime/descriptor.h" -#include "flang/Runtime/memory.h" namespace { diff --git a/flang/runtime/terminator.cpp b/flang-rt/lib/runtime/terminator.cpp similarity index 95% rename from flang/runtime/terminator.cpp rename to flang-rt/lib/runtime/terminator.cpp index bab9edc64fa35..8a57ba06b1304 100644 --- a/flang/runtime/terminator.cpp +++ b/flang-rt/lib/runtime/terminator.cpp @@ -1,4 +1,4 @@ -//===-- runtime/terminate.cpp ---------------------------------------------===// +//===-- lib/runtime/terminator.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "terminator.h" +#include "flang-rt/runtime/terminator.h" #include #include diff --git a/flang/runtime/time-intrinsic.cpp b/flang-rt/lib/runtime/time-intrinsic.cpp similarity index 98% rename from flang/runtime/time-intrinsic.cpp rename to flang-rt/lib/runtime/time-intrinsic.cpp index 942604a92aaad..69c344f5d24bc 100644 --- a/flang/runtime/time-intrinsic.cpp +++ b/flang-rt/lib/runtime/time-intrinsic.cpp @@ -1,4 +1,4 @@ -//===-- runtime/time-intrinsic.cpp ----------------------------------------===// +//===-- lib/runtime/time-intrinsic.cpp --------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,10 +9,10 @@ // Implements time-related intrinsic subroutines. #include "flang/Runtime/time-intrinsic.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include #include #include diff --git a/flang/runtime/tools.cpp b/flang-rt/lib/runtime/tools.cpp similarity index 98% rename from flang/runtime/tools.cpp rename to flang-rt/lib/runtime/tools.cpp index 73d6c2cf7e1d2..b9d9ca4fc378c 100644 --- a/flang/runtime/tools.cpp +++ b/flang-rt/lib/runtime/tools.cpp @@ -1,4 +1,4 @@ -//===-- runtime/tools.cpp -------------------------------------------------===// +//===-- lib/runtime/tools.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "tools.h" -#include "terminator.h" +#include "flang-rt/runtime/tools.h" +#include "flang-rt/runtime/terminator.h" #include #include #include diff --git a/flang/runtime/transformational.cpp b/flang-rt/lib/runtime/transformational.cpp similarity index 99% rename from flang/runtime/transformational.cpp rename to flang-rt/lib/runtime/transformational.cpp index ab303bdef9b1d..eb694a9f2c833 100644 --- a/flang/runtime/transformational.cpp +++ b/flang-rt/lib/runtime/transformational.cpp @@ -1,4 +1,4 @@ -//===-- runtime/transformational.cpp --------------------------------------===// +//===-- lib/runtime/transformational.cpp ------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -18,10 +18,10 @@ #include "flang/Runtime/transformational.h" #include "copy.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include "flang/Common/float128.h" -#include "flang/Runtime/descriptor.h" namespace Fortran::runtime { diff --git a/flang/runtime/type-code.cpp b/flang-rt/lib/runtime/type-code.cpp similarity index 98% rename from flang/runtime/type-code.cpp rename to flang-rt/lib/runtime/type-code.cpp index d6948983bfe9f..8cfec9a4ec2fb 100644 --- a/flang/runtime/type-code.cpp +++ b/flang-rt/lib/runtime/type-code.cpp @@ -1,4 +1,4 @@ -//===-- runtime/type-code.cpp ---------------------------------------------===// +//===-- lib/runtime/type-code.cpp -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/type-code.h" +#include "flang-rt/runtime/type-code.h" namespace Fortran::runtime { diff --git a/flang/runtime/type-info.cpp b/flang-rt/lib/runtime/type-info.cpp similarity index 97% rename from flang/runtime/type-info.cpp rename to flang-rt/lib/runtime/type-info.cpp index d4daa72aee6a1..82182696d70c6 100644 --- a/flang/runtime/type-info.cpp +++ b/flang-rt/lib/runtime/type-info.cpp @@ -1,4 +1,4 @@ -//===-- runtime/type-info.cpp ---------------------------------------------===// +//===-- lib/runtime/type-info.cpp -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "type-info.h" -#include "terminator.h" -#include "tools.h" +#include "flang-rt/runtime/type-info.h" +#include "flang-rt/runtime/terminator.h" +#include "flang-rt/runtime/tools.h" #include namespace Fortran::runtime::typeInfo { @@ -86,7 +86,7 @@ RT_API_ATTRS std::size_t Component::SizeInBytes( } else if (category() == TypeCategory::Derived) { const DerivedType *type{derivedType()}; return Descriptor::SizeInBytes( - rank_, true, type ? type->LenParameters() : 0); + rank_, true, type ? type->LenParameters() : 0); } else { return Descriptor::SizeInBytes(rank_); } diff --git a/flang/runtime/unit-map.cpp b/flang-rt/lib/runtime/unit-map.cpp similarity index 97% rename from flang/runtime/unit-map.cpp rename to flang-rt/lib/runtime/unit-map.cpp index 684a9b9e20b97..41a03f3319d64 100644 --- a/flang/runtime/unit-map.cpp +++ b/flang-rt/lib/runtime/unit-map.cpp @@ -1,4 +1,4 @@ -//===-- runtime/unit-map.cpp ----------------------------------------------===// +//===-- lib/runtime/unit-map.cpp --------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/runtime/unit-map.h b/flang-rt/lib/runtime/unit-map.h similarity index 92% rename from flang/runtime/unit-map.h rename to flang-rt/lib/runtime/unit-map.h index 6f1e01bb1e64a..fa61288a1e18d 100644 --- a/flang/runtime/unit-map.h +++ b/flang-rt/lib/runtime/unit-map.h @@ -1,4 +1,4 @@ -//===-- runtime/unit-map.h --------------------------------------*- C++ -*-===// +//===-- lib/runtime/unit-map.h ----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,13 +9,13 @@ // Maps Fortran unit numbers to their ExternalFileUnit instances. // A simple hash table with forward-linked chains per bucket. -#ifndef FORTRAN_RUNTIME_UNIT_MAP_H_ -#define FORTRAN_RUNTIME_UNIT_MAP_H_ +#ifndef FLANG_RT_RUNTIME_UNIT_MAP_H_ +#define FLANG_RT_RUNTIME_UNIT_MAP_H_ -#include "lock.h" #include "unit.h" +#include "flang-rt/runtime/lock.h" +#include "flang-rt/runtime/memory.h" #include "flang/Common/fast-int-set.h" -#include "flang/Runtime/memory.h" #include #include @@ -100,4 +100,4 @@ class UnitMap { int emergencyNewUnit_{maxNewUnits_}; // not recycled }; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_UNIT_MAP_H_ +#endif // FLANG_RT_RUNTIME_UNIT_MAP_H_ diff --git a/flang/runtime/unit.cpp b/flang-rt/lib/runtime/unit.cpp similarity index 99% rename from flang/runtime/unit.cpp rename to flang-rt/lib/runtime/unit.cpp index 4aee8397d477e..1d4d54ae01956 100644 --- a/flang/runtime/unit.cpp +++ b/flang-rt/lib/runtime/unit.cpp @@ -1,4 +1,4 @@ -//===-- runtime/unit.cpp --------------------------------------------------===// +//===-- lib/runtime/unit.cpp ------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -11,9 +11,9 @@ // //===----------------------------------------------------------------------===// #include "unit.h" -#include "io-error.h" -#include "lock.h" -#include "tools.h" +#include "flang-rt/runtime/io-error.h" +#include "flang-rt/runtime/lock.h" +#include "flang-rt/runtime/tools.h" #include #include diff --git a/flang/runtime/unit.h b/flang-rt/lib/runtime/unit.h similarity index 95% rename from flang/runtime/unit.h rename to flang-rt/lib/runtime/unit.h index a3ea268681680..eb762a2d3b235 100644 --- a/flang/runtime/unit.h +++ b/flang-rt/lib/runtime/unit.h @@ -1,4 +1,4 @@ -//===-- runtime/unit.h ------------------------------------------*- C++ -*-===// +//===-- lib/runtime/unit.h --------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,21 +8,21 @@ // Fortran external I/O units -#ifndef FORTRAN_RUNTIME_IO_UNIT_H_ -#define FORTRAN_RUNTIME_IO_UNIT_H_ - -#include "buffer.h" -#include "connection.h" -#include "environment.h" -#include "file.h" -#include "format.h" -#include "io-error.h" -#include "io-stmt.h" -#include "lock.h" -#include "terminator.h" +#ifndef FLANG_RT_RUNTIME_UNIT_H_ +#define FLANG_RT_RUNTIME_UNIT_H_ + +#include "flang-rt/runtime/buffer.h" +#include "flang-rt/runtime/connection.h" +#include "flang-rt/runtime/environment.h" +#include "flang-rt/runtime/file.h" +#include "flang-rt/runtime/format.h" +#include "flang-rt/runtime/io-error.h" +#include "flang-rt/runtime/io-stmt.h" +#include "flang-rt/runtime/lock.h" +#include "flang-rt/runtime/memory.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Common/constexpr-bitset.h" #include "flang/Common/optional.h" -#include "flang/Runtime/memory.h" #include #include #include @@ -291,4 +291,4 @@ class ChildIo { }; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_IO_UNIT_H_ +#endif // FLANG_RT_RUNTIME_UNIT_H_ diff --git a/flang/runtime/utf.cpp b/flang-rt/lib/runtime/utf.cpp similarity index 97% rename from flang/runtime/utf.cpp rename to flang-rt/lib/runtime/utf.cpp index b09819cb2f736..ef9df49f24f66 100644 --- a/flang/runtime/utf.cpp +++ b/flang-rt/lib/runtime/utf.cpp @@ -1,4 +1,4 @@ -//===-- runtime/utf.cpp ---------------------------------------------------===// +//===-- lib/runtime/utf.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "utf.h" +#include "flang-rt/runtime/utf.h" namespace Fortran::runtime { diff --git a/flang-rt/test/CMakeLists.txt b/flang-rt/test/CMakeLists.txt new file mode 100644 index 0000000000000..f5f7b8832d381 --- /dev/null +++ b/flang-rt/test/CMakeLists.txt @@ -0,0 +1,59 @@ +#===-- test/CMakeLists.txt -------------------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +# Test runner infrastructure for Flang. This configures the Flang test trees +# for use by Lit, and delegates to LLVM's lit test handlers. + +llvm_canonicalize_cmake_booleans( + FLANG_STANDALONE_BUILD + LLVM_BUILD_EXAMPLES + LLVM_BYE_LINK_INTO_TOOLS + LLVM_ENABLE_PLUGINS +) + +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py +) + +if (TARGET FlangRTUnitTests) + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.cfg.py + ) + + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/NonGtestUnit/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/NonGtestUnit/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/NonGtestUnit/lit.cfg.py + ) +endif () + + +add_custom_target(flang-rt-test-depends) +set_target_properties(flang-rt-test-depends PROPERTIES FOLDER "Flang-RT/Meta") +add_dependencies(flang-rt-test-depends + FlangRTUnitTests + flang_rt.runtime + flang_rt.runtime.unittest + ) + +add_lit_testsuite(check-flang-rt "Running the Flang-RT regression tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS flang-rt-test-depends + ) +set_target_properties(check-flang-rt PROPERTIES FOLDER "Flang-RT/Meta") + +add_lit_testsuites(flang-rt ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS flang-rt-test-depends + ) diff --git a/flang/test/Driver/ctofortran.f90 b/flang-rt/test/Driver/ctofortran.f90 similarity index 69% rename from flang/test/Driver/ctofortran.f90 rename to flang-rt/test/Driver/ctofortran.f90 index 10c7adaccc958..e385e7974cdc1 100644 --- a/flang/test/Driver/ctofortran.f90 +++ b/flang-rt/test/Driver/ctofortran.f90 @@ -1,8 +1,10 @@ ! UNSUPPORTED: system-windows -! REQUIRES: flang-rt +! UNSUPPORTED: offload-cuda + ! RUN: split-file %s %t -! RUN: chmod +x %t/runtest.sh -! RUN: %t/runtest.sh %t %t/ffile.f90 %t/cfile.c %flang | FileCheck %s +! RUN: %clang -I"%include/flang" -c %t/cfile.c -o %t/cfile.o +! RUN: %flang -L"%libdir" %t/ffile.f90 %t/cfile.o -o %t/ctofortran +! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%libdir" %t/ctofortran | FileCheck %s !--- ffile.f90 program fmain @@ -66,24 +68,3 @@ end subroutine foo foo(desc); return; } -!--- runtest.sh -#!/bin/bash -TMPDIR=$1 -FFILE=$2 -CFILE=$3 -FLANG=$4 -shift 4 -FLAGS="$*" -BINDIR=`dirname $FLANG` -LIBDIR=$BINDIR/../lib -CCOMP=$BINDIR/clang -if [ -x $CCOMP ] -then - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBDIR - $CCOMP $FLAGS -c $CFILE -o $TMPDIR/cfile.o - $FLANG $FLAGS $FFILE $TMPDIR/cfile.o -o $TMPDIR/ctofortran - $TMPDIR/ctofortran # should print "PASS" -else - # No clang compiler, just pass by default - echo "PASS" -fi diff --git a/flang/test/Driver/exec.f90 b/flang-rt/test/Driver/exec.f90 similarity index 50% rename from flang/test/Driver/exec.f90 rename to flang-rt/test/Driver/exec.f90 index 9ca91ee24011c..5a81a1e4c3e45 100644 --- a/flang/test/Driver/exec.f90 +++ b/flang-rt/test/Driver/exec.f90 @@ -1,10 +1,10 @@ -! UNSUPPORTED: system-windows ! REQUIRES: flang-rt +! UNSUPPORTED: offload-cuda + ! Verify that flang can correctly build executables. -! RUN: %flang %s -o %t -! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%llvmshlibdir" %t | FileCheck %s -! RUN: rm -f %t +! RUN: %flang -L"%libdir" %s -o %t +! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%libdir" %t | FileCheck %s ! CHECK: Hello, World! program hello diff --git a/flang-rt/test/NonGtestUnit/lit.cfg.py b/flang-rt/test/NonGtestUnit/lit.cfg.py new file mode 100644 index 0000000000000..4bee709b78f43 --- /dev/null +++ b/flang-rt/test/NonGtestUnit/lit.cfg.py @@ -0,0 +1,22 @@ +# -*- Python -*- + +import os + +import lit.formats + +# name: The name of this test suite. +config.name = "flang-rt-OldUnit" + +# suffixes: A list of file extensions to treat as test files. +# On Windows, ".exe" also matches the GTests and will execited redundantly. +config.suffixes = [".test", ".exe"] + +# test_source_root: The root path where unit test binaries are located. +config.test_source_root = os.path.join(config.flangrt_binary_dir, "unittests") + +# test_exec_root: The root path where tests should be run. +# lit writes a '.lit_test_times.txt' file into this directory. +config.test_exec_root = config.flang_rt_binary_test_dir + +# testFormat: The test format to use to interpret tests. +config.test_format = lit.formats.ExecutableTest() diff --git a/flang-rt/test/NonGtestUnit/lit.site.cfg.py.in b/flang-rt/test/NonGtestUnit/lit.site.cfg.py.in new file mode 100644 index 0000000000000..8244b5b62d3aa --- /dev/null +++ b/flang-rt/test/NonGtestUnit/lit.site.cfg.py.in @@ -0,0 +1,14 @@ +@LIT_SITE_CFG_IN_HEADER@ + +import os + +config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" +config.flang_rt_source_dir = "@FLANG_RT_SOURCE_DIR@" +config.flangrt_binary_dir = "@FLANG_RT_BINARY_DIR@" +config.flang_rt_binary_test_dir = os.path.dirname(__file__) + +import lit.llvm +lit.llvm.initialize(lit_config, config) + +# Let the main config do the real work. +lit_config.load_config(config, os.path.join(config.flang_rt_source_dir, 'test', 'NonGtestUnit', 'lit.cfg.py')) diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang-rt/test/Runtime/no-cpp-dep.c similarity index 91% rename from flang/test/Runtime/no-cpp-dep.c rename to flang-rt/test/Runtime/no-cpp-dep.c index 4fcf8f9d478d8..c98678b69aa14 100644 --- a/flang/test/Runtime/no-cpp-dep.c +++ b/flang-rt/test/Runtime/no-cpp-dep.c @@ -3,10 +3,11 @@ This test makes sure that flang's runtime does not depend on the C++ runtime library. It tries to link this simple file against libflang_rt.runtime.a with a C compiler. -REQUIRES: c-compiler, flang-rt +UNSUPPORTED: system-windows +UNSUPPORTED: offload-cuda RUN: %if system-aix %{ export OBJECT_MODE=64 %} -RUN: %cc -std=c99 %s -I%include %libruntime -lm \ +RUN: %cc -std=c99 %s -I%include -L"%libdir" -lflang_rt.runtime -lm \ RUN: %if system-aix %{-lpthread %} RUN: rm a.out */ diff --git a/flang-rt/test/Unit/lit.cfg.py b/flang-rt/test/Unit/lit.cfg.py new file mode 100644 index 0000000000000..516bc653f413f --- /dev/null +++ b/flang-rt/test/Unit/lit.cfg.py @@ -0,0 +1,21 @@ +# -*- Python -*- + +import os + +import lit.formats + +# name: The name of this test suite. +config.name = "flang-rt-Unit" + +# suffixes: A list of file extensions to treat as test files. +config.suffixes = [] + +# test_source_root: The root path where unit test binaries are located. +config.test_source_root = os.path.join(config.flangrt_binary_dir, "unittests") + +# test_exec_root: The root path where tests should be run. +# lit writes a '.lit_test_times.txt' file into this directory. +config.test_exec_root = config.flang_rt_binary_test_dir + +# testFormat: The test format to use to interpret tests. +config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, "Tests") diff --git a/flang-rt/test/Unit/lit.site.cfg.py.in b/flang-rt/test/Unit/lit.site.cfg.py.in new file mode 100644 index 0000000000000..ed6dea07bcdde --- /dev/null +++ b/flang-rt/test/Unit/lit.site.cfg.py.in @@ -0,0 +1,15 @@ +@LIT_SITE_CFG_IN_HEADER@ + +import os + +config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" +config.llvm_build_mode = "@LLVM_BUILD_MODE@" +config.flang_rt_source_dir = "@FLANG_RT_SOURCE_DIR@" +config.flangrt_binary_dir = "@FLANG_RT_BINARY_DIR@" +config.flang_rt_binary_test_dir = os.path.dirname(__file__) + +import lit.llvm +lit.llvm.initialize(lit_config, config) + +# Let the main config do the real work. +lit_config.load_config(config, os.path.join(config.flang_rt_source_dir, 'test', 'Unit', 'lit.cfg.py')) diff --git a/flang-rt/test/lit.cfg.py b/flang-rt/test/lit.cfg.py new file mode 100644 index 0000000000000..652da31e6438f --- /dev/null +++ b/flang-rt/test/lit.cfg.py @@ -0,0 +1,100 @@ +# -*- Python -*- + +import shlex +import lit.util + +from lit.llvm import llvm_config +from lit.llvm.subst import ToolSubst, FindTool + + +def shjoin(args, sep=" "): + return sep.join([shlex.quote(arg) for arg in args]) + + +# Configuration file for the 'lit' test runner. + +# name: The name of this test suite. +config.name = "flang-rt" + +# testFormat: The test format to use to interpret tests. +# +# For now we require '&&' between commands, until they get globally killed and +# the test runner updated. +config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) + +# suffixes: A list of file extensions to treat as test files. +config.suffixes = [ + ".c", + ".cpp", + ".f", + ".F", + ".ff", + ".FOR", + ".for", + ".f77", + ".f90", + ".F90", + ".ff90", + ".f95", + ".F95", + ".ff95", + ".fpp", + ".FPP", + ".cuf", + ".CUF", + ".f18", + ".F18", + ".f03", + ".F03", + ".f08", + ".F08", + ".ll", + ".fir", + ".mlir", +] + +llvm_config.use_default_substitutions() + +# test_source_root: The root path where tests are located. +config.test_source_root = os.path.dirname(__file__) + +# test_exec_root: The root path where tests should be run. +# lit writes a '.lit_test_times.txt' file into this directory. +config.test_exec_root = config.flang_rt_binary_test_dir + +# On MacOS, -isysroot is needed to build binaries. +isysroot_flag = [] +if config.osx_sysroot: + isysroot_flag = ["-isysroot", config.osx_sysroot] + +tools = [ + ToolSubst( + "%flang", + command=config.flang, + extra_args=isysroot_flag, + unresolved="fatal", + ), + ToolSubst( + "%clang", + command=FindTool("clang"), + extra_args=isysroot_flag, + unresolved="fatal", + ), + ToolSubst("%cc", command=config.cc, extra_args=isysroot_flag, unresolved="fatal"), +] +llvm_config.add_tool_substitutions(tools) + +# Let tests find LLVM's standard tools (FileCheck, split-file, not, ...) +llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True) + +# Include path for C headers that define Flang's Fortran ABI. +config.substitutions.append( + ("%include", os.path.join(config.flang_source_dir, "include")) +) + +# Library path of libflang_rt.runtime.a (for lib search path when using non-Flang driver for linking) +config.substitutions.append(("%libdir", config.flang_rt_output_resource_lib_dir)) + +# For CUDA offloading, additional steps (device linking) and libraries (cudart) are needed. +if config.flang_rt_experimental_offload_support == "CUDA": + config.available_features.add("offload-cuda") diff --git a/flang-rt/test/lit.site.cfg.py.in b/flang-rt/test/lit.site.cfg.py.in new file mode 100644 index 0000000000000..662d076b1fe24 --- /dev/null +++ b/flang-rt/test/lit.site.cfg.py.in @@ -0,0 +1,19 @@ +@LIT_SITE_CFG_IN_HEADER@ + +import sys + +config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" +config.flang_source_dir = "@FLANG_SOURCE_DIR@" +config.flang_rt_source_dir = "@FLANG_RT_SOURCE_DIR@" +config.flang_rt_binary_test_dir = os.path.dirname(__file__) +config.flang_rt_output_resource_lib_dir = "@FLANG_RT_OUTPUT_RESOURCE_LIB_DIR@" +config.flang_rt_experimental_offload_support = "@FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT@" +config.cc = "@CMAKE_C_COMPILER@" +config.flang = "@CMAKE_Fortran_COMPILER@" +config.osx_sysroot = path(r"@CMAKE_OSX_SYSROOT@") + +import lit.llvm +lit.llvm.initialize(lit_config, config) + +# Let the main config do the real work. +lit_config.load_config(config, os.path.join(config.flang_rt_source_dir, 'test', 'lit.cfg.py')) diff --git a/flang-rt/unittests/CMakeLists.txt b/flang-rt/unittests/CMakeLists.txt new file mode 100644 index 0000000000000..e2a50d8b40a9d --- /dev/null +++ b/flang-rt/unittests/CMakeLists.txt @@ -0,0 +1,105 @@ +#===-- unittests/CMakeLists.txt --------------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +# LLVM uses a modified version of GTest that uses LLVMSupport for console +# output. Therefore it also needs to include files from LLVM. Unfortunately, +# LLVM/GTest doesn't add the include search path itself. Limiting the scope +# using target_include_directories does not work because with +# LLVM_INSTALL_GTEST=ON, as llvm_gtest is an IMPORT library. +include_directories("${LLVM_INCLUDE_DIR}" "${LLVM_MAIN_INCLUDE_DIR}") + +# Add GTest if not already present. +# Using a function so LLVM_SUBPROJECT_TITLE does not propagate. +function (build_gtest) + set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test") + add_subdirectory("${LLVM_THIRD_PARTY_DIR}/unittest" "${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest") +endfunction () +if (NOT TARGET llvm_gtest) + build_gtest() +endif () + +if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG) + add_compile_options("-Wno-suggest-override") +endif() + + +# Target that depends on all unittests +add_custom_target(FlangRTUnitTests) +set_target_properties(FlangRTUnitTests PROPERTIES FOLDER "Flang-RT/Meta") + + +function(add_flangrt_unittest_offload_properties target) + # Set CUDA_RESOLVE_DEVICE_SYMBOLS. + if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA") + set_target_properties(${target} + PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON + ) + endif() + # Enable OpenMP offload during linking. We may need to replace + # LINK_OPTIONS with COMPILE_OPTIONS when there are OpenMP offload + # unittests. + # + # FIXME: replace 'native' in --offload-arch option with the list + # of targets that Fortran Runtime was built for. + if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "OpenMP") + set_target_properties(${target} + PROPERTIES LINK_OPTIONS + "-fopenmp;--offload-arch=native" + ) + endif() +endfunction() + + +function(add_flangrt_unittest test_dirname) + cmake_parse_arguments(ARG + "" + "" + "LINK_LIBS" + ${ARGN}) + + add_unittest(FlangRTUnitTests ${test_dirname} ${ARG_UNPARSED_ARGUMENTS}) + + target_link_libraries(${test_dirname} PRIVATE ${ARG_LINK_LIBS}) + add_flangrt_unittest_offload_properties(${test_dirname}) + + # Required because LLVMSupport is compiled with this option. + # FIXME: According to CMake documentation, this is the default. Why is it + # needed? LLVM's add_unittest doesn't set it either. + set_target_properties(${test_dirname} + PROPERTIES + MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL" + ) +endfunction() + +function(add_flangrt_nongtest_unittest test_name) + cmake_parse_arguments(ARG + "SLOW_TEST" + "" + "LINK_LIBS" + ${ARGN}) + + if(ARG_SLOW_TEST) + set(suffix .slow) + else() + set(suffix .test) + endif() + + add_executable(${test_name}${suffix} EXCLUDE_FROM_ALL ${ARG_UNPARSED_ARGUMENTS}) + set_target_properties(${test_name}${suffix} PROPERTIES FOLDER "Flang-RT/Tests/Unit") + + target_link_libraries(${test_name}${suffix} PRIVATE NonGTestTesting ${ARG_LINK_LIBS}) + + if(NOT ARG_SLOW_TEST) + add_dependencies(FlangRTUnitTests ${test_name}${suffix}) + endif() + + add_flangrt_unittest_offload_properties(${test_name}${suffix}) +endfunction() + +add_subdirectory(Evaluate) +add_subdirectory(Runtime) diff --git a/flang-rt/unittests/Evaluate/CMakeLists.txt b/flang-rt/unittests/Evaluate/CMakeLists.txt new file mode 100644 index 0000000000000..526ec234d57da --- /dev/null +++ b/flang-rt/unittests/Evaluate/CMakeLists.txt @@ -0,0 +1,21 @@ +#===-- unittests/Evaluate/CMakeLists.txt -----------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +add_flangrt_nongtest_unittest(reshape + reshape.cpp + + LINK_LIBS + flang_rt.runtime.unittest +) + +add_flangrt_nongtest_unittest(ISO-Fortran-binding + ISO-Fortran-binding.cpp + + LINK_LIBS + flang_rt.runtime.unittest +) diff --git a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp similarity index 98% rename from flang/unittests/Evaluate/ISO-Fortran-binding.cpp rename to flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp index 2884686b3f26e..8c0a6f29b6967 100644 --- a/flang/unittests/Evaluate/ISO-Fortran-binding.cpp +++ b/flang-rt/unittests/Evaluate/ISO-Fortran-binding.cpp @@ -1,5 +1,13 @@ +//===-- unittests/Evaluate/ISO-Fortran-binding.cpp --------------*- 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 +// +//===----------------------------------------------------------------------===// + +#include "flang-rt/runtime/descriptor.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" -#include "flang/Runtime/descriptor.h" #include "flang/Testing/testing.h" #include "llvm/Support/raw_ostream.h" #include diff --git a/flang/unittests/Evaluate/reshape.cpp b/flang-rt/unittests/Evaluate/reshape.cpp similarity index 88% rename from flang/unittests/Evaluate/reshape.cpp rename to flang-rt/unittests/Evaluate/reshape.cpp index 16cba15dcef60..2abe46c0969fb 100644 --- a/flang/unittests/Evaluate/reshape.cpp +++ b/flang-rt/unittests/Evaluate/reshape.cpp @@ -1,4 +1,12 @@ -#include "flang/Runtime/descriptor.h" +//===-- unittests/Evaluate/reshape.cpp --------------------------*- 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 +// +//===----------------------------------------------------------------------===// + +#include "flang-rt/runtime/descriptor.h" #include "flang/Runtime/transformational.h" #include "flang/Testing/testing.h" #include diff --git a/flang/unittests/Runtime/AccessTest.cpp b/flang-rt/unittests/Runtime/AccessTest.cpp similarity index 99% rename from flang/unittests/Runtime/AccessTest.cpp rename to flang-rt/unittests/Runtime/AccessTest.cpp index c2a2d7d398220..d431d0d19bd61 100644 --- a/flang/unittests/Runtime/AccessTest.cpp +++ b/flang-rt/unittests/Runtime/AccessTest.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/AccessTest.cpp ----------------------------===// +//===-- unittests/Runtime/AccessTest.cpp ------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/unittests/Runtime/Allocatable.cpp b/flang-rt/unittests/Runtime/Allocatable.cpp similarity index 97% rename from flang/unittests/Runtime/Allocatable.cpp rename to flang-rt/unittests/Runtime/Allocatable.cpp index f15f26bfd9c57..4702f48e0f440 100644 --- a/flang/unittests/Runtime/Allocatable.cpp +++ b/flang-rt/unittests/Runtime/Allocatable.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Allocatable.cpp--------- ---------*- C++-*-===// +//===-- unittests/Runtime/Allocatable.cpp -----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,7 +8,7 @@ #include "flang/Runtime/allocatable.h" #include "gtest/gtest.h" -#include "tools.h" +#include "flang-rt/runtime/tools.h" using namespace Fortran::runtime; diff --git a/flang/unittests/Runtime/ArrayConstructor.cpp b/flang-rt/unittests/Runtime/ArrayConstructor.cpp similarity index 96% rename from flang/unittests/Runtime/ArrayConstructor.cpp rename to flang-rt/unittests/Runtime/ArrayConstructor.cpp index 53774a0eea07d..5f791e7f4a7c3 100644 --- a/flang/unittests/Runtime/ArrayConstructor.cpp +++ b/flang-rt/unittests/Runtime/ArrayConstructor.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/ArrayConstructor.cpp-------------*- C++ -*-===// +//===-- unittests/Runtime/ArrayConstructor.cpp ------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,13 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "tools.h" +#include "gtest/gtest.h" +#include "flang-rt/runtime/array-constructor.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/type-code.h" #include "flang/Runtime/allocatable.h" -#include "flang/Runtime/array-constructor.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" -#include "flang/Runtime/type-code.h" #include diff --git a/flang/unittests/Runtime/BufferTest.cpp b/flang-rt/unittests/Runtime/BufferTest.cpp similarity index 97% rename from flang/unittests/Runtime/BufferTest.cpp rename to flang-rt/unittests/Runtime/BufferTest.cpp index 0632324b25d22..f4b9e901d6fcb 100644 --- a/flang/unittests/Runtime/BufferTest.cpp +++ b/flang-rt/unittests/Runtime/BufferTest.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/BufferTest.cpp ------------------*- C++ -*-===// +//===-- unittests/Runtime/BufferTest.cpp ------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "../../runtime/buffer.h" +#include "flang-rt/runtime/buffer.h" #include "CrashHandlerFixture.h" #include "gtest/gtest.h" #include diff --git a/flang-rt/unittests/Runtime/CMakeLists.txt b/flang-rt/unittests/Runtime/CMakeLists.txt new file mode 100644 index 0000000000000..61d0aba93b14b --- /dev/null +++ b/flang-rt/unittests/Runtime/CMakeLists.txt @@ -0,0 +1,48 @@ +#===-- unittests/Runtime/CMakeLists.txt ------------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +add_flangrt_unittest(RuntimeTests + AccessTest.cpp + Allocatable.cpp + ArrayConstructor.cpp + BufferTest.cpp + CharacterTest.cpp + CommandTest.cpp + Complex.cpp + CrashHandlerFixture.cpp + Derived.cpp + ExternalIOTest.cpp + Format.cpp + Inquiry.cpp + ListInputTest.cpp + LogicalFormatTest.cpp + Matmul.cpp + MatmulTranspose.cpp + MiscIntrinsic.cpp + Namelist.cpp + Numeric.cpp + NumericalFormatTest.cpp + Pointer.cpp + Ragged.cpp + Random.cpp + Reduction.cpp + RuntimeCrashTest.cpp + Stop.cpp + Support.cpp + Time.cpp + TemporaryStack.cpp + Transformational.cpp + + LINK_LIBS + flang_rt.runtime.unittest +) +target_compile_definitions(RuntimeTests PRIVATE NOT_EXE="${LLVM_TOOLS_DIR}/not${CMAKE_EXECUTABLE_SUFFIX}") + +if (FLANG_RT_INCLUDE_CUF) + add_subdirectory(CUDA) +endif () diff --git a/flang/unittests/Runtime/CUDA/Allocatable.cpp b/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp similarity index 90% rename from flang/unittests/Runtime/CUDA/Allocatable.cpp rename to flang-rt/unittests/Runtime/CUDA/Allocatable.cpp index bdfa8f5cc3213..3f759a69c0388 100644 --- a/flang/unittests/Runtime/CUDA/Allocatable.cpp +++ b/flang-rt/unittests/Runtime/CUDA/Allocatable.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Allocatable.cpp ------------------*- C++-*-===// +//===-- unittests/Runtime/CUDA/Allocatable.cpp ------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,16 +7,16 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/allocatable.h" +#include "cuda_runtime.h" #include "gtest/gtest.h" -#include "../../../runtime/terminator.h" +#include "flang-rt/runtime/allocator-registry.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/allocator.h" #include "flang/Runtime/CUDA/common.h" #include "flang/Runtime/CUDA/descriptor.h" -#include "flang/Runtime/allocator-registry.h" #include "flang/Support/Fortran.h" -#include "cuda_runtime.h" - using namespace Fortran::runtime; using namespace Fortran::runtime::cuda; diff --git a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp similarity index 92% rename from flang/unittests/Runtime/CUDA/AllocatorCUF.cpp rename to flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp index 5ec122e4c5777..9bda3270fe8a1 100644 --- a/flang/unittests/Runtime/CUDA/AllocatorCUF.cpp +++ b/flang-rt/unittests/Runtime/CUDA/AllocatorCUF.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/AllocatableCUF.cpp ---------------*- C++-*-===// +//===-- unittests/Runtime/CUDA/AllocatorCUF.cpp -----------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,16 +6,16 @@ // //===----------------------------------------------------------------------===// +#include "cuda_runtime.h" #include "gtest/gtest.h" -#include "../../../runtime/terminator.h" +#include "flang-rt/runtime/allocator-registry.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/allocator.h" #include "flang/Runtime/CUDA/descriptor.h" #include "flang/Runtime/allocatable.h" -#include "flang/Runtime/allocator-registry.h" #include "flang/Support/Fortran.h" -#include "cuda_runtime.h" - using namespace Fortran::runtime; using namespace Fortran::runtime::cuda; diff --git a/flang-rt/unittests/Runtime/CUDA/CMakeLists.txt b/flang-rt/unittests/Runtime/CUDA/CMakeLists.txt new file mode 100644 index 0000000000000..cd69a6f472873 --- /dev/null +++ b/flang-rt/unittests/Runtime/CUDA/CMakeLists.txt @@ -0,0 +1,18 @@ +#===-- unittests/Runtime/CUDA/CMakeLists.txt -------------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# + +add_flangrt_unittest(FlangCufRuntimeTests + Allocatable.cpp + AllocatorCUF.cpp + Memory.cpp +) + +target_link_libraries(FlangCufRuntimeTests + PRIVATE + flang_rt.cuda +) diff --git a/flang/unittests/Runtime/CUDA/Memory.cpp b/flang-rt/unittests/Runtime/CUDA/Memory.cpp similarity index 93% rename from flang/unittests/Runtime/CUDA/Memory.cpp rename to flang-rt/unittests/Runtime/CUDA/Memory.cpp index 61c9d1131ee56..37ae59ec238c8 100644 --- a/flang/unittests/Runtime/CUDA/Memory.cpp +++ b/flang-rt/unittests/Runtime/CUDA/Memory.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Memory.cpp -----------------------*- C++-*-===// +//===-- unittests/Runtime/CUDA/Memory.cpp -----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,18 +7,17 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/CUDA/memory.h" -#include "gtest/gtest.h" -#include "../../../runtime/terminator.h" +#include "cuda_runtime.h" #include "../tools.h" +#include "gtest/gtest.h" +#include "flang-rt/runtime/allocator-registry.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/CUDA/allocator.h" #include "flang/Runtime/CUDA/common.h" #include "flang/Runtime/CUDA/descriptor.h" #include "flang/Runtime/allocatable.h" -#include "flang/Runtime/allocator-registry.h" #include "flang/Support/Fortran.h" -#include "cuda_runtime.h" - using namespace Fortran::runtime; using namespace Fortran::runtime::cuda; diff --git a/flang/unittests/Runtime/CharacterTest.cpp b/flang-rt/unittests/Runtime/CharacterTest.cpp similarity index 99% rename from flang/unittests/Runtime/CharacterTest.cpp rename to flang-rt/unittests/Runtime/CharacterTest.cpp index d462c9120fd8c..83ec9b36d9b0c 100644 --- a/flang/unittests/Runtime/CharacterTest.cpp +++ b/flang-rt/unittests/Runtime/CharacterTest.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/CharacterTest.cpp ---------------*- C++ -*-===// +//===-- unittests/Runtime/CharacterTest.cpp ---------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -11,7 +11,7 @@ #include "flang/Runtime/character.h" #include "gtest/gtest.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" #include #include #include diff --git a/flang/unittests/Runtime/CommandTest.cpp b/flang-rt/unittests/Runtime/CommandTest.cpp similarity index 99% rename from flang/unittests/Runtime/CommandTest.cpp rename to flang-rt/unittests/Runtime/CommandTest.cpp index ecb325330f1ad..72fe7629dbbb8 100644 --- a/flang/unittests/Runtime/CommandTest.cpp +++ b/flang-rt/unittests/Runtime/CommandTest.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/CommandTest.cpp ---------------------------===// +//===-- unittests/Runtime/CommandTest.cpp -----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,7 +9,7 @@ #include "flang/Runtime/command.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" #include "flang/Runtime/execute.h" #include "flang/Runtime/extensions.h" #include "flang/Runtime/main.h" diff --git a/flang/unittests/Runtime/Complex.cpp b/flang-rt/unittests/Runtime/Complex.cpp similarity index 98% rename from flang/unittests/Runtime/Complex.cpp rename to flang-rt/unittests/Runtime/Complex.cpp index d714da24dc4e5..d7e5f55414fe2 100644 --- a/flang/unittests/Runtime/Complex.cpp +++ b/flang-rt/unittests/Runtime/Complex.cpp @@ -1,10 +1,11 @@ -//===-- flang/unittests/Runtime/Complex.cpp ---------------------*- C++ -*-===// +//===-- unittests/Runtime/Complex.cpp ---------------------------*- 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 // //===----------------------------------------------------------------------===// + #include "gmock/gmock.h" #include "gtest/gtest-matchers.h" #include diff --git a/flang/unittests/Runtime/CrashHandlerFixture.cpp b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp similarity index 92% rename from flang/unittests/Runtime/CrashHandlerFixture.cpp rename to flang-rt/unittests/Runtime/CrashHandlerFixture.cpp index 811603337e660..8213edd1f9225 100644 --- a/flang/unittests/Runtime/CrashHandlerFixture.cpp +++ b/flang-rt/unittests/Runtime/CrashHandlerFixture.cpp @@ -1,12 +1,13 @@ -//===-- flang/unittests/Runtime/CrashHandlerFixture.cpp ---------*- C++ -*-===// +//===-- unittests/Runtime/CrashHandlerFixture.cpp ---------------*- 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 // //===----------------------------------------------------------------------===// + #include "CrashHandlerFixture.h" -#include "../../runtime/terminator.h" +#include "flang-rt/runtime/terminator.h" #include #include diff --git a/flang/unittests/Runtime/CrashHandlerFixture.h b/flang-rt/unittests/Runtime/CrashHandlerFixture.h similarity index 70% rename from flang/unittests/Runtime/CrashHandlerFixture.h rename to flang-rt/unittests/Runtime/CrashHandlerFixture.h index fe0ee0da5204e..74531d1e728f4 100644 --- a/flang/unittests/Runtime/CrashHandlerFixture.h +++ b/flang-rt/unittests/Runtime/CrashHandlerFixture.h @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/CrashHandlerFixture.h -----------*- C++ -*-===// +//===-- unittests/Runtime/CrashHandlerFixture.h -----------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,12 +10,13 @@ /// with expected message. // //===----------------------------------------------------------------------===// -#ifndef LLVM_FLANG_UNITTESTS_RUNTIMEGTEST_CRASHHANDLERFIXTURE_H -#define LLVM_FLANG_UNITTESTS_RUNTIMEGTEST_CRASHHANDLERFIXTURE_H + +#ifndef FLANG_RT_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_ +#define FLANG_RT_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_ #include struct CrashHandlerFixture : testing::Test { void SetUp(); }; -#endif +#endif /* FLANG_RT_UNITTESTS_RUNTIME_CRASHHANDLERFIXTURE_H_ */ diff --git a/flang/unittests/Runtime/Derived.cpp b/flang-rt/unittests/Runtime/Derived.cpp similarity index 93% rename from flang/unittests/Runtime/Derived.cpp rename to flang-rt/unittests/Runtime/Derived.cpp index 019d5e8309e4a..3196ba796ad19 100644 --- a/flang/unittests/Runtime/Derived.cpp +++ b/flang-rt/unittests/Runtime/Derived.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Pointer.cpp--------- -------------*- C++-*-===// +//===-- unittests/Runtime/Derived.cpp ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "gtest/gtest.h" -#include "tools.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/tools.h" #include "flang/Runtime/derived-api.h" -#include "flang/Runtime/descriptor.h" using namespace Fortran::runtime; diff --git a/flang/unittests/Runtime/ExternalIOTest.cpp b/flang-rt/unittests/Runtime/ExternalIOTest.cpp similarity index 99% rename from flang/unittests/Runtime/ExternalIOTest.cpp rename to flang-rt/unittests/Runtime/ExternalIOTest.cpp index b9407b5e7a591..c83535ca82bd3 100644 --- a/flang/unittests/Runtime/ExternalIOTest.cpp +++ b/flang-rt/unittests/Runtime/ExternalIOTest.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/RuntimeGTest/ExternalIOTest.cpp ---------*- C++ -*-===// +//===-- unittests/Runtime/ExternalIOTest.cpp --------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -12,7 +12,7 @@ #include "CrashHandlerFixture.h" #include "gtest/gtest.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" #include "flang/Runtime/io-api-consts.h" #include "flang/Runtime/main.h" #include "flang/Runtime/stop.h" diff --git a/flang/unittests/Runtime/Format.cpp b/flang-rt/unittests/Runtime/Format.cpp similarity index 96% rename from flang/unittests/Runtime/Format.cpp rename to flang-rt/unittests/Runtime/Format.cpp index 01803c628de26..fe7403f26700b 100644 --- a/flang/unittests/Runtime/Format.cpp +++ b/flang-rt/unittests/Runtime/Format.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Format.cpp ----------------------*- C++ -*-===// +//===-- unittests/Runtime/Format.cpp ----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "CrashHandlerFixture.h" -#include "../runtime/connection.h" -#include "../runtime/format-implementation.h" -#include "../runtime/io-error.h" +#include "flang-rt/runtime/connection.h" +#include "flang-rt/runtime/format-implementation.h" +#include "flang-rt/runtime/io-error.h" #include #include #include diff --git a/flang/unittests/Runtime/Inquiry.cpp b/flang-rt/unittests/Runtime/Inquiry.cpp similarity index 97% rename from flang/unittests/Runtime/Inquiry.cpp rename to flang-rt/unittests/Runtime/Inquiry.cpp index 3b523e992a317..e79c037864d9c 100644 --- a/flang/unittests/Runtime/Inquiry.cpp +++ b/flang-rt/unittests/Runtime/Inquiry.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Inquiry.cpp -------------------------------===// +//===-- unittests/Runtime/Inquiry.cpp ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/inquiry.h" -#include "gtest/gtest.h" #include "tools.h" -#include "flang/Runtime/type-code.h" +#include "gtest/gtest.h" +#include "flang-rt/runtime/type-code.h" using namespace Fortran::runtime; using Fortran::common::TypeCategory; diff --git a/flang/unittests/Runtime/ListInputTest.cpp b/flang-rt/unittests/Runtime/ListInputTest.cpp similarity index 98% rename from flang/unittests/Runtime/ListInputTest.cpp rename to flang-rt/unittests/Runtime/ListInputTest.cpp index 38c758b7ef966..310c41a5c3fa5 100644 --- a/flang/unittests/Runtime/ListInputTest.cpp +++ b/flang-rt/unittests/Runtime/ListInputTest.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/ListInputTest.cpp ---------------*- C++ -*-===// +//===-- unittests/Runtime/ListInputTest.cpp ---------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "CrashHandlerFixture.h" -#include "../../runtime/io-error.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/io-error.h" #include "flang/Runtime/io-api-consts.h" using namespace Fortran::runtime; diff --git a/flang/unittests/Runtime/LogicalFormatTest.cpp b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp similarity index 94% rename from flang/unittests/Runtime/LogicalFormatTest.cpp rename to flang-rt/unittests/Runtime/LogicalFormatTest.cpp index 26c9374be1338..bc933292181c1 100644 --- a/flang/unittests/Runtime/LogicalFormatTest.cpp +++ b/flang-rt/unittests/Runtime/LogicalFormatTest.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/LogicalFormatTest.cpp -----------*- C++ -*-===// +//===-- unittests/Runtime/LogicalFormatTest.cpp -----------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "CrashHandlerFixture.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" #include "flang/Runtime/io-api-consts.h" #include #include diff --git a/flang/unittests/Runtime/Matmul.cpp b/flang-rt/unittests/Runtime/Matmul.cpp similarity index 98% rename from flang/unittests/Runtime/Matmul.cpp rename to flang-rt/unittests/Runtime/Matmul.cpp index c3fed9b972df2..1b716fd01fd42 100644 --- a/flang/unittests/Runtime/Matmul.cpp +++ b/flang-rt/unittests/Runtime/Matmul.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Matmul.cpp--------- -------------*- C++ -*-===// +//===-- unittests/Runtime/Matmul.cpp ----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,12 +7,12 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/matmul.h" -#include "gtest/gtest.h" #include "tools.h" +#include "gtest/gtest.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/type-code.h" #include "flang/Runtime/allocatable.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" -#include "flang/Runtime/type-code.h" using namespace Fortran::runtime; using Fortran::common::TypeCategory; diff --git a/flang/unittests/Runtime/MatmulTranspose.cpp b/flang-rt/unittests/Runtime/MatmulTranspose.cpp similarity index 98% rename from flang/unittests/Runtime/MatmulTranspose.cpp rename to flang-rt/unittests/Runtime/MatmulTranspose.cpp index c582e945dc7c9..cc14ab755505a 100644 --- a/flang/unittests/Runtime/MatmulTranspose.cpp +++ b/flang-rt/unittests/Runtime/MatmulTranspose.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/MatmulTranspose.cpp -------------*- C++ -*-===// +//===-- unittests/Runtime/MatmulTranspose.cpp -------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,13 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "tools.h" +#include "gtest/gtest.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/type-code.h" #include "flang/Runtime/allocatable.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include "flang/Runtime/matmul-transpose.h" -#include "flang/Runtime/type-code.h" using namespace Fortran::runtime; using Fortran::common::TypeCategory; diff --git a/flang/unittests/Runtime/MiscIntrinsic.cpp b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp similarity index 96% rename from flang/unittests/Runtime/MiscIntrinsic.cpp rename to flang-rt/unittests/Runtime/MiscIntrinsic.cpp index 7e19ed250bdc0..c6783381bfc35 100644 --- a/flang/unittests/Runtime/MiscIntrinsic.cpp +++ b/flang-rt/unittests/Runtime/MiscIntrinsic.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/MiscIntrinsic.cpp ---------------*- C++ -*-===// +//===-- unittests/Runtime/MiscIntrinsic.cpp ---------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,12 +6,12 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "tools.h" -#include "flang/Runtime//misc-intrinsic.h" +#include "gtest/gtest.h" +#include "flang-rt/runtime/descriptor.h" #include "flang/Runtime/allocatable.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/misc-intrinsic.h" using namespace Fortran::runtime; diff --git a/flang/unittests/Runtime/Namelist.cpp b/flang-rt/unittests/Runtime/Namelist.cpp similarity index 99% rename from flang/unittests/Runtime/Namelist.cpp rename to flang-rt/unittests/Runtime/Namelist.cpp index 0a28f3590b86e..040dedb8cd47c 100644 --- a/flang/unittests/Runtime/Namelist.cpp +++ b/flang-rt/unittests/Runtime/Namelist.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Namelist.cpp --------------------*- C++ -*-===// +//===-- unittests/Runtime/Namelist.cpp --------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,10 @@ // //===----------------------------------------------------------------------===// -#include "../../runtime/namelist.h" +#include "flang-rt/runtime/namelist.h" #include "CrashHandlerFixture.h" #include "tools.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" #include "flang/Runtime/io-api-consts.h" #include #include diff --git a/flang/unittests/Runtime/Numeric.cpp b/flang-rt/unittests/Runtime/Numeric.cpp similarity index 99% rename from flang/unittests/Runtime/Numeric.cpp rename to flang-rt/unittests/Runtime/Numeric.cpp index 29ebbc8ad7aa7..4baad3fc9ad0e 100644 --- a/flang/unittests/Runtime/Numeric.cpp +++ b/flang-rt/unittests/Runtime/Numeric.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Numeric.cpp ---------------------*- C++ -*-===// +//===-- unittests/Runtime/Numeric.cpp ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/unittests/Runtime/NumericalFormatTest.cpp b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp similarity index 99% rename from flang/unittests/Runtime/NumericalFormatTest.cpp rename to flang-rt/unittests/Runtime/NumericalFormatTest.cpp index 274498b8e8695..5a8ead48dcef9 100644 --- a/flang/unittests/Runtime/NumericalFormatTest.cpp +++ b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/NumericalFormatTest.cpp ---------*- C++ -*-===// +//===-- unittests/Runtime/NumericalFormatTest.cpp ---------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "CrashHandlerFixture.h" -#include "flang/Runtime/descriptor.h" +#include "flang-rt/runtime/descriptor.h" #include "flang/Runtime/io-api-consts.h" #include #include diff --git a/flang/unittests/Runtime/Pointer.cpp b/flang-rt/unittests/Runtime/Pointer.cpp similarity index 97% rename from flang/unittests/Runtime/Pointer.cpp rename to flang-rt/unittests/Runtime/Pointer.cpp index 54720afab8d8a..6e8861d374889 100644 --- a/flang/unittests/Runtime/Pointer.cpp +++ b/flang-rt/unittests/Runtime/Pointer.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Pointer.cpp--------- -------------*- C++-*-===// +//===-- unittests/Runtime/Pointer.cpp ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/pointer.h" -#include "gtest/gtest.h" #include "tools.h" -#include "flang/Runtime/descriptor.h" +#include "gtest/gtest.h" +#include "flang-rt/runtime/descriptor.h" using namespace Fortran::runtime; diff --git a/flang/unittests/Runtime/Ragged.cpp b/flang-rt/unittests/Runtime/Ragged.cpp similarity index 94% rename from flang/unittests/Runtime/Ragged.cpp rename to flang-rt/unittests/Runtime/Ragged.cpp index 5049bc83405f1..feadd032f59bd 100644 --- a/flang/unittests/Runtime/Ragged.cpp +++ b/flang-rt/unittests/Runtime/Ragged.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Ragged.cpp ----------------------*- C++ -*-===// +//===-- unittests/Runtime/Ragged.cpp ----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/unittests/Runtime/Random.cpp b/flang-rt/unittests/Runtime/Random.cpp similarity index 92% rename from flang/unittests/Runtime/Random.cpp rename to flang-rt/unittests/Runtime/Random.cpp index cb739b9451429..bf4b540e768fd 100644 --- a/flang/unittests/Runtime/Random.cpp +++ b/flang-rt/unittests/Runtime/Random.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Random.cpp ----------------------*- C++ -*-===// +//===-- unittests/Runtime/Random.cpp ----------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,10 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime//random.h" +#include "flang/Runtime/random.h" #include "gtest/gtest.h" -#include "flang/Runtime/descriptor.h" -#include "flang/Runtime/type-code.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/type-code.h" #include using namespace Fortran::runtime; diff --git a/flang/unittests/Runtime/Reduction.cpp b/flang-rt/unittests/Runtime/Reduction.cpp similarity index 99% rename from flang/unittests/Runtime/Reduction.cpp rename to flang-rt/unittests/Runtime/Reduction.cpp index 29675399abf5c..3701a32042c58 100644 --- a/flang/unittests/Runtime/Reduction.cpp +++ b/flang-rt/unittests/Runtime/Reduction.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Reductions.cpp ----------------------------===// +//===-- unittests/Runtime/Reduction.cpp -------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,14 +7,14 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/reduction.h" -#include "gtest/gtest.h" #include "tools.h" +#include "gtest/gtest.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/type-code.h" #include "flang/Common/float128.h" #include "flang/Runtime/allocatable.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include "flang/Runtime/reduce.h" -#include "flang/Runtime/type-code.h" #include #include #include diff --git a/flang/unittests/Runtime/RuntimeCrashTest.cpp b/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp similarity index 98% rename from flang/unittests/Runtime/RuntimeCrashTest.cpp rename to flang-rt/unittests/Runtime/RuntimeCrashTest.cpp index 72a0b290cf864..e716dac2d1203 100644 --- a/flang/unittests/Runtime/RuntimeCrashTest.cpp +++ b/flang-rt/unittests/Runtime/RuntimeCrashTest.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/CrashHandlerFixture.cpp ---------*- C++ -*-===// +//===-- unittests/Runtime/RuntimeCrashTest.cpp ------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "CrashHandlerFixture.h" #include "tools.h" -#include "../../runtime/terminator.h" +#include "flang-rt/runtime/terminator.h" #include "flang/Runtime/io-api-consts.h" #include "flang/Runtime/transformational.h" #include diff --git a/flang/unittests/Runtime/Stop.cpp b/flang-rt/unittests/Runtime/Stop.cpp similarity index 96% rename from flang/unittests/Runtime/Stop.cpp rename to flang-rt/unittests/Runtime/Stop.cpp index b13602eaee5ea..5d1af20e77de7 100644 --- a/flang/unittests/Runtime/Stop.cpp +++ b/flang-rt/unittests/Runtime/Stop.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Stop.cpp ----------------------------------===// +//===-- unittests/Runtime/Stop.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,9 +9,10 @@ /// Test runtime API for STOP statement and runtime API to kill the program. // //===----------------------------------------------------------------------===// + #include "flang/Runtime/stop.h" #include "CrashHandlerFixture.h" -#include "../../runtime/environment.h" +#include "flang-rt/runtime/environment.h" #include #include diff --git a/flang/unittests/Runtime/Support.cpp b/flang-rt/unittests/Runtime/Support.cpp similarity index 96% rename from flang/unittests/Runtime/Support.cpp rename to flang-rt/unittests/Runtime/Support.cpp index 8c8de73b5b979..c97a6eae3a155 100644 --- a/flang/unittests/Runtime/Support.cpp +++ b/flang-rt/unittests/Runtime/Support.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Support.cpp ----------------------*- C++-*-===// +//===-- unittests/Runtime/Support.cpp ---------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/support.h" -#include "gtest/gtest.h" #include "tools.h" -#include "flang/Runtime/descriptor.h" +#include "gtest/gtest.h" +#include "flang-rt/runtime/descriptor.h" using namespace Fortran::runtime; using Fortran::common::TypeCategory; diff --git a/flang/unittests/Runtime/TemporaryStack.cpp b/flang-rt/unittests/Runtime/TemporaryStack.cpp similarity index 98% rename from flang/unittests/Runtime/TemporaryStack.cpp rename to flang-rt/unittests/Runtime/TemporaryStack.cpp index 4f701e09b2945..ff8efe123d7cc 100644 --- a/flang/unittests/Runtime/TemporaryStack.cpp +++ b/flang-rt/unittests/Runtime/TemporaryStack.cpp @@ -1,4 +1,4 @@ -//===--- flang/unittests/Runtime/TemporaryStack.cpp -------------*- C++ -*-===// +//===-- unittests/Runtime/TemporaryStack.cpp --------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,13 +7,13 @@ //===----------------------------------------------------------------------===// #include "gtest/gtest.h" -#include "tools.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/tools.h" +#include "flang-rt/runtime/type-code.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" #include "flang/Runtime/allocatable.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" #include "flang/Runtime/temporary-stack.h" -#include "flang/Runtime/type-code.h" #include using namespace Fortran::runtime; diff --git a/flang/unittests/Runtime/Time.cpp b/flang-rt/unittests/Runtime/Time.cpp similarity index 98% rename from flang/unittests/Runtime/Time.cpp rename to flang-rt/unittests/Runtime/Time.cpp index 9309d7b1ceffa..548c0834e34a3 100644 --- a/flang/unittests/Runtime/Time.cpp +++ b/flang-rt/unittests/Runtime/Time.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Time.cpp ----------------------------===// +//===-- unittests/Runtime/Time.cpp ------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang/unittests/Runtime/Transformational.cpp b/flang-rt/unittests/Runtime/Transformational.cpp similarity index 99% rename from flang/unittests/Runtime/Transformational.cpp rename to flang-rt/unittests/Runtime/Transformational.cpp index 1d84b7e23779a..06df96a3cc45a 100644 --- a/flang/unittests/Runtime/Transformational.cpp +++ b/flang-rt/unittests/Runtime/Transformational.cpp @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/Transformational.cpp ----------------------===// +//===-- unittests/Runtime/Transformational.cpp ------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,10 +7,10 @@ //===----------------------------------------------------------------------===// #include "flang/Runtime/transformational.h" -#include "gtest/gtest.h" #include "tools.h" +#include "gtest/gtest.h" +#include "flang-rt/runtime/type-code.h" #include "flang/Common/float128.h" -#include "flang/Runtime/type-code.h" #include using namespace Fortran::runtime; diff --git a/flang/unittests/Runtime/tools.h b/flang-rt/unittests/Runtime/tools.h similarity index 85% rename from flang/unittests/Runtime/tools.h rename to flang-rt/unittests/Runtime/tools.h index 0347edace5c05..36a4c2bd9c8b7 100644 --- a/flang/unittests/Runtime/tools.h +++ b/flang-rt/unittests/Runtime/tools.h @@ -1,4 +1,4 @@ -//===-- flang/unittests/Runtime/tools.h -------------------------*- C++ -*-===// +//===-- unittests/Runtime/tools.h -------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,14 +6,14 @@ // //===----------------------------------------------------------------------===// -#ifndef FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_ -#define FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_ +#ifndef FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_ +#define FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_ #include "gtest/gtest.h" +#include "flang-rt/runtime/descriptor.h" +#include "flang-rt/runtime/type-code.h" #include "flang/Runtime/allocatable.h" #include "flang/Runtime/cpp-type.h" -#include "flang/Runtime/descriptor.h" -#include "flang/Runtime/type-code.h" #include #include #include @@ -54,4 +54,4 @@ static OwningPtr MakeArray(const std::vector &shape, } } // namespace Fortran::runtime -#endif // FORTRAN_UNITTESTS_RUNTIME_TOOLS_H_ +#endif // FLANG_RT_UNITTESTS_RUNTIME_TOOLS_H_ diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index c012b884ae3be..ac8f784fd811e 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -23,6 +23,7 @@ if (LLVM_ENABLE_EH) endif() set(FLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(FLANG_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../flang-rt") if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE) message(FATAL_ERROR "In-source builds are not allowed. \ @@ -34,17 +35,6 @@ endif() option(FLANG_ENABLE_WERROR "Fail and stop building flang if a warning is triggered." OFF) -# The out of tree builds of the compiler and the Fortran runtime -# must use the same setting of FLANG_RUNTIME_F128_MATH_LIB -# to be composable. Failure to synchronize this setting may result -# in linking errors or fatal failures in F128 runtime functions. -set(FLANG_RUNTIME_F128_MATH_LIB "" CACHE STRING - "Specifies the target library used for implementing IEEE-754 128-bit float \ - math in F18 runtime, e.g. it might be libquadmath for targets where \ - REAL(16) is mapped to __float128, or libm for targets where REAL(16) \ - is mapped to long double, etc." - ) - # Check for a standalone build and configure as appropriate from # there. if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) @@ -199,6 +189,11 @@ if (FLANG_STANDALONE_BUILD) ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) set(LLVM_EXTERNAL_LIT "${LLVM_TOOLS_BINARY_DIR}/llvm-lit" CACHE STRING "Command used to spawn lit") + set(LIT_ARGS_DEFAULT "-sv") + if (MSVC OR XCODE) + set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") + endif() + set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") option(FLANG_INCLUDE_TESTS "Generate build targets for the Flang unit tests." @@ -248,7 +243,25 @@ else() include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR}) endif() -option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ON) +set(FLANG_INCLUDE_RUNTIME_default ON) +if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES) + set(FLANG_INCLUDE_RUNTIME_default OFF) +endif () +option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ${FLANG_INCLUDE_RUNTIME_default}) +if (FLANG_INCLUDE_RUNTIME) + if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES) + message(WARNING "Building Flang-RT using LLVM_ENABLE_RUNTIMES. FLANG_INCLUDE_RUNTIME=${FLANG_INCLUDE_RUNTIME} ignored.") + set(FLANG_INCLUDE_RUNTIME OFF) + else () + message(STATUS "Building Flang-RT in-tree") + endif () +else () + if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES) + message(STATUS "Building Flang-RT using LLVM_ENABLE_RUNTIMES") + else () + message(STATUS "Not building Flang-RT. For a usable Fortran toolchain, either add LLVM_ENABLE_RUNTIMES=flang-rt, or compile a standalone Flang-RT.") + endif () +endif () set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") @@ -358,20 +371,6 @@ if (FLANG_REPOSITORY_STRING) add_definitions(-DFLANG_REPOSITORY_STRING="${FLANG_REPOSITORY_STRING}") endif() -if (FLANG_RUNTIME_F128_MATH_LIB) - add_compile_definitions( - FLANG_RUNTIME_F128_MATH_LIB="${FLANG_RUNTIME_F128_MATH_LIB}" - ) -endif() - -include(TestBigEndian) -test_big_endian(IS_BIGENDIAN) -if (IS_BIGENDIAN) - add_compile_definitions(FLANG_BIG_ENDIAN=1) -else () - add_compile_definitions(FLANG_LITTLE_ENDIAN=1) -endif () - # Configure Flang's Version.inc file. configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/flang/Version.inc.in @@ -469,6 +468,7 @@ if (APPLE) endif() include(AddFlang) +include(FlangCommon) if (FLANG_INCLUDE_TESTS) add_compile_definitions(FLANG_INCLUDE_TESTS=1) @@ -562,7 +562,13 @@ include(GetClangResourceDir) get_clang_resource_dir(HEADER_BINARY_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include) configure_file( ${FLANG_SOURCE_DIR}/include/flang/ISO_Fortran_binding.h - ${HEADER_BINARY_DIR}/ISO_Fortran_binding.h) + ${HEADER_BINARY_DIR}/ISO_Fortran_binding.h COPYONLY) + +# llvm-test-suite explicitly searches for this header file +# (`ISO_FORTRAN_C_HEADER`), cannot hide it in Clang's resource dir. +configure_file( + ${FLANG_SOURCE_DIR}/include/flang/ISO_Fortran_binding.h + ${LLVM_RUNTIME_OUTPUT_INTDIR}/../include/flang/ISO_Fortran_binding.h COPYONLY) # And also install it into the install area get_clang_resource_dir(HEADER_INSTALL_DIR SUBDIR include) diff --git a/flang/cmake/modules/AddFlang.cmake b/flang/cmake/modules/AddFlang.cmake index c9f65eb73fef0..badbd4e7b964b 100644 --- a/flang/cmake/modules/AddFlang.cmake +++ b/flang/cmake/modules/AddFlang.cmake @@ -18,7 +18,7 @@ endmacro() function(add_flang_library name) set(options SHARED STATIC INSTALL_WITH_TOOLCHAIN) - set(multiValueArgs ADDITIONAL_HEADERS CLANG_LIBS MLIR_LIBS) + set(multiValueArgs ADDITIONAL_HEADERS CLANG_LIBS MLIR_LIBS MLIR_DEPS) cmake_parse_arguments(ARG "${options}" "" @@ -69,6 +69,9 @@ function(add_flang_library name) if (ARG_MLIR_LIBS) mlir_target_link_libraries(${name} PRIVATE ${ARG_MLIR_LIBS}) endif() + if (ARG_MLIR_DEPS AND NOT FLANG_STANDALONE_BUILD) + add_dependencies(${name} ${ARG_MLIR_DEPS}) + endif() if (TARGET ${name}) diff --git a/flang/cmake/modules/FlangCommon.cmake b/flang/cmake/modules/FlangCommon.cmake new file mode 100644 index 0000000000000..1b8606843b224 --- /dev/null +++ b/flang/cmake/modules/FlangCommon.cmake @@ -0,0 +1,43 @@ +#===-- cmake/modules/FlangCommon.txt ----------------------------===# +# +# 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 +# +#===------------------------------------------------------------------------===# +# +# CMake definitions shared between Flang and Flang-RT +# +#===------------------------------------------------------------------------===# + +# The out of tree builds of the compiler and the Fortran runtime +# must use the same setting of FLANG_RUNTIME_F128_MATH_LIB +# to be composable. Failure to synchronize this setting may result +# in linking errors or fatal failures in F128 runtime functions. +set(FLANG_RUNTIME_F128_MATH_LIB "" CACHE STRING + "Specifies the target library used for implementing IEEE-754 128-bit float \ + math in F18 runtime, e.g. it might be libquadmath for targets where \ + REAL(16) is mapped to __float128, or libm for targets where REAL(16) \ + is mapped to long double, etc." + ) +if (FLANG_RUNTIME_F128_MATH_LIB) + add_compile_definitions(FLANG_RUNTIME_F128_MATH_LIB="${FLANG_RUNTIME_F128_MATH_LIB}") +endif() + +# Check if 128-bit float computations can be done via long double +check_cxx_source_compiles( + "#include + #if LDBL_MANT_DIG != 113 + #error LDBL_MANT_DIG != 113 + #endif + int main() { return 0; } + " + HAVE_LDBL_MANT_DIG_113) + +include(TestBigEndian) +test_big_endian(IS_BIGENDIAN) +if (IS_BIGENDIAN) + add_compile_definitions(FLANG_BIG_ENDIAN=1) +else () + add_compile_definitions(FLANG_LITTLE_ENDIAN=1) +endif () diff --git a/flang/docs/GettingStarted.md b/flang/docs/GettingStarted.md index e422a31a0b402..0b3b551ffbfba 100644 --- a/flang/docs/GettingStarted.md +++ b/flang/docs/GettingStarted.md @@ -30,7 +30,7 @@ https://llvm.org/docs/GettingStarted.html. All of the examples below use GCC as the C/C++ compilers and ninja as the build tool. -### Building flang in tree +### Building flang in tree with bootstrapped Flang-RT Building flang in tree means building flang along with all of the projects on which it depends. These projects include mlir, clang, flang, openmp, and compiler-rt. Note that compiler-rt is only needed to access libraries that @@ -82,7 +82,7 @@ cmake \ -DLLVM_TARGETS_TO_BUILD=host \ -DLLVM_LIT_ARGS=-v \ -DLLVM_ENABLE_PROJECTS="clang;mlir;flang;openmp" \ - -DLLVM_ENABLE_RUNTIMES="compiler-rt" \ + -DLLVM_ENABLE_RUNTIMES="compiler-rt;flang-rt" \ ../llvm-project/llvm ninja @@ -101,7 +101,7 @@ the cmake command above: To run the flang tests on this build, execute the command in the "build" directory: ```bash -ninja check-flang +ninja check-flang check-flang-rt ``` To create the installed files: @@ -111,34 +111,6 @@ ninja install echo "latest" > $INSTALLDIR/bin/versionrc ``` -To build compiler-rt: -```bash -cd $ROOTDIR -rm -rf compiler-rt -mkdir compiler-rt -cd compiler-rt -CC=$INSTALLDIR/bin/clang \ -CXX=$INSTALLDIR/bin/clang++ \ -cmake \ - -G Ninja \ - ../llvm-project/compiler-rt \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=$INSTALLDIR \ - -DCMAKE_CXX_STANDARD=11 \ - -DCMAKE_C_CFLAGS=-mlong-double-128 \ - -DCMAKE_CXX_CFLAGS=-mlong-double-128 \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ - -DCOMPILER_RT_BUILD_ORC=OFF \ - -DCOMPILER_RT_BUILD_XRAY=OFF \ - -DCOMPILER_RT_BUILD_MEMPROF=OFF \ - -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ - -DCOMPILER_RT_BUILD_SANITIZERS=OFF \ - -DLLVM_CONFIG_PATH=$INSTALLDIR/bin/llvm-config - -ninja -ninja install -``` - Note that these instructions specify flang as one of the projects to build in the in tree build. This is not strictly necessary for subsequent standalone builds, but doing so lets you run the flang tests to verify that the source @@ -192,7 +164,32 @@ directory: ninja check-flang ``` -### Building flang runtime for accelerators +To build Flang-RT (required for linking executables): +```bash +cd $ROOTDIR +rm -rf flang-rt +mkdir flang-rt +cd flang-rt +CC=$INSTALLDIR/bin/clang \ +CXX=$INSTALLDIR/bin/clang++ \ +cmake \ + -G Ninja \ + ../llvm-project/runtimes \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=$INSTALLDIR \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DLLVM_ENABLE_RUNTIMES=flang-rt \ + -DLLVM_BINARY_DIR=$ROOTDIR/build \ + -DLLVM_Fortran_COMPILER=$INSTALLDIR/bin/flang \ + -DLLVM_Fortran_COMPILER_WORKS=ON + +ninja +ninja check-flang-rt +ninja install +``` + + +### Building Flang-RT for accelerators Flang runtime can be built for accelerators in experimental mode, i.e. complete enabling is WIP. CUDA and OpenMP target offload builds are currently supported. @@ -203,20 +200,21 @@ are currently supported. Clang with NVPTX backend and NVCC compilers are supported. ```bash -cd llvm-project/flang +cd llvm-project rm -rf build_flang_runtime mkdir build_flang_runtime cd build_flang_runtime cmake \ - -DFLANG_EXPERIMENTAL_CUDA_RUNTIME=ON \ + -DLLVM_ENABLE_RUNTIMES=flang-rt \ + -DFLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA \ -DCMAKE_CUDA_ARCHITECTURES=80 \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_CUDA_COMPILER=clang \ -DCMAKE_CUDA_HOST_COMPILER=clang++ \ - ../runtime/ -make -j flang-rt + ../runtimes/ +make flang-rt ``` Note that the used version of `clang` must [support](https://releases.llvm.org/16.0.0/tools/clang/docs/ReleaseNotes.html#cuda-support) @@ -225,21 +223,22 @@ CUDA toolkit installations, please use `-DCUDAToolkit_ROOT=/some/path` to specify the compatible version. ```bash -cd llvm-project/flang +cd llvm-project rm -rf build_flang_runtime mkdir build_flang_runtime cd build_flang_runtime cmake \ - -DFLANG_EXPERIMENTAL_CUDA_RUNTIME=ON \ + -DLLVM_ENABLE_RUNTIMES=flang-rt \ + -DFLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA \ -DCMAKE_CUDA_ARCHITECTURES=80 \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_CUDA_COMPILER=nvcc \ -DCMAKE_CUDA_HOST_COMPILER=clang++ \ - ../runtime/ + ../runtimes/ -make -j flang-rt +make flang-rt ``` Note that `nvcc` might limit support to certain @@ -251,50 +250,59 @@ code. Note that the packaging of the libraries is different between [Clang](https://clang.llvm.org/docs/OffloadingDesign.html#linking-target-device-code) and NVCC, so the library must be linked using compatible compiler drivers. -#### Building in-tree +#### Building in-tree (bootstrapping build) One may build Flang runtime library along with building Flang itself by providing these additional CMake variables on top of the Flang in-tree build config: For example: ```bash - -DFLANG_EXPERIMENTAL_CUDA_RUNTIME=ON \ + -DLLVM_ENABLE_RUNTIMES=flang-rt \ + -DFLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA \ -DCMAKE_CUDA_ARCHITECTURES=80 \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_CUDA_COMPILER=clang \ -DCMAKE_CUDA_HOST_COMPILER=clang++ \ + ../llvm ``` Or: ```bash - -DFLANG_EXPERIMENTAL_CUDA_RUNTIME=ON \ + -DLLVM_ENABLE_RUNTIMES=flang-rt \ + -DFLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA \ -DCMAKE_CUDA_ARCHITECTURES=80 \ -DCMAKE_C_COMPILER=gcc \ -DCMAKE_CXX_COMPILER=g++ \ -DCMAKE_CUDA_COMPILER=nvcc \ -DCMAKE_CUDA_HOST_COMPILER=g++ \ + ../llvm ``` -Normal `make -j check-flang` will work with such CMake configuration. +Normal `make check-flang` will work with such CMake configuration. +Consider building in parallel using the `-j` flag, where `` is a +number sufficiently low for all build jobs to fit into the available RAM. Using +the number of harware threads (`nprocs`) is likely too much for most +commodity machines. ##### OpenMP target offload build Only Clang compiler is currently supported. ```bash -cd llvm-project/flang +cd llvm-project rm -rf build_flang_runtime mkdir build_flang_runtime cd build_flang_runtime cmake \ - -DFLANG_EXPERIMENTAL_OMP_OFFLOAD_BUILD="host_device" \ + -DLLVM_ENABLE_RUNTIMES=flang-rt \ + -DFLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT="OpenMP" \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ - -DFLANG_OMP_DEVICE_ARCHITECTURES="all" \ - ../runtime/ + -DFLANG_RT_DEVICE_ARCHITECTURES=all \ + ../runtimes/ -make -j flang-rt +make flang-rt ``` The result of the build is a "device-only" library, i.e. the host diff --git a/flang/docs/ReleaseNotes.md b/flang/docs/ReleaseNotes.md index 387d4b2e62e0f..9396d956e2233 100644 --- a/flang/docs/ReleaseNotes.md +++ b/flang/docs/ReleaseNotes.md @@ -43,6 +43,12 @@ page](https://llvm.org/releases/). * The CufRuntime_cuda_${version} library has been renamed to `flang_rt.cuda_${version}`. + * The Fortran Runtime library has been move to a new top-level directory + named "flang-rt". It now supports the LLVM_ENABLE_RUNTIMES mechanism to + build Flang-RT for multiple target triples. libflang_rt.runtime.{a|so} will + now be emitted into Clang's per-target resource directory + (next to libclang_rt.*.*) where it is also found by Flang's driver. + ## New Issues Found diff --git a/flang/examples/ExternalHelloWorld/CMakeLists.txt b/flang/examples/ExternalHelloWorld/CMakeLists.txt index b61948718a5e3..dbb69475976dd 100644 --- a/flang/examples/ExternalHelloWorld/CMakeLists.txt +++ b/flang/examples/ExternalHelloWorld/CMakeLists.txt @@ -1,6 +1,6 @@ # This test is not run by default as it requires input. add_llvm_example(external-hello-world - external-hello.cpp + ${FLANG_RT_SOURCE_DIR}/examples/ExternalHelloWorld/external-hello.cpp ) target_link_libraries(external-hello-world diff --git a/flang/include/flang/Runtime/allocatable.h b/flang/include/flang/Runtime/allocatable.h index 58061d9862095..714d85ec073c6 100644 --- a/flang/include/flang/Runtime/allocatable.h +++ b/flang/include/flang/Runtime/allocatable.h @@ -11,7 +11,7 @@ #ifndef FORTRAN_RUNTIME_ALLOCATABLE_H_ #define FORTRAN_RUNTIME_ALLOCATABLE_H_ -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Runtime/entry-names.h" namespace Fortran::runtime { diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h index abcdbc4a12002..acd7bc5ddbdef 100644 --- a/flang/include/flang/Runtime/descriptor-consts.h +++ b/flang/include/flang/Runtime/descriptor-consts.h @@ -9,6 +9,7 @@ #ifndef FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ #define FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ +#include "flang/Common/Fortran-consts.h" #include "flang/Common/ISO_Fortran_binding_wrapper.h" #include "flang/Common/api-attrs.h" #include @@ -29,6 +30,7 @@ class DerivedType; namespace Fortran::runtime { class Descriptor; using SubscriptValue = ISO::CFI_index_t; +using common::TypeCategory; /// Returns size in bytes of the descriptor (not the data) /// This must be at least as large as the largest descriptor of any target diff --git a/flang/include/flang/Runtime/pointer.h b/flang/include/flang/Runtime/pointer.h index 704144f08114f..67c4fe266f55c 100644 --- a/flang/include/flang/Runtime/pointer.h +++ b/flang/include/flang/Runtime/pointer.h @@ -12,7 +12,7 @@ #ifndef FORTRAN_RUNTIME_POINTER_H_ #define FORTRAN_RUNTIME_POINTER_H_ -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Runtime/entry-names.h" namespace Fortran::runtime { diff --git a/flang/include/flang/Support/LangOptions.h b/flang/include/flang/Support/LangOptions.h index fac6fb92df85a..1dd676e62a9e5 100644 --- a/flang/include/flang/Support/LangOptions.h +++ b/flang/include/flang/Support/LangOptions.h @@ -62,7 +62,10 @@ class LangOptions : public LangOptionsBase { #define LANGOPT(Name, Bits, Default) #define ENUM_LANGOPT(Name, Type, Bits, Default) \ Type get##Name() const { return static_cast(Name); } \ - void set##Name(Type Value) { Name = static_cast(Value); } + void set##Name(Type Value) { \ + assert(static_cast(Value) < (1u << Bits)); \ + Name = static_cast(Value); \ + } #include "LangOptions.def" /// Name of the IR file that contains the result of the OpenMP target diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt index 81eef2d468d8c..80d63fca6fb76 100644 --- a/flang/lib/Frontend/CMakeLists.txt +++ b/flang/lib/Frontend/CMakeLists.txt @@ -18,9 +18,6 @@ add_flang_library(flangFrontend FIROptCodeGenPassIncGen FIROptTransformsPassIncGen HLFIRDialect - MLIRIR - ${dialect_libs} - ${extension_libs} LINK_LIBS CUFDialect @@ -56,6 +53,11 @@ add_flang_library(flangFrontend FrontendOpenACC FrontendOpenMP + MLIR_DEPS + MLIRIR + ${dialect_libs} + ${extension_libs} + MLIR_LIBS MLIRTransforms MLIRBuiltinToLLVMIRTranslation diff --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt index c9b249781552e..87dc2a052796a 100644 --- a/flang/lib/Lower/CMakeLists.txt +++ b/flang/lib/Lower/CMakeLists.txt @@ -44,8 +44,6 @@ add_flang_library(FortranLower FIRDialect FIRTransforms HLFIRDialect - ${dialect_libs} - ${extension_libs} LINK_LIBS CUFAttrs @@ -64,6 +62,10 @@ add_flang_library(FortranLower LINK_COMPONENTS Support + MLIR_DEPS + ${dialect_libs} + ${extension_libs} + MLIR_LIBS ${dialect_libs} ${extension_libs} diff --git a/flang/lib/Optimizer/Analysis/CMakeLists.txt b/flang/lib/Optimizer/Analysis/CMakeLists.txt index c4dae898f8e57..4d4ad882c27d3 100644 --- a/flang/lib/Optimizer/Analysis/CMakeLists.txt +++ b/flang/lib/Optimizer/Analysis/CMakeLists.txt @@ -6,8 +6,6 @@ add_flang_library(FIRAnalysis FIRDialect FIRSupport HLFIRDialect - MLIRIR - MLIROpenMPDialect LINK_LIBS FIRBuilder @@ -15,6 +13,10 @@ add_flang_library(FIRAnalysis FIRSupport HLFIRDialect + MLIR_DEPS + MLIRIR + MLIROpenMPDialect + MLIR_LIBS MLIRFuncDialect MLIRLLVMDialect diff --git a/flang/lib/Optimizer/Builder/CMakeLists.txt b/flang/lib/Optimizer/Builder/CMakeLists.txt index f8faeaa81c90c..f0563d092e3dc 100644 --- a/flang/lib/Optimizer/Builder/CMakeLists.txt +++ b/flang/lib/Optimizer/Builder/CMakeLists.txt @@ -40,8 +40,6 @@ add_flang_library(FIRBuilder CUFDialect FIRDialect HLFIRDialect - ${dialect_libs} - ${extension_libs} LINK_LIBS CUFAttrs @@ -52,6 +50,10 @@ add_flang_library(FIRBuilder FortranEvaluate HLFIRDialect + MLIR_DEPS + ${dialect_libs} + ${extension_libs} + MLIR_LIBS ${dialect_libs} ${extension_libs} diff --git a/flang/lib/Optimizer/Dialect/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CMakeLists.txt index d39dca8ed0000..61f9c6110491e 100644 --- a/flang/lib/Optimizer/Dialect/CMakeLists.txt +++ b/flang/lib/Optimizer/Dialect/CMakeLists.txt @@ -12,7 +12,6 @@ add_flang_library(FIRDialect DEPENDS CanonicalizationPatternsIncGen - MLIRIR FIROpsIncGen CUFAttrsIncGen intrinsics_gen @@ -26,6 +25,9 @@ add_flang_library(FIRDialect AsmPrinter Remarks + MLIR_DEPS + MLIRIR + MLIR_LIBS MLIRArithDialect MLIRBuiltinToLLVMIRTranslation diff --git a/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt index a0f58504eff05..713bd0e97bac3 100644 --- a/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt +++ b/flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt @@ -3,7 +3,6 @@ add_flang_library(CUFAttrs CUFAttr.cpp DEPENDS - MLIRIR CUFAttrsIncGen CUFOpsIncGen @@ -12,6 +11,9 @@ add_flang_library(CUFAttrs AsmPrinter Remarks + MLIR_DEPS + MLIRIR + MLIR_LIBS MLIRTargetLLVMIRExport ) diff --git a/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt index e483b4a164113..5b398f2ad506a 100644 --- a/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt +++ b/flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt @@ -6,7 +6,6 @@ add_flang_library(CUFDialect CUFToLLVMIRTranslation.cpp DEPENDS - MLIRIR CUFAttrsIncGen CUFOpsIncGen @@ -20,6 +19,9 @@ add_flang_library(CUFDialect AsmPrinter Remarks + MLIR_DEPS + MLIRIR + MLIR_LIBS MLIRIR MLIRGPUDialect diff --git a/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt b/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt index bfdd5279b6f29..a85d9521af1c4 100644 --- a/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt +++ b/flang/lib/Optimizer/Dialect/Support/CMakeLists.txt @@ -5,9 +5,11 @@ add_flang_library(FIRDialectSupport FIRContext.cpp DEPENDS - MLIRIR intrinsics_gen + MLIR_DEPS + MLIRIR + MLIR_LIBS ${dialect_libs} ) diff --git a/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt b/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt index 8a646bedf94b8..99e31a43e01e5 100644 --- a/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt +++ b/flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt @@ -8,7 +8,6 @@ add_flang_library(HLFIRDialect CUFAttrsIncGen FIRDialect HLFIROpsIncGen - ${dialect_libs} LINK_LIBS CUFAttrs @@ -19,6 +18,9 @@ add_flang_library(HLFIRDialect AsmPrinter Remarks + MLIR_DEPS + ${dialect_libs} + MLIR_LIBS MLIRIR ${dialect_libs} diff --git a/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt b/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt index 09286aced6089..7eb3cb4001d5f 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt +++ b/flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt @@ -15,7 +15,6 @@ add_flang_library(HLFIRTransforms CUFAttrsIncGen FIRDialect HLFIROpsIncGen - ${dialect_libs} LINK_LIBS CUFAttrs @@ -33,6 +32,9 @@ add_flang_library(HLFIRTransforms AsmPrinter Remarks + MLIR_DEPS + ${dialect_libs} + MLIR_LIBS MLIRIR ${dialect_libs} diff --git a/flang/lib/Optimizer/OpenACC/CMakeLists.txt b/flang/lib/Optimizer/OpenACC/CMakeLists.txt index 1bfae603fd80d..4a09133fc110d 100644 --- a/flang/lib/Optimizer/OpenACC/CMakeLists.txt +++ b/flang/lib/Optimizer/OpenACC/CMakeLists.txt @@ -11,7 +11,6 @@ add_flang_library(FIROpenACCSupport FIRDialectSupport FIRSupport HLFIRDialect - MLIROpenACCDialect LINK_LIBS FIRBuilder @@ -21,6 +20,9 @@ add_flang_library(FIROpenACCSupport FIRSupport HLFIRDialect + MLIR_DEPS + MLIROpenACCDialect + MLIR_LIBS MLIROpenACCDialect ) diff --git a/flang/lib/Optimizer/OpenMP/CMakeLists.txt b/flang/lib/Optimizer/OpenMP/CMakeLists.txt index 86ae93f3207cc..4a48d6e0936db 100644 --- a/flang/lib/Optimizer/OpenMP/CMakeLists.txt +++ b/flang/lib/Optimizer/OpenMP/CMakeLists.txt @@ -12,7 +12,6 @@ add_flang_library(FlangOpenMPTransforms FIRDialect HLFIROpsIncGen FlangOpenMPPassesIncGen - ${dialect_libs} LINK_LIBS FIRAnalysis @@ -24,6 +23,9 @@ add_flang_library(FlangOpenMPTransforms FortranSupport HLFIRDialect + MLIR_DEPS + ${dialect_libs} + MLIR_LIBS MLIRFuncDialect MLIROpenMPDialect diff --git a/flang/lib/Optimizer/Support/CMakeLists.txt b/flang/lib/Optimizer/Support/CMakeLists.txt index f8e4fc5bcefea..7ccdd4fd9c25c 100644 --- a/flang/lib/Optimizer/Support/CMakeLists.txt +++ b/flang/lib/Optimizer/Support/CMakeLists.txt @@ -10,9 +10,6 @@ add_flang_library(FIRSupport DEPENDS FIROpsIncGen HLFIROpsIncGen - MLIRIR - ${dialect_libs} - ${extension_libs} LINK_LIBS FIRDialect @@ -20,6 +17,11 @@ add_flang_library(FIRSupport LINK_COMPONENTS TargetParser + MLIR_DEPS + MLIRIR + ${dialect_libs} + ${extension_libs} + MLIR_LIBS ${dialect_libs} ${extension_libs} diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt index 1f4ee69598918..fbd1e1e2cc56e 100644 --- a/flang/runtime/CMakeLists.txt +++ b/flang/runtime/CMakeLists.txt @@ -16,6 +16,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(CMAKE_CXX_EXTENSIONS OFF) set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..") + set(FLANG_RT_SOURCE_DIR "${FLANG_SOURCE_DIR}/../flang-rt") set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake") set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake") @@ -57,8 +58,31 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) REAL(16) is mapped to __float128, or libm for targets where REAL(16) \ is mapped to long double, etc." ) + + option(FLANG_CUF_RUNTIME + "Compile CUDA Fortran runtime sources" OFF) + if (FLANG_CUF_RUNTIME) + find_package(CUDAToolkit REQUIRED) + endif() endif() +# Runtime files are in Flang-RT's source dir. +function (runtime_source_files outvar) + cmake_parse_arguments(ARG "" "SUBDIR" "" ${ARGN}) + + set(new_sources "") + foreach (source IN LISTS "${outvar}") + set(new_source "${FLANG_RT_SOURCE_DIR}/lib") + cmake_path(APPEND new_source "${ARG_SUBDIR}") + cmake_path(APPEND new_source "${source}") + list(APPEND new_sources "${new_source}") + endforeach () + set("${outvar}" ${new_sources} PARENT_SCOPE) +endfunction () + +# Runtime includes are in Flang-RT's source dir. +include_directories(BEFORE "${FLANG_RT_SOURCE_DIR}/include") + set(linked_libraries "") # function checks @@ -108,7 +132,7 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL") set(NO_RTTI_FLAGS "-qnoeh -qnortti") endif () -configure_file(config.h.cmake config.h) +configure_file("${FLANG_RT_SOURCE_DIR}/cmake/config.h.cmake.in" config.h) # include_directories is used here instead of target_include_directories # because add_flang_library creates multiple objects (STATIC/SHARED, OBJECT) # with different names @@ -252,6 +276,7 @@ set(supported_files unit.cpp utf.cpp ) +runtime_source_files(supported_files SUBDIR "runtime") enable_cuda_compilation(flang_rt "${supported_files}") enable_omp_offload_compilation("${supported_files}") @@ -285,6 +310,8 @@ if (NOT TARGET flang_rt.quadmath) list(APPEND sources ${f128_sources}) endif() endif() +runtime_source_files(sources SUBDIR "runtime") + if (NOT DEFINED MSVC) add_flang_library(flang_rt.runtime diff --git a/flang/runtime/CUDA/CMakeLists.txt b/flang/runtime/CUDA/CMakeLists.txt index 1fd3bf22a83cf..aac1f62661810 100644 --- a/flang/runtime/CUDA/CMakeLists.txt +++ b/flang/runtime/CUDA/CMakeLists.txt @@ -13,7 +13,7 @@ include_directories(${CUDAToolkit_INCLUDE_DIRS}) # added to the library name. set(CUFRT_LIBNAME flang_rt.cuda_${CUDAToolkit_VERSION_MAJOR}) -add_flang_library(${CUFRT_LIBNAME} +set(sources allocator.cpp allocatable.cpp descriptor.cpp @@ -24,6 +24,11 @@ add_flang_library(${CUFRT_LIBNAME} pointer.cpp registration.cpp ) +runtime_source_files(sources SUBDIR "cuda") + +add_flang_library(${CUFRT_LIBNAME} + ${sources} +) if (BUILD_SHARED_LIBS) set(CUDA_RT_TARGET CUDA::cudart) diff --git a/flang/runtime/Float128Math/CMakeLists.txt b/flang/runtime/Float128Math/CMakeLists.txt index 3c382d16a21cd..cdac5f893cf91 100644 --- a/flang/runtime/Float128Math/CMakeLists.txt +++ b/flang/runtime/Float128Math/CMakeLists.txt @@ -68,6 +68,7 @@ set(sources y1.cpp yn.cpp ) +runtime_source_files(sources SUBDIR "quadmath") include_directories(AFTER "${CMAKE_CURRENT_SOURCE_DIR}/..") add_library(FortranFloat128MathILib INTERFACE) diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt index 3fac8717e9bd9..777cf5fc5433b 100644 --- a/flang/test/CMakeLists.txt +++ b/flang/test/CMakeLists.txt @@ -59,26 +59,30 @@ set(FLANG_TEST_PARAMS set(FLANG_TEST_DEPENDS flang - llvm-config - FileCheck - count - not module_files fir-opt tco bbc - llvm-dis - llvm-objdump - llvm-readobj - split-file FortranDecimal ) +if (NOT FLANG_STANDALONE_BUILD) + list(APPEND FLANG_TEST_DEPENDS + llvm-config + FileCheck + count + not + llvm-dis + llvm-objdump + llvm-readobj + split-file + ) +endif () if (FLANG_INCLUDE_RUNTIME) list(APPEND FLANG_TEST_DEPENDS flang_rt.runtime) endif () -if (LLVM_ENABLE_PLUGINS AND NOT WIN32) +if (LLVM_ENABLE_PLUGINS AND NOT WIN32 AND NOT FLANG_STANDALONE_BUILD) list(APPEND FLANG_TEST_DEPENDS Bye) endif() diff --git a/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt b/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt index cba47a4114517..16df2b607ca93 100644 --- a/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt +++ b/flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt @@ -8,7 +8,6 @@ add_flang_library(FIRTestAnalysis FIRSupport FIRTransforms FIRAnalysis - ${dialect_libs} LINK_LIBS FIRDialect @@ -18,6 +17,9 @@ add_flang_library(FIRTestAnalysis FIRAnalysis MLIRTestAnalysis + MLIR_DEPS + ${dialect_libs} + MLIR_LIBS ${dialect_libs} MLIRFuncDialect diff --git a/flang/test/lib/OpenACC/CMakeLists.txt b/flang/test/lib/OpenACC/CMakeLists.txt index e296827ef53be..1c0ac748f85e8 100644 --- a/flang/test/lib/OpenACC/CMakeLists.txt +++ b/flang/test/lib/OpenACC/CMakeLists.txt @@ -5,16 +5,18 @@ add_flang_library(FIRTestOpenACCInterfaces FIRDialect FIROpenACCSupport FIRSupport - MLIRIR - MLIROpenACCDialect - MLIRPass - MLIRSupport LINK_LIBS FIRDialect FIROpenACCSupport FIRSupport + MLIR_DEPS + MLIRIR + MLIROpenACCDialect + MLIRPass + MLIRSupport + MLIR_LIBS MLIRIR MLIROpenACCDialect diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py index c6266f3976f7c..0ba80f9a03f2e 100644 --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -166,26 +166,6 @@ if config.flang_include_runtime: config.available_features.add("flang-rt") -# Define some variables to help us test that the flang runtime doesn't depend on -# the C++ runtime libraries. For this we need a C compiler. If for some reason -# we don't have one, we can just disable the test. -if config.flang_include_runtime and config.cc: - libruntime = os.path.join(config.flang_lib_dir, "libflang_rt.runtime.a") - include = os.path.join(config.flang_src_dir, "include") - - if ( - os.path.isfile(libruntime) - and os.path.isdir(include) - ): - config.available_features.add("c-compiler") - tools.append( - ToolSubst( - "%cc", command=config.cc, extra_args=isysroot_flag, unresolved="fatal" - ) - ) - tools.append(ToolSubst("%libruntime", command=libruntime, unresolved="fatal")) - tools.append(ToolSubst("%include", command=include, unresolved="fatal")) - # Add all the tools and their substitutions (if applicable). Use the search paths provided for # finding the tools. if config.flang_standalone_build: diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in index 697ba3fa79763..5b66e592bcfee 100644 --- a/flang/test/lit.site.cfg.py.in +++ b/flang/test/lit.site.cfg.py.in @@ -11,18 +11,15 @@ config.llvm_target_triple_env = "@LLVM_TARGET_TRIPLE_ENV@" config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" config.errc_messages = "@LLVM_LIT_ERRC_MESSAGES@" config.flang_obj_root = "@FLANG_BINARY_DIR@" -config.flang_src_dir = "@FLANG_SOURCE_DIR@" config.flang_tools_dir = lit_config.substitute("@FLANG_TOOLS_DIR@") config.flang_intrinsic_modules_dir = "@FLANG_INTRINSIC_MODULES_DIR@" config.flang_llvm_tools_dir = "@CMAKE_BINARY_DIR@/bin" -config.flang_lib_dir = "@CMAKE_BINARY_DIR@/lib" config.flang_test_triple = "@FLANG_TEST_TARGET_TRIPLE@" config.flang_examples = @LLVM_BUILD_EXAMPLES@ config.python_executable = "@PYTHON_EXECUTABLE@" config.flang_standalone_build = @FLANG_STANDALONE_BUILD@ config.has_plugins = @LLVM_ENABLE_PLUGINS@ config.linked_bye_extension = @LLVM_BYE_LINK_INTO_TOOLS@ -config.cc = "@CMAKE_C_COMPILER@" config.osx_sysroot = path(r"@CMAKE_OSX_SYSROOT@") config.targets_to_build = "@TARGETS_TO_BUILD@" config.default_sysroot = "@DEFAULT_SYSROOT@" diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt index c54ceb3332abf..a02f791135f1f 100644 --- a/flang/unittests/CMakeLists.txt +++ b/flang/unittests/CMakeLists.txt @@ -12,6 +12,8 @@ endif() add_custom_target(FlangUnitTests) set_target_properties(FlangUnitTests PROPERTIES FOLDER "Flang/Tests") +include_directories("${FLANG_RT_SOURCE_DIR}/include") + function(add_flang_unittest_offload_properties target) # Do not apply runtime properties if not even compiling the runtime. if (NOT FLANG_INCLUDE_RUNTIME) @@ -61,7 +63,13 @@ function(add_flang_nongtest_unittest test_name) set(suffix .test) endif() - add_executable(${test_name}${suffix} ${test_name}.cpp) + # Sources for runtime tests are in Flang-RT. + set(test_filepath "${FLANG_RT_SOURCE_DIR}/unittests/Evaluate/${test_name}.cpp") + if (NOT EXISTS "${test_filepath}") + set(test_filepath "${test_name}.cpp") + endif () + + add_executable(${test_name}${suffix} "${test_filepath}") set_target_properties(${test_name}${suffix} PROPERTIES FOLDER "Flang/Tests/Unit") if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB) diff --git a/flang/unittests/Optimizer/CMakeLists.txt b/flang/unittests/Optimizer/CMakeLists.txt index f535677c19fd2..1289341619118 100644 --- a/flang/unittests/Optimizer/CMakeLists.txt +++ b/flang/unittests/Optimizer/CMakeLists.txt @@ -1,6 +1,10 @@ get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS) +set(LLVM_LINK_COMPONENTS + TargetParser +) + set(LIBS CUFDialect FIRBuilder @@ -9,7 +13,6 @@ set(LIBS FIRDialectSupport FIRSupport HLFIRDialect - LLVMTargetParser ) add_flang_unittest(FlangOptimizerTests @@ -39,8 +42,12 @@ DEPENDS CUFDialect FIRDialect FIRSupport - HLFIRDialect - ${dialect_libs}) + HLFIRDialect) + +if(NOT FLANG_STANDALONE_BUILD) + add_dependencies(FlangOptimizerTests + ${dialect_libs}) +endif() target_link_libraries(FlangOptimizerTests PRIVATE diff --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt index f3743be49b015..40afec3e113f3 100644 --- a/flang/unittests/Runtime/CMakeLists.txt +++ b/flang/unittests/Runtime/CMakeLists.txt @@ -1,34 +1,34 @@ add_flang_unittest(FlangRuntimeTests - AccessTest.cpp - Allocatable.cpp - ArrayConstructor.cpp - BufferTest.cpp - CharacterTest.cpp - CommandTest.cpp - Complex.cpp - CrashHandlerFixture.cpp - Derived.cpp - ExternalIOTest.cpp - Format.cpp - Inquiry.cpp - ListInputTest.cpp - LogicalFormatTest.cpp - Matmul.cpp - MatmulTranspose.cpp - MiscIntrinsic.cpp - Namelist.cpp - Numeric.cpp - NumericalFormatTest.cpp - Pointer.cpp - Ragged.cpp - Random.cpp - Reduction.cpp - RuntimeCrashTest.cpp - Stop.cpp - Support.cpp - Time.cpp - TemporaryStack.cpp - Transformational.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/AccessTest.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Allocatable.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/ArrayConstructor.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/BufferTest.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CharacterTest.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CommandTest.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Complex.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CrashHandlerFixture.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Derived.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/ExternalIOTest.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Format.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Inquiry.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/ListInputTest.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/LogicalFormatTest.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Matmul.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/MatmulTranspose.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/MiscIntrinsic.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Namelist.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Numeric.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/NumericalFormatTest.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Pointer.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Ragged.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Random.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Reduction.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/RuntimeCrashTest.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Stop.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Support.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Time.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/TemporaryStack.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/Transformational.cpp ) target_link_libraries(FlangRuntimeTests diff --git a/flang/unittests/Runtime/CUDA/CMakeLists.txt b/flang/unittests/Runtime/CUDA/CMakeLists.txt index 860b2664d623b..6901da3920a46 100644 --- a/flang/unittests/Runtime/CUDA/CMakeLists.txt +++ b/flang/unittests/Runtime/CUDA/CMakeLists.txt @@ -1,9 +1,9 @@ if (FLANG_CUF_RUNTIME) add_flang_unittest(FlangCufRuntimeTests - Allocatable.cpp - AllocatorCUF.cpp - Memory.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CUDA/Allocatable.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CUDA/AllocatorCUF.cpp + ${FLANG_RT_SOURCE_DIR}/unittests/Runtime/CUDA/Memory.cpp ) if (BUILD_SHARED_LIBS) diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h index a0fa506c01ab8..212e3c6a9446c 100644 --- a/libc/include/__llvm-libc-common.h +++ b/libc/include/__llvm-libc-common.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_COMMON_H -#define LLVM_LIBC_COMMON_H +#ifndef _LLVM_LIBC_COMMON_H +#define _LLVM_LIBC_COMMON_H #define __LLVM_LIBC__ 1 @@ -87,4 +87,4 @@ #endif // __cplusplus -#endif // LLVM_LIBC_COMMON_H +#endif // _LLVM_LIBC_COMMON_H diff --git a/libc/include/malloc.yaml b/libc/include/malloc.yaml index bf7678797c023..cd84723557bcb 100644 --- a/libc/include/malloc.yaml +++ b/libc/include/malloc.yaml @@ -9,6 +9,12 @@ macros: - macro_name: M_PURGE_ALL macro_header: malloc-macros.h functions: + - name: malloc_usable_size + standards: + - gnu + return_type: size_t + arguments: + - type: void * - name: mallopt standards: - gnu @@ -16,3 +22,10 @@ functions: arguments: - type: int - type: int + - name: pvalloc + standards: + - bsd + - gnu + return_type: void * + arguments: + - type: size_t diff --git a/libc/include/stdlib-malloc.yaml b/libc/include/stdlib-malloc.yaml index 648a6e58a90a0..51c11f5602e2c 100644 --- a/libc/include/stdlib-malloc.yaml +++ b/libc/include/stdlib-malloc.yaml @@ -1,4 +1,10 @@ # This file has declarations that appear both in and in . +# These include the subset of GNU extensions that Scudo supports. +# +# Note: glibc's and both also have `reallocarray`, +# which Scudo does not support and is omitted here. (Each of those glibc +# headers also has related functions the other lacks, but those should be +# covered separately in stdlib.yaml and malloc.yaml instead.) functions: - name: aligned_alloc @@ -27,6 +33,13 @@ functions: return_type: void * arguments: - type: size_t + - name: memalign + standards: + - gnu + return_type: void * + arguments: + - type: size_t + - type: size_t - name: realloc standards: - stdc @@ -34,11 +47,10 @@ functions: arguments: - type: void * - type: size_t - -# Note: glibc's and both have these, which are -# currently missing here: -# - name: reallocarray -# - name: memalign -# - name: valloc -# Each of those glibc headers also has related functions the other lacks. -# Only the common subset is mentioned here for future consideration. + - name: valloc + standards: + - bsd + - gnu + return_type: void * + arguments: + - type: size_t diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml index 6ada26f020179..8d2b3f357e1a9 100644 --- a/libc/include/stdlib.yaml +++ b/libc/include/stdlib.yaml @@ -127,6 +127,14 @@ functions: arguments: - type: long long - type: long long + - name: posix_memalign + standards: + - posix + return_type: int + arguments: + - type: void ** + - type: size_t + - type: size_t - name: qsort standards: - stdc diff --git a/libc/src/math/generic/sqrtf128.cpp b/libc/src/math/generic/sqrtf128.cpp index c844d3afa11c8..3aa7db8362734 100644 --- a/libc/src/math/generic/sqrtf128.cpp +++ b/libc/src/math/generic/sqrtf128.cpp @@ -383,25 +383,26 @@ LLVM_LIBC_FUNCTION(float128, sqrtf128, (float128 x)) { // 1 so just need to add shifted m and 1. Int128 t1 = t0; Int128 sgn = t0 >> 127; // sign of the difference - t1 -= (m << 1) ^ sgn; - t1 += 1 + sgn; + Int128 m_xor_sgn = static_cast(m << 1) ^ sgn; + t1 -= m_xor_sgn; + t1 += Int128(1) + sgn; Int128 sgn1 = t1 >> 127; if (LIBC_UNLIKELY(sgn == sgn1)) { t0 = t1; v -= sgn << 15; - t1 -= (m << 1) ^ sgn; - t1 += 1 + sgn; + t1 -= m_xor_sgn; + t1 += Int128(1) + sgn; } if (t1 == 0) { // 1 ulp offset brings again an exact root - v = (m - (2 * sgn + 1)) << 15; + v = (m - static_cast((sgn << 1) + 1)) << 15; } else { t1 += t0; Int128 side = t1 >> 127; // select what is closer m or m+-1 v &= ~UInt128(0) << 15; // wipe the fractional bits - v -= ((sgn & side) | (~sgn & 1)) << (15 + side); + v -= ((sgn & side) | (~sgn & 1)) << (15 + static_cast(side)); v |= 1; // add sticky bit since we cannot have an exact mid-point // situation } diff --git a/libc/utils/hdrgen/header.py b/libc/utils/hdrgen/header.py index 9ea9f98f8fc83..42a075c4b6c89 100644 --- a/libc/utils/hdrgen/header.py +++ b/libc/utils/hdrgen/header.py @@ -124,7 +124,7 @@ def includes(self): } def header_guard(self): - return "LLVM_LIBC_" + "_".join( + return "_LLVM_LIBC_" + "_".join( word.upper() for word in NONIDENTIFIER.split(self.name) if word ) diff --git a/libc/utils/hdrgen/tests/expected_output/subdir/test.h b/libc/utils/hdrgen/tests/expected_output/subdir/test.h index 20bab502e6821..40936bcfcba6d 100644 --- a/libc/utils/hdrgen/tests/expected_output/subdir/test.h +++ b/libc/utils/hdrgen/tests/expected_output/subdir/test.h @@ -6,8 +6,8 @@ // //===---------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SUBDIR_TEST_H -#define LLVM_LIBC_SUBDIR_TEST_H +#ifndef _LLVM_LIBC_SUBDIR_TEST_H +#define _LLVM_LIBC_SUBDIR_TEST_H #include "../__llvm-libc-common.h" #include "../llvm-libc-types/type_a.h" @@ -23,4 +23,4 @@ int *ptrfunc(void) __NOEXCEPT; __END_C_DECLS -#endif // LLVM_LIBC_SUBDIR_TEST_H +#endif // _LLVM_LIBC_SUBDIR_TEST_H diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index b520626c6ffd1..a3b311f12a1e3 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -249,13 +249,19 @@ function(add_libclc_builtin_set) get_filename_component( file_dir ${file} DIRECTORY ) + if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 ) + set(CONVERT_DEP clspv-generate_convert.cl) + else() + set(CONVERT_DEP generate_convert.cl) + endif() + compile_to_bc( TRIPLE ${ARG_TRIPLE} INPUT ${input_file} OUTPUT ${output_file} EXTRA_OPTS -fno-builtin -nostdlib "${ARG_COMPILE_FLAGS}" -I${CMAKE_CURRENT_SOURCE_DIR}/${file_dir} - DEPENDENCIES generate_convert.cl clspv-generate_convert.cl + DEPENDENCIES ${CONVERT_DEP} ) list( APPEND bytecode_files ${output_file} ) endforeach() diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h index 2a92ce209b91f..cff99376ee24b 100644 --- a/libcxx/include/__configuration/platform.h +++ b/libcxx/include/__configuration/platform.h @@ -30,12 +30,9 @@ // ... add new file formats here ... #endif -// To detect which libc we're using -#if __has_include() +// Need to detect which libc we're using if we're on Linux. +#if defined(__linux__) || defined(__AMDGPU__) || defined(__NVPTX__) # include -#endif - -#if defined(__linux__) # if defined(__GLIBC_PREREQ) # define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) # else diff --git a/libcxx/include/__string/extern_template_lists.h b/libcxx/include/__string/extern_template_lists.h index cc536e514d4ff..dc66fa512b8bd 100644 --- a/libcxx/include/__string/extern_template_lists.h +++ b/libcxx/include/__string/extern_template_lists.h @@ -32,7 +32,6 @@ #define _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_Func, _CharType) \ _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \ _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \ - _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \ _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::basic_string(basic_string const&)) \ _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \ _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::basic_string(basic_string const&, allocator<_CharType> const&)) \ @@ -82,7 +81,6 @@ #define _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_Func, _CharType) \ _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*, size_type)) \ _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::rfind(value_type const*, size_type, size_type) const) \ - _Func(_LIBCPP_EXPORTED_FROM_ABI void basic_string<_CharType>::__init(value_type const*, size_type, size_type)) \ _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>& basic_string<_CharType>::replace(size_type, size_type, value_type const*)) \ _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::size_type basic_string<_CharType>::find_last_not_of(value_type const*, size_type, size_type) const) \ _Func(_LIBCPP_EXPORTED_FROM_ABI basic_string<_CharType>::~basic_string()) \ diff --git a/libcxx/include/optional b/libcxx/include/optional index c325140ee66f2..db236f86e74dd 100644 --- a/libcxx/include/optional +++ b/libcxx/include/optional @@ -672,44 +672,41 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr optional(optional&&) = default; _LIBCPP_HIDE_FROM_ABI constexpr optional(nullopt_t) noexcept {} - template < - class _InPlaceT, - class... _Args, - class = enable_if_t< _And< _IsSame<_InPlaceT, in_place_t>, is_constructible >::value > > + template , is_constructible>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_InPlaceT, _Args&&... __args) : __base(in_place, std::forward<_Args>(__args)...) {} template &, _Args...>> > + enable_if_t&, _Args...>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args) : __base(in_place, __il, std::forward<_Args>(__args)...) {} - template ::template __enable_implicit<_Up>(), int> = 0> + template ::template __enable_implicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr optional(_Up&& __v) : __base(in_place, std::forward<_Up>(__v)) {} - template ::template __enable_explicit<_Up>(), int> = 0> + template ::template __enable_explicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Up&& __v) : __base(in_place, std::forward<_Up>(__v)) {} // LWG2756: conditionally explicit conversion from const optional<_Up>& - template ::template __enable_implicit<_Up>(), int> = 0> + template ::template __enable_implicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(const optional<_Up>& __v) { this->__construct_from(__v); } - template ::template __enable_explicit<_Up>(), int> = 0> + template ::template __enable_explicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(const optional<_Up>& __v) { this->__construct_from(__v); } // LWG2756: conditionally explicit conversion from optional<_Up>&& - template ::template __enable_implicit<_Up>(), int> = 0> + template ::template __enable_implicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(optional<_Up>&& __v) { this->__construct_from(std::move(__v)); } - template ::template __enable_explicit<_Up>(), int> = 0> + template ::template __enable_explicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(optional<_Up>&& __v) { this->__construct_from(std::move(__v)); } @@ -718,7 +715,7 @@ public: template ::value, int> = 0> + enable_if_t<_IsSame<_Tag, __optional_construct_from_invoke_tag>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Tag, _Fp&& __f, _Args&&... __args) : __base(__optional_construct_from_invoke_tag{}, std::forward<_Fp>(__f), std::forward<_Args>(__args)...) {} # endif @@ -732,12 +729,12 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr optional& operator=(optional&&) = default; // LWG2756 - template < - class _Up = value_type, - class = enable_if_t< _And< _IsNotSame<__remove_cvref_t<_Up>, optional>, - _Or< _IsNotSame<__remove_cvref_t<_Up>, value_type>, _Not> >, - is_constructible, - is_assignable >::value> > + template , optional>, + _Or<_IsNotSame<__remove_cvref_t<_Up>, value_type>, _Not>>, + is_constructible, + is_assignable>::value, + int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(_Up&& __v) { if (this->has_value()) this->__get() = std::forward<_Up>(__v); @@ -747,21 +744,20 @@ public: } // LWG2756 - template ::template __enable_assign<_Up>(), int> = 0> + template ::template __enable_assign<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(const optional<_Up>& __v) { this->__assign_from(__v); return *this; } // LWG2756 - template ::template __enable_assign<_Up>(), int> = 0> + template ::template __enable_assign<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(optional<_Up>&& __v) { this->__assign_from(std::move(__v)); return *this; } - template > > + template , int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(_Args&&... __args) { reset(); this->__construct(std::forward<_Args>(__args)...); @@ -770,7 +766,7 @@ public: template &, _Args...> > > + enable_if_t&, _Args...>, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) { reset(); this->__construct(__il, std::forward<_Args>(__args)...); @@ -982,17 +978,15 @@ public: using __base::reset; }; -# if _LIBCPP_STD_VER >= 17 template optional(_Tp) -> optional<_Tp>; -# endif // Comparisons between optionals -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() == std::declval()), bool>, - bool > -operator==(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() == std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const optional<_Up>& __y) { if (static_cast(__x) != static_cast(__y)) return false; if (!static_cast(__x)) @@ -1000,11 +994,11 @@ operator==(const optional<_Tp>& __x, const optional<_Up>& __y) { return *__x == *__y; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() != std::declval()), bool>, - bool > -operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() != std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) { if (static_cast(__x) != static_cast(__y)) return true; if (!static_cast(__x)) @@ -1012,11 +1006,11 @@ operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) { return *__x != *__y; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() < std::declval()), bool>, - bool > -operator<(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() < std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const optional<_Up>& __y) { if (!static_cast(__y)) return false; if (!static_cast(__x)) @@ -1024,11 +1018,11 @@ operator<(const optional<_Tp>& __x, const optional<_Up>& __y) { return *__x < *__y; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() > std::declval()), bool>, - bool > -operator>(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() > std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const optional<_Up>& __y) { if (!static_cast(__x)) return false; if (!static_cast(__y)) @@ -1036,11 +1030,11 @@ operator>(const optional<_Tp>& __x, const optional<_Up>& __y) { return *__x > *__y; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() <= std::declval()), bool>, - bool > -operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() <= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) { if (!static_cast(__x)) return true; if (!static_cast(__y)) @@ -1048,11 +1042,11 @@ operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) { return *__x <= *__y; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() >= std::declval()), bool>, - bool > -operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() >= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) { if (!static_cast(__y)) return true; if (!static_cast(__x)) @@ -1145,99 +1139,99 @@ _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const optional<_Tp>& # endif // _LIBCPP_STD_VER <= 17 // Comparisons with T -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() == std::declval()), bool>, - bool > -operator==(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() == std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x == __v : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() == std::declval()), bool>, - bool > -operator==(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() == std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v == *__x : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() != std::declval()), bool>, - bool > -operator!=(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() != std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x != __v : true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() != std::declval()), bool>, - bool > -operator!=(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() != std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v != *__x : true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() < std::declval()), bool>, - bool > -operator<(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() < std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x < __v : true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() < std::declval()), bool>, - bool > -operator<(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() < std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v < *__x : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() <= std::declval()), bool>, - bool > -operator<=(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() <= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x <= __v : true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() <= std::declval()), bool>, - bool > -operator<=(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() <= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v <= *__x : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() > std::declval()), bool>, - bool > -operator>(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() > std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x > __v : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() > std::declval()), bool>, - bool > -operator>(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() > std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v > *__x : true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() >= std::declval()), bool>, - bool > -operator>=(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() >= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x >= __v : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() >= std::declval()), bool>, - bool > -operator>=(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() >= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v >= *__x : true; } @@ -1252,9 +1246,8 @@ operator<=>(const optional<_Tp>& __x, const _Up& __v) { # endif // _LIBCPP_STD_VER >= 20 -template -inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_SINCE_CXX20 enable_if_t< is_move_constructible_v<_Tp> && is_swappable_v<_Tp>, void > +template && is_swappable_v<_Tp>, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) { __x.swap(__y); } diff --git a/libcxx/include/set b/libcxx/include/set index 2784e82760d7e..3c6ea360bd06c 100644 --- a/libcxx/include/set +++ b/libcxx/include/set @@ -1003,9 +1003,9 @@ operator<=(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, # else // _LIBCPP_STD_VER <= 17 -template +template _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key> -operator<=>(const set<_Key, _Allocator>& __x, const set<_Key, _Allocator>& __y) { +operator<=>(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) { return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way); } @@ -1470,9 +1470,9 @@ operator<=(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, # else // _LIBCPP_STD_VER <= 17 -template +template _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key> -operator<=>(const multiset<_Key, _Allocator>& __x, const multiset<_Key, _Allocator>& __y) { +operator<=>(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) { return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way); } diff --git a/libcxx/include/string b/libcxx/include/string index b280f5f458459..396e73522d3e7 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -2254,7 +2254,6 @@ private: return __guess; } - inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(const value_type* __s, size_type __sz, size_type __reserve); inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(const value_type* __s, size_type __sz); inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(size_type __n, value_type __c); @@ -2439,6 +2438,12 @@ private: template friend inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool operator==(const basic_string<_CharT2, _Traits2, _Allocator2>&, const _CharT2*) _NOEXCEPT; + + // These functions aren't used anymore but are part of out ABI, so we need to provide them in the dylib for backwards + // compatibility +# ifdef _LIBCPP_BUILDING_LIBRARY + void __init(const value_type* __s, size_type __sz, size_type __reserve); +# endif }; // These declarations must appear before any functions are implicitly used @@ -2490,30 +2495,6 @@ basic_string(from_range_t, _Range&&, _Allocator = _Allocator()) -> basic_string, char_traits>, _Allocator>; # endif -template -_LIBCPP_CONSTEXPR_SINCE_CXX20 void -basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve) { - if (__libcpp_is_constant_evaluated()) - __rep_ = __rep(); - if (__reserve > max_size()) - __throw_length_error(); - pointer __p; - if (__fits_in_sso(__reserve)) { - __set_short_size(__sz); - __p = __get_short_pointer(); - } else { - auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__reserve) + 1); - __p = __allocation.ptr; - __begin_lifetime(__p, __allocation.count); - __set_long_pointer(__p); - __set_long_cap(__allocation.count); - __set_long_size(__sz); - } - traits_type::copy(std::__to_address(__p), __s, __sz); - traits_type::assign(__p[__sz], value_type()); - __annotate_new(__sz); -} - template _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) { diff --git a/libcxx/src/iostream.cpp b/libcxx/src/iostream.cpp index d91f9f0c04826..416725235c340 100644 --- a/libcxx/src/iostream.cpp +++ b/libcxx/src/iostream.cpp @@ -18,8 +18,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD template union stream_data { - stream_data() {} - ~stream_data() {} + constexpr stream_data() {} + constexpr ~stream_data() {} struct { // The stream has to be the first element, since that's referenced by the stream declarations in StreamT stream; @@ -38,13 +38,19 @@ union stream_data { #define CHAR_MANGLING_wchar_t "_W" #define CHAR_MANGLING(CharT) CHAR_MANGLING_##CharT +#ifdef _LIBCPP_COMPILER_CLANG_BASED +# define STRING_DATA_CONSTINIT constinit +#else +# define STRING_DATA_CONSTINIT +#endif + #ifdef _LIBCPP_ABI_MICROSOFT # define STREAM(StreamT, BufferT, CharT, var) \ - stream_data, BufferT> var __asm__( \ + STRING_DATA_CONSTINIT stream_data, BufferT> var __asm__( \ "?" #var "@" ABI_NAMESPACE_STR "@std@@3V?$" #StreamT \ "@" CHAR_MANGLING(CharT) "U?$char_traits@" CHAR_MANGLING(CharT) "@" ABI_NAMESPACE_STR "@std@@@12@A") #else -# define STREAM(StreamT, BufferT, CharT, var) stream_data, BufferT> var +# define STREAM(StreamT, BufferT, CharT, var) STRING_DATA_CONSTINIT stream_data, BufferT> var #endif // These definitions and the declarations in technically cause ODR violations, since they have different diff --git a/libcxx/src/string.cpp b/libcxx/src/string.cpp index dc16ce781f76b..e335639883dba 100644 --- a/libcxx/src/string.cpp +++ b/libcxx/src/string.cpp @@ -37,6 +37,44 @@ void __basic_string_common::__throw_out_of_range() const { std::__throw_ou #endif // _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON +// Define legacy ABI functions +// --------------------------- + +#ifndef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION + +template +void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve) { + if (__libcpp_is_constant_evaluated()) + __rep_ = __rep(); + if (__reserve > max_size()) + __throw_length_error(); + pointer __p; + if (__fits_in_sso(__reserve)) { + __set_short_size(__sz); + __p = __get_short_pointer(); + } else { + auto __allocation = std::__allocate_at_least(__alloc_, __recommend(__reserve) + 1); + __p = __allocation.ptr; + __begin_lifetime(__p, __allocation.count); + __set_long_pointer(__p); + __set_long_cap(__allocation.count); + __set_long_size(__sz); + } + traits_type::copy(std::__to_address(__p), __s, __sz); + traits_type::assign(__p[__sz], value_type()); + __annotate_new(__sz); +} + +# define STRING_LEGACY_API(CharT) \ + template _LIBCPP_EXPORTED_FROM_ABI void basic_string::__init(const value_type*, size_type, size_type) + +STRING_LEGACY_API(char); +# if _LIBCPP_HAS_WIDE_CHARACTERS +STRING_LEGACY_API(wchar_t); +# endif + +#endif // _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION + #define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__; #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char) diff --git a/libcxx/test/benchmarks/algorithms/fill.bench.cpp b/libcxx/test/benchmarks/algorithms/fill.bench.cpp index c157b5e5c9862..6a48b25b7eb63 100644 --- a/libcxx/test/benchmarks/algorithms/fill.bench.cpp +++ b/libcxx/test/benchmarks/algorithms/fill.bench.cpp @@ -12,40 +12,40 @@ #include #include -static void bm_fill_n(benchmark::State& state) { +static void bm_fill_n_vector_bool(benchmark::State& state) { std::vector vec1(state.range()); for (auto _ : state) { benchmark::DoNotOptimize(vec1); benchmark::DoNotOptimize(std::fill_n(vec1.begin(), vec1.size(), false)); } } -BENCHMARK(bm_fill_n)->DenseRange(1, 8)->Range(16, 1 << 20); +BENCHMARK(bm_fill_n_vector_bool)->DenseRange(1, 8)->Range(16, 1 << 20); -static void bm_ranges_fill_n(benchmark::State& state) { +static void bm_ranges_fill_n_vector_bool(benchmark::State& state) { std::vector vec1(state.range()); for (auto _ : state) { benchmark::DoNotOptimize(vec1); benchmark::DoNotOptimize(std::ranges::fill_n(vec1.begin(), vec1.size(), false)); } } -BENCHMARK(bm_ranges_fill_n)->DenseRange(1, 8)->Range(16, 1 << 20); +BENCHMARK(bm_ranges_fill_n_vector_bool)->DenseRange(1, 8)->Range(16, 1 << 20); -static void bm_fill(benchmark::State& state) { +static void bm_fill_vector_bool(benchmark::State& state) { std::vector vec1(state.range()); for (auto _ : state) { benchmark::DoNotOptimize(vec1); std::fill(vec1.begin(), vec1.end(), false); } } -BENCHMARK(bm_fill)->DenseRange(1, 8)->Range(16, 1 << 20); +BENCHMARK(bm_fill_vector_bool)->DenseRange(1, 8)->Range(16, 1 << 20); -static void bm_ranges_fill(benchmark::State& state) { +static void bm_ranges_fill_vector_bool(benchmark::State& state) { std::vector vec1(state.range()); for (auto _ : state) { benchmark::DoNotOptimize(vec1); benchmark::DoNotOptimize(std::ranges::fill(vec1, false)); } } -BENCHMARK(bm_ranges_fill)->DenseRange(1, 8)->Range(16, 1 << 20); +BENCHMARK(bm_ranges_fill_vector_bool)->DenseRange(1, 8)->Range(16, 1 << 20); BENCHMARK_MAIN(); diff --git a/libcxx/test/benchmarks/algorithms/ranges_contains.bench.cpp b/libcxx/test/benchmarks/algorithms/ranges_contains.bench.cpp index b98e17a00ef83..c9a10202c8cfc 100644 --- a/libcxx/test/benchmarks/algorithms/ranges_contains.bench.cpp +++ b/libcxx/test/benchmarks/algorithms/ranges_contains.bench.cpp @@ -15,7 +15,7 @@ #include "test_iterators.h" -static void bm_contains_char(benchmark::State& state) { +static void bm_contains_vector_char(benchmark::State& state) { std::vector a(state.range(), 'a'); for (auto _ : state) { @@ -24,9 +24,9 @@ static void bm_contains_char(benchmark::State& state) { benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), 'B')); } } -BENCHMARK(bm_contains_char)->RangeMultiplier(16)->Range(16, 16 << 20); +BENCHMARK(bm_contains_vector_char)->RangeMultiplier(16)->Range(16, 16 << 20); -static void bm_contains_int(benchmark::State& state) { +static void bm_contains_vector_int(benchmark::State& state) { std::vector a(state.range(), 1); for (auto _ : state) { @@ -35,9 +35,9 @@ static void bm_contains_int(benchmark::State& state) { benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), 2)); } } -BENCHMARK(bm_contains_int)->RangeMultiplier(16)->Range(16, 16 << 20); +BENCHMARK(bm_contains_vector_int)->RangeMultiplier(16)->Range(16, 16 << 20); -static void bm_contains_bool(benchmark::State& state) { +static void bm_contains_vector_bool(benchmark::State& state) { std::vector a(state.range(), true); for (auto _ : state) { @@ -46,6 +46,6 @@ static void bm_contains_bool(benchmark::State& state) { benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), false)); } } -BENCHMARK(bm_contains_bool)->RangeMultiplier(16)->Range(16, 16 << 20); +BENCHMARK(bm_contains_vector_bool)->RangeMultiplier(16)->Range(16, 16 << 20); BENCHMARK_MAIN(); diff --git a/libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp b/libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp new file mode 100644 index 0000000000000..ac6a7213bb722 --- /dev/null +++ b/libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include + +// FIXME: Remove after issue https://github.com/llvm/llvm-project/issues/127348 resolved. +extern "C" const char* __asan_default_options() { return "check_initialization_order=true:strict_init_order=true"; } + +// Test that ios used from globals constructors doesn't trigger Asan initialization-order-fiasco. + +struct Global { + Global() { std::cout << "Hello!"; } +} global; + +int main(int, char**) { return 0; } diff --git a/libcxx/test/support/test_container_comparisons.h b/libcxx/test/support/test_container_comparisons.h index 543c5899922d0..f7bf78e48a1f8 100644 --- a/libcxx/test/support/test_container_comparisons.h +++ b/libcxx/test/support/test_container_comparisons.h @@ -13,51 +13,52 @@ #include #include +#include "test_allocator.h" #include "test_comparisons.h" // Implementation detail of `test_sequence_container_spaceship` -template