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

    <tr>
        <th>Summary</th>
        <td>
            Clang-18 crash in -rewrite-legacy-objc
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Hi! I was trying to understand another compiler bug (I don't know enough about it to post here, but you can see symptoms at https://github.com/gnustep/libobjc2/issues/283) which occurred in the combination of the library [libs-quartzcore](https://github.com/ethanc8/libs-quartzcore) and parts of the application [GitUp](https://github.com/ethanc8/Gitup). I've attached the logs of the issue. The issue only occurred in `-rewrite-legacy-objc -fno-ms-extensions -fpermissive`. Under normal compilation, it compiled fine, and under `-rewrite-objc -fno-ms-extensions -fpermissive`, it returned errors because the code contained constructs only allowed in C and not in C++, such as assigning booleans (`BOOL`) to variables of type `struct objc_object*` (`id`) without a typecast.

[CAAnimation-f7059d.m](https://github.com/user-attachments/files/15567874/CAAnimation-f7059d.m.txt)
[CAAnimation-f7059d.sh](https://github.com/user-attachments/files/15567876/CAAnimation-f7059d.sh.txt)

```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: clang-18 CAAnimation.m -c -MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNUSTEP_RUNTIME=1 -D_NONFRAGILE_ABI=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -pthread -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -O2 -rewrite-legacy-objc -fno-ms-extensions -fpermissive -fobjc-runtime=gnustep-2.1 -fblocks -fconstant-string-class=NSConstantString -I./derived_src -I. -I/home/ethan/GNUstep/Library/Headers -I/usr/GNUstep/Local/Library/Headers -I/usr/GNUstep/System/Library/Headers -o obj/QuartzCore.obj/CAAnimation.m.o
1.      <eof> parser at end of file
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM.so.18.1      0x00007f9417d94716 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 54
1 libLLVM.so.18.1      0x00007f9417d926d0 llvm::sys::RunSignalHandlers() + 80
2  libLLVM.so.18.1      0x00007f9417ce41f0
3  libc.so.6 0x00007f9416842520
4  libclang-cpp.so.18.1 0x00007f9420a75f24
5 libclang-cpp.so.18.1 0x00007f9420a7641a
6  libclang-cpp.so.18.1 0x00007f9420a770e6 clang::RewriteBuffer::ReplaceText(unsigned int, unsigned int, llvm::StringRef) + 86
7  libclang-cpp.so.18.1 0x00007f9420a78175 clang::Rewriter::ReplaceText(clang::SourceLocation, unsigned int, llvm::StringRef) + 197
8  libclang-cpp.so.18.1 0x00007f942109922b
9 libclang-cpp.so.18.1 0x00007f9421071f73
10 libclang-cpp.so.18.1 0x00007f941f37ffc6 clang::ParseAST(clang::Sema&, bool, bool) + 614
11 libclang-cpp.so.18.1 0x00007f94211b0ab5 clang::FrontendAction::Execute() + 85
12 libclang-cpp.so.18.1 0x00007f942112a084 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 708
13 libclang-cpp.so.18.1 0x00007f942122b25e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 750
14 clang-18             0x000059055c74ad55 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 4069
15 clang-18 0x000059055c748155
16 libclang-cpp.so.18.1 0x00007f9420de25c9
17 libLLVM.so.18.1      0x00007f9417ce3f8c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 140
18 libclang-cpp.so.18.1 0x00007f9420de1f5e clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 366
19 libclang-cpp.so.18.1 0x00007f9420daa4d1 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 897
20 libclang-cpp.so.18.1 0x00007f9420daa71e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 142
21 libclang-cpp.so.18.1 0x00007f9420dc6d2d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 333
22 clang-18             0x000059055c747ac4 clang_main(int, char**, llvm::ToolContext const&) + 11172
23 clang-18 0x000059055c754bf6 main + 102
24 libc.so.6 0x00007f9416829d90
25 libc.so.6            0x00007f9416829e40 __libc_start_main + 128
26 clang-18             0x000059055c744bc5 _start + 37
clang-18: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Ubuntu clang version 18.1.6 (++20240518023229+1118c2e05e67-1~exp1~20240518143321.130)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-18: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-18: note: diagnostic msg: /tmp/CAAnimation-f7059d.m
clang-18: note: diagnostic msg: /tmp/CAAnimation-f7059d.sh
clang-18: note: diagnostic msg: 

********************
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8WV1z4rjS_jXOjcqULX9ykQsgkGErk-QNZOfdc0PJchu0Y0s-kpzAXuxvPyVZfGWSCbtn60xRBMstdffT3U9LGqIUW3OAay8Ze8nNFen0Rshr0BvCaX5ViHJ3_YV5OERz9EoU0nLH-BppgTpeglSa8BIRLvQGJKKiaVkNEhXdGnk4n6NScA9nGn3n4hUBF916g0ghOo2YNou0Qmm0AQkenq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