<html>
    <head>
      <base href="http://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 - Combining instructions loses TBAA metadata."
   href="http://bugs.llvm.org/show_bug.cgi?id=32032">32032</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Combining instructions loses TBAA metadata.
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Transformation Utilities
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>hardekopf@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18012" name="attach_18012" title="Complete LLVM bitcode for C++ source code.">attachment 18012</a> <a href="attachment.cgi?id=18012&action=edit" title="Complete LLVM bitcode for C++ source code.">[details]</a></span>
Complete LLVM bitcode for C++ source code.

We have encountered a case where we believe TBAA metadata is supposed to be
present, yet it is not there. We hypothesize, given the affected instructions,
that the reason is because two instructions (a load and getelementptr) were
merged and thus lost TBAA metadata. In particular, see
lib/Transforms/Utils/Local.cpp::combineMetadata(), which doesn't handle
MD_tbaa_struct. This is just a guess, though.

Below is the C++ source code and the relevant corresponding LLVM bitcode. The
variable names in the source code are meaningless, the key parts are the struct
accesses in main. The complete LLVM bitcode is attached.

C++ SOURCE:

extern "C" char *source(int label);
extern "C" void sink(char label, char *argument);

struct Foo {
  int fld;
  char *src1;
};

struct Bar {
  char *src2;
  Foo foo;
};

struct Baz {
  Bar bar[2];
};

char *tainted1 = source(1);
char *tainted2 = source(2);

Baz a{{{tainted2, {0, nullptr}}, {nullptr, {1, tainted1}}}};

int main() {
  Baz b = a;

  sink('A', b.bar[1].foo.src1);
  sink('B', b.bar[0].src2);

  return 0;
}

RELEVANT LLVM BITCODE:

define i32 @main() local_unnamed_addr #3 {
  %1 = load i8*, i8** getelementptr inbounds (%struct.Baz, %struct.Baz* @a, i64
0, i32 0, i64 0, i32 0), align 8
  %2 = load i8*, i8** getelementptr inbounds (%struct.Baz, %struct.Baz* @a, i64
0, i32 0, i64 1, i32 1, i32 1), align 8
  tail call void @sink(i8 signext 65, i8* %2)
  tail call void @sink(i8 signext 66, i8* %1)
  ret i32 0
}

We believe that the two load instructions in @main should have TBAA metadata.</pre>
        </div>
      </p>


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

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