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

    <tr>
        <th>Summary</th>
        <td>
            [Clang15] clang -O stops emitting code for function when indeterminate value encountered in controlling condition of `if`
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          ian-abbott
      </td>
    </tr>
</table>

<pre>
    Consider this invalid program using an uninitialized variable:

**foo.c**
```c
#include <stdio.h>

int main (void)
{
   int garbage; // garbage is indeterminate
   int *addr = &garbage; // address of garbage has been used
   int a = 0;

   puts("Garbage test");
 fflush(stdout);
   if (garbage)
   {
     a = 1;
   }
 printf("a = %d\n", a);
   fflush(stdout);
}
```

Compiling to assembly language with clang-15 on Debian, with optimizer enabled:
```text
$ clang-15 -O -S foo.c
```

Details of compiler used:
```text
$ clang-15 --version
Debian clang version 15.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```

Resulting assembly language:

**foo.s**
```gas
        .text
        .file   "foo.c"
        .globl  main # -- Begin function main
        .p2align        4, 0x90
        .type   main,@function
main:                                   # @main
        .cfi_startproc
# %bb.0:
        pushq   %rax
        .cfi_def_cfa_offset 16
        leaq    .L.str(%rip), %rdi
        callq   puts@PLT
        movq    stdout@GOTPCREL(%rip), %rax
        movq    (%rax), %rdi
        callq   fflush@PLT
.Lfunc_end0:
        .size   main, .Lfunc_end0-main
        .cfi_endproc
 # -- End function
        .type   .L.str,@object                  # @.str
        .section        .rodata.str1.1,"aMS",@progbits,1
.L.str:
        .asciz  "Garbage test"
        .size   .L.str, 13

        .ident  "Debian clang version 15.0.6"
        .section        ".note.GNU-stack","",@progbits
        .addrsig
```

Note that no assembly code been emitted for the C code from the line `if (garbage)` to the end of the function, including any code to return from the function. 

Related question by user **Lundin** (not me) on Stackoverflow:

https://stackoverflow.com/q/75533693/5264491
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVttu2zwSfhr6ZiCBpg62LnzR2HWxQLYt2u51QIkjmbsUqZCU4-TpF9TBltM2-APDoTnDb745ktw52WjEHckeSHZY8d6fjN1JriNelsb7VWnE625vtJMCLfiTdCD1mSspoLOmsbyF3kndANfQa6mll1zJNxRw5lbyUiFJPhF6IHT-ZuFTGxNX43Lazun4qWa1ROpK9QKBJHvnhTTxiSSfl1BSe2i51EDY9mykIKyYxJuHcQEAQanhtuQNkuQBCDsSdpx3YHBHoEfbSs093h0j7BMXwgJJDkBY_jtKkKJzYOor4Ik7KBE19A7FHRofcChJHpY-AEDXe0fYljD2ZQLx6DxhLPgza0Ndq96dCNs6L0zv72QAsg5BmBnOcQCAZShg4rBeniSbw7TurNS-HpnwyelMkGyvBy574O-MfkDpinrN69LpvWk7qULVeAPcOWxL9QqK66YP7r9If4Iq_IzWGRgNBywl14HCIDKdl618QwuoQ4WJW4nN1jxe_FxI6Q0r-gbRTxiL7-_0Dui5VENaq4Ep2jGd_9hMdEbrpNEzXqA_imGSwDqLaZyPCr-4bdCT5BNctvlTnkZdFSmp-0vU6H5SOVnkAlojUAXFzjh5GUX_0s5zpVAcpA0iwo69s4QdS6k_8PIHul75oXXfZ-CvLev-2LINd7N6ES9CQou4lgoJLQhjU8ezm6xRplSEFlMLJxBF8ICN1FD3uvIhSEF0O9AxrmSjCS3SUAv0UtCF3dcOJzDC9iSlM8ioMuwnYxd8_BeYkJTem65q-eQ8t76z5jahQoOUZUwX8Sq63p2eB5czyy_3CALrp6rmT6auHXpY51exQh4OxY-x83ZowczKLnQU2wcrVsirbsWVeh4seUdS-v3x11XUmnOQTP2Y0i_ffn3f__j8-CfEBbnp2KTFLx_bndp-YTl-DMF-Qi3uQhE7-bbICSzUot_Di1rcgjvXw2ct4D6Ri1zP0QrZNuV_sfJ_zeageOOFE2ARWyO450G8jtcBijH-75_jwCMpDXdcKcN83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