aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGDebugInfo.cpp
AgeCommit message (Collapse)AuthorFilesLines
5 days[clang][DebugInfo] Emit DW_AT_language_{name, version} for DWARFv6 (#163208)Michael Buch1-30/+93
Depends on: * https://github.com/llvm/llvm-project/pull/163348 * https://github.com/llvm/llvm-project/pull/162632 With this patch Clang will start emitting `DW_AT_language_{name, version}` for C++/C/Objective-C/Objective-C++ when using `-gdwarf-6`. We adjust the `DISourceLanguageName` (which we pass to `DICompileUnit`) to hold a `DW_AT_language_name_` and version code when in DWARFv6. Otherwise we continue using the `DW_LANG_` version of `DISourceLanguageName`. We didn't back-port emitting `DW_AT_language_name`/`DW_AT_language_version` to DWARFv5 (unlike GCC, which emits both the new and old language attributes in DWARFv5) because there wasn't a compelling reason to do so (yet).
6 days[clang] NFC: rename TagType::getOriginalDecl back to getDecl (#163271)Matheus Izvekov1-15/+13
This rename was made as part of https://github.com/llvm/llvm-project/pull/147835 in order to ease rebasing the PR, and give a nice window for other patches to get rebased as well. It has been a while already, so lets go ahead and rename it back.
12 days[clang][DWARF] Add DW_AT_bit_stride for SVE predicate types (#161409)Mary Kassayova1-4/+7
Fixes #159285
13 days[llvm][DebugInfo][NFC] Abstract DICompileUnit::SourceLanguage to allow ↵Michael Buch1-5/+7
alternate DWARF SourceLanguage encoding (#162255) This patch sets up `DICompileUnit` to support the DWARFv6 `DW_AT_language_name` and `DW_AT_language_version` attributes (which are set to replace `DW_AT_language`). This patch changes the `DICompileUnit::SourceLanguage` field type to a `DISourceLanguageName` that encapsulates the notion of "versioned vs. unversioned name". A "versioned" name is one that has an associated version stored separately in `DISourceLanguageName::Version`. This patch just changes all the clients of the `getSourceLanguage` API to the expect a `DISourceLanguageName`. Currently they all just `assert` (via `DISourceLanguageName::getUnversionedName`) that we're dealing with "unversioned names" (i.e., the pre-DWARFv6 language codes). In follow-up patches (e.g., draft is at https://github.com/llvm/llvm-project/pull/162261), when we start emitting versioned language codes, the `getUnversionedName` calls can then be adjusted to `getName`. **Implementation considerations** * We could have added a new member to `DICompileUnit` alongside the existing `SourceLanguage` field. I don't think this would have made the transition any simpler (clients would still need to be aware of "versioned" vs. "unversioned" language names). I felt that encapsulating this inside a `DISourceLanguageName` was easier to reason about for maintainers. * Currently DISourceLanguageName is a `12` byte structure. We could probably pack all the info inside a `uint64_t` (16-bits for the name, 32-bits for the version, 1-bit for answering the `hasVersionedName`). Just to keep the prototype simple I used a `std::optional`. But since the guts of the structure are hidden, we can always change the layout to a more compact representation instead. **How to review** * The new `DISourceLanguageName` structure is defined in `DebugInfoMetadata.h`. All the other changes fall out from changing the `DICompileUnit::SourceLanguage` from `unsigned` to `DISourceLanguageName`.
2025-09-29Reland "[clang][DebugInfo][NFC] Simplify CollectRecordLambdaFields"Michael Buch1-24/+40
This reverts commit 99a29f640809f32d1271ed5cac9764b839daeed1. Original change was reverted because following assertion started firing: ``` clang++: clang/include/clang/AST/LambdaCapture.h:105: ValueDecl *clang::LambdaCapture::getCapturedVar() const: Assertion `capturesVariable() && "No variable available for capture"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0.Program arguments: ../../prebuilt/third_party/clang/custom/bin/clang++ -MD -MF host_x64/obj/third_party/android/platform/system/libbase/libbase.logging.cpp.o.d -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES -I../.. -Ihost_x64/gen -I../../third_party/android/platform/system/libbase/include -I../../third_party/fmtlib/src/include -I../../third_party/android/platfo...com 1.<eof> parser at end of file 2.Per-file LLVM IR generation clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation) Fuchsia clang version 22.0.0git (https://llvm.googlesource.com/llvm-project 8553bd2b29ad2b17a9a884f14da6c43b606ec776) ******************** ``` The relanded patch just adds a `Capture.capturesVariable()` check before calling `getCapturedVar`. That's what the code did before the refactor.
2025-09-26Revert "[clang][DebugInfo][NFC] Simplify CollectRecordLambdaFields" (#160932)Petr Hosek1-38/+24
Reverts llvm/llvm-project#160690
2025-09-25[clang][DebugInfo][NFC] Simplify CollectRecordLambdaFields (#160690)Michael Buch1-24/+38
This patch creates a helper to retrieve the name from a lambda capture and only calls `createFieldType` once. This will simplify reviewing some upcoming changes in this function.
2025-09-23[clang][DebugInfo] Re-enable VTable debug info on COFF platforms (#158450)Tomohiro Kashiwada1-2/+12
The debug info for VTables introduced in #130255 was temporarily disabled on COFF platforms by #151684, due to the risk of emitting dangling relocations (see also: https://github.com/llvm/llvm-project/issues/149639#issuecomment-3114257062 ). This patch re-enables that debug info and adds a guard to prevent emitting dangling relocations by checking whether the VTable definition is actually emitted. Resolves #149639
2025-09-09[clang][DebugInfo] Emit unified (Itanium) mangled name to structor ↵Michael Buch1-6/+29
declarations (#154142) Depends on https://github.com/llvm/llvm-project/pull/154137 This patch is motivated by https://github.com/llvm/llvm-project/pull/149827, where we plan on using mangled names on structor declarations to find the exact structor definition that LLDB's expression evaluator should call. Given a `DW_TAG_subprogram` for a function declaration, the most convenient way for a debugger to find the corresponding definition is to use the `DW_AT_linkage_name` (i.e., the mangled name). However, we currently can't do that for constructors/destructors because Clang doesn't attach linkage names to them. This is because, depending on ABI, there can be multiple definitions for a single constructor/destructor declaration. The way GCC works around this is by producing a `C4`/`D4` "unified" mangling for structor declarations (see [godbolt](https://godbolt.org/z/Wds6cja9K)). GDB uses this to locate the relevant definitions. This patch aligns Clang with GCC's DWARF output and allows us to implement the same lookup scheme in LLDB.
2025-08-27[clang] AST: fix getAs canonicalization of leaf types (#155028)Matheus Izvekov1-1/+1
2025-08-26[clang] NFC: introduce Type::getAsEnumDecl, and cast variants for all ↵Matheus Izvekov1-2/+1
TagDecls (#155463) And make use of those. These changes are split from prior PR #155028, in order to decrease the size of that PR and facilitate review.
2025-08-21Fix scope of typedefs present inside a template class (#146729)ykhatav1-1/+8
When a typedef is declared within a templated class, clang incorrectly assigns the typedef to the compilation unit (CU) scope rather than the intended scope of the templated class. This issue arises because, during the creation of the typedef, the context lookup in the RegionMap fails to locate the templated class, despite its prior creation. The problem stems from the way the context is stored in the RegionMap. When handling templated types, the current implementation stores the class specialization rather than the templated declaration itself. This leads to a mismatch when attempting to retrieve the context for the typedef. To address this issue, the solution involves modifying the CreatedLimitedType() function. Specifically, when a struct or class is a templated type, we should store the actual templated declaration in the RegionMap instead of the class specialization. This ensures that subsequent lookups for context, such as those needed for typedef declarations, correctly identify the templated class scope. Fixes https://github.com/llvm/llvm-project/issues/91451
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-62/+65
This is a major change on how we represent nested name qualifications in the AST. * The nested name specifier itself and how it's stored is changed. The prefixes for types are handled within the type hierarchy, which makes canonicalization for them super cheap, no memory allocation required. Also translating a type into nested name specifier form becomes a no-op. An identifier is stored as a DependentNameType. The nested name specifier gains a lightweight handle class, to be used instead of passing around pointers, which is similar to what is implemented for TemplateName. There is still one free bit available, and this handle can be used within a PointerUnion and PointerIntPair, which should keep bit-packing aficionados happy. * The ElaboratedType node is removed, all type nodes in which it could previously apply to can now store the elaborated keyword and name qualifier, tail allocating when present. * TagTypes can now point to the exact declaration found when producing these, as opposed to the previous situation of there only existing one TagType per entity. This increases the amount of type sugar retained, and can have several applications, for example in tracking module ownership, and other tools which care about source file origins, such as IWYU. These TagTypes are lazily allocated, in order to limit the increase in AST size. This patch offers a great performance benefit. It greatly improves compilation time for [stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for `test_on2.cpp` in that project, which is the slowest compiling test, this patch improves `-c` compilation time by about 7.2%, with the `-fsyntax-only` improvement being at ~12%. This has great results on compile-time-tracker as well: ![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831) This patch also further enables other optimziations in the future, and will reduce the performance impact of template specialization resugaring when that lands. It has some other miscelaneous drive-by fixes. About the review: Yes the patch is huge, sorry about that. Part of the reason is that I started by the nested name specifier part, before the ElaboratedType part, but that had a huge performance downside, as ElaboratedType is a big performance hog. I didn't have the steam to go back and change the patch after the fact. There is also a lot of internal API changes, and it made sense to remove ElaboratedType in one go, versus removing it from one type at a time, as that would present much more churn to the users. Also, the nested name specifier having a different API avoids missing changes related to how prefixes work now, which could make existing code compile but not work. How to review: The important changes are all in `clang/include/clang/AST` and `clang/lib/AST`, with also important changes in `clang/lib/Sema/TreeTransform.h`. The rest and bulk of the changes are mostly consequences of the changes in API. PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just for easier to rebasing. I plan to rename it back after this lands. Fixes #136624 Fixes https://github.com/llvm/llvm-project/issues/43179 Fixes https://github.com/llvm/llvm-project/issues/68670 Fixes https://github.com/llvm/llvm-project/issues/92757
2025-08-05[clang] Use llvm::iterator_range::empty (NFC) (#152088)Kazu Hirata1-1/+1
2025-08-04[clang][DebugInfo] Disable VTable debug info (#130255) on COFF platforms ↵Tomohiro Kashiwada1-1/+2
(#151684) On COFF platform, d1b0cbff806b50d399826e79b9a53e4726c21302 generates a debug info linked with VTable regardless definition is present or not. If that VTable ends up implicitly dllimported from another DLL, ld.bfd produces a runtime pseudo relocation for it (LLD doesn't, since d17db6066d2524856fab493dd894f8396e896bc7). If the debug section is stripped, the runtime pseudo relocation points to memory space outside of the module, causing an access violation. At this moment, we simply disable VTable debug info on COFF platform to avoid this problem.
2025-08-01[clang] Fix clang debug info generation for unprtototyped function (#150022)Georgiy Samoylov1-1/+1
Consider this declaration: `int foo();` This function is described in LLVM with `clang::FunctionNoProtoType` class. ([See description](https://clang.llvm.org/doxygen/classclang_1_1FunctionNoProtoType.html)) Judging by [this comment](https://github.com/llvm/llvm-project/blob/a1bf0d1394e48894be05d274d3942ff77c35ce87/clang/lib/CodeGen/CGCall.cpp#L159C11-L159C12) all such functions are treated like functions with variadic number of parameters. When we want to [emit debug info](https://github.com/llvm/llvm-project/blob/0a8ddd396546bec7eaa4c3b7ef2f495e52bca0b8/clang/lib/CodeGen/CGDebugInfo.cpp#L4808) we have to know function that we calling. In method [getCalledFunction()](https://github.com/llvm/llvm-project/blob/0a8ddd396546bec7eaa4c3b7ef2f495e52bca0b8/llvm/include/llvm/IR/InstrTypes.h#L1348) we compare two types of function: 1. Function that we deduce from calling operand, and 2. Function that we store locally If they differ we get `nullptr` and can't emit appropriate debug info. The only thing they differ is: lhs function is variadic, but rhs function isn't Reason of this difference is that under RISC-V there is no overridden function that tells us about treating functions with no parameters. [Default function](https://github.com/llvm/llvm-project/blob/0a8ddd396546bec7eaa4c3b7ef2f495e52bca0b8/clang/lib/CodeGen/TargetInfo.cpp#L87) always return `false`. This patch overrides this function for RISC-V
2025-07-31[clang][CodeGen] Remove CWD fallback in compilation directory (#150130)Steven Wu1-10/+4
CWD is queried in clang driver and passed to clang cc1 via flags when needed. Respect the cc1 flags and do not repeated checking current working directory in CodeGen.
2025-07-30[clang][DebugInfo] Don't emit VTable debug symbols for -gline-tables-only. ↵Steve Merritt1-0/+2
(#151025) The -gline-tables-only option emits minimal debug info for functions, files and line numbers while omitting variables, parameters and most type information. VTable debug symbols are emitted to facilitate a debugger's ability to perform automatic type promotion on variables and parameters. With variables and parameters being omitted, the VTable symbols are unnecessary.
2025-07-26[Clang][CodeGen] Emit “trap reasons” on UBSan traps (#145967)Anthony Tran1-1/+1
This patch adds a human readable trap category and message to UBSan traps. The category and message are encoded in a fake frame in the debug info where the function is a fake inline function where the name encodes the trap category and message. This is the same mechanism used by Clang’s `__builtin_verbose_trap()`. This change allows consumers of binaries built with trapping UBSan to more easily identify the reason for trapping. In particular LLDB already has a frame recognizer that recognizes the fake function names emitted in debug info by this patch. A patch testing this behavior in LLDB will be added in a separately. The human readable trap messages are based on the messages currently emitted by the userspace runtime for UBSan in compiler-rt. Note the wording is not identical because the userspace UBSan runtime has access to dynamic information that is not available during Clang’s codegen. Test cases for each UBSan trap kind are included. This complements the [`-fsanitize-annotate-debug-info` feature](https://github.com/llvm/llvm-project/pull/141997). While `-fsanitize-annotate-debug-info` attempts to annotate all UBSan-added instructions, this feature (`-fsanitize-debug-trap-reasons`) only annotates the final trap instruction using SanitizerHandler information. This work is part of a GSoc 2025 project.
2025-07-21[DebugInfo] Remove intrinsic-flavours of findDbgUsers (#149816)Jeremy Morse1-3/+2
This is one of the final remaining debug-intrinsic specific codepaths out there, and pieces of cross-LLVM infrastructure to do with debug intrinsics.
2025-07-19Reland [Clang] Make the SizeType, SignedSizeType and PtrdiffType be named ↵YexuanXiao1-1/+2
sugar types (#149613) The checks for the 'z' and 't' format specifiers added in the original PR #143653 had some issues and were overly strict, causing some build failures and were consequently reverted at https://github.com/llvm/llvm-project/commit/4c85bf2fe8042c855c9dd5be4b02191e9d071ffd. In the latest commit https://github.com/llvm/llvm-project/pull/149613/commits/27c58629ec76a703fde9c0b99b170573170b4a7a, I relaxed the checks for the 'z' and 't' format specifiers, so warnings are now only issued when they are used with mismatched types. The original intent of these checks was to diagnose code that assumes the underlying type of `size_t` is `unsigned` or `unsigned long`, for example: ```c printf("%zu", 1ul); // Not portable, but not an error when size_t is unsigned long ``` However, it produced a significant number of false positives. This was partly because Clang does not treat the `typedef` `size_t` and `__size_t` as having a common "sugar" type, and partly because a large amount of existing code either assumes `unsigned` (or `unsigned long`) is `size_t`, or they define the equivalent of size_t in their own way (such as sanitizer_internal_defs.h).https://github.com/llvm/llvm-project/blob/2e67dcfdcd023df2f06e0823eeea23990ce41534/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h#L203
2025-07-18[Sanitizer] remove array-bounds-pseudofn (#149430)Florian Mayer1-16/+7
This has been replaced by -fsanitize-annotate-debug-info
2025-07-17Revert "[Clang] Make the SizeType, SignedSizeType and PtrdiffType be named ↵Kazu Hirata1-2/+1
sugar types instead of built-in types (#143653)" This reverts commit c27e283cfbca2bd22f34592430e98ee76ed60ad8. A builbot failure has been reported: https://lab.llvm.org/buildbot/#/builders/186/builds/10819/steps/10/logs/stdio I'm also getting a large number of warnings related to %zu and %zx.
2025-07-17[Clang] Make the SizeType, SignedSizeType and PtrdiffType be named sugar ↵YexuanXiao1-1/+2
types instead of built-in types (#143653) Including the results of `sizeof`, `sizeof...`, `__datasizeof`, `__alignof`, `_Alignof`, `alignof`, `_Countof`, `size_t` literals, and signed `size_t` literals, the results of pointer-pointer subtraction and checks for standard library functions (and their calls). The goal is to enable clang and downstream tools such as clangd and clang-tidy to provide more portable hints and diagnostics. The previous discussion can be found at #136542. This PR implements this feature by introducing a new subtype of `Type` called `PredefinedSugarType`, which was considered appropriate in discussions. I tried to keep `PredefinedSugarType` simple enough yet not limited to `size_t` and `ptrdiff_t` so that it can be used for other purposes. `PredefinedSugarType` wraps a canonical `Type` and provides a name, conceptually similar to a compiler internal `TypedefType` but without depending on a `TypedefDecl` or a source file. Additionally, checks for the `z` and `t` format specifiers in format strings for `scanf` and `printf` were added. It will precisely match expressions using `typedef`s or built-in expressions. The affected tests indicates that it works very well. Several code require that `SizeType` is canonical, so I kept `SizeType` to its canonical form. The failed tests in CI are allowed to fail. See the [comment](https://github.com/llvm/llvm-project/pull/135386#issuecomment-3049426611) in another PR #135386.
2025-07-16[Sanitize] fix crash in -fsanitize-annotate-debug-info (#149237)Florian Mayer1-5/+8
2025-07-16[KeyInstr] Fix verifier check (#149043)Orlando Cazalet-Hyams1-0/+4
The verifier check was in the wrong place, meaning it wasn't actually checking many instructions. Fixing that causes a test failure (coro-dwarf-key-instrs.cpp) because coros turn off the feature but still annotate instructions with the metadata (which is a supported situation, but the verifier doesn't like it, and it's hard to teach the verifier to like it). Fix that by avoiding emitting any key instruction metadata if the DISubprogram has opted out of key instructions.
2025-07-15[clang][modules] Serialize `CodeGenOptions` (#146422)Jan Svoboda1-17/+22
Some `LangOptions` duplicate their `CodeGenOptions` counterparts. My understanding is that this was done solely because some infrastructure (like preprocessor initialization, serialization, module compatibility checks, etc.) were only possible/convenient for `LangOptions`. This PR implements the missing support for `CodeGenOptions`, which makes it possible to remove some duplicate `LangOptions` fields and simplify the logic. Motivated by https://github.com/llvm/llvm-project/pull/146342.
2025-07-14[DebugInfo] Add option for producing no source-file hash (#148657)Jeremy Morse1-0/+2
Clang can chose which sort of source-file hash is attached to a DIFile metadata node. However, whenever hashing is possible, we /always/ attach a hash. This patch permits users who want DWARF5 but don't want the file hashes to opt out, by adding a "none" option to the -gsrc-hash option that skips hash computation.
2025-07-14[KeyInstr] Disable key-instructions for coroutine scopes (#147551)Jeremy Morse1-1/+5
At this time (immediately prior to llvm21 branching) we haven't instrumented coroutine generation to identify the "key" instructions of things like co_return and similar. This will lead to worse stepping behaviours, as there won't be any key instruction for those lines. This patch removes the key-instructions flag from the DISubprograms for coroutines, which will cause AsmPrinter to use the "old" / existing linetable stepping behaviour, avoiding a regression until we can instrument these constructs. (I'm going to post on discourse about whether this is a good idea or not in a moment)
2025-07-04[debuginfo][coro] Emit debug info labels for coroutine resume points (#141937)Adrian Vogelsgesang1-2/+3
RFC on discourse: https://discourse.llvm.org/t/rfc-debug-info-for-coroutine-suspension-locations-take-2/86606 With this commit, we add `DILabel` debug infos to the resume points of a coroutine. Those labels can be used by debugging scripts to figure out the exact line and column at which a coroutine was suspended by looking up current `__coro_index` value inside the coroutines frame, and then searching for the corresponding label inside the coroutine's resume function. The DWARF information generated for such a label looks like: ``` 0x00000f71: DW_TAG_label DW_AT_name ("__coro_resume_1") DW_AT_decl_file ("generator-example.cpp") DW_AT_decl_line (5) DW_AT_decl_column (3) DW_AT_artificial (true) DW_AT_LLVM_coro_suspend_idx (0x01) DW_AT_low_pc (0x00000000000019be) ``` The labels can be mapped to their corresponding `__coro_idx` values either via their naming convention `__coro_resume_<N>` or using the new `DW_AT_LLVM_coro_suspend_idx` attribute. In gdb, those line numebrs can be looked up using `info line -function my_coroutine -label __coro_resume_1`. LLDB unfortunately does not understand DW_TAG_label debug information, yet. Given this is an artificial compiler-generated label, I did apply the DW_AT_artificial tag to it. The DWARFv5 standard only allows that tag on type and variable definitions, but this is a natural extension and was also blessed in the RFC on discourse. Also, this commit adds `DW_AT_decl_column` to labels, not only for coroutines but also for normal C and C++ labels. While not strictly necessary, I am doing so now because it would be harder to do so later without breaking the binary LLVM-IR format Drive-by fixes: While reading the existing test cases to understand how to write my own test case, I did a couple of small typo fixes and comment improvements
2025-07-02Reapply "[Clang,debuginfo] added vtt parameter in destructor ↵Reid Kleckner1-3/+18
DISubroutineType (#130674)" (#145697) This reverts commit cd826d6e840ed33ad88458c862da5f9fcc6e908c and relands 27c1aa9b9cf9e0b14211758ff8f7d3aaba24ffcf This fixes #104765 I tweaked the code to avoid an OOB.
2025-06-30[KeyInstr] Add DISubprogram::keyInstructions bit (#144107)Orlando Cazalet-Hyams1-5/+14
Patch 1/4 adding bitcode support. Store whether or not a function is using Key Instructions in its DISubprogram so that we don't need to rely on the -mllvm flag -dwarf-use-key-instructions to determine whether or not to interpret Key Instructions metadata to decide is_stmt placement at DWARF emission time. This makes bitcode support simple and enables well defined mixing of non-key-instructions and key-instructions functions in an LTO context. This patch adds the bit (using DISubprogram::SubclassData1). PR 144104 and 144103 use it during DWARF emission. PR 44102 adds bitcode support. See pull request for overview of alternative attempts.
2025-06-25Non constant size and offset in DWARF (#141106)Tom Tromey1-2/+2
In Ada, a record type can have a non-constant size, and a field can appear at a non-constant bit offset in a record. To support this, this patch changes DIType to record the size and offset using metadata, rather than plain integers. In addition to a constant offset, both DIVariable and DIExpression are now supported here. One thing of note in this patch is the choice of how exactly to represent a non-constant bit offset, with the difficulty being that DWARF 5 does not support this. DWARF 3 did have a way to support a non-constant byte offset, combined with a constant bit offset within the byte, but this was deprecated in DWARF 4 and removed from DWARF 5. This patch takes a simple approach: a DWARF extension allowing the use of an expression with DW_AT_data_bit_offset. There is a corresponding DWARF issue, see https://dwarfstd.org/issues/250501.1.html. The main reason for this approach is that it keeps API simplicity: just a single value is needed, rather than having separate data describing the byte offset and the bit within the byte.
2025-06-08[clang] AST: fix dependency calculation for TypedefTypes (#143291)Matheus Izvekov1-22/+1
The dependency from the type sugar of the underlying type of a Typedef were not being considered for the dependency of the TypedefType itself. A TypedefType should be instantiation dependent if it involves non-instantiated template parameters, even if they don't contribute to the canonical type. Besides, a TypedefType should be instantiation dependent if it is declared in a dependent context, but fixing that would have performance consequences, as otherwise non-dependent typedef declarations would need to be transformed during instantiation as well. This removes the workaround added in https://github.com/llvm/llvm-project/pull/90032 Fixes https://github.com/llvm/llvm-project/issues/89774
2025-06-06[ubsan] Add more -fsanitize-annotate-debug-info checks (#141997)Thurston Dang1-0/+82
This extends https://github.com/llvm/llvm-project/pull/138577 to more UBSan checks, by changing SanitizerDebugLocation (formerly SanitizerScope) to add annotations if enabled for the specified ordinals. Annotations will use the ordinal name if there is exactly one ordinal specified in the SanitizerDebugLocation; otherwise, it will use the handler name. Updates the tests from https://github.com/llvm/llvm-project/pull/141814. --------- Co-authored-by: Vitaly Buka <vitalybuka@google.com>
2025-06-05[clang] Simplify device kernel attributes (#137882)Nick Sarnie1-3/+2
We have multiple different attributes in clang representing device kernels for specific targets/languages. Refactor them into one attribute with different spellings to make it more easily scalable for new languages/targets. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-06-02[llvm][DebugInfo][clang] Finalize all declaration subprograms in ↵Vladislav Dzhidzhoev1-3/+1
DIBuilder::finalize() (#139914) DIBuilder began tracking definition subprograms and finalizing them in `DIBuilder::finalize()` in eb1bb4e419. Currently, `finalizeSubprogram()` attaches local variables, imported entities, and labels to the `retainedNodes:` field of a corresponding subprogram. After 75819aedf, the definition and some declaration subprograms are finalized in `DIBuilder::finalize()`: `AllSubprograms` holds references to definition subprograms. `AllRetainTypes` holds references to declaration subprograms. For DISubprogram elements of both variables, `finalizeSubprogram()` was called there. However, `retainTypes()` is not necessarily called for every declaration subprogram (as in 40a3fcb0). DIBuilder clients may also want to attach DILocalVariables to declaration subprograms, for example, in 58bdf8f9a8. Thus, the `finalizeSubprogram()` function is called for all definition subprograms in `DIBuilder::finalize()` because they are stored in the `AllSubprograms` by the `CreateFunction(isDefinition: true)` call. But for the declaration subprograms, it should be called manually. With this commit, `AllSubprograms` is used for holding and finalizing all DISubprograms.
2025-05-28[AArch64] Rename AArch64SVEACLETypes.def and add base SVE_TYPE.David Green1-1/+1
2025-05-28[clang][DebugInfo] Add symbol for debugger with VTable information. (#130255)Carlos Alberto Enciso1-0/+49
The IR now includes a global variable for the debugger that holds the address of the vtable. Now every class that contains virtual functions, has a static member (marked as artificial) that identifies where that vtable is loaded in memory. The unmangled name is '_vtable$'. This new symbol will allow a debugger to easily associate classes with the physical location of their VTables using only the DWARF information. Previously, this had to be done by searching for ELF symbols with matching names; something that was time-consuming and error-prone in certain edge cases.
2025-05-27[HLSL] Implement `SpirvType` and `SpirvOpaqueType` (#134034)Cassandra Beckley1-0/+8
This implements the design proposed by [Representing SpirvType in Clang's Type System](https://github.com/llvm/wg-hlsl/pull/181). It creates `HLSLInlineSpirvType` as a new `Type` subclass, and `__hlsl_spirv_type` as a new builtin type template to create such a type. This new type is lowered to the `spirv.Type` target extension type, as described in [Target Extension Types for Inline SPIR-V and Decorated Types](https://github.com/llvm/wg-hlsl/blob/main/proposals/0017-inline-spirv-and-decorated-types.md).
2025-05-22[CodeGen] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#141191)Kazu Hirata1-4/+3
2025-05-21Fix-forward excess ';' from 9459c8309c6768cf6aa7956885b2540e16582a93 (#134632)Thurston Dang1-1/+1
clang/lib/CodeGen/CGDebugInfo.cpp:153:2: error: extra ';' outside of a function is incompatible with C++98 [-Werror,-Wc++98-compat-extra-semi] 153 | }; | ^ 1 error generated.
2025-05-21[KeyInstr][Clang] Add ApplyAtomGroup (#134632)Orlando Cazalet-Hyams1-1/+101
This is a scoped helper similar to ApplyDebugLocation that creates a new source location atom group which instructions can be added to. A source atom is a source construct that is "interesting" for debug stepping purposes. We use an atom group number to track the instruction(s) that implement the functionality for the atom, plus backup instructions/source locations. This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.
2025-05-11[clang] Use StringRef::consume_front (NFC) (#139472)Kazu Hirata1-4/+2
2025-05-08[RISCV] Fix generation of DWARF info for vector segmented types (#137941)Kirill Radkin1-1/+5
In DWARF info RISC-V Vector types are presented as DW_TAG_array_type with tags DW_AT_type (what elements does this array consist of) and DW_TAG_subrange_type. DW_TAG_subrange_type have DW_AT_upper_bound tag which contain upper bound value for this array. For now, it's generate same DWARF info about length of segmented types and their corresponding non-tuple types. For example, vint32m4x2_t and vint32m4_t have DW_TAG_array_type with same DW_AT_type and DW_TAG_subrange_type, it means that this types have same length, which is not correct (vint32m4x2_t length is twice as big as vint32m4_t)
2025-04-23Revert "[Clang,debuginfo] added vtt parameter in destructor DISubroutineType ↵Reid Kleckner1-18/+3
(#130674)" This reverts commit 27c1aa9b9cf9e0b14211758ff8f7d3aaba24ffcf. See comments on PR. After this change, Clang now asserts like this: clang: ../llvm/include/llvm/IR/Metadata.h:1435: const MDOperand &llvm::MDNode::getOperand(unsigned int) const: Assertion `I < getNumOperands() && "Out of range"' failed. ... #8 0x000055f345c4e4cb clang::CodeGen::CGDebugInfo::getOrCreateInstanceMethodType() #9 0x000055f345c5ba4f clang::CodeGen::CGDebugInfo::EmitFunctionDecl() #10 0x000055f345b52519 clang::CodeGen::CodeGenModule::EmitExternalFunctionDeclaration() This is due to pre-existing jankiness in the way BPF emits extra declarations for debug info, but we should rollback and then fix forward.
2025-04-16[Clang,debuginfo] added vtt parameter in destructor DISubroutineType (#130674)mgschossmann1-3/+18
Fixes issue #104765: When creating a virtual destructor with an artificial "vtt" argument, the type of "vtt" was previously missing in the `DISubroutineType` `types` array. This commit fixes this behavior and adds a regression test.
2025-04-15[PAC] Add support for __ptrauth type qualifier (#100830)Akira Hatanaka1-2/+17
The qualifier allows programmer to directly control how pointers are signed when they are stored in a particular variable. The qualifier takes three arguments: the signing key, a flag specifying whether address discrimination should be used, and a non-negative integer that is used for additional discrimination. ``` typedef void (*my_callback)(const void*); my_callback __ptrauth(ptrauth_key_process_dependent_code, 1, 0xe27a) callback; ``` Co-Authored-By: John McCall rjmccall@apple.com
2025-04-14[clang] implement printing of canonical expressions (#135133)Matheus Izvekov1-1/+1
This patch extends the canonicalization printing policy to cover expressions and template names, and wires that up to the template argument printer, covering expressions, and to the expression within a dependent decltype. This is helpful for debugging, or if these expressions somehow end up in diagnostics, as without this patch they can print as completely unrelated expressions, which can be quite confusing. This is because expressions are not uniqued, unlike types, and when a template specialization containing an expression is the first to be canonicalized, the expression ends up appearing in the canonical type of subsequent equivalent specializations. Fixes https://github.com/llvm/llvm-project/issues/92292
2025-04-14[MS][clang] Revert vector deleting destructors support (#135611)Mariya Podchishchaeva1-2/+1
Finding operator delete[] is still problematic, without it the extension is a security hazard, so reverting until the problem with operator delete[] is figured out. This reverts the following PRs: Reland [MS][clang] Add support for vector deleting destructors (llvm#133451) [MS][clang] Make sure vector deleting dtor calls correct operator delete (llvm#133950) [MS][clang] Fix crash on deletion of array of pointers (llvm#134088) [clang] Do not diagnose unused deleted operator delete[] (llvm#134357) [MS][clang] Error about ambiguous operator delete[] only when required (llvm#135041)