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

    <tr>
        <th>Summary</th>
        <td>
            Crash in HandleVirtRegUse with invalid inline-asm and optimization
        </td>
    </tr>

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

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

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

<pre>
    Consider the [following function](https://godbolt.org/z/n61v7EYK1) with invalid (?) inline-asm:
```c
long syscall() {
    long result;
    __asm__("syscall"
            : "=a"(result)
            : "#"(0));
    return result;
}
```

Compiling this code using GCC 11.3 you get:

```
<source>: In function 'long int syscall()':
<source>:3:5: warning: 'asm' operand 1 probably does not match constraints
    3 |     __asm__("syscall"
      |     ^~~~~~~
<source>:3:5: error: impossible constraint in 'asm'
Compiler returned: 1
```

Compiling this code using clang 14.0.0 you get:
```
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: /opt/compiler-explorer/clang-14.0.0/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-11.2.0 -fcolor-diagnostics -fno-crash-diagnostics -O1 <source>
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '<source>'.
4.      Running pass 'Live Variable Analysis' on function '@_Z7syscallv'
 #0 0x0000557c98b7de8f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x0000557c98b7bd60 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x357bd60)
 #2 0x0000557c98ab6b78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f909a8fd3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #4 0x0000557c97e13dc4 llvm::LiveVariables::HandleVirtRegUse(llvm::Register, llvm::MachineBasicBlock*, llvm::MachineInstr&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x2813dc4)
 #5 0x0000557c97e153a9 llvm::LiveVariables::runOnInstr(llvm::MachineInstr&, llvm::SmallVectorImpl<unsigned int>&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x28153a9)
 #6 0x0000557c97e15d89 llvm::LiveVariables::runOnBlock(llvm::MachineBasicBlock*, unsigned int) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x2815d89)
 #7 0x0000557c97e170a1 llvm::LiveVariables::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x28170a1)
 #8 0x0000557c97e83638 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x2883638)
 #9 0x0000557c982e8ca9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x2ce8ca9)
#10 0x0000557c982e8f41 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x2ce8f41)
#11 0x0000557c982e99e7 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x2ce99e7)
#12 0x0000557c98eace84 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x38ace84)
#13 0x0000557c99b0592f clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x450592f)
#14 0x0000557c9a99aa79 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x539aa79)
#15 0x0000557c99b05b02 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x4505b02)
#16 0x0000557c99501161 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x3f01161)
#17 0x0000557c9949c2f2 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x3e9c2f2)
#18 0x0000557c995cc853 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x3fcc853)
#19 0x0000557c9679b1d4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x119b1d4)
#20 0x0000557c9679718d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#21 0x0000557c993375f5 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#22 0x0000557c98ab7163 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x34b7163)
#23 0x0000557c993396c8 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x3d396c8)
#24 0x0000557c9930cb1a clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x3d0cb1a)
#25 0x0000557c9930d65f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x3d0d65f)
#26 0x0000557c99316005 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x3d16005)
#27 0x0000557c966a80b2 main (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x10a80b2)
#28 0x00007f909a3ab0b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b3)
#29 0x0000557c96796d0a _start (/opt/compiler-explorer/clang-14.0.0/bin/clang+++0x1196d0a)
clang-14: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```

This problem is _possibly_ related to other issues which mention "crash in `HandleVirtRegUse`"
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlWUtz47gR_jX0BSUVnyJ58EGW7d1JZmpctneqkgsLBEGJWYpgANC29tenG6QkgpI9k40mOURF2RQeja-_bjQaQC6K3fVKNKoquCR6w4kT3ZSirsVr1axJ2TVMV6JxolvHTzZat8oJlo5_D89aFLmo9VzINfz6A77NwnuJ7_72V8_xU_Ja6Q2pmhdaVwWBzk5wj8VVU1cNn1G1RUHureMunYXbP6z_XQsYWe0Uo3WNHaGXE9_0dQQ-pl5y1dXaCUblWQZSs8x08Q_9_WOD_QdGJlgR3FL85yeDMD99v60f9E1dbAXPeGDJdSebKSQnvp3oN_w0f1di21Y1cqw3lSJMFJx0Cn__sloRz5sHZCc6sub6yNNZacFKiU4y7gR3iPVTczAa4I4NV1WjbT6h4ijVFhDAN0JBr1Q2AKfXP0Z7-TERLZe0KYhHWilymtc7UgiuSCM02VLNNqBIo7SkMKQ6EhSAAVfkB220b-pEd0588nyImUspJL5U21YoVeU1HwECHo6qjK0Ant-bkBfY2ftTZmM1hb9eOHfn7qnpbFkPn--WT3dEdfm20oSSvEOHboXURAsymWYwj7p8zg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