Last active
December 27, 2018 18:58
-
-
Save marzer/0ef6545e027704458227b459b7837d15 to your computer and use it in GitHub Desktop.
Repro of an internal compiler error in Visual Studio 2017 15.9.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // compiled in x64, Release with: | |
| // /std:c++latest /permissive- /arch:AVX2 /fp:except- /Qpar- /GF /GS- /O2 /Ot /fp:fast /Oy /openmp- /GL | |
| // bug encountered using visual studio 2017 15.9.4 (_MSC_FULL_VER: 191627025) | |
| #include <string_view> | |
| #include <array> | |
| #include <cstdint> | |
| using namespace std::literals; | |
| constexpr auto operator"" _u8(unsigned long long n) noexcept | |
| { | |
| return static_cast<uint8_t>(n); | |
| } | |
| template <typename T> | |
| constexpr bool __vectorcall Between(T value, T min, T max) noexcept | |
| { | |
| return !(value < min || value > max); | |
| } | |
| constexpr bool IsDigit(char c) noexcept | |
| { | |
| return Between(c, '0', '9'); | |
| } | |
| constexpr bool IsHexadecimal(char c) noexcept | |
| { | |
| return IsDigit(c) | |
| || Between(c, 'a', 'f') | |
| || Between(c, 'A', 'F'); | |
| } | |
| constexpr uint8_t HexToByte(char c) noexcept | |
| { | |
| if (IsDigit(c)) | |
| return static_cast<uint8_t>(c - '0'); | |
| else if (Between(c, 'a', 'f')) | |
| return static_cast<uint8_t>(c - 'a' + 10_u8); | |
| else if (Between(c, 'A', 'F')) | |
| return static_cast<uint8_t>(c - 'A' + 10_u8); | |
| return 255_u8; | |
| } | |
| struct Guid | |
| { | |
| std::array<uint8_t, 16> Bytes; | |
| constexpr Guid() noexcept | |
| : Bytes{ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } | |
| {} | |
| template <typename STR> | |
| static constexpr bool TryParse(STR && str, Guid& output) noexcept | |
| { | |
| if (str.length() < 32u) //two hex characters per byte, ignoring punctuation etc. | |
| return false; | |
| Guid outVal; | |
| char last{}; | |
| size_t index{}; | |
| for (auto ch : str) | |
| { | |
| const auto ishex = IsHexadecimal(ch); | |
| if (!(ishex | |
| || ch == '\t' || ch == ' ' | |
| || ch == ',' || ch == '-' | |
| || ch == '{' || ch == '}')) | |
| return false; | |
| if (ishex) | |
| { | |
| if (!last) | |
| last = ch; | |
| else | |
| { | |
| outVal.Bytes[ParseIndices[index++]] = static_cast<uint8_t>((HexToByte(last) << 4) | HexToByte(ch)); | |
| last = 0; | |
| if (index == 16) | |
| { | |
| output = outVal; | |
| return true; | |
| } | |
| } | |
| } | |
| } | |
| return false; | |
| } | |
| template <typename STR> | |
| static constexpr Guid Parse(STR && str) noexcept | |
| { | |
| Guid guid; | |
| TryParse(std::forward<STR>(str), guid); | |
| return guid; | |
| } | |
| private: | |
| static constexpr std::array<size_t, 16> ParseIndices = { { | |
| 3,2,1,0, | |
| 5,4, | |
| 7,6, | |
| 8,9,10,11,12,13,14,15 | |
| } }; | |
| }; | |
| struct AssetLibraryID final | |
| { | |
| Guid ID; | |
| constexpr AssetLibraryID(const Guid& id) noexcept | |
| : ID{ id } | |
| {} | |
| }; | |
| constexpr Guid operator"" _guid(const char* str, size_t len) noexcept | |
| { | |
| return Guid::Parse(std::string_view{ str, len }); | |
| // changing this function's implementation to this also fixes the issue: | |
| // auto view = std::string_view{ str, len }; | |
| // return Guid::Parse(view); | |
| } | |
| //this will cause an ICE when whole program optimization (/GL) is enabled | |
| inline constexpr auto assetLibID_constexpr = AssetLibraryID { "5C0C3B98-5E24-4319-83C0-1710A2C9353F"_guid }; | |
| int main() | |
| { | |
| return 0; | |
| } | |
| /* | |
| the compiler log for the error looks like this: | |
| 1>------ Build started: Project: wpo_guid_bug, Configuration: Release x64 ------ | |
| 1>cl : Command line warning D9025 : overriding '/sdl' with '/GS-' | |
| 1>Main.cpp | |
| 1>Generating code | |
| 1>c:\users\marze\source\repos\wpo_guid_bug\main.cpp : fatal error C1001: An internal error has occurred in the compiler. | |
| 1>(compiler file 'd:\agent\_work\2\s\src\vctools\compiler\utc\src\p2\main.c', line 187) | |
| 1> To work around this problem, try simplifying or changing the program near the locations listed above. | |
| 1>Please choose the Technical Support command on the Visual C++ | |
| 1> Help menu, or open the Technical Support help file for more information | |
| 1> link!InvokeCompilerPassW()+0x4357e | |
| 1> | |
| 1>c:\users\marze\source\repos\wpo_guid_bug\main.cpp : fatal error C1001: An internal error has occurred in the compiler. | |
| 1>(compiler file 'd:\agent\_work\2\s\src\vctools\compiler\utc\src\p2\main.c', line 187) | |
| 1> To work around this problem, try simplifying or changing the program near the locations listed above. | |
| 1>Please choose the Technical Support command on the Visual C++ | |
| 1> Help menu, or open the Technical Support help file for more information | |
| 1> link!InvokeCompilerPassW()+0x4357e | |
| 1> | |
| 1> | |
| 1>LINK : fatal error LNK1000: Internal error during IMAGE::BuildImage | |
| 1> | |
| 1> Version 14.16.27025.1 | |
| 1> | |
| 1> ExceptionCode = C0000005 | |
| 1> ExceptionFlags = 00000000 | |
| 1> ExceptionAddress = 0FE7092E (0FBC0000) "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\c2.dll" | |
| 1> NumberParameters = 00000002 | |
| 1> ExceptionInformation[ 0] = 00000000 | |
| 1> ExceptionInformation[ 1] = 00000034 | |
| 1> | |
| 1>CONTEXT: | |
| 1> Eax = 00000000 Esp = 010FE000 | |
| 1> Ebx = 043073D4 Ebp = 010FE034 | |
| 1> Ecx = 00000000 Esi = 043CB21C | |
| 1> Edx = 013A9010 Edi = 05533EFC | |
| 1> Eip = 0FE7092E EFlags = 00010246 | |
| 1> SegCs = 00000023 SegDs = 0000002B | |
| 1> SegSs = 0000002B SegEs = 0000002B | |
| 1> SegFs = 00000053 SegGs = 0000002B | |
| 1> Dr0 = 00000000 Dr3 = 00000000 | |
| 1> Dr1 = 00000000 Dr6 = 00000000 | |
| 1> Dr2 = 00000000 Dr7 = 00000000 | |
| 1>Done building project "wpo_guid_bug.vcxproj" -- FAILED. | |
| Build has been canceled. | |
| */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment