<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 - LLDB sometimes can't determine the dynamic type of an object if the program is compiled with fPIC"
   href="https://bugs.llvm.org/show_bug.cgi?id=50685">50685</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLDB sometimes can't determine the dynamic type of an object if the program is compiled with fPIC
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lldb
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>12.0
          </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>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>lldb-dev@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>officesamurai@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>jdevlieghere@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>If I compile the following code with fPIC or fPIE:
===
#include <boost/asio/io_context.hpp>
#include <boost/asio/strand.hpp>

void foo(boost::asio::io_context& context)
{
    boost::asio::io_context::strand s{context};
}

struct Base
{
    virtual ~Base() {}
};

struct Derived: Base
{
    Derived(int zzz) : zzz(zzz) {}

    int zzz = 0;
};

int main()
{
    Derived d{123};
    Base* b = &d;

    return 0;
}
===
and run it in lldb, "print b" will print:
(Base *) $0 = 0x00007fffffffdc58

But if I compile it without fPIC/fPIE, or modify the code slightly, e.g. by
commenting out the unused function "foo", I get the expected output:
(Derived *) $0 = 0x00007fffffffdc58

The behaviour doesn't depend on the compiler; I tried clang 11.0 and gcc-10.2
and the result was the same.

Since the code depends on boost, I'm attaching the preprocessed version too.

I compile it as follows:
$ clang++ -g -fPIC test_preproc_clang.cpp -o test -lpthread

Clang version:
Ubuntu clang version 11.0.0-2

LLDB version:
lldb version 12.0.0 (<a href="mailto:git@github.com">git@github.com</a>:llvm/llvm-project.git revision
d28af7c654d8db0b68c175db5ce212d74fb5e9bc)
  clang revision d28af7c654d8db0b68c175db5ce212d74fb5e9bc
  llvm revision d28af7c654d8db0b68c175db5ce212d74fb5e9bc

boost version: 1.73.0</pre>
        </div>
      </p>


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

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>