|
58 | 58 |
|
59 | 59 | namespace SPIRV { |
60 | 60 |
|
| 61 | +namespace { |
| 62 | +std::string to_string(uint32_t Version) { |
| 63 | + std::string Res(formatVersionNumber(Version)); |
| 64 | + Res += " (" + std::to_string(Version) + ")"; |
| 65 | + return Res; |
| 66 | +} |
| 67 | + |
| 68 | +std::string to_string(VersionNumber Version) { |
| 69 | + return to_string(static_cast<uint32_t>(Version)); |
| 70 | +} |
| 71 | +} // Anonymous namespace |
| 72 | + |
61 | 73 | SPIRVModule::SPIRVModule() |
62 | 74 | : AutoAddCapability(true), ValidateCapability(false), IsValid(true) {} |
63 | 75 |
|
@@ -173,7 +185,16 @@ class SPIRVModuleImpl : public SPIRVModule { |
173 | 185 | void insertEntryNoId(SPIRVEntry *Entry) override { EntryNoId.insert(Entry); } |
174 | 186 |
|
175 | 187 | void setSPIRVVersion(SPIRVWord Ver) override { |
176 | | - assert(this->isAllowedToUseVersion(static_cast<VersionNumber>(Ver))); |
| 188 | + if (!this->isAllowedToUseVersion(static_cast<VersionNumber>(Ver))) { |
| 189 | + std::stringstream SS; |
| 190 | + SS << "SPIR-V version was restricted to at most " |
| 191 | + << to_string(getMaximumAllowedSPIRVVersion()) |
| 192 | + << " but a construct from the input requires SPIR-V version " |
| 193 | + << to_string(Ver) << " or above\n"; |
| 194 | + getErrorLog().checkError(false, SPIRVEC_RequiresVersion, SS.str()); |
| 195 | + setInvalid(); |
| 196 | + return; |
| 197 | + } |
177 | 198 | SPIRVVersion = Ver; |
178 | 199 | } |
179 | 200 |
|
@@ -2098,16 +2119,6 @@ void SPIRVModuleImpl::addUnknownStructField(SPIRVTypeStruct *Struct, unsigned I, |
2098 | 2119 | UnknownStructFieldMap[Struct].push_back(std::make_pair(I, ID)); |
2099 | 2120 | } |
2100 | 2121 |
|
2101 | | -static std::string to_string(uint32_t Version) { |
2102 | | - std::string Res(formatVersionNumber(Version)); |
2103 | | - Res += " (" + std::to_string(Version) + ")"; |
2104 | | - return Res; |
2105 | | -} |
2106 | | - |
2107 | | -static std::string to_string(VersionNumber Version) { |
2108 | | - return to_string(static_cast<uint32_t>(Version)); |
2109 | | -} |
2110 | | - |
2111 | 2122 | std::istream &operator>>(std::istream &I, SPIRVModule &M) { |
2112 | 2123 | SPIRVDecoder Decoder(I, M); |
2113 | 2124 | SPIRVModuleImpl &MI = *static_cast<SPIRVModuleImpl *>(&M); |
|
0 commit comments