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

    <tr>
        <th>Summary</th>
        <td>
            lldb: cannot print runtime type of object if thread_local variable is present
        </td>
    </tr>

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

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

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

<pre>
    Using the following program:

```c++
#include <iostream>

#ifdef BUG
thread_local int bug;
#endif

class Base {
  public:
 virtual ~Base() {}
};

class Derived : public Base {
 public:
    virtual ~Derived() {}
};

void test(Base *base) {
 std::cout << base;
}

int main() {
    test(new Derived());
    return 0;
}
```

compiling and debugging with:

`clang++-17 -glldb -O0 test.cc && lldb-17 a.out -o "b test" -o r -o "p base" -o exit`

gives:

```
(lldb) p base
(Derived *) 0x000055555556aeb0
```

compiling and debugging with:

`clang++-17 -DBUG -glldb -O0 test.cc && lldb-17 a.out -o "b test" -o r -o "p base" -o exit`

gives:

```
(lldb) p base
(Base *) 0x000055555556aeb0
```

So depending on whether the `thread_local` is present or not, the runtime type of the `base` function argument is not printed correctly.

Using the official clang-17 PPA:

```
levy@valardohaeris:~/workspace$ lldb-17 --version
lldb version 17.0.6
```

```
levy@valardohaeris:~/workspace$ clang++-17 --version
Ubuntu clang version 17.0.6 (++20231128094036+6009708b4367-1~exp1~20231128094051.72)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```

Tested on Ubuntu 22.04, 23.10, but I guess this depends on the compiler/debugger.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU-Po7gT_TTOpQQyNoHkkEMy-WU0p99IO30eGVOAdx0b-U86fenPvjKQdLpnd7S70kobIQLlqnrl51eF8F71BnFH1geyPq5EDIN1O42Xl1Vj25fdk1emhzAgdFZr-5zeRmd7J86E7wk9Enq7V3S-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