aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/AST/ASTImporterTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
25 hoursNFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151782)James Y Knight1-3/+4
This commit handles the following types: - clang::ExternalASTSource - clang::TargetInfo - clang::ASTContext - clang::SourceManager - clang::FileManager Part of cleanup #151026
2025-07-09Ast importer visitors (#138838)ganenkokb-yandex1-0/+97
I've rebased commit from [Evianaive](https://github.com/Evianaive/llvm-project/commits?author=Evianaive) and compiled it. I hope it will speed up fix for #129393. --------- Co-authored-by: Evianaive <153540933@qq.com>
2025-05-26Thread Safety Analysis: Support reentrant capabilities (#137133)Marco Elver1-0/+9
Introduce the `reentrant_capability` attribute, which may be specified alongside the `capability(..)` attribute to denote that the defined capability type is reentrant. Marking a capability as reentrant means that acquiring the same capability multiple times is safe, and does not produce warnings on attempted re-acquisition. The most significant changes required are plumbing to propagate if the attribute is present to a CapabilityExpr, and introducing ReentrancyDepth to the LockableFactEntry class.
2025-05-14[clang] Save ShuffleVectorExpr args as ConstantExpr (#139709)Timm Baeder1-2/+4
The passed indices have to be constant integers anyway, which we verify before creating the ShuffleVectorExpr. Use the value we create there and save the indices using a ConstantExpr instead. This way, we don't have to evaluate the args every time we call getShuffleMaskIdx().
2025-05-06[clang][ASTImporter] Fix AST import if anonymous namespaces are merged (#128735)Balázs Kéri1-0/+76
Fix of a faulty case that is shown in the second of the added tests (an anonymous namespace is imported that resides in a `extern "C"` block).
2025-04-15Merge similar Clang Thread Safety attributes (#135561)Aaron Puchert1-36/+0
Some of the old lock-based and new capability-based spellings behave basically in the same way, so merging them simplifies the code significantly. There are two minor functional changes: we only warn (instead of an error) when the try_acquire_capability attribute is used on something else than a function. The alternative would have been to produce an error for the old spelling, but we seem to only warn for all function attributes, so this is arguably more consistent. The second change is that we also check the first argument (which is the value returned for a successful try-acquire) for `this`. But from what I can tell, this code is defunct anyway at the moment (see #31414).
2025-04-03[clang] NFC: introduce UnsignedOrNone as a replacement for ↵Matheus Izvekov1-6/+6
std::optional<unsigned> (#134142) This introduces a new class 'UnsignedOrNone', which models a lite version of `std::optional<unsigned>`, but has the same size as 'unsigned'. This replaces most uses of `std::optional<unsigned>`, and similar schemes utilizing 'int' and '-1' as sentinel. Besides the smaller size advantage, this is simpler to serialize, as its internal representation is a single unsigned int as well.
2025-02-02[clang] Add tracking source deduction guide for the explicitly-writtenHaojian Wu1-0/+23
deduction guide. We miss this case in the original f94c481543bdd3b11a668ad78d46593cf974788f commit.
2025-01-27[clang] Track source deduction guide for alias template deduction guides ↵antangelo1-0/+26
(#123875) For deduction guides generated from alias template CTAD, store the deduction guide they were originated from. The source kind is also maintained for future expansion in CTAD from inherited constructors. This tracking is required to determine whether an alias template already has a deduction guide corresponding to some deduction guide on the original template, in order to support deduction guides for the alias from deduction guides declared after the initial usage.
2025-01-27[clang][ASTImporter] Import source location of explicit object parameter ↵Michael Buch1-0/+20
instead of copying it (#124305) We used to copy the `SourceLocation` instead of importing it, which isn't correct since the `SourceManager`'s of the source and target ASTContext might differ. Also adds test that confirms that we import the explicit object parameter location for `ParmVarDecl`s. This is how Clang determines whether a parameter `isExplicitObjectParamater`. The LLDB expression evaluator relies on this for calling "explicit object member functions".
2025-01-13[clang][ASTImporter] Fix unused variable warning (NFC) (#122686)Balázs Kéri1-2/+2
2025-01-13[clang][ASTImporter] Not using primary context in lookup table (#118466)Balázs Kéri1-2/+150
`ASTImporterLookupTable` did use the `getPrimaryContext` function to get the declaration context of the inserted items. This is problematic because the primary context can change during import of AST items, most likely if a definition of a previously not defined class is imported. (For any record the primary context is the definition if there is one.) The use of primary context is really not important, only for namespaces because these can be re-opened and lookup in one namespace block is not enough. This special search is now moved into ASTImporter instead of relying on the lookup table.
2025-01-11[AST] Fix a warningKazu Hirata1-1/+0
This patch fixes: clang/unittests/AST/ASTImporterTest.cpp:3397:9: error: unused variable 'ToTU' [-Werror,-Wunused-variable]
2025-01-11Reapply "[clang] Avoid re-evaluating field bitwidth" (#122289)Timm Baeder1-2/+2
2025-01-08Revert "[clang] Avoid re-evaluating field bitwidth (#117732)"Timm Bäder1-2/+2
This reverts commit 81fc3add1e627c23b7270fe2739cdacc09063e54. This breaks some LLDB tests, e.g. SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp: lldb: ../llvm-project/clang/lib/AST/Decl.cpp:4604: unsigned int clang::FieldDecl::getBitWidthValue() const: Assertion `isa<ConstantExpr>(getBitWidth())' failed.
2025-01-08[clang] Avoid re-evaluating field bitwidth (#117732)Timm Baeder1-2/+2
Save the bitwidth value as a `ConstantExpr` with the value set. Remove the `ASTContext` parameter from `getBitWidthValue()`, so the latter simply returns the value from the `ConstantExpr` instead of constant-evaluating the bitwidth expression every time it is called.
2025-01-03[Clang][ASTMatcher] Add `dependentTemplateSpecializationType` matcher (#121435)kefan cao1-4/+0
Fixes https://github.com/llvm/llvm-project/issues/121307
2024-12-29[Clang][ASTMatcher] Add `dependentNameType` AST matcher (#121263)Amr Hesham1-3/+0
Fixes: https://github.com/llvm/llvm-project/issues/121240
2024-12-27[Clang][ASTMatcher] Add `dependentScopeDeclRefExpr` matcher (#120996)Amr Hesham1-3/+0
Fixes https://github.com/llvm/llvm-project/issues/120937
2024-12-14[AST] Migrate away from PointerUnion::get (NFC) (#119949)Kazu Hirata1-1/+1
Note that PointerUnion::get has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T>
2024-12-02[clang][ASTImporter] Allow import of similar friend template with different ↵Balázs Kéri1-0/+105
depth (#115734) This fix applies to a case that occurs when the AST contains a friend template that is contained within another template and this (outer) template has specialization. (See the added test code in the commit.)
2024-10-18[clang][ASTImporter] Fix of unchecked Error object (#112688)Balázs Kéri1-0/+28
After commits 9c72a30 and 30a9cac error handling in function 'importTemplateParameterDefaultArgument' was not correct, probably related to (not) using std::move. A crash with unchecked Error result could happen when the import error path was taken. Here a test is added that reproduces this case and the problem is fixed.
2024-09-06[clang][ASTImporter] New fix for default template parameter values. (#101836)Balázs Kéri1-68/+266
Commit e4440b8 added a change that introduced new crash in an incorrectly handled case. This is fixed here. Default argument definition or inheritance is preserved in the "To" AST compared to the "From". If the default argument is defined already in the "To" AST it can be duplicated at the import.
2024-08-07[clang][ASTImporter] support import return with UnaryTransformType (#101517)Ding Fei1-0/+19
This fixes infinite recursion crash on return with UnaryTransformType, whose underlying type is a SubstTemplateTypeParmType which is associated with current imported function.
2024-08-07[clang][ASTImporter] Remove trailing return testing on lambda proto (#101031)Ding Fei1-0/+17
Lambdas without trailing return could also have return type defined inside its body. This fixes crashes (infinite recursion) on lambda expr without parameters (no parentheses).
2024-07-30[clang][ASTImporter] Fix import of template parameter default values. (#100100)Balázs Kéri1-0/+125
Default values of template parameters (non-type, type, template) were not correctly handled in the "inherited" case. This occurs if the first declaration contains the default value but a next one not. The default value is "inherited" from the first. In ASTImporter it was only possible to set the inherited status after the template object was created with the template parameters that were imported without handling the inherited case. The import function of the template parameter contains not enough information (previous declaration) to set the inherited-from status. After the template was created, default value of the parameters that should be inherited is reset to inherited mode.
2024-07-29Revert "Reland [clang][ASTImport] Add support for import of empty records" ↵Michael Buch1-23/+0
(#100903) This reverts commit 88e5206f2c96a34e23a4d63f0a38afb2db044f0a. The original change went in a while ago (last year) in https://reviews.llvm.org/D145057. The specific reason I'm proposing a revert is that this is now causing exactly the issue that @balazske predicted in https://reviews.llvm.org/D145057#4164717: > Problematic case is if the attribute has pointer to a Decl or Type that is imported here in a state when the field is already created but not initialized. Another problem is that attributes are added a second time in Import(Decl *) This now came up in the testing of LLDB support for https://github.com/llvm/llvm-project/issues/93069. There, `__compressed_pair`s are now replaced with fields that have an `alignof(...)` and `[[no_unique_address]]` attribute. In the specific failing case, we're importing following `std::list` method: ``` size_type& __sz() _NOEXCEPT { return __size_; } ``` During this process, we create a new `__size_` `FieldDecl` (but don't initialize it yet). Then we go down the `ImportAttrs` codepath added in D145057. This imports the `alignof` expression which then references the uninitialized `__size_` and we trigger an assertion. Important to note, this codepath was added specifically to support `[[no_unique_address]]` in LLDB, and was supposed to land with https://reviews.llvm.org/D143347. But the LLDB side of that never landed, and the way we plan to support `[[no_unique_address]]` doesn't require things like the `markEmpty` method added here. So really, this is a dead codepath, which as pointed out in the original review isn't fully sound.
2024-07-26[clang][ASTImporter][NFC] add unittests for unnamed EnumDecl (#100545)Ding Fei1-0/+37
These tests are for multiple anonymous EnumDecls structural eq test & importing. We found the anonymous enums importing issue a few days ago and tried to fix it but 0a6233a68c7b575d05bca0f0c708b7e97cc710d1 already did this. I think these tests are still useful for regressions.
2024-07-23[clang][ASTImporter] Fix import of anonymous enums if multiple are present ↵Balázs Kéri1-13/+82
(#99281) After changes in PR #87144 and #93923 regressions appeared in some cases. The problem was that if multiple anonymous enums are present in a class and are imported as new the import of the second enum can fail because it is detected as different from the first and causes ODR error. Now in case of enums without name an existing similar enum is searched, if not found the enum is imported. ODR error is not detected. This may be incorrect if non-matching structures are imported, but this is the less important case (import of matching classes is more important to work).
2024-07-01[clang][ThreadSafety] Revert stricter typing on trylock attributes (#97293)Dan McArdle1-3/+3
This PR reverts #95290 and the one-liner followup PR #96494. I received some substantial feedback on #95290, which I plan to address in a future PR. I've also received feedback that because the change emits errors where they were not emitted before, we should at least have a flag to disable the stricter warnings.
2024-06-24[clang][ThreadSafety] Check trylock function success and return types (#95290)Dan McArdle1-3/+3
With this change, Clang will generate errors when trylock functions have improper return types. Today, it silently fails to apply the trylock attribute to these functions which may incorrectly lead users to believe they have correctly acquired locks before accessing guarded data. As a side effect of explicitly checking the success argument type, I seem to have fixed a false negative in the analysis that could occur when a trylock's success argument is an enumerator. I've added a regression test to warn-thread-safety-analysis.cpp named `TrylockSuccessEnumFalseNegative`. This change also improves the documentation with descriptions of of the subtle gotchas that arise from the analysis interpreting the success arg as a boolean. Issue #92408
2024-06-04[clang][ASTImport] fix issue on anonymous enum import (#93923)Qizhi Hu1-0/+40
Don't skip searching in `ToContext` during importing `EnumDecl`. And `IsStructuralMatch` in `StructralEquivalence` can make sure to determine whether the found result is match or not. --------- Co-authored-by: huqizhi <836744285@qq.com>
2024-05-22[clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (#92852)Matheus Izvekov1-1/+1
This is an enabler for https://github.com/llvm/llvm-project/pull/92855 This allows an NTTP default argument to be set as an arbitrary TemplateArgument, not just an expression. This allows template parameter packs to have default arguments in the AST, even though the language proper doesn't support the syntax for it. This allows NTTP default arguments to be other kinds of arguments, like packs, integral constants, and such.
2024-05-21[clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (#92854)Matheus Izvekov1-1/+1
This is an enabler for a future patch. This allows an type-parameter default argument to be set as an arbitrary TemplateArgument, not just a type. This allows template parameter packs to have default arguments in the AST, even though the language proper doesn't support the syntax for it. This will be used in a later patch which synthesizes template parameter lists with arbitrary default arguments taken from template specializations. There are a few places we used SubsType, because we only had a type, now we use SubstTemplateArgument. SubstTemplateArgument was missing arguments for setting Instantiation location and entity names. Adding those is needed so we don't regress in diagnostics.
2024-04-20[ASTImporter] Fix infinite recurse on return type declared inside body (#68775)Ding Fei1-0/+17
Lambda without trailing auto could have return type declared inside the body too. Fixes #68775
2024-04-05[clang][ASTImporter] fix variable inline of CXX17 (#87314)Qizhi Hu1-0/+28
Fix crash in the testcase from https://github.com/llvm/llvm-project/issues/75114#issuecomment-1872595956 Forget to set inline of variable declaration would make `isThisDeclarationADefinition` get incorrect result and didn't get imported variable. This will lead to a new `VarTemplateDecl` being created and call `setDescribedVarTemplate` again which produces the crash. Co-authored-by: huqizhi <836744285@qq.com>
2024-01-29[clang][ASTImporter] Improve import of variable template specializations. ↵Balázs Kéri1-1/+53
(#78284) Code of `VisitVarTemplateSpecializationDecl` was rewritten based on code of `VisitVarDecl`. Additional changes (in structural equivalence) were made to make tests pass.
2024-01-16[clang][ASTMatcher] Add matchers for CXXFoldExpr (#71245)Julian Schmidt1-17/+10
Adds support for the following matchers related to `CXXFoldExpr`: `cxxFoldExpr`, `callee`, `hasInit`, `hasPattern`, `isRightFold`, `isLeftFold`, `isUnaryFold`, `isBinaryFold`, `hasOperator`, `hasLHS`, `hasRHS`.
2024-01-15[clang][ASTImporter] Fix import of variable template redeclarations. (#72841)Balázs Kéri1-0/+53
In some cases variable templates (specially if static member of record) were not correctly imported and an assertion "Missing call to MapImported?" could happen.
2024-01-11[clang][ASTImporter] Improve import of friend class templates. (#74627)Balázs Kéri1-0/+156
A friend template that is in a dependent context is not linked into declaration chains (for example with the definition of the befriended template). This condition was not correctly handled by `ASTImporter`.
2024-01-04[clang][ASTImporter] import InstantiatedFromMember of ↵Qizhi Hu1-0/+33
ClassTemplateSpecializationDecl (#76493) import of `ClassTemplateSpecializationDecl` didn't set `InstantiatedFromMember` and this makes ast-dump crash. import and set `InstantiatedFromMember`. fix [issue](https://github.com/llvm/llvm-project/issues/76469) Co-authored-by: huqizhi <836744285@qq.com>
2023-12-25[clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl ↵Qizhi Hu1-0/+47
(#74919) Skip checking `TemplateTypeParmDecl ` in `VisitTypeAliasTemplateDecl`. [Fix this crash](https://github.com/llvm/llvm-project/issues/74765) Co-authored-by: huqizhi <836744285@qq.com>
2023-12-22[clang][ASTImporter] Support Importer of BuiltinBitCastExpr (#74813)Qizhi Hu1-0/+12
Since import `ExplicitCastExpr` lacks of processing `BuiltinBitCastExprClass` type, it would reach to the 'unreachable' code and produce the crash. This patch aims to fix the [crash](https://github.com/llvm/llvm-project/issues/74774) and try to handle `BuiltinBitCastExpr`. Co-authored-by: huqizhi <836744285@qq.com>
2023-12-22[clang][ASTImporter] Import AlignValueAttr correctly. (#75308)Balázs Kéri1-46/+25
Expression of attribute `align_value` was not imported. Import of the attribute is corrected, a test for it is added, other related tests with FIXME are updated. Fixes #75054.
2023-12-21[clang][ASTImporter] add processing of SubstNonTypeTemplateParmExpr in ↵Qizhi Hu1-0/+20
isAncestorDeclContextOf (#74991) Lack of processing of `SubstNonTypeTemplateParmExpr` in `isAncestorDeclContextOf` would make `hasAutoReturnTypeDeclaredInside` returns false and lead to infinite recursion. This patch adds the processor and try to fix [this issue](https://github.com/llvm/llvm-project/issues/74839) Co-authored-by: huqizhi <836744285@qq.com>
2023-11-29[clang][ASTImporter] IdentifierInfo of Attribute should be set using ↵Qizhi Hu1-2/+11
'ToASTContext' (#73290) Co-authored-by: huqizhi <836744285@qq.com>
2023-11-24[clang][ASTImporter] Fix import of SubstTemplateTypeParmType in return type ↵Balázs Kéri1-3/+20
of function. (#69724) Import of a function with `auto` return type that is expanded to a `SubstTemplateTypeParmType` could fail if the function itself is the template specialization where the parameter was replaced.
2023-11-03[clang][NFC] Refactor `TagTypeKind` (#71160)Vlad Serebrennikov1-2/+3
This patch converts TagTypeKind into scoped enum. Among other benefits, this allows us to forward-declare it where necessary.
2023-11-01[clang][ASTImporter] Fix crash when template class static member imported to ↵Exile1-0/+34
other translation unit. (#68774) Fixes: #68769 Co-authored-by: miaozhiyuan <miaozhiyuan@feysh.com>
2023-10-26[AST] Only dump desugared type when visibly different (#65214)Jessica Clarke1-1/+1
These are an artifact of how types are structured but serve little purpose, merely showing that the type is sugared in some way. For example, ElaboratedType's existence means struct S gets printed as 'struct S':'struct S' in the AST, which is unnecessary visual clutter. Note that skipping the second print when the types have the same string matches what we do for diagnostics, where the aka will be skipped.