[Lldb-commits] [clang] [lldb] [clang][AST] Added assert to prevent infinite recursion in computing layout (PR #154123)

via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 18 07:57:16 PDT 2025


tgs-sc wrote:

> Hmm yea guarding against incorrect DWARF has been mostly best effort. Can you provide a test-case for this?

Sure. Originally this bug was discovered by debugging llc, but I minimized it to such example:

--- b1.cc ---
```
#include <optional>
#include <iostream>

struct Type {
  Type() {
    printf("ctor\n");
  }

  Type(const Type& T) {
    printf("ctor copy\n");
  }

  Type(Type&& ) {
    printf("ctor move\n");
  }

  ~Type() {
    printf("dtor");
  }
};

std::optional<Type> var{};
std::optional<Type>* x = &var;
```
--- b2.cc ---
```
#include <iostream>

struct Type {
  Type() {
    printf("ctor\n");
  }

  Type(const Type& T) {
    printf("ctor copy\n");
  }

  Type(Type&& ) {
    printf("ctor move\n");
  }

  ~Type() {
    printf("dtor");
  }
};

std::optional<Type> var{};
std::optional<Type>* x = &var;

root at coder-timurgolubovich-timur-work-20:~/rnd/reproduction# cat b2.cc
#include <iostream>

class Type;
namespace std{
template<typename T>
class optional;
}
extern std::optional<Type>* x;

int main() {
        std::cout << x << std::endl;
}
```
Compilation: `/usr/bin/g++ b1.cc b2.cc -g -O0 -std=c++17 -o b.out`. The version of g++ should be 9.4.0.
Running: `lldb b.out -o "b main" -o "r" -o "p x"`
The problem is going to happen in internals of std::optional (https://gcc.gnu.org/onlinedocs/gcc-12.3.0/libstdc++/api/a00152_source.html) as the have 2 specializations of `_Optional_payload` that have the same type and differ only with template parameters.

https://github.com/llvm/llvm-project/pull/154123


More information about the lldb-commits mailing list