aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGDebugInfo.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-08-16[Clang][DebugInfo] Emit narrower base types for structured binding ↵Victor Campos1-2/+41
declarations that bind to struct bitfields In cases where a structured binding declaration is made to a struct with bitfields: struct A { unsigned int x : 16; unsigned int y : 16; } g; auto [a, b] = g; // structured binding declaration Clang assigns the 'unsigned int' DWARF base type to 'a' and 'b' because this is their deduced C++ type in the structured binding declaration. However, their actual type in memory is 'unsigned short' as they have 16 bits allocated for each. This is a problem for debug information consumers: if the debug information for 'a' has the 'unsigned int' base type, a debugger will assume it has 4 bytes, whereas it actually has a length of 2, resulting in a read (or write) past its length. This patch mimics GCC's behaviour: in case of structured bindings to bitfields, the binding declaration's DWARF base type is of the target's integer type with the same bitwidth as the bitfield. If no suitable integer type is found in the target, no debug information is emitted anymore in order to prevent wrong debug output. Reviewed By: tmatheson Differential Revision: https://reviews.llvm.org/D157479
2023-06-20[clang][DebugInfo] Emit DW_AT_deleted on any deleted member functionMichael Buch1-21/+2
Currently we emit `DW_AT_deleted` for `deleted` special-member functions (i.e., ctors/dtors). However, in C++ one can mark any member function as deleted. This patch expands the set of member functions for which we emit `DW_AT_deleted`. The DWARFv5 spec section 5.7.8 says: ``` <non-normative> In C++, a member function may be declared as deleted. This prevents the compiler from generating a default implementation of a special member function such as a constructor or destructor, and can affect overload resolution when used on other member functions. </non-normative> If the member function entry has been declared as deleted, then that entry has a DW_AT_deleted attribute. ``` Thus this change is conforming. Differential Revision: https://reviews.llvm.org/D153282
2023-06-14[DebugInfo] Always emit `.debug_names` with DWARF 5 for Apple platformsJonas Devlieghere1-5/+9
On Apple platforms, we generate .apple_names, .apple_types, .apple_namespaces and .apple_objc Apple accelerator tables for DWARF 4 and earlier. For DWARF 5 we should generate .debug_names, but instead we get no accelerator tables at all. In the backend we are correctly determining that we should be emitting .debug_names instead of .apple_names. However, when we get to the point of emitting the section, if the CU debug name table kind is not "default", the accelerator table emission is skipped. This patch sets the DebugNameTableKind to Apple in the frontend when target an Apple target. That way we know that the CU was compiled with the intent of emitting accelerator tables. For DWARF 4 and earlier, that means Apple accelerator tables. For DWARF 5 and later, that means .debug names. Differential revision: https://reviews.llvm.org/D118754
2023-06-14Revert "[DebugInfo] Always emit `.debug_names` with DWARF 5 for Apple platforms"Jonas Devlieghere1-9/+5
This reverts commit e0d57295bf6a3c04f2901d9c70f529d570f48b65 because the accel-tables-apple.ll test is failing on a few buildbots.
2023-06-14[DebugInfo] Always emit `.debug_names` with DWARF 5 for Apple platformsJonas Devlieghere1-5/+9
On Apple platforms, we generate .apple_names, .apple_types, .apple_namespaces and .apple_objc Apple accelerator tables for DWARF 4 and earlier. For DWARF 5 we should generate .debug_names, but instead we get no accelerator tables at all. In the backend we are correctly determining that we should be emitting .debug_names instead of .apple_names. However, when we get to the point of emitting the section, if the CU debug name table kind is not "default", the accelerator table emission is skipped. This patch sets the DebugNameTableKind to Apple in the frontend when target an Apple target. That way we know that the CU was compiled with the intent of emitting accelerator tables. For DWARF 4 and earlier, that means Apple accelerator tables. For DWARF 5 and later, that means .debug names. Differential revision: https://reviews.llvm.org/D118754
2023-06-04[NFC][CLANG] Fix Static Code Analyzer ConcernsManna, Soumi1-1/+1
This patch uses castAs instead of getAs which will assert if the type doesn't match to resolve dereference issue with nullptr FPT when calling getThisType() in clang::CodeGen::CGDebugInfo::CreateType(clang::MemberPointerType const *, llvm::DIFile *). Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D151947
2023-05-17[gcov] Simplify cc1 options and remove CodeGenOptions EmitCovNotes/EmitCovArcsFangrui Song1-2/+2
After a07b135ce0c0111bd83450b5dc29ef0381cdbc39, we always pass -coverage-notes-file/-coverage-data-file for driver options -ftest-coverage/-fprofile-arcs/--coverage. As a bonus, we can make the following simplification to cc1 options: * `-ftest-coverage -coverage-notes-file a.gcno` => `-coverage-notes-file a.gcno` * `-fprofile-arcs -coverage-data-file a.gcda` => `-coverage-data-file a.gcda` and remove EmitCovNotes/EmitCovArcs.
2023-04-25-fdebug-prefix-map=: make the last win when multiple prefixes matchFangrui Song1-7/+2
For `clang -c -g -fdebug-prefix-map=a/b=y -fdebug-prefix-map=a=x a/b/c.c`, we apply the longest prefix substitution, but GCC has always been picking the last applicable option (`a=x`, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109591). I feel that GCC's behavior is reasonable given the convention that the last value wins for the same option. Before D49466, Clang appeared to apply the shortest prefix substitution, which likely made the least sense. Reviewed By: #debug-info, scott.linder Differential Revision: https://reviews.llvm.org/D148975
2023-04-17[DebugInfo] Fix file path separator when targeting windows.Zequan Wu1-4/+10
This fixes two problems: 1. When crossing compiling for windows on linux, source file path in debug info is concatenated with directory by host native separator ('/'). For windows local build, they are concatenated by '\'. This causes non-determinism bug. The solution here is to let `LangOptions.UseTargetPathSeparator` to control if we should use host native separator or not. 2. Objectfile path in CodeView also uses host native separator when generated. It's fixed by changing the path separator in `/Fo` to '\' if the path is not an absolute path when adding the `-object-file-name=` flag. Reviewed By: hans Differential Revision: https://reviews.llvm.org/D147256
2023-04-07[clang][DebugInfo] Emit DW_AT_type of preferred name if availableMichael Buch1-9/+32
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-03-29[NFC][Clang] Move DebugOptions to llvm/Frontend for reuse in FlangKiran Chandramohan1-36/+39
This patch moves the Debug Options to llvm/Frontend so that it can be shared by Flang as well. Reviewed By: kiranchandramohan, awarzynski Differential Revision: https://reviews.llvm.org/D142347
2023-03-28[Clang][DebugInfo][AMDGPU] Emit zero size bitfields in the debug info to ↵Juan Manuel MARTINEZ CAAMAÑO1-4/+81
delimit bitfields in different allocation units. Consider the following sturctures when targetting: struct foo { int space[4]; char a : 8; char b : 8; char x : 8; char y : 8; }; struct bar { int space[4]; char a : 8; char b : 8; char : 0; char x : 8; char y : 8; }; Even if both structs have the same layout in memory, they are handled differenlty by the AMDGPU ABI. With the following code: // clang --target=amdgcn-amd-amdhsa -g -O1 example.c -S char use_foo(struct foo f) { return f.y; } char use_bar(struct bar b) { return b.y; } For use_foo, the 'y' field is passed in v4 ; v_ashrrev_i32_e32 v0, 24, v4 ; s_setpc_b64 s[30:31] For use_bar, the 'y' field is passed in v5 ; v_bfe_i32 v0, v5, 8, 8 ; s_setpc_b64 s[30:31] To make this distinction, we record a single 0-size bitfield for every member that is preceded by it. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D144870
2023-03-07[Clang] Create opaque type for AArch64 SVE2p1/SME2 svcount_t.Sander de Smalen1-12/+29
This patch adds the builtin type __SVCount_t to Clang, which is an opaque scalable type defined in the SME2 C and C++ Language Extensions. The type maps to the `target("aarch64.svcount")` LLVM IR type. Reviewed By: paulwalker-arm Differential Revision: https://reviews.llvm.org/D136864
2023-02-28DebugInfo: Disable ctor homing for types with only deleted (non copy/move) ctorsDavid Blaikie1-3/+12
Such a type is never going to have a ctor home, and may be used for type punning or other ways of creating objects. May be a more generally acceptable solution in some cases compared to attributing with [[clang::standalone_debug]]. Differential Revision: https://reviews.llvm.org/D144931
2023-02-20[debug-info][codegen] Prevent creation of self-referential SP nodeFelipe de Azevedo Piovezan1-4/+3
The function `CGDebugInfo::EmitFunctionDecl` is supposed to create a declaration -- never a _definition_ -- of a subprogram. This is made evident by the fact that the SPFlags never have the "Declaration" bit set by that function. However, when `EmitFunctionDecl` calls `DIBuilder::createFunction`, it still tries to fill the "Declaration" argument by passing it the result of `getFunctionDeclaration(D)`. This will query an internal cache of previously created declarations and, for most code paths, we return nullptr; all is good. However, as reported in [0], there are pathological cases in which we attempt to recreate a declaration, so the cache query succeeds, resulting in a subprogram declaration whose declaration field points to another declaration. Through a series of RAUWs, the declaration field ends up pointing to the SP itself. Self-referential MDNodes can't be `unique`, which causes the verifier to fail (declarations must be `unique`). We can argue that the caller should check the cache first, but this is not a correctness issue (declarations are `unique` anyway). The bug is that `CGDebugInfo::EmitFunctionDecl` should always pass `nullptr` to the declaration argument of `DIBuilder::createFunction`, expressing the fact that declarations don't point to other declarations. AFAICT this is not something for which any reasonable meaning exists. This seems a lot like a copy-paste mistake that has survived for ~10 years, since other places in this file have the exact same call almost token-by-token. I've tested this by compiling LLVMSupport with and without the patch, O2 and O0, and comparing the dwarfdump of the lib. The dumps are identical modulo the attributes decl_file/producer/comp_dir. [0]: https://github.com/llvm/llvm-project/issues/59241 Differential Revision: https://reviews.llvm.org/D143921
2023-02-17[WebAssembly] Initial support for reference type externref in clangPaulo Matos1-0/+11
This patch introduces a new type __externref_t that denotes a WebAssembly opaque reference type. It also implements builtin __builtin_wasm_ref_null_extern(), that returns a null value of __externref_t. This lays the ground work for further builtins and reference types. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D122215
2023-02-05Revert "[clang][WebAssembly] Initial support for reference type externref in ↵Vitaly Buka1-11/+0
clang" Very likely breaks stage 3 of msan build bot. Good: 764c88a50ac76a2df2d051a0eb5badc6867aabb6 https://lab.llvm.org/buildbot/#/builders/74/builds/17058 Looks unrelated: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c Bad: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c https://lab.llvm.org/buildbot/#/builders/74/builds/17059 This reverts commit eb66833d19573df97034a81279eda31b8d19815b.
2023-02-01Reland "[codegen] Store address of indirect arguments on the stack"Felipe de Azevedo Piovezan1-2/+3
The commit was reverted due to a regression in debug information of an optimized code test in lldb. This has since been addressed by: 1. rGf753e5be8239: [LiveDebugValues] Allow EntryValue with OP_deref expressions 2. rG055f2f04e658: [mem2reg][debuginfo] Handle op_deref when converting dbg.declare Differential Revision: https://reviews.llvm.org/D141381
2023-01-31[clang][WebAssembly] Initial support for reference type externref in clangPaulo Matos1-0/+11
This patch introduces a new type __externref_t that denotes a WebAssembly opaque reference type. It also implements builtin __builtin_wasm_ref_null_extern(), that returns a null value of __externref_t. This lays the ground work for further builtins and reference types. Differential Revision: https://reviews.llvm.org/D122215
2023-01-27[clang][DebugInfo] Check TemplateArgument::IsDefaultedMichael Buch1-7/+2
Since `ClassTemplateSpecializationDecl`s now set the `TemplateArgument::IsDefaulted` bit, there's no need to derive it here. Differential Revision: https://reviews.llvm.org/D142333
2023-01-23[clang][DebugInfo] Don't canonicalize names in template argument list for ↵Michael Buch1-3/+15
alias templates **Summary** This patch customizes the `CGDebugInfo` printing policy to stop canonicalizing the template arugment list in `DW_AT_name` for alias templates. The motivation for this is that we want to be able to use the `TypePrinter`s support for omitting defaulted template arguments when emitting `DW_AT_name`. For reference, GCC currently completely omits the template arguments when emitting alias template DIEs. **Testing** * Added unit-test Differential Revision: https://reviews.llvm.org/D142268
2023-01-20[APSInt] Fix bug in APSInt mentioned in ↵Peter Rong1-4/+12
https://github.com/llvm/llvm-project/issues/59515 Also provide a `tryExtValue()` API like APInt did in D139683 Reviewed By: RKSimon, efriedma Differential Revision: https://reviews.llvm.org/D140059
2023-01-16Revert "[codegen] Store address of indirect arguments on the stack"Felipe de Azevedo Piovezan1-3/+2
This reverts commit 7e4447a17db4a070f01c8f8a87505a4b2a1b0e3a.
2023-01-16[codegen] Store address of indirect arguments on the stackFelipe de Azevedo Piovezan1-2/+3
With codegen prior to this patch, truly indirect arguments -- i.e. those that are not `byval` -- can have their debug information lost even at O0. Because indirect arguments are passed by pointer, and this pointer is likely placed in a register as per the function call ABI, debug information is lost as soon as the register gets clobbered. This patch solves the issue by storing the address of the parameter on the stack, using a similar strategy employed when C++ references are passed. In other words, this patch changes codegen from: ``` define @foo(ptr %arg) { call void @llvm.dbg.declare(%arg, [...], metadata !DIExpression()) ``` To: ``` define @foo(ptr %arg) { %ptr_storage = alloca ptr store ptr %arg, ptr %ptr_storage call void @llvm.dbg.declare(%ptr_storage, [...], metadata !DIExpression(DW_OP_deref)) ``` Some common cases where this may happen with C or C++ function calls: 1. "Big enough" trivial structures passed by value under the ARM ABI. 2. Structures that are non-trivial for the purposes of call (as per the Itanium ABI) when passed by value. A few tests were matching the wrong alloca (matching against the new alloca, instead of the old one), so they were updated to either match both allocas or include a `,` right after the alloca type, to prevent matching against a pointer type. Differential Revision: https://reviews.llvm.org/D141381
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-8/+8
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-06[BPF] preserve btf_decl_tag for parameters of extern functionsEduard Zingerman1-4/+22
Generate DILocalVariable entries for parameters of extern functions, the "annotations" field of DILocalVariable is used to link "btf_decl_tag" annotation with the parameter. Do this only for BPF backend as there are no other users for this information. Final DWARF is valid as "Appendix A" is very much lax in what is allowed as attributes for "DW_TAG_formal_parameter": DWARF does not in general require that a given debugging information entry contain a particular attribute or set of attributes. Instead, a DWARF producer is free to generate any, all, or none of the attributes ... other attributes ... may also appear in a given debugging information entry. DWARF Debugging Information Format Version 5, Appendix A: Attributes by Tag Value (Informative) Page 251, Line 3. Differential Revision: https://reviews.llvm.org/D140970
2022-12-25[DebugInfo] make DW_LANG_C11 respect -gstrict-dwarfChen Zheng1-2/+2
Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D140544
2022-12-21[Clang][CGDebugInfo][ObjC] Mark objc bitfields with the DIFlagBitfield flagJuan Manuel MARTINEZ CAAMAÑO1-0/+3
Reviewed By: aprantl Differential Revision: https://reviews.llvm.org/D140195
2022-12-20[Clang] Prepare for llvm::Optional becoming std::optional.Benjamin Kramer1-1/+1
The needed tweaks are mostly trivial, the one nasty bit is Clang's usage of OptionalStorage. To keep this working old Optional stays around as clang::CustomizableOptional, with the default Storage removed. Optional<File/DirectoryEntryRef> is replaced with a typedef. I tested this with GCC 7.5, the oldest supported GCC I had around. Differential Revision: https://reviews.llvm.org/D140332
2022-12-18Revert "[clang] Convert OptionalFileEntryRefDegradesToFileEntryPtr to ↵Krzysztof Parzyszek1-1/+1
std::optional" This reverts commit 8f0df9f3bbc6d7f3d5cbfd955c5ee4404c53a75d. The Optional*RefDegradesTo*EntryPtr types want to keep the same size as the underlying type, which std::optional doesn't guarantee. For use with llvm::Optional, they define their own storage class, and there is no way to do that in std::optional. On top of that, that commit broke builds with older GCCs, where std::optional was not trivially copyable (static_assert in the clang sources was failing).
2022-12-17[clang] Convert OptionalFileEntryRefDegradesToFileEntryPtr to std::optionalKrzysztof Parzyszek1-1/+1
2022-12-16[clang][DebugInfo] Add DW_AT_default_value support for template template ↵Michael Buch1-1/+1
parameters After this patch, in the following snippet: ``` template <typename T> Foo {}; template <template <typename T> class CT = Foo> Bar {}; Bar<> b; ``` The debug-info entry for the `CT` template parameter will have a `DW_AT_default_value (true)` attached to it. Differential Revision: https://reviews.llvm.org/D139989
2022-12-16[clang][DebugInfo] Simplify logic to determine DW_AT_default_value for ↵Michael Buch1-19/+7
template parameters DWARFv5 added support for labelling template parameters with DW_AT_default_value to indicate whether the particular instantiation defaulted parameter. The current implementation only supports a limited set of possible cases. Namely for non-value-dependent integral template parameters and simple type template parameters. Useful cases that don't work are: 1. Type template parameters with defaults that are themselves templates. E.g., ``` template<typename T1, typename T2 = Foo<T1>> class C1; template<typename T = Foo<int>> class C2; etc. ``` 2. Template template parameters `clang::isSubstitutedDefaultArgument` already implement the required logic to determine whether a template argument is defaulted. This patch re-uses this logic for DWARF CodeGen. Differential Revision: https://reviews.llvm.org/D139988
2022-12-14[clang][DebugInfo] Attach DW_AT_default_value to template arg metadata ↵Michael Buch1-1/+1
regardless of DwarfVersion **Summary** Starting with DWARFv5, DW_AT_default_value can be used to indicate that a template argument has a default value. With this patch Clang will attach the attribute to the debug metadata regardless of version. In a follow-up patch we will change llvm to emit this attribute in earlier versions of DWARF, unless compiling with -gstrict-dwarf. **Details** * Previously the DwarfVersion check in CGDebugInfo was inconsistent: For non-type template arguments we attached the attribute to the debug metadata in DWARFv5 only. Whereas for type template arguments we didn't have such a version restriction. With this patch we attach the attribute regardless of DWARF version (and instead offload the check to the AsmPrinter in a future patch).
2022-12-12Reapply "DebugInfo: Add/support new DW_LANG codes for recent C and C++ ↵David Blaikie1-5/+8
versions"" This may be a breaking change for consumers if they're trying to detect if code is C or C++, since it'll start using new codes that they may not be ready to recognize, in which case they may fall back to non-C handling. This caused regressions due to PS4 having a different default for C language version than other targets. Those tests were adapted to be relaxed about which C version is used. This reapplies commit 3c312e48f325c1b1ee11404ee6cfa08ee00037b0 Which was reverted by commit 6ab6085c77ef9bcdabf842342f63fba4291791a4. Differential Revision: https://reviews.llvm.org/D138597
2022-12-06Revert "DebugInfo: Add/support new DW_LANG codes for recent C and C++ versions"David Blaikie1-8/+5
Some buildbots are failing in Clang and LLDB tests. (I guess the LLDB failure is due to the explicit C language tests in DwarfUnit.cpp that need to be updated - not sure what the Clang failures are about, they seem to be still emitting C99 when we're expecting C11 and I checked those tests pass... maybe systems with a different C language version default?) This reverts commit 3c312e48f325c1b1ee11404ee6cfa08ee00037b0.
2022-12-06DebugInfo: Add/support new DW_LANG codes for recent C and C++ versionsDavid Blaikie1-5/+8
This may be a breaking change for consumers if they're trying to detect if code is C or C++, since it'll start using new codes that they may not be ready to recognize, in which case they may fall back to non-C handling. Differential Revision: https://reviews.llvm.org/D138597
2022-12-06[CodeView] Don't generate dummy unnamed strcut/class/union type.Zequan Wu1-1/+6
2022-12-04DebugInfoMetadata: convert Optional to std::optionalKrzysztof Parzyszek1-16/+19
2022-12-03[CodeGen] Use std::nullopt instead of None (NFC)Kazu Hirata1-11/+12
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-01[clang] Avoid duplicating ProgramAddressSpace in TargetInfo. NFCIAlex Richardson1-5/+4
This value was added to clang/Basic in D111566, but is only used during codegen, where we can use the LLVM IR DataLayout instead. I noticed this because the downstream CHERI targets would have to also set this value for AArch64/RISC-V/MIPS. Instead of duplicating more information between LLVM IR and Clang, this patch moves getTargetAddressSpace(QualType T) to CodeGenTypes, where we can consult the DataLayout. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D138296
2022-11-30[clang][TargetInfo] Use LangAS for getPointer{Width,Align}()Alex Richardson1-12/+9
Mixing LLVM and Clang address spaces can result in subtle bugs, and there is no need for this hook to use the LLVM IR level address spaces. Most of this change is just replacing zero with LangAS::Default, but it also allows us to remove a few calls to getTargetAddressSpace(). This also removes a stale comment+workaround in CGDebugInfo::CreatePointerLikeType(): ASTContext::getTypeSize() does return the expected size for ReferenceType (and handles address spaces). Differential Revision: https://reviews.llvm.org/D138295
2022-10-28[clang][DebugInfo] Emit DISubprogram for extern functions with reserved namesEduard Zingerman1-9/+3
Callsite `DISubprogram` entries are not generated for: - builtin functions; - external functions with reserved names (e.g. names starting from "__"). This limitation was added by the commit [1] as a workaround for the situation described in [2] that triggered the IR verifier error. The goal of the present commit is to lift this limitation by adjusting the IR verifier logic. The logic behind [1] is to avoid the following situation: - a `DISubprogram` is added for some builtin function; - there is some location where this builtin is also emitted by a transformation (w/o debug location); - the `Verifier::visitCallBase` sees a call to a function with `DISubprogram` but w/o debug location and emits an error. Here is an updated example of such situation taken from [2]: ``` extern "C" int memcmp(void *, void *, long); struct a { int b; int c; int d; }; struct e { int f[1000]; }; bool foo(e g, e &h) { // DISubprogram for memcmp is created here when [1] is commented out return memcmp(&g, &h, sizeof(e)); } bool bar(a &g, a &h) { // memcmp might be generated here by MergeICmps return g.b == h.b && g.c == h.c && g.d == h.d; } ``` This triggers the verifier error when: - compiled for AArch64: `clang++ -c -g -Oz -target aarch64-unknown-linux-android21 test.cpp`; - [1] check is commented out. Instead of forbidding generation of `DISubprogram` entries as in [1] one can instead adjust the verifier to additionally check if callee has a body. Functions w/o bodies cannot be inlined and thus verifier warning is not necessary. E.g. `llvm::InlineFunction` requires functions for which `GlobalValue::isDeclaration() == false`. [1] 568db780bb7267651a902da8e85bc59fc89aea70 [2] https://bugs.chromium.org/p/chromium/issues/detail?id=1022296 Differential Revision: https://reviews.llvm.org/D136041
2022-10-04[clang][DebugInfo] Respect fmodule-file-home-is-cwd in skeleton CUs for ↵Alex Langford1-2/+6
clang modules When -fmodule-file-home-is-cwd and the path to the PCM is relative, we shouldn't assume that the path to the PCM is relative to the modulemap that produced it. To respect the option -fmodule-file-home-is-cwd, we should assume the path is relative to the current working directory. Reviewed By: rmaz Differential Revision: https://reviews.llvm.org/D134911
2022-09-28[C2x] implement typeof and typeof_unqualAaron Ballman1-1/+1
This implements WG14 N2927 and WG14 N2930, which together define the feature for typeof and typeof_unqual, which get the type of their argument as either fully qualified or fully unqualified. The argument to either operator is either a type name or an expression. If given a type name, the type information is pulled directly from the given name. If given an expression, the type information is pulled from the expression. Recursive use of these operators is allowed and has the expected behavior (the innermost operator is resolved to a type, and that's used to resolve the next layer of typeof specifier, until a fully resolved type is determined. Note, we already supported typeof in GNU mode as a non-conforming extension and we are *not* exposing typeof_unqual as a non-conforming extension in that mode, nor are we exposing typeof or typeof_unqual as a nonconforming extension in other language modes. The GNU variant of typeof supports a form where the parentheses are elided from the operator when given an expression (e.g., typeof 0 i = 12;). When in C2x mode, we do not support this extension. Differential Revision: https://reviews.llvm.org/D134286
2022-09-26Fix MSVC "not all control paths return a value" warning. NFCI.Simon Pilgrim1-0/+1
2022-09-25[clang-cl] Implement /ZH: flagNico Weber1-7/+17
Based on a patch by Arlo Siemsen (D98438)! Differential Revision: https://reviews.llvm.org/D134544
2022-09-22[clang][DebugInfo] Emit access specifiers for typedefsJonathan Camilleri1-28/+34
The accessibility level of a typedef or using declaration in a struct or class was being lost when producing debug information. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D134339
2022-09-16[clang] Fixes how we represent / emulate builtin templatesMatheus Izvekov1-3/+4
We change the template specialization of builtin templates to behave like aliases. Though unlike real alias templates, these might still produce a canonical TemplateSpecializationType when some important argument is dependent. For example, we can't do anything about make_integer_seq when the count is dependent, or a type_pack_element when the index is dependent. We change type deduction to not try to deduce canonical TSTs of builtin templates. We also change those buitin templates to produce substitution sugar, just like a real instantiation would, making the resulting type correctly represent the template arguments used to specialize the underlying template. And make_integer_seq will now produce a TST for the specialization of it's first argument, which we use as the underlying type of the builtin alias. When performing member access on the resulting type, it's now possible to map from a Subst* node to the template argument as-written used in a regular fashion, without special casing. And this fixes a bunch of bugs with relation to these builtin templates factoring into deduction. Fixes GH42102 and GH51928. Depends on D133261 Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D133262
2022-09-03[clang] Qualify auto in range-based for loops (NFC)Kazu Hirata1-1/+1