<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Emitted binary code changes when -g is enabled at -O1 -m32 (interestingly, this behaviour disappears after preprocessing)"
   href="https://bugs.llvm.org/show_bug.cgi?id=52540">52540</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Emitted binary code changes when -g is enabled at -O1 -m32 (interestingly, this behaviour disappears after preprocessing)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tlwang@uwaterloo.ca
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>cnsun@uwaterloo.ca, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>37728
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The .text section for the following program (transformed_program0.c) changes
after toggling the -g flag. However, this behaviour goes away after running
transformed_program0.c through the preprocessor.

$ clang-trunk -v
clang version 14.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
82fc4cc60bec6d0eacad7e8575f404dcdf5144c5)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/cnsun/usr/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
$ cat transformed_program0.c
#include "csmith.h" //
<a href="https://github.com/csmith-project/csmith/blob/master/runtime/csmith.h">https://github.com/csmith-project/csmith/blob/master/runtime/csmith.h</a>
struct a {
  int32_t b;
} c;
struct {
  uint64_t d;
} i;
int e, f;
int volatile g;
long h[1][3];
struct a volatile j[1][1][1];
void l() {
  int k[1];
  int o;
  int *m = &o;
  int *n[][1] = {k, k, k, k, m};
  uint32_t p;
  int32_t q;
  for (;;) {
    int32_t *r = n[4];
    for (p = 0; p <= 1; p++)
      for (c.b = 7; c.b; c.b--) {
        int32_t **s = n[4];
        if ((*s = n[0][4]) == &o)
          if (h[e][0])
            break;
        for (i.d = 0; i.d <= 4; i.d++) {
          uint16_t *aa = l;
          q &= *aa = h[p][e + 1], j[i.d][e][p], f || g;
        }
      }
    *r = 0;
  }
}
int main() {}
$ clang-trunk -I /usr/local/include/csmith -w -c -m32 -O1
transformed_program0.c -o a.out; objdump --disassemble --section=.text a.out >
no_g.txt
$ clang-trunk -I /usr/local/include/csmith -w -c -m32 -O1 -g
transformed_program0.c -o a.out; objdump --disassemble --section=.text a.out >
g.txt
$ diff no_g.txt g.txt
37,42c37,42
<   65: 8d 04 88                lea    (%eax,%ecx,4),%eax
<   68: 05 00 00 00 00          add    $0x0,%eax
<   6d: 89 44 24 0c             mov    %eax,0xc(%esp)
<   71: c7 05 00 00 00 00 07    movl   $0x7,0x0
<   78: 00 00 00
<   7b: b9 07 00 00 00          mov    $0x7,%ecx
---
<span class="quote">>   65:  8d 84 88 00 00 00 00    lea    0x0(%eax,%ecx,4),%eax
>   6c:      89 44 24 0c             mov    %eax,0xc(%esp)
>   70:      c7 05 00 00 00 00 07    movl   $0x7,0x0
>   77:      00 00 00
>   7a:      b9 07 00 00 00          mov    $0x7,%ecx
>   7f:      90                      nop</span >
$

This change in the emitted binary doesn't occur if we preprocess the program.

$ clang -E -I /usr/local/include/csmith transformed_program0.c -o
transformed_program0_preprocessed.c
$ clang-trunk -w -c -m32 -O1 transformed_program0_preprocessed.c -o a.out;
objdump --disassemble --section=.text a.out > no_g.txt
$ clang-trunk -w -c -m32 -O1 -g transformed_program0_preprocessed.c -o a.out;
objdump --disassemble --section=.text a.out > g.txt
$ diff no_g.txt g.txt
$</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [meta] Make llvm passes debug info invariant"
   href="https://bugs.llvm.org/show_bug.cgi?id=37728">Bug 37728</a>] [meta] Make llvm passes debug info invariant
              </li>
          </ul>
        </div>
        <br>

      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>