Michael137 wrote:

This is quite an interesting case. Basically the issue arises only because we 
have an `anonymous` struct in `B` with a base class that has an "indirect 
field" called `x`:
```
IndirectFieldDecl 0x104145868 <<invalid sloc>> <invalid sloc> implicit x 'int'  
|-Field 0x104145758 '' 'A::(anonymous struct)'
`-Field 0x104145700 'x' 'int'                                                   
      
```

It's important that the nested structure in `B` is `anonymous` (not `unnamed`) 
because that's what [causes us to 
recurse](https://github.com/llvm/llvm-project/blob/cf47898453c83c977f92155c03e9cf205bfb2b19/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp#L6755)).
 Clang creates a `FieldDecl` with an empty name for that anonymous structure.

The lookup into base class `A` for name `x` works fine from Clang's 
perspective. But then we try to `GetIndexForRecordChild` to find the index of 
`x` in `A`, but that fails [because `RecordDecl::field_begin` doesn't iterate 
over 
`IndirectFieldDecl`s](https://github.com/llvm/llvm-project/blob/cf47898453c83c977f92155c03e9cf205bfb2b19/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp#L6688).

So even if we fix the crash, we still wouldn't be able to access `x`. I think 
we can address that separately from the crash, but I think we should not be 
clearing the vector in `TypeSystemClang::GetIndexofChildMemberWithName` and 
instead propagate errors properly.

Separately (outside the scope of this PR) we should make 
`GetIndexForRecordChild` account for fields of anonymous structures. E.g., we 
might want to do another lookup for `x` into the anonymous structure.

https://github.com/llvm/llvm-project/pull/117808
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to