<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/69811>69811</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang Crash Report: Small C++ Function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          britown88
      </td>
    </tr>
</table>

<pre>
    Here's the function it crashes on:
```C
struct StringParser {
   const char* pos, * end;

   char peek() { return *pos; }
   bool atEnd() { return pos >= end; }
   void skip(int skip = 1) { pos += skip; }
 void rewind(int skip = 1) { pos -= skip; }

   bool accept(char c) {
      if (*pos == c) {
         ++pos;
         return true;
 }
      return false;
   }
   bool accept(const char* str) {
 auto start = pos;
      while (*str) {
         if (!accept(*str)) {
            pos = start;
            return false;
         }
 ++str;
      }
      return true;
   }
   bool acceptAnyOf(const char* str, char* cout = nullptr) {
      while (*str) {
         if (accept(*str)) {
            if (cout) {
 *cout = *str;
            }
            return true;
         }
 ++str;
      }
      return false;
   }
   bool acceptInRanges(std::initializer_list<std::initializer_list<char>> ranges, char* cout = nullptr) {
      //auto r = ranges.begin();
      for (auto&& range : ranges) {
         if (range.size() == 1) {
 if (*pos == *range.begin()) {
               if (cout) { *cout = *pos; }
               ++pos;
               return true;
 }
         }
         else if (range.size() == 2) {
            if (*pos >= *range.begin() && *pos <= *(range.begin() + 1)) {
 if (cout) { *cout = *pos; }
               ++pos;
               return true;
            }
         }
      }

      return false;
   }
};


int sound::semitoneFromNote(char note, int octave, char accidental) {
   int index = (note >= 'C' && note <= 'G') ? (note - 'C') : (note - 'A' + 5);

   int semitone_number = octave * SEMITONES_PER_OCTAVE + NOTE_SEMITONE_INDICES[index];
   if (accidental == '#') semitone_number++;
   else if (accidental == 'b') semitone_number--;

   return semitone_number;
}
int sound::semitoneFromString(const char* str) {
   StringParser p = { str, str + strlen(str) };

   char n = 0, o = 0, a = 0;
   if (p.acceptInRanges({ {'A', 'G'} }, &n) && p.acceptAnyOf("#-b", &a) && p.acceptInRanges({{'0', '9'}}, &o)) {
      return semitoneFromNote(n, o - '0', a);
   }
   return 0;
}
```

```
4>PATCHABLE_OP 2, 14, !7828, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_constu, 1, DW_OP_mul, DW_OP_plus, DW_OP_stack_value, DW_OP_LLVM_fragment, 64, 64), $noreg, $noreg, debug-location !7860; sound.cpp:0
4>PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
4>Stack dump:
4>0. Program arguments: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Tools\\Llvm\\x64\\bin\\clang-cl.exe" @C:\\Users\\p4r4d\\AppData\\Local\\Temp\\MSBuildTempp4r4d\\tmp40f9a054e2344074b2904c4edd44b8cf.rsp
4>1. <eof> parser at end of file
4>2. Code generation
4>3. Running pass 'Function Pass Manager' on module 'sound.cpp'.
4>4. Running pass 'X86 Assembly Printer' on function '@"?semitoneFromString@sound@@YAHPEBD@Z"'
4>Exception Code: 0x80000003
4> #0 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x12007fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x11f9983
4> #1 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x86dc4b C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x242c26
4> #2 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x8e188b C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x3c0268
4> #3 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x3c5f73 C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x3c088f
4> #4 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x174f8fc C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x1ada133
4> #5 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x313bfbe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x1a45a92
4> #6 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x7d554d C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x866bde
4> #7 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x7b1b C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x4a73
4> #8 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x18270e6 C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x66a61f
4> #9 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x1826e6b C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x792a55
4>#10 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x792d9d C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x7ace3c
4>#11 0x00007ff6fe4307fe C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x438f C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe 0x41e7dd0
4>#12 0x00007ff6fe4307fe (C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe+0x12007fe)
4>#13 0x00007ff6fe429983 (C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe+0x11f9983)
4>0x00007FF6FE4307FE, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x12007FE byte(s)
4>0x00007FF6FE429983, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x11F9983 byte(s)
4>0x00007FF6FDA9DC4B, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x86DC4B byte(s)
4>0x00007FF6FD472C26, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x242C26 byte(s)
4>0x00007FF6FDB1188B, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x8E188B byte(s)
4>0x00007FF6FD5F0268, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x3C0268 byte(s)
4>0x00007FF6FD5F5F73, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x3C5F73 byte(s)
4>0x00007FF6FD5F088F, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x3C088F byte(s)
4>0x00007FF6FE97F8FC, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x174F8FC byte(s)
4>0x00007FF6FED0A133, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x1ADA133 byte(s)
4>0x00007FF70036BFBE, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x313BFBE byte(s)
4>0x00007FF6FEC75A92, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x1A45A92 byte(s)
4>0x00007FF6FDA0554D, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x7D554D byte(s)
4>0x00007FF6FDA96BDE, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x866BDE byte(s)
4>0x00007FF6FD237B1B, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x7B1B byte(s)
4>0x00007FF6FD234A73, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x4A73 byte(s)
4>0x00007FF6FEA570E6, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x18270E6 byte(s)
4>0x00007FF6FD89A61F, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x66A61F byte(s)
4>0x00007FF6FEA56E6B, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x1826E6B byte(s)
4>0x00007FF6FD9C2A55, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x792A55 byte(s)
4>0x00007FF6FD9C2D9D, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x792D9D byte(s)
4>0x00007FF6FD9DCE3C, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x7ACE3C byte(s)
4>0x00007FF6FD23438F, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x438F byte(s)
4>0x00007FF701417DD0, C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin\clang-cl.exe(0x00007FF6FD230000) + 0x41E7DD0 byte(s)
4>0x00007FF992297344, C:\WINDOWS\System32\KERNEL32.DLL(0x00007FF992280000) + 0x17344 byte(s), BaseThreadInitThunk() + 0x14 byte(s)
4>0x00007FF9926226B1, C:\WINDOWS\SYSTEM32\ntdll.dll(0x00007FF9925D0000) + 0x526B1 byte(s), RtlUserThreadStart() + 0x21 byte(s)
4>clang-cl : error : clang frontend command failed due to signal (use -v to see invocation)
4>clang version 15.0.1
4>Target: x86_64-pc-windows-msvc
4>Thread model: posix
4>InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin
4>clang-cl: note: diagnostic msg:
4>********************
4>
4>PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
4>Preprocessed source(s) and associated run script(s) are located at:
4>clang-cl: note: diagnostic msg: C:\Users\p4r4d\AppData\Local\Temp\sound-086d8b.cpp
4>clang-cl: note: diagnostic msg: C:\Users\p4r4d\AppData\Local\Temp\sound-086d8b.sh
4>clang-cl: note: diagnostic msg:
4>
4>********************
```

[sound-086d8b.zip](https://github.com/llvm/llvm-project/files/13059891/sound-086d8b.zip)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMW99z26ry_2vICxOPBOjXQx5kST7NfNMkE_u033NfMkhCjm5loQGUpuevvwOSbMt26vTcO7U6nQbDsvvZzy4LuIRKWa5rxm6AMwdOfEVb9cLFTSpKxb_Xvn-V8vzHzScmGECehOqFwaKtM1XyGpYKZoLKFyYhrwEOgRUDKwSu1f2Nus9SiTZTcKlEWa8fqZBMQODNu0EIYcZrqWD2QgVAIWy4BCiCusnqHOBebif9QgVsGPsGkA9QoDVBwVQraj1Hz8ZzCLx4OyHlvIJUJXV-PKPhEgKcABz3xkYzX3mZQ_mtbADyy1qZJtSy9qDGzEdz3WfkRgrMdMG-l8by-wquT04_wJ9lrFEA-cb9rJ--lYEQlgU0_oWdT7FWekoOQoMYzTuqDoZ6XpRo2W5wn5OdTEEryfY1HJO-BT2KsFRijIu2ikOpqFCGnGNg31_KivXuHc0e_gwE2FuzW-nTEyDs4x93xo_Z-ImzPZNblztOtbmx0Gnuxvy-S11Y_3goTvMXbT9mvO14q9uqak6y8wv8_QJ53QRtfiwCULjF1Gs5xewBMz_l579j-6OZels_0XrNJEC-VLmuZzgs61KVtCr_ZuK5KqUCOPrZmAmKLigJFL2uX4oUQAuAFmZBCCPaaZmlbF3WXf06cLngwsStVRwgFyC3mwIBDrcQ3g-3kZjJ8m82FMeuctjjSaeKC0BhN3sf23u5cipdDhPlRO0e5cv7VesnuXOs7biHVZKd4QOdWQVbapL3qIF9dLaSUS-5tToWnpsYnArD76bwp2v2oOd4-_rIMtSN8Ubf_W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