llvm-capstone/clang
Michael Buch 711a644127 [clang][DebugInfo] Emit DW_AT_type of preferred name if available
With this patch, whenever we emit a `DW_AT_type` for some declaration
and the type is a template class with a `clang::PreferredNameAttr`, we
will emit the typedef that the attribute refers to instead. I.e.,

```
0x123 DW_TAG_variable
        DW_AT_name "var"
        DW_AT_type (0x123 "basic_string<char>")

0x124 DW_TAG_structure_type
        DW_AT_name "basic_string<char>"
```
...becomes
```
0x123 DW_TAG_variable
        DW_AT_name "var"
        DW_AT_type (0x124 "std::string")

0x124 DW_TAG_structure_type
        DW_AT_name "basic_string<char>"

0x125 DW_TAG_typedef
        DW_AT_name "std::string"
        DW_AT_type (0x124 "basic_string<char>")
```

We do this by returning the preferred name typedef `DIType` when
we create a structure definition. In some cases, e.g., with `-gmodules`,
we don't complete the structure definition immediately but do so later
via `completeClassData`, which overwrites the `TypeCache`. In such cases
we don't actually want to rewrite the cache with the preferred name. We
handle this by returning both the definition and the preferred typedef
from `CreateTypeDefinition` and let the callee decide what to do with
it.

Essentially we set up the types as:
```
TypeCache[Record] => DICompositeType
ReplaceMap[Record] => DIDerivedType(baseType: DICompositeType)
```

For now we keep this behind LLDB tuning.

**Testing**

- Added clang unit-test
- `check-llvm`, `check-clang` pass
- Confirmed that this change correctly repoints
  `basic_string` references in some of my test programs.
- Will add follow-up LLDB API tests

Differential Revision: https://reviews.llvm.org/D145803
2023-04-07 01:37:36 +01:00
..
bindings [python] Expose clang_Location_isInSystemHeader 2023-04-04 09:21:04 -04:00
cmake [CMake] Switch to -fPIE for Fuchsia Toolchain 2023-03-30 18:00:50 +00:00
docs [Clang][Attributes] Add MeaningfulToClassTemplateDefinition to unavailable attribute 2023-04-06 14:40:39 -07:00
examples [clang][pp] Handle attributes defined by plugin in __has_attribute 2023-03-13 16:47:51 +01:00
include Revert "Revert "[Modules] Remove unnecessary check when generating name lookup table in ASTWriter"" 2023-04-06 15:42:00 -07:00
lib [clang][DebugInfo] Emit DW_AT_type of preferred name if available 2023-04-07 01:37:36 +01:00
runtime [NFC] Add split-file as runtime test dependency 2023-02-02 11:22:26 -08:00
test [clang][DebugInfo] Emit DW_AT_type of preferred name if available 2023-04-07 01:37:36 +01:00
tools [nvptx-arch] Dynamically load libcuda.so.1 directly instead 2023-04-04 19:50:31 -05:00
unittests [C++20] [Coroutines] Handle function-try-block in SemaCoroutine 2023-04-06 15:11:34 +08:00
utils [NFC] Remove unused member variable PolicyBitMask in SemaRecord 2023-03-27 17:39:40 -04:00
www [Clang][Sema] Fix comparison of constraint expressions 2023-04-04 02:31:13 +00:00
.clang-format
.clang-tidy
.gitignore
CMakeLists.txt Revert "Reland "[CMake] Bumps minimum version to 3.20.0."" 2023-03-18 20:32:43 +01:00
CodeOwners.rst [NFC]Fix github identification. 2023-01-20 08:40:38 -08:00
INSTALL.txt
LICENSE.TXT
ModuleInfo.txt
NOTES.txt
README.txt

//===----------------------------------------------------------------------===//
// C Language Family Front-end
//===----------------------------------------------------------------------===//

Welcome to Clang.  This is a compiler front-end for the C family of languages
(C, C++, Objective-C, and Objective-C++) which is built as part of the LLVM
compiler infrastructure project.

Unlike many other compiler frontends, Clang is useful for a number of things
beyond just compiling code: we intend for Clang to be host to a number of
different source-level tools.  One example of this is the Clang Static Analyzer.

If you're interested in more (including how to build Clang) it is best to read
the relevant web sites.  Here are some pointers:

Information on Clang:             http://clang.llvm.org/
Building and using Clang:         http://clang.llvm.org/get_started.html
Clang Static Analyzer:            http://clang-analyzer.llvm.org/
Information on the LLVM project:  http://llvm.org/

If you have questions or comments about Clang, a great place to discuss them is
on the Clang forums:
  https://discourse.llvm.org/c/clang/

If you find a bug in Clang, please file it in the LLVM bug tracker:
  http://llvm.org/bugs/