aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGDebugInfo.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-06-07Fix #pragma (packed, n) not emitting the alignment in debug info (#94673)Augusto Noronha1-1/+10
Debug info generation won't emit the alignment of types that have a standard alignment. It was not taking into account the that case. rdar://127785973
2024-06-03Add option to generate additional debug info for expression dereferencing ↵William Junda Huang1-0/+84
pointer to pointers. (#94100) This is another attempt to land #81545, which was reverted. Fixed test case by adding a target triple so that clang generates the same IR for all platforms
2024-05-30Reapply "[DebugInfo] Add flag to only emit referenced member functions" (#93767)David Blaikie1-1/+1
This reverts commit 02c6845c762dfd0a19d4a2f997990e160f392dae, reapplying bfabc958c7c0d7ddc15f23383d9da836e8c6093f. The patch was reverted due to the test failing on MacOS and Windows where type units aren't supported. This is addressed by limiting type unit flag/test coverage to Linux. Complete C++ type information can be quite expensive - and there's limited value in representing every member function, even those that can't be called (we don't do similarly for every non-member function anyway). So add a flag to opt out of this behavior for experimenting with this more terse behavior. I think Sony already does this by default, so perhaps with a change to the defaults, Sony can migrate to this rather than a downstream patch. This breaks current debuggers in some expected ways - but those breakages are visible without this feature too. Consider member function template instantiations - they can't be consistently enumerated in every translation unit: a.h: ``` struct t1 { template <int i> static int f1() { return i; } }; namespace ns { template <int i> int f1() { return i; } } // namespace ns ``` a.cpp: ``` void f1() { t1::f1<0>(); ns::f1<0>(); } ``` b.cpp: ``` void f1(); int main() { f1(); t1::f1<1>(); ns::f1<1>(); } ``` ``` (gdb) p ns::f1<0>() $1 = 0 (gdb) p ns::f1<1>() $2 = 1 (gdb) p t1::f1<0>() Couldn't find method t1::f1<0> (gdb) p t1::f1<1>() $3 = 1 (gdb) s f1 () at a.cpp:3 3 t1::f1<0>(); (gdb) p t1::f1<0>() $4 = 0 (gdb) p t1::f1<1>() Couldn't find method t1::f1<1> (gdb) ``` (other similar non-canonical features are implicit special members (copy/move ctor/assignment operator, default ctor) and nested types (eg: pimpl idiom, where the nested type is declared-but-not-defined in one TU, and defined in another TU)) lldb can't parse the template expressions above, so I'm not sure how to test it there, but I'd guess it has similar problems. ( https://stackoverflow.com/questions/64602475/how-to-print-value-returned-by-template-member-function-in-gdb-lldb-debugging so... I guess that's just totally not supported in lldb, how unfortunate. And implicit special members are instantiated implicitly by lldb, so missing those doesn't tickle the same issue) Some very rudimentary numbers for a clang debug build: .debug_info section size: -g: 476MiB -g -fdebug-types-section: 357MiB -g -gomit-unreferenced-members: 340MiB Though it also means a major reduction in .debug_str size, -fdebug-types-section doesn't reduce string usage (so the first two examples have the same .debug_str size, 247MiB), down to 175MiB. So for total clang binary size (I don't have a quick "debug section size reduction" on-hand): 1.45 (no type units) GiB -> 1.34 -> 1.22, so it saves about 120MiB of binary size. Original Differential Revision: https://reviews.llvm.org/D152017
2024-05-29Revert "Add option to generate additional debug info for expression ↵Mehdi Amini1-84/+0
dereferencing pointer to pointers. (#81545)" This reverts commit aeccfee348c717165541d8d895b9b0cdfe31415c, and dependents: Revert "[NFC] Fix PPC buildbot failure https://lab.llvm.org/buildbot/#/builders/230/builds/29066" This reverts commit 2b1d1c51f6e321267cc86e9db7808298c59caf0e. Revert "Fix test - remove unnecessary/incorrect `-S`, in favor of `-emit-llvm`" This reverts commit ea1ecb50fa831583241fc531153bd2c072955d29. The test is failing on MacOs and Windows
2024-05-29Revert "[DebugInfo] Add flag to only emit referenced member functions" (#93767)Mehdi Amini1-1/+1
Reverts llvm/llvm-project#87018 MacOS and Windows bots are broken.
2024-05-29Add option to generate additional debug info for expression dereferencing ↵William Junda Huang1-0/+84
pointer to pointers. (#81545) Such expression does not correspond to a variable in the source code thus does not have a debug location. When the user collects perf data on the program, if the intermediate memory load instruction is sampled, it could not be attributed to any variable/class member, which causes the sampling results to be under-counted. This patch adds an option `-fdebug_info_for_pointer_type` to generate a psuedo variable and its debug info for intermediate expression with pointer dereferencing, so that perf data collected on the instruction of that expression can be attributed to the correct class member. This is a prototype so comments are needed.
2024-05-29[DebugInfo] Add flag to only emit referenced member functions (#87018)David Blaikie1-1/+1
Complete C++ type information can be quite expensive - and there's limited value in representing every member function, even those that can't be called (we don't do similarly for every non-member function anyway). So add a flag to opt out of this behavior for experimenting with this more terse behavior. I think Sony already does this by default, so perhaps with a change to the defaults, Sony can migrate to this rather than a downstream patch. This breaks current debuggers in some expected ways - but those breakages are visible without this feature too. Consider member function template instantiations - they can't be consistently enumerated in every translation unit: a.h: ``` struct t1 { template <int i> static int f1() { return i; } }; namespace ns { template <int i> int f1() { return i; } } // namespace ns ``` a.cpp: ``` void f1() { t1::f1<0>(); ns::f1<0>(); } ``` b.cpp: ``` void f1(); int main() { f1(); t1::f1<1>(); ns::f1<1>(); } ``` ``` (gdb) p ns::f1<0>() $1 = 0 (gdb) p ns::f1<1>() $2 = 1 (gdb) p t1::f1<0>() Couldn't find method t1::f1<0> (gdb) p t1::f1<1>() $3 = 1 (gdb) s f1 () at a.cpp:3 3 t1::f1<0>(); (gdb) p t1::f1<0>() $4 = 0 (gdb) p t1::f1<1>() Couldn't find method t1::f1<1> (gdb) ``` (other similar non-canonical features are implicit special members (copy/move ctor/assignment operator, default ctor) and nested types (eg: pimpl idiom, where the nested type is declared-but-not-defined in one TU, and defined in another TU)) lldb can't parse the template expressions above, so I'm not sure how to test it there, but I'd guess it has similar problems. ( https://stackoverflow.com/questions/64602475/how-to-print-value-returned-by-template-member-function-in-gdb-lldb-debugging so... I guess that's just totally not supported in lldb, how unfortunate. And implicit special members are instantiated implicitly by lldb, so missing those doesn't tickle the same issue) Some very rudimentary numbers for a clang debug build: .debug_info section size: -g: 476MiB -g -fdebug-types-section: 357MiB -g -gomit-unreferenced-members: 340MiB Though it also means a major reduction in .debug_str size, -fdebug-types-section doesn't reduce string usage (so the first two examples have the same .debug_str size, 247MiB), down to 175MiB. So for total clang binary size (I don't have a quick "debug section size reduction" on-hand): 1.45 (no type units) GiB -> 1.34 -> 1.22, so it saves about 120MiB of binary size. Also open to any riffing on the flag name for sure. @probinson - would this be an accurate upstreaming of your internal handling/would you use this functionality? If it wouldn't be useful to you, it's maybe not worth adding upstream yet - not sure we'll use it at Google, but if it was useful to you folks and meant other folks could test with it it seemed maybe useful. Original Differential Revision: https://reviews.llvm.org/D152017
2024-04-30[NFC][Clang] Add FIXME comment to the workaround for issue #89774Orlando Cazalet-Hyams1-0/+2
2024-04-25[Clang] Fall back to DW_TAG_typedef for instantiation dependent template ↵Orlando Cazalet-Hyams1-1/+20
aliases (#90032) Workaround for issue #89774 until it can be properly fixed. When `-gtemplate-alias` is specified Clang emits a DW_TAG_template_alias for template aliases. This patch avoids an assertion failure by falling back to the `-gno-template-alias` (default) behaviour, emitting a DW_TAG_typedef, if the alias is instantiation dependent.
2024-04-18[Clang] Emit DW_TAG_template_alias for template aliases (#87623)Orlando Cazalet-Hyams1-45/+112
Fix issue https://github.com/llvm/llvm-project/issues/54624 Add front end flags -gtemplate-alias (also a cc1 flag) and -gno-template-alias to enable/disable usage of the feature. It's enabled by default in the front end for SCE debugger tuning only. GCC emits DW_TAG_typedef for template aliases (as does Clang with this feature disabled), and GDB and LLDB appear not to support DW_TAG_template_alias. The -Xclang option -gsimple-template-names=mangled is treated the same as =full, which is not a regression from current behaviour for template aliases. The current implementation omits defaulted arguments and as a consequence also omits empty parameter packs that come after defaulted arguments. Again, this isn't a regression as the DW_TAG_typedef name doesn't contain defaulted arguments. LLVM support added in https://github.com/llvm/llvm-project/pull/88943 Added template-alias.cpp - Check the metadata construction & interaction with -gsimple-template-names. Added variadic-template-alias.cpp - Check template parameter packs work. Added defaulted-template-alias.cpp - Check defaulted args (don't) work. Modified debug-options.c - Check Clang generates correct cc1 flags.
2024-04-01[HLSL] Implement array temporary support (#79382)Chris B1-0/+1
HLSL constant sized array function parameters do not decay to pointers. Instead constant sized array types are preserved as unique types for overload resolution, template instantiation and name mangling. This implements the change by adding a new `ArrayParameterType` which represents a non-decaying `ConstantArrayType`. The new type behaves the same as `ConstantArrayType` except that it does not decay to a pointer. Values of `ConstantArrayType` in HLSL decay during overload resolution via a new `HLSLArrayRValue` cast to `ArrayParameterType`. `ArrayParamterType` values are passed indirectly by-value to functions in IR generation resulting in callee generated memcpy instructions. The behavior of HLSL function calls is documented in the [draft language specification](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf) under the Expr.Post.Call heading. Additionally the design of this implementation approach is documented in [Clang's documentation](https://clang.llvm.org/docs/HLSL/FunctionCalls.html) Resolves #70123
2024-03-28[CodeGen/DWARF] Introduce DWARF tag for SwiftTail and emit it in CodeGen.Adrian Prantl1-2/+1
swifttailcc is a new calling convention in LLVM introduced in https://reviews.llvm.org/D95443. We add a new DWARF tag to capture this in debuginfo. Differential Revision: https://reviews.llvm.org/D95704 [Note: This patch seems to have been forgotten about, landing it now with considerable delay]
2024-03-27[RISCV] RISCV vector calling convention (1/2) (#77560)Brandon Wu1-0/+2
[RISCV] RISCV vector calling convention (1/2) This is the vector calling convention based on https://github.com/riscv-non-isa/riscv-elf-psabi-doc, the idea is to split between "scalar" callee-saved registers and "vector" callee-saved registers. "scalar" ones remain the original strategy, however, "vector" ones are handled together with RVV objects. The stack layout would be: |--------------------------| <-- FP | callee-allocated save | | area for register varargs| |--------------------------| | callee-saved registers | <-- scalar callee-saved | (scalar) | |--------------------------| | RVV alignment padding | |--------------------------| | callee-saved registers | <-- vector callee-saved | (vector) | |--------------------------| | RVV objects | |--------------------------| | padding before RVV | |--------------------------| | scalar local variables | |--------------------------| <-- BP | variable size objects | |--------------------------| <-- SP Note: This patch doesn't contain "tuple" type, e.g. vint32m1x2. It will be handled in https://github.com/riscv-non-isa/riscv-elf-psabi-doc (2/2). Differential Revision: https://reviews.llvm.org/D154576
2024-03-26[NFC] Refactor ConstantArrayType size storage (#85716)Chris B1-1/+1
In PR #79382, I need to add a new type that derives from ConstantArrayType. This means that ConstantArrayType can no longer use `llvm::TrailingObjects` to store the trailing optional Expr*. This change refactors ConstantArrayType to store a 60-bit integer and 4-bits for the integer size in bytes. This replaces the APInt field previously in the type but preserves enough information to recreate it where needed. To reduce the number of places where the APInt is re-constructed I've also added some helper methods to the ConstantArrayType to allow some common use cases that operate on either the stored small integer or the APInt as appropriate. Resolves #85124.
2024-03-23Unwrap CountAttributed for debug info (#86017)Yeoul Na1-0/+3
Fix crash caused by 3eb9ff30959a670559bcba03d149d4c51bf7c9c9
2024-03-20Turn 'counted_by' into a type attribute and parse it into ↵Yeoul Na1-0/+1
'CountAttributedType' (#78000) In `-fbounds-safety`, bounds annotations are considered type attributes rather than declaration attributes. Constructing them as type attributes allows us to extend the attribute to apply nested pointers, which is essential to annotate functions that involve out parameters: `void foo(int *__counted_by(*out_count) *out_buf, int *out_count)`. We introduce a new sugar type to support bounds annotated types, `CountAttributedType`. In order to maintain extra data (the bounds expression and the dependent declaration information) that is not trackable in `AttributedType` we create a new type dedicate to this functionality. This patch also extends the parsing logic to parse the `counted_by` argument as an expression, which will allow us to extend the model to support arguments beyond an identifier, e.g., `__counted_by(n + m)` in the future as specified by `-fbounds-safety`. This also adjusts `__bdos` and array-bounds sanitizer code that already uses `CountedByAttr` to check `CountAttributedType` instead to get the field referred to by the attribute.
2024-02-05New calling convention preserve_none (#76868)weiguozhi1-0/+2
The new experimental calling convention preserve_none is the opposite side of existing preserve_all. It tries to preserve as few general registers as possible. So all general registers are caller saved registers. It can also uses more general registers to pass arguments. This attribute doesn't impact floating-point registers. Floating-point registers still follow the c calling convention. Currently preserve_none is supported on X86-64 only. It changes the c calling convention in following fields: * RSP and RBP are the only preserved general registers, all other general registers are caller saved registers. * We can use [RDI, RSI, RDX, RCX, R8, R9, R11, R12, R13, R14, R15, RAX] to pass arguments. It can improve the performance of hot tailcall chain, because many callee saved registers' save/restore instructions can be removed if the tail functions are using preserve_none. In my experiment in protocol buffer, the parsing functions are improved by 3% to 10%.
2024-01-27[Clang][C++26] Implement Pack Indexing (P2662R3). (#72644)cor3ntin1-0/+5
Implements https://isocpp.org/files/papers/P2662R3.pdf The feature is exposed as an extension in older language modes. Mangling is not yet supported and that is something we will have to do before release.
2024-01-21[c++20] P1907R1: Support for generalized non-type template arguments of ↵Andrey Ali Khan Bolshakov1-0/+10
scalar type. (#78041) Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and reverted because a dependency commit was reverted, then committed again as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because "dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was reverted. But it doesn't seem that 5a391d38ac6c was a real dependency for this. This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and 18e093faf726d15f210ab4917142beec51848258 by Richard Smith (@zygoloid), with some minor fixes, most notably: - `UncommonValue` renamed to `StructuralValue` - `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and member pointer handling branch in `BuildExpressionFromNonTypeTemplateArgumentValue`; - handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`; - filling in `SugaredConverted` along with `CanonicalConverted` parameter in `Sema::CheckTemplateArgument`; - minor cleanup in `TemplateInstantiator::transformNonTypeTemplateParmRef`; - `TemplateArgument` constructors refactored; - `ODRHash` calculation for `UncommonValue`; - USR generation for `UncommonValue`; - more correct MS compatibility mangling algorithm (tested on MSVC ver. 19.35; toolset ver. 143); - IR emitting fixed on using a subobject as a template argument when the corresponding template parameter is used in an lvalue context; - `noundef` attribute and opaque pointers in `template-arguments` test; - analysis for C++17 mode is turned off for templates in `warn-bool-conversion` test; in C++17 and C++20 mode, array reference used as a template argument of pointer type produces template argument of UncommonValue type, and `BuildExpressionFromNonTypeTemplateArgumentValue` makes `OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see through it; despite of "These cases should not warn" comment, I'm not sure about correct behavior; I'd expect a suggestion to replace `if` by `if constexpr`; - `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
2024-01-18[Clang][NFC] Rename CXXMethodDecl::isPure -> is VirtualPure (#78463)cor3ntin1-1/+1
To avoid any possible confusion with the notion of pure function and the gnu::pure attribute.
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-3/+4
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-12-12[DebugInfo] Fix duplicate DIFile when main file is preprocessed (#75022)Fangrui Song1-4/+6
When the main file is preprocessed and we change `MainFileName` to the original source file name (e.g. `a.i => a.c`), the source manager does not contain `a.c`, but we incorrectly associate the DIFile(a.c) with md5(a.i). This causes CGDebugInfo::emitFunctionStart to create a duplicate DIFile and leads to a spurious "inconsistent use of MD5 checksums" warning. ``` % cat a.c void f() {} % clang -c -g a.c # no warning % clang -E a.c -o a.i && clang -g -S a.i && clang -g -c a.s a.s:9:2: warning: inconsistent use of MD5 checksums .file 1 "a.c" ^ % grep DIFile a.ll !1 = !DIFile(filename: "a.c", directory: "/tmp/c", checksumkind: CSK_MD5, checksum: "c5b2e246df7d5f53e176b097a0641c3d") !11 = !DIFile(filename: "a.c", directory: "/tmp/c") % grep 'file.*a.c' a.s .file "a.c" .file 0 "/tmp/c" "a.c" md5 0x2d14ea70fee15102033eb8d899914cce .file 1 "a.c" ``` Fix #56378 by disassociating md5(a.i) with a.c.
2023-12-06[clang][DebugInfo] Revert "emit definitions for constant-initialized static ↵Michael Buch1-73/+0
data-members" (#74580) This commit reverts the changes in https://github.com/llvm/llvm-project/pull/71780 and all of its follow-up patches. We got reports of the `.debug_names/.debug_gnu_pubnames/gdb_index/etc.` sections growing by a non-trivial amount for some large projects. While GCC emits definitions for static data member constants into the Names index, they do so *only* for explicitly `constexpr` members. We were indexing *all* constant-initialized const-static members, which is likely where the significant size difference comes from. However, only emitting explicitly `constexpr` variables into the index doesn't seem like a good way forward, since from clang's perspective `const`-static integrals are `constexpr` too, and that shouldn't be any different in the debug-info component. Also, as new code moves to `constexpr` instead of `const` static for constants, such solution would just delay the growth of the Names index. To prevent the size regression we revert to not emitting definitions for static data-members that have no location. To support access to such constants from LLDB we'll most likely have to have to make LLDB find the constants by looking at the containing class first.
2023-11-30[clang][DebugInfo] Improve heuristic to determine whether to evaluate a ↵Michael Buch1-4/+24
static variable's initializer (#72974) This patch extracts the logic to evaluate a C++ static data-member's constant initializer. This logic will be re-used in an upcoming patch. It also makes the check for whether we are dealing with a constant initializer more robust/idiomatic, which revealed a bug in the `debug-info-static-inline-member` test (which existed since its introduction in https://github.com/llvm/llvm-project/pull/71780) **Test changes** * `debug-info-static-member.cpp`: * We added the check for `const_b` as part of the patch series in `638a8393615e911b729d5662096f60ef49f1c65e`. The check for `isUsableAsConstantExpression` added in the current patch doesn't support constant inline floats (since they are neither constexpr nor integrals). This isn't a regression since before said patch series we wouldn't ever emit the definition for `const_b` anyway. Now we just don't do it for `inline const float`s. This is consistent with GCC's behaviour starting with C++11. * `debug-info-static-inline-member`: * This was just a bug which is now fixed. We shouldn't emit a `DW_AT_const_value` for a non-const static.
2023-11-28[clang][DebugInfo] Revert to attaching DW_AT_const_value on static member ↵Michael Buch1-3/+15
declarations (#73626) In https://github.com/llvm/llvm-project/pull/71780 we started emitting definitions for all static data-members with constant initialisers, even if they were constants (i.e., didn't have a location). We also dropped the DW_AT_const_value from the declaration to [help resolve inconsistencies during type merging in the DWARFParallelLinker](https://github.com/llvm/llvm-project/pull/68721). However, for static data members that do have locations, we wouldn't emit a DW_AT_const_value on it, assuming that the consumer knows how to read the value using the location. This broke some consumers that really wanted to find a DW_AT_const_value. Ultimately we want to attach a DW_AT_const_value to definitions that have a location too. But to fix consumers broken by said change, this patch adds the constant back onto the declaration. This is what we used to do prior to https://github.com/llvm/llvm-project/pull/71780
2023-11-21Supports viewing class member variables in lambda when using the vs debugger ↵GkvJwa1-1/+3
(#71564) Use "__this" in DataMemberRecord, make vs debugger can be parsed normally Fixes #71562
2023-11-15Add RunTimeLang to Class and Enumeration DIBuilder functions (#72011)Augusto Noronha1-3/+3
RunTimeLang is already supported by DICompositeType, and already used by structs and unions. Add a new parameter in the class and enumeration create methods, so they can use the RunTimeLang attribute as well.
2023-11-15[clang][DebugInfo] Fix iterator invalidation during EmitGlobalVariable (#72415)Michael Buch1-2/+7
2023-11-15[clang][DebugInfo] DWARFv5: static data members declarations are ↵Michael Buch1-3/+6
DW_TAG_variable (#72235) This patch implements the DWARFv5 issue 161118.1: "DW_TAG for C++ static data members". This will simplify LLDB's handling of static data members greatly in the long term since we no longer need to differentiate non-static from static data member declarations using non-portable heuristics. Depends on: * https://github.com/llvm/llvm-project/pull/72234
2023-11-15Reland "[llvm][DebugInfo] DWARFv5: static data members declarations are ↵Michael Buch1-1/+2
DW_TAG_variable (#72234)" This was reverted because it broke the OCaml LLVM bindings. Relanding the original patch but without changing the C-API. They'll continue to work just fine as they do today. If in the future there is a need to pass a new tag to the C-API for creating static members, then we'll make the change to the OCaml bindings at that time. Original commit message: """ This patch adds the LLVM-side infrastructure to implement DWARFv5 issue 161118.1: "DW_TAG for C++ static data members". The clang-side of this patch will simply construct the DIDerivedType with a different DW_TAG. """
2023-11-15Revert "[llvm][DebugInfo] DWARFv5: static data members declarations are ↵Michael Buch1-2/+1
DW_TAG_variable (#72234)" This reverts commit 9a9933fae23249fbf6cf5b3c090e630f578b7f98. The OCaml bindings were using `LLVMDIBuilderCreateStaticMemberType`, causing the API change in `9a9933fae23249fbf6cf5b3c090e630f578b7f98` to break buildbots that built the bindings. Revert until we figure out whether to fixup the bindings or just not change the C-API
2023-11-15[llvm][DebugInfo] DWARFv5: static data members declarations are ↵Michael Buch1-1/+2
DW_TAG_variable (#72234) This patch adds the LLVM-side infrastructure to implement DWARFv5 issue 161118.1: "DW_TAG for C++ static data members". The clang-side of this patch will simply construct the DIDerivedType with a different DW_TAG.
2023-11-13Reland "[clang][DebugInfo] Emit global variable definitions for static data ↵Michael Buch1-11/+49
members with constant initializers" (#71780) This patch relands https://github.com/llvm/llvm-project/pull/70639 It was reverted because under certain conditions we triggered an assertion in `DIBuilder`. Specifically, in the original patch we called `EmitGlobalVariable` at the end of `CGDebugInfo::finalize`, after all the temporary `DIType`s have been uniqued. With limited debug-info such temporary nodes would be created more frequently, leaving us with non-uniqued nodes by the time we got to `DIBuilder::finalize`; this violated its pre-condition and caused assertions to trigger. To fix this, the latest iteration of the patch moves `EmitGlobalVariable` to the beginning of `CGDebugInfo::finalize`. Now, when we create a temporary `DIType` node as a result of emitting a variable definition, it will get uniqued in time. A test-case was added for this scenario. We also now don't emit a linkage name for non-locationed constants since LLDB doesn't make use of it anyway. Original commit message: """ When an LLDB user asks for the value of a static data member, LLDB starts by searching the Names accelerator table for the corresponding variable definition DIE. For static data members with out-of-class definitions that works fine, because those get represented as global variables with a location and making them eligible to be added to the Names table. However, in-class definitions won’t get indexed because we usually don't emit global variables for them. So in DWARF we end up with a single `DW_TAG_member` that usually holds the constant initializer. But we don't get a corresponding CU-level `DW_TAG_variable` like we do for out-of-class definitions. To make it more convenient for debuggers to get to the value of inline static data members, this patch makes sure we emit definitions for static variables with constant initializers the same way we do for other static variables. This also aligns Clang closer to GCC, which produces CU-level definitions for inline statics and also emits these into `.debug_pubnames`. The implementation keeps track of newly created static data members. Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable` with a `DW_AT_const_value` for any of those declarations that didn't end up with a definition in the `DeclCache`. The newly emitted `DW_TAG_variable` will look as follows: ``` 0x0000007b: DW_TAG_structure_type DW_AT_calling_convention (DW_CC_pass_by_value) DW_AT_name ("Foo") ... 0x0000008d: DW_TAG_member DW_AT_name ("i") DW_AT_type (0x00000062 "const int") DW_AT_external (true) DW_AT_declaration (true) DW_AT_const_value (4) Newly added vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 0x0000009a: DW_TAG_variable DW_AT_specification (0x0000008d "i") DW_AT_const_value (4) DW_AT_linkage_name ("_ZN2t2IiE1iIfEE") ``` This patch also drops the `DW_AT_const_value` off of the declaration since we now always have it on the definition. This ensures that the `DWARFParallelLinker` can type-merge class with static members where we couldn't attach the constant on the declaration in some CUs. """ Dependent changes: * https://github.com/llvm/llvm-project/pull/71800
2023-11-07Revert "Reland "clang][DebugInfo] Emit global variable definitions for ↵Hans Wennborg1-47/+11
static data members with constant initializers (#70639)"" This casued asserts: llvm/lib/IR/Metadata.cpp:689: void llvm::MDNode::resolve(): Assertion `isUniqued() && "Expected this to be uniqued"' failed. See comments on the PR. This also reverts the dependent follow-up commits, see below. > When an LLDB user asks for the value of a static data member, LLDB > starts by searching the Names accelerator table for the corresponding > variable definition DIE. For static data members with out-of-class > definitions that works fine, because those get represented as global > variables with a location and making them eligible to be added to the > Names table. However, in-class definitions won<E2><80><99>t get indexed because > we usually don't emit global variables for them. So in DWARF we end > up with a single `DW_TAG_member` that usually holds the constant > initializer. But we don't get a corresponding CU-level > `DW_TAG_variable` like we do for out-of-class definitions. > > To make it more convenient for debuggers to get to the value of > inline static data members, this patch makes sure we emit definitions > for static variables with constant initializers the same way we do > for other static variables. This also aligns Clang closer to GCC, > which produces CU-level definitions for inline statics and also > emits these into `.debug_pubnames`. > > The implementation keeps track of newly created static data members. > Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable` > with a `DW_AT_const_value` for any of those declarations that didn't > end up with a definition in the `DeclCache`. > > The newly emitted `DW_TAG_variable` will look as follows: > ``` > 0x0000007b: DW_TAG_structure_type > DW_AT_calling_convention (DW_CC_pass_by_value) > DW_AT_name ("Foo") > ... > > 0x0000008d: DW_TAG_member > DW_AT_name ("i") > DW_AT_type (0x00000062 "const int") > DW_AT_external (true) > DW_AT_declaration (true) > DW_AT_const_value (4) > > Newly added > vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv > > 0x0000009a: DW_TAG_variable > DW_AT_specification (0x0000008d "i") > DW_AT_const_value (4) > DW_AT_linkage_name ("_ZN2t2IiE1iIfEE") > ``` > > This patch also drops the `DW_AT_const_value` off of the declaration > since we now always have it on the definition. This ensures that the > `DWARFParallelLinker` can type-merge class with static members where > we couldn't attach the constant on the declaration in some CUs. This reverts commit 7c3707aea8a6f1fc245ad2862982b8a51b6c0fea. This reverts commit cab0a19467ac2e6e1e022087f4b6cb90d55da040. This reverts commit 317481b3c8b34b0c3f106c514e6aa39b70886110. This reverts commit 15fc809404d4715822e5349b76dcca50eb100eec. This reverts commit 470de2bbec7f5fdd199775aa99c68ac76f4d5c74.
2023-11-07Reland "clang][DebugInfo] Emit global variable definitions for static data ↵Michael Buch1-11/+47
members with constant initializers (#70639)" When an LLDB user asks for the value of a static data member, LLDB starts by searching the Names accelerator table for the corresponding variable definition DIE. For static data members with out-of-class definitions that works fine, because those get represented as global variables with a location and making them eligible to be added to the Names table. However, in-class definitions won’t get indexed because we usually don't emit global variables for them. So in DWARF we end up with a single `DW_TAG_member` that usually holds the constant initializer. But we don't get a corresponding CU-level `DW_TAG_variable` like we do for out-of-class definitions. To make it more convenient for debuggers to get to the value of inline static data members, this patch makes sure we emit definitions for static variables with constant initializers the same way we do for other static variables. This also aligns Clang closer to GCC, which produces CU-level definitions for inline statics and also emits these into `.debug_pubnames`. The implementation keeps track of newly created static data members. Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable` with a `DW_AT_const_value` for any of those declarations that didn't end up with a definition in the `DeclCache`. The newly emitted `DW_TAG_variable` will look as follows: ``` 0x0000007b: DW_TAG_structure_type DW_AT_calling_convention (DW_CC_pass_by_value) DW_AT_name ("Foo") ... 0x0000008d: DW_TAG_member DW_AT_name ("i") DW_AT_type (0x00000062 "const int") DW_AT_external (true) DW_AT_declaration (true) DW_AT_const_value (4) Newly added vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 0x0000009a: DW_TAG_variable DW_AT_specification (0x0000008d "i") DW_AT_const_value (4) DW_AT_linkage_name ("_ZN2t2IiE1iIfEE") ``` This patch also drops the `DW_AT_const_value` off of the declaration since we now always have it on the definition. This ensures that the `DWARFParallelLinker` can type-merge class with static members where we couldn't attach the constant on the declaration in some CUs.
2023-11-06Revert "[clang][DebugInfo] Emit global variable definitions for static data ↵Michael Buch1-47/+11
members with constant initializers (#70639)" This reverts commit 4909814c08fdf4ec8bd9dad4f157d03de7c3c800. Following LLDB patch had to be reverted due to Linux test failures: ``` ef3febadf606c2fc4f1ad8d85a7ecdde16e4cbb3 ``` Since without that LLDB patch the LLDB tests would fail, revert this clang patch for now.
2023-11-06[clang][DebugInfo] Emit global variable definitions for static data members ↵Michael Buch1-11/+47
with constant initializers (#70639) When an LLDB user asks for the value of a static data member, LLDB starts by searching the Names accelerator table for the corresponding variable definition DIE. For static data members with out-of-class definitions that works fine, because those get represented as global variables with a location and making them eligible to be added to the Names table. However, in-class definitions won’t get indexed because we usually don't emit global variables for them. So in DWARF we end up with a single `DW_TAG_member` that usually holds the constant initializer. But we don't get a corresponding CU-level `DW_TAG_variable` like we do for out-of-class definitions. To make it more convenient for debuggers to get to the value of inline static data members, this patch makes sure we emit definitions for static variables with constant initializers the same way we do for other static variables. This also aligns Clang closer to GCC, which produces CU-level definitions for inline statics and also emits these into `.debug_pubnames`. The implementation keeps track of newly created static data members. Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable` with a `DW_AT_const_value` for any of those declarations that didn't end up with a definition in the `DeclCache`. The newly emitted `DW_TAG_variable` will look as follows: ``` 0x0000007b: DW_TAG_structure_type DW_AT_calling_convention (DW_CC_pass_by_value) DW_AT_name ("Foo") ... 0x0000008d: DW_TAG_member DW_AT_name ("i") DW_AT_type (0x00000062 "const int") DW_AT_external (true) DW_AT_declaration (true) DW_AT_const_value (4) Newly added vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 0x0000009a: DW_TAG_variable DW_AT_specification (0x0000008d "i") DW_AT_const_value (4) DW_AT_linkage_name ("_ZN2t2IiE1iIfEE") ``` This patch also drops the `DW_AT_const_value` off of the declaration since we now always have it on the definition. This ensures that the `DWARFParallelLinker` can type-merge class with static members where we couldn't attach the constant on the declaration in some CUs.
2023-11-06[clang][DebugInfo][NFC] Add createConstantValueExpression helper (#70674)Michael Buch1-18/+30
This patch factors out the code to create a DIExpression from an APValue into a separate helper function. This will be useful in a follow-up patch where we re-use this logic elsewhere. Pre-requisite for https://github.com/llvm/llvm-project/pull/70639
2023-11-06[clang][NFC] Refactor `ImplicitParamDecl::ImplicitParamKind`Vlad Serebrennikov1-3/+3
This patch converts `ImplicitParamDecl::ImplicitParamKind` into a scoped enum at namespace scope, making it eligible for forward declaring. This is useful for `preferred_type` annotations on bit-fields.
2023-10-31[clang][NFC] Refactor `VectorType::VectorKind`Vlad Serebrennikov1-2/+2
This patch moves `VectorKind` to namespace scope, and make it complete at the point its bit-field is declared. It also converts it to a scoped enum.
2023-10-31[clang][NFC] Refactor `ArrayType::ArraySizeModifier`Vlad Serebrennikov1-2/+2
This patch moves `ArraySizeModifier` before `Type` declaration so that it's complete at `ArrayTypeBitfields` declaration. It's also converted to scoped enum along the way.
2023-10-25[Clang][DebugInfo] Clang generates an extra spurious unnamed 'dbg.declare' ↵Carlos Alberto Enciso1-1/+5
(#69681) Do not emit call to llvm.dbg.declare when the variable declaration is a DecompositionDecl as its instance class is always unnamed. The emitted debug declare looks like: call void @llvm.dbg.declare(metadata ..., metadata !xx, metadata ...) !xx = !DILocalVariable(scope: !..., file: !..., line: ..., type: !...)
2023-10-23[clang] Add clang::preferred_type attribute for bitfields (#69104)Vlad Serebrennikov1-0/+2
This attribute allows user to specify type of the bitfield that will be emitted to debug info without affecting semantics of the program. Since it doesn't affect semantics, this attribute can be safely ignored by other compilers. This is useful when user is forced to use the same type for all bitfields in a class to get better [layout](https://godbolt.org/z/ovWqzqv9x) and [codegen](https://godbolt.org/z/bdoqvz9e6) from MSVC, because it allows debuggers to interpret the value of bitfield in the most human-friendly way (e.g. when value actually comes from an enum). This is driven by my work on LLDB formatters for Clang. I have two use cases for this: ```cpp namespace Clang { class Type { enum TypeClass { ... }; struct TypeBitfields { [[clang::preferred_type(clang::Type::TypeClass)]] unsigned TC: 8; [[clang::preferred_type(bool)]] mutable unsigned FromAST : 1; }; }; } ```
2023-10-15[Clang][M68k] Add Clang support for the new M68k_RTD CCMin-Yih Hsu1-0/+2
This patch adds `CC_M68kRTD`, which will be used on function if either `__attribute__((m68k_rtd))` is presented or `-mrtd` flag is given. Differential Revision: https://reviews.llvm.org/D149867
2023-10-02[C++] Implement "Deducing this" (P0847R7)Corentin Jabot1-2/+2
This patch implements P0847R7 (partially), CWG2561 and CWG2653. Reviewed By: aaron.ballman, #clang-language-wg Differential Revision: https://reviews.llvm.org/D140828
2023-08-18Reapply "[DebugInfo] Alternate (more efficient) MD5 fix"Paul Robinson1-5/+8
D155991 changed the file lookup to do a full string compare on the filename; however, this added ~0.5% to compile time with -g. Go back to the previous pointer-based lookup, but capture the main file's checksum as well as its name to use when creating the extra DIFile entry. This causes all entries to be consistent and also avoids computing the checksum twice. This reverts commit 5956648fc3ba11dd6b0d0f2d1d9b923e7f80f247. There was a string lifetime issue that is now corrected. Differential Revision: https://reviews.llvm.org/D156571
2023-08-18Revert "Reapply "[DebugInfo] Alternate (more efficient) MD5 fix""Paul Robinson1-8/+6
This reverts commit 2e4d2d800b9ce0924513a2f24e7a1f3d22b52383. Invalid checksums detected here: https://lab.llvm.org/buildbot/#/builders/37/builds/24465
2023-08-18Reapply "[DebugInfo] Alternate (more efficient) MD5 fix"Paul Robinson1-6/+8
D155991 changed the file lookup to do a full string compare on the filename; however, this added ~0.5% to compile time with -g. Go back to the previous pointer-based lookup, but capture the main file's checksum as well as its name to use when creating the extra DIFile entry. This causes all entries to be consistent and also avoids computing the checksum twice. This reverts commit 21e7f73494663814e0296066895dfacdebfac6d4. I'm unable to find a reason for the memory management issues that caused the revert, so trying again.
2023-08-17Revert "[DebugInfo] Alternate (more efficient) MD5 fix"Paul Robinson1-8/+6
This reverts commit ca1295c5a15f03ede2fe620cc80d6a1e6e6735b8. It seems to be the culprit for at least some of today's bot failures, for example https://lab.llvm.org/buildbot/#/builders/238/builds/4952
2023-08-17[DebugInfo] Alternate (more efficient) MD5 fixPaul Robinson1-6/+8
D155991 changed the file lookup to do a full string compare on the filename; however, this added ~0.5% to compile time with -g. Go back to the previous pointer-based lookup, but capture the main file's checksum as well as its name to use when creating the extra DIFile entry. This causes all entries to be consistent and also avoids computing the checksum twice. Differential revision: https://reviews.llvm.org/D156571