diff --git a/llvm/include/llvm/MC/MCSectionXCOFF.h b/llvm/include/llvm/MC/MCSectionXCOFF.h --- a/llvm/include/llvm/MC/MCSectionXCOFF.h +++ b/llvm/include/llvm/MC/MCSectionXCOFF.h @@ -32,22 +32,24 @@ class MCSectionXCOFF final : public MCSection { friend class MCContext; - XCOFF::StorageMappingClass MappingClass; - XCOFF::SymbolType Type; + Optional MappingClass; + Optional Type; MCSymbolXCOFF *const QualName; StringRef SymbolTableName; bool MultiSymbolsAllowed; static constexpr unsigned DefaultAlignVal = 4; - MCSectionXCOFF(StringRef Name, XCOFF::StorageMappingClass SMC, - XCOFF::SymbolType ST, SectionKind K, MCSymbolXCOFF *QualName, - MCSymbol *Begin, StringRef SymbolTableName, - bool MultiSymbolsAllowed) + MCSectionXCOFF(StringRef Name, Optional SMC, + Optional ST, SectionKind K, + MCSymbolXCOFF *QualName, MCSymbol *Begin, + StringRef SymbolTableName, bool MultiSymbolsAllowed) : MCSection(SV_XCOFF, Name, K, Begin), MappingClass(SMC), Type(ST), QualName(QualName), SymbolTableName(SymbolTableName), MultiSymbolsAllowed(MultiSymbolsAllowed) { - assert((ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) && - "Invalid or unhandled type for csect."); + if (ST) + assert( + (ST == XCOFF::XTY_SD || ST == XCOFF::XTY_CM || ST == XCOFF::XTY_ER) && + "Invalid or unhandled type for csect."); assert(QualName != nullptr && "QualName is needed."); QualName->setRepresentedCsect(this); QualName->setStorageClass(XCOFF::C_HIDEXT); @@ -65,11 +67,13 @@ return S->getVariant() == SV_XCOFF; } - XCOFF::StorageMappingClass getMappingClass() const { return MappingClass; } - XCOFF::StorageClass getStorageClass() const { + Optional getMappingClass() const { + return MappingClass; + } + Optional getStorageClass() const { return QualName->getStorageClass(); } - XCOFF::SymbolType getCSectType() const { return Type; } + Optional getCSectType() const { return Type; } MCSymbolXCOFF *getQualNameSymbol() const { return QualName; } void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, diff --git a/llvm/lib/MC/MCSectionXCOFF.cpp b/llvm/lib/MC/MCSectionXCOFF.cpp --- a/llvm/lib/MC/MCSectionXCOFF.cpp +++ b/llvm/lib/MC/MCSectionXCOFF.cpp @@ -39,7 +39,8 @@ } if (getKind().isData()) { - switch (getMappingClass()) { + assert(getMappingClass() && "Data kind section should be a csect."); + switch (getMappingClass().getValue()) { case XCOFF::XMC_RW: case XCOFF::XMC_DS: printCsectDirective(OS); diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp --- a/llvm/lib/MC/XCOFFObjectWriter.cpp +++ b/llvm/lib/MC/XCOFFObjectWriter.cpp @@ -205,7 +205,7 @@ const ControlSection &, int16_t, uint64_t); void writeSymbolTableEntryForControlSection(const ControlSection &, int16_t, - XCOFF::StorageClass); + Optional); void writeFileHeader(); void writeSectionHeaderTable(); void writeSections(const MCAssembler &Asm, const MCAsmLayout &Layout); @@ -273,7 +273,13 @@ } CsectGroup &XCOFFObjectWriter::getCsectGroup(const MCSectionXCOFF *MCSec) { - switch (MCSec->getMappingClass()) { + Optional SMC = MCSec->getMappingClass(); + Optional Ty = MCSec->getCSectType(); + + if (!SMC || !Ty) + report_fatal_error("Can not get Csect Group for a non csect section!"); + + switch (MCSec->getMappingClass().getValue()) { case XCOFF::XMC_PR: assert(XCOFF::XTY_SD == MCSec->getCSectType() && "Only an initialized csect can contain program code."); @@ -592,7 +598,7 @@ // Symbol type: Label W.write(XCOFF::XTY_LD); // Storage mapping class. - W.write(CSectionRef.MCCsect->getMappingClass()); + W.write(CSectionRef.MCCsect->getMappingClass().getValue()); // Reserved (x_stab). W.write(0); // Reserved (x_snstab). @@ -601,7 +607,7 @@ void XCOFFObjectWriter::writeSymbolTableEntryForControlSection( const ControlSection &CSectionRef, int16_t SectionIndex, - XCOFF::StorageClass StorageClass) { + Optional StorageClass) { // n_name, n_zeros, n_offset writeSymbolName(CSectionRef.getSymbolTableName()); // n_value @@ -617,7 +623,8 @@ // when debugging is enabled. W.write(0); // n_sclass - W.write(StorageClass); + assert(StorageClass && "Not a csect section!"); + W.write(StorageClass.getValue()); // Always 1 aux entry for now. W.write(1); @@ -630,7 +637,7 @@ // Symbol type. W.write(getEncodedType(CSectionRef.MCCsect)); // Storage mapping class. - W.write(CSectionRef.MCCsect->getMappingClass()); + W.write(CSectionRef.MCCsect->getMappingClass().getValue()); // Reserved (x_stab). W.write(0); // Reserved (x_snstab). @@ -883,7 +890,8 @@ // significant bits. Shift this value into the 5 most significant bits, and // bitwise-or in the csect type. uint8_t EncodedAlign = Log2Align << 3; - return EncodedAlign | Sec->getCSectType(); + assert(Sec->getCSectType() && "Not a csect!"); + return EncodedAlign | Sec->getCSectType().getValue(); } } // end anonymous namespace