aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/DeclBase.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-05-27Also remove the empty StoredDeclsList entry from the lookup tableVassil Vassilev1-1/+5
In case where we have removed all declarations for a given declaration name entry we should remove the whole StoredDeclsMap entry. This patch improves consistency in the lookup tables and helps cling/clang-repl error recovery. Differential revision: https://reviews.llvm.org/D119675
2022-05-09Revert ""Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation"""""Erich Keane1-10/+0
This reverts commit a425cac31e2e4cee8e14b7b9a99c8ba17c1ebb52. There is another libc++ test, that this time causes us to hit an assertion. Reverting, likely for a while this time.
2022-05-09"Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation""""Erich Keane1-0/+10
This includes a fix for the libc++ issue I ran across with friend declarations not properly being identified as overloads. This reverts commit 45c07db31cc76802a1a2e41bed1ce9c1b8198181.
2022-05-02Revert "Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation"""Erich Keane1-10/+0
This reverts commit a97899108e495147985e5e9492e742d51d5cc97a. The patch caused some problems with the libc++ `__range_adaptor_closure` that I haven't been able to figure out the cause of, so I am reverting while I figure out whether this is a solvable problem/issue with the CFE, or libc++ depending on an older 'incorrect' behavior.
2022-05-02Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation""Erich Keane1-0/+10
This reverts commit 0c31da48389754822dc3eecc4723160c295b9ab2. I've solved the issue with the PointerUnion by making the `FunctionTemplateDecl` pointer be a NamedDecl, that could be a `FunctionDecl` or `FunctionTemplateDecl` depending. This is enforced with an assert.
2022-05-02Revert "Deferred Concept Instantiation Implementation"Erich Keane1-10/+0
This reverts commit 4b6c2cd647e9e5a147954886338f97ffb6a1bcfb. The patch caused numerous ARM 32 bit build failures, since we added a 5th item to the PointerUnion, and went over the 2-bits available in the 32 bit pointers.
2022-05-02Deferred Concept Instantiation ImplementationErich Keane1-0/+10
As reported here: https://github.com/llvm/llvm-project/issues/44178 Concepts are not supposed to be instantiated until they are checked, so this patch implements that and goes through significant amounts of work to make sure we properly re-instantiate the concepts correctly. Differential Revision: https://reviews.llvm.org/D119544
2022-03-28[Clang] Implement __builtin_source_location.James Y Knight1-0/+1
This builtin returns the address of a global instance of the `std::source_location::__impl` type, which must be defined (with an appropriate shape) before calling the builtin. It will be used to implement std::source_location in libc++ in a future change. The builtin is compatible with GCC's implementation, and libstdc++'s usage. An intentional divergence is that GCC declares the builtin's return type to be `const void*` (for ease-of-implementation reasons), while Clang uses the actual type, `const std::source_location::__impl*`. In order to support this new functionality, I've also added a new 'UnnamedGlobalConstantDecl'. This artificial Decl is modeled after MSGuidDecl, and is used to represent a generic concept of an lvalue constant with global scope, deduplicated by its value. It's possible that MSGuidDecl itself, or some of the other similar sorts of things in Clang might be able to be refactored onto this more-generic concept, but there's enough special-case weirdness in MSGuidDecl that I gave up attempting to share code there, at least for now. Finally, for compatibility with libstdc++'s <source_location> header, I've added a second exception to the "cannot cast from void* to T* in constant evaluation" rule. This seems a bit distasteful, but feels like the best available option. Reviewers: aaron.ballman, erichkeane Differential Revision: https://reviews.llvm.org/D120159
2022-03-25[Clang] Fix Unevaluated LambdasCorentin Jabot1-0/+2
Unlike other types, when lambdas are instanciated, they are recreated from scratch. When an unevaluated lambdas appear in the type of a function, parameter it is instanciated in the wrong declaration context, as parameters are transformed before the function. To support lambda in function parameters, we try to compute whether they are dependant without looking at the declaration context. This is a short term stopgap solution to avoid clang iceing. A better fix might be to inject some kind of transparent declaration with correctly computed dependency for function parameters, variable templates, etc. Fixes https://github.com/llvm/llvm-project/issues/50376 Fixes https://github.com/llvm/llvm-project/issues/51414 Fixes https://github.com/llvm/llvm-project/issues/51416 Fixes https://github.com/llvm/llvm-project/issues/51641 Fixes https://github.com/llvm/llvm-project/issues/54296 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D121532
2022-01-24[C++20] [Module] fix bug 47716 and implement [module.interface]/p6Chuanqi Xu1-0/+9
This fixes bug 47716. According to [module.interface]p2, it is meaningless to export an entity which is not in namespace scope. The reason why the compiler crashes is that the compiler missed ExportDecl when the compiler traverse the subclass of DeclContext. So here is the crash. Also, the patch implements [module.interface]p6 in Sema::CheckRedeclaration* functions. Reviewed By: aaron.ballman, urnathan Differential Revision: https://reviews.llvm.org/D112903
2022-01-11[AST] lookup in parent DeclContext for transparent DeclContextChuanqi Xu1-3/+3
The compiler would crash if we lookup for name in transparent decl context. See the tests attached for example. I think this should make sense since the member declared in transparent DeclContext are semantically defined in the enclosing (non-transparent) DeclContext, this is the definition for transparent DeclContext. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D116792
2022-01-11[AST] Don't consider 'ExportDecl' when calculating DeclContext 'Encloses'Chuanqi Xu1-1/+2
This mimics the style of 90010c2e1 (Don't consider 'LinkageSpec' when calculating DeclContext 'Encloses'). Since ExportDecl and LinkageSpec are transparent DeclContext, they share some similarity. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D116911
2021-11-29Don't consider 'LinkageSpec' when calculating DeclContext 'Encloses'Erich Keane1-1/+1
We don't properly handle lookup through using directives when there is a linkage spec in the common chain. This is because `CppLookupName` and `CppNamespaceLookup` end up skipping `LinkageSpec`'s (correctly, as they are not lookup scopes), but the `UnqualUsingDirectiveSet` does not. I discovered that when we are calculating the `CommonAncestor` for a using-directive, we were coming up with the `LinkageSpec`, instead of the `LinkageSpec`'s parent. Then, when we use `UnqualUsingDirectiveSet::getNamespacesFor` a scope, we don't end up finding any that were in the `LinkageSpec` (again, since `CppLookupName` skips linkage specs), so those don't end up participating in the lookup. The function `UnqualUsingDirectiveSet::addUsingDirective` calculates this common ancestor via a loop through the the `DeclSpec::Encloses` function. Changing this Encloses function to believe that a `LinkageSpec` `Encloses` nothing ends up fixing the problem without breaking any other tests, so I opted to do that. A less aggressive patch could perhaps change only the `addUsingDirective`, but my examination of all uses of `Encloses` showed that it seems to be used exclusively in lookup, which makes me think this is correct everywhere. Differential Revision: https://reviews.llvm.org/D113709
2021-11-25[clang][NFC] Inclusive terms: rename AccessDeclContextSanity to ↵Zarko Todorovski1-1/+1
AccessDeclContextCheck Rename function to more inclusive name. Reviewed By: quinnp Differential Revision: https://reviews.llvm.org/D114029
2021-10-14[clang] Support -clear-ast-before-backend without -disable-freeArthur Eubanks1-0/+1
Previously without -disable-free, -clear-ast-before-backend would crash in ~ASTContext() due to various reasons. This works around that by doing a lot of the cleanup ahead of the destructor so that the destructor doesn't actually do any manual cleanup if we've already cleaned up beforehand. This actually does save a measurable amount of memory with -clear-ast-before-backend, although at an almost unnoticeable runtime cost: https://llvm-compile-time-tracker.com/compare.php?from=5d755b32f2775b9219f6d6e2feda5e1417dc993b&to=58ef1c7ad7e2ad45f9c97597905a8cf05a26258c&stat=max-rss Previously we weren't doing any cleanup with -disable-free, so I tried measuring the impact of always doing the cleanup and didn't measure anything noticeable on llvm-compile-time-tracker. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D111767
2021-08-20Replace an unnecessary null check with an assert; NFCAaron Ballman1-1/+3
2021-08-20Fix assertion when generating diagnostic for inline namespacesAaron Ballman1-0/+7
When calculating the name to display for inline namespaces, we have custom logic to try to hide redundant inline namespaces from the diagnostic. Calculating these redundancies requires performing a lookup in the parent declaration context, but that lookup should not try to look through transparent declaration contexts, like linkage specifications. Instead, loop up the declaration context chain until we find a non-transparent context and use that instead. This fixes PR49954.
2021-07-12Reland "[clang-repl] Implement partial translation units and error recovery."Vassil Vassilev1-13/+18
Original commit message: [clang-repl] Implement partial translation units and error recovery. https://reviews.llvm.org/D96033 contained a discussion regarding efficient modeling of error recovery. @rjmccall has outlined the key ideas: Conceptually, we can split the translation unit into a sequence of partial translation units (PTUs). Every declaration will be associated with a unique PTU that owns it. The first key insight here is that the owning PTU isn't always the "active" (most recent) PTU, and it isn't always the PTU that the declaration "comes from". A new declaration (that isn't a redeclaration or specialization of anything) does belong to the active PTU. A template specialization, however, belongs to the most recent PTU of all the declarations in its signature - mostly that means that it can be pulled into a more recent PTU by its template arguments. The second key insight is that processing a PTU might extend an earlier PTU. Rolling back the later PTU shouldn't throw that extension away. For example, if the second PTU defines a template, and the third PTU requires that template to be instantiated at float, that template specialization is still part of the second PTU. Similarly, if the fifth PTU uses an inline function belonging to the fourth, that definition still belongs to the fourth. When we go to emit code in a new PTU, we map each declaration we have to emit back to its owning PTU and emit it in a new module for just the extensions to that PTU. We keep track of all the modules we've emitted for a PTU so that we can unload them all if we decide to roll it back. Most declarations/definitions will only refer to entities from the same or earlier PTUs. However, it is possible (primarily by defining a previously-declared entity, but also through templates or ADL) for an entity that belongs to one PTU to refer to something from a later PTU. We will have to keep track of this and prevent unwinding to later PTU when we recognize it. Fortunately, this should be very rare; and crucially, we don't have to do the bookkeeping for this if we've only got one PTU, e.g. in normal compilation. Otherwise, PTUs after the first just need to record enough metadata to be able to revert any changes they've made to declarations belonging to earlier PTUs, e.g. to redeclaration chains or template specialization lists. It should even eventually be possible for PTUs to provide their own slab allocators which can be thrown away as part of rolling back the PTU. We can maintain a notion of the active allocator and allocate things like Stmt/Expr nodes in it, temporarily changing it to the appropriate PTU whenever we go to do something like instantiate a function template. More care will be required when allocating declarations and types, though. We would want the PTU to be efficiently recoverable from a Decl; I'm not sure how best to do that. An easy option that would cover most declarations would be to make multiple TranslationUnitDecls and parent the declarations appropriately, but I don't think that's good enough for things like member function templates, since an instantiation of that would still be parented by its original class. Maybe we can work this into the DC chain somehow, like how lexical DCs are. We add a different kind of translation unit `TU_Incremental` which is a complete translation unit that we might nonetheless incrementally extend later. Because it is complete (and we might want to generate code for it), we do perform template instantiation, but because it might be extended later, we don't warn if it declares or uses undefined internal-linkage symbols. This patch teaches clang-repl how to recover from errors by disconnecting the most recent PTU and update the primary PTU lookup tables. For instance: ```./clang-repl clang-repl> int i = 12; error; In file included from <<< inputs >>>:1: input_line_0:1:13: error: C++ requires a type specifier for all declarations int i = 12; error; ^ error: Parsing failed. clang-repl> int i = 13; extern "C" int printf(const char*,...); clang-repl> auto r1 = printf("i=%d\n", i); i=13 clang-repl> quit ``` Differential revision: https://reviews.llvm.org/D104918
2021-07-11Revert "[clang-repl] Implement partial translation units and error recovery."Vassil Vassilev1-18/+13
This reverts commit 6775fc6ffa3ca1c36b20c25fa4e7f48f81213cf2. It also reverts "[lldb] Fix compilation by adjusting to the new ASTContext signature." This reverts commit 03a3f86071c10a1f6cbbf7375aa6fe9d94168972. We see some failures on the lldb infrastructure, these changes might play a role in it. Let's revert it now and see if the bots will become green. Ref: https://reviews.llvm.org/D104918
2021-07-11[clang-repl] Implement partial translation units and error recovery.Vassil Vassilev1-13/+18
https://reviews.llvm.org/D96033 contained a discussion regarding efficient modeling of error recovery. @rjmccall has outlined the key ideas: Conceptually, we can split the translation unit into a sequence of partial translation units (PTUs). Every declaration will be associated with a unique PTU that owns it. The first key insight here is that the owning PTU isn't always the "active" (most recent) PTU, and it isn't always the PTU that the declaration "comes from". A new declaration (that isn't a redeclaration or specialization of anything) does belong to the active PTU. A template specialization, however, belongs to the most recent PTU of all the declarations in its signature - mostly that means that it can be pulled into a more recent PTU by its template arguments. The second key insight is that processing a PTU might extend an earlier PTU. Rolling back the later PTU shouldn't throw that extension away. For example, if the second PTU defines a template, and the third PTU requires that template to be instantiated at float, that template specialization is still part of the second PTU. Similarly, if the fifth PTU uses an inline function belonging to the fourth, that definition still belongs to the fourth. When we go to emit code in a new PTU, we map each declaration we have to emit back to its owning PTU and emit it in a new module for just the extensions to that PTU. We keep track of all the modules we've emitted for a PTU so that we can unload them all if we decide to roll it back. Most declarations/definitions will only refer to entities from the same or earlier PTUs. However, it is possible (primarily by defining a previously-declared entity, but also through templates or ADL) for an entity that belongs to one PTU to refer to something from a later PTU. We will have to keep track of this and prevent unwinding to later PTU when we recognize it. Fortunately, this should be very rare; and crucially, we don't have to do the bookkeeping for this if we've only got one PTU, e.g. in normal compilation. Otherwise, PTUs after the first just need to record enough metadata to be able to revert any changes they've made to declarations belonging to earlier PTUs, e.g. to redeclaration chains or template specialization lists. It should even eventually be possible for PTUs to provide their own slab allocators which can be thrown away as part of rolling back the PTU. We can maintain a notion of the active allocator and allocate things like Stmt/Expr nodes in it, temporarily changing it to the appropriate PTU whenever we go to do something like instantiate a function template. More care will be required when allocating declarations and types, though. We would want the PTU to be efficiently recoverable from a Decl; I'm not sure how best to do that. An easy option that would cover most declarations would be to make multiple TranslationUnitDecls and parent the declarations appropriately, but I don't think that's good enough for things like member function templates, since an instantiation of that would still be parented by its original class. Maybe we can work this into the DC chain somehow, like how lexical DCs are. We add a different kind of translation unit `TU_Incremental` which is a complete translation unit that we might nonetheless incrementally extend later. Because it is complete (and we might want to generate code for it), we do perform template instantiation, but because it might be extended later, we don't warn if it declares or uses undefined internal-linkage symbols. This patch teaches clang-repl how to recover from errors by disconnecting the most recent PTU and update the primary PTU lookup tables. For instance: ```./clang-repl clang-repl> int i = 12; error; In file included from <<< inputs >>>:1: input_line_0:1:13: error: C++ requires a type specifier for all declarations int i = 12; error; ^ error: Parsing failed. clang-repl> int i = 13; extern "C" int printf(const char*,...); clang-repl> auto r1 = printf("i=%d\n", i); i=13 clang-repl> quit ``` Differential revision: https://reviews.llvm.org/D104918
2021-06-08[clang] p1099 using enum part 2Nathan Sidwell1-0/+1
This implements the 'using enum maybe-qualified-enum-tag ;' part of 1099. It introduces a new 'UsingEnumDecl', subclassed from 'BaseUsingDecl'. Much of the diff is the boilerplate needed to get the new class set up. There is one case where we accept ill-formed, but I believe this is merely an extended case of an existing bug, so consider it orthogonal. AFAICT in class-scope the c++20 rule is that no 2 using decls can bring in the same target decl ([namespace.udecl]/8). But we already accept: struct A { enum { a }; }; struct B : A { using A::a; }; struct C : B { using A::a; using B::a; }; // same enumerator this patch permits mixtures of 'using enum Bob;' and 'using Bob::member;' in the same way. Differential Revision: https://reviews.llvm.org/D102241
2021-06-02[clang] Implement the using_if_exists attributeErik Pilkington1-0/+3
This attribute applies to a using declaration, and permits importing a declaration without knowing if that declaration exists. This is useful for libc++ C wrapper headers that re-export declarations in std::, in cases where the base C library doesn't provide all declarations. This attribute was proposed in http://lists.llvm.org/pipermail/cfe-dev/2020-June/066038.html. rdar://69313357 Differential Revision: https://reviews.llvm.org/D90188
2021-03-17Make iteration over the DeclContext::lookup_result safe.Vassil Vassilev1-53/+4
The idiom: ``` DeclContext::lookup_result R = DeclContext::lookup(Name); for (auto *D : R) {...} ``` is not safe when in the loop body we trigger deserialization from an AST file. The deserialization can insert new declarations in the StoredDeclsList whose underlying type is a vector. When the vector decides to reallocate its storage the pointer we hold becomes invalid. This patch replaces a SmallVector with an singly-linked list. The current approach stores a SmallVector<NamedDecl*, 4> which is around 8 pointers. The linked list is 3, 5, or 7. We do better in terms of memory usage for small cases (and worse in terms of locality -- the linked list entries won't be near each other, but will be near their corresponding declarations, and we were going to fetch those memory pages anyway). For larger cases: the vector uses a doubling strategy for reallocation, so will generally be between half-full and full. Let's say it's 75% full on average, so there's N * 4/3 + 4 pointers' worth of space allocated currently and will be 2N pointers with the linked list. So we break even when there are N=6 entries and slightly lose in terms of memory usage after that. We suspect that's still a win on average. Thanks to @rsmith! Differential revision: https://reviews.llvm.org/D91524
2021-01-25[clang] NFC: Remove else-after-return pattern from some filesKirill Bobyrev1-16/+15
Follow-up on D95336. A bunch of these cases were found manually, the rest made sense to be included to eliminate llvm-else-after-return Clang-Tidy warnings.
2021-01-25[clang] NFC: Remove else if after returnKirill Bobyrev1-3/+1
Update the code to be compatible with LLVM Coding Guidelines. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D95336
2021-01-18[clang] Allow LifetimeExtendedTemporary to have no access specifierAdam Czachorowski1-9/+7
The check only runs in debug mode during serialization, but assert()-fail on: struct S { const int& x = 7; }; in C++ mode. Differential Revision: https://reviews.llvm.org/D94804
2020-10-21[c++20] For P0732R2 / P1907R1: Basic frontend support for class types asRichard Smith1-0/+1
non-type template parameters. Create a unique TemplateParamObjectDecl instance for each such value, representing the globally unique template parameter object to which the template parameter refers. No IR generation support yet; that will follow in a separate patch.
2020-10-19[NFC] Refactor DiagnosticBuilder and PartialDiagnosticYaxun (Sam) Liu1-2/+2
PartialDiagnostic misses some functions compared to DiagnosticBuilder. This patch refactors DiagnosticBuilder and PartialDiagnostic, extracts the common functionality so that the streaming << operators are shared. Differential Revision: https://reviews.llvm.org/D84362
2020-10-12Canonicalize declaration pointers when forming APValues.Richard Smith1-1/+1
References to different declarations of the same entity aren't different values, so shouldn't have different representations. Recommit of e6393ee813178e9d3306b8e3c6949a4f32f8a2cb, most recently reverted in 9a33f027ac7d73e14ae287e78ab554142d1cbc8f due to a bug caused by ObjCInterfaceDecls not propagating availability attributes along their redeclaration chains; that bug was fixed in e2d4174e9c66251d1b408234b53f53d0903c0285.
2020-10-12Revert "Canonicalize declaration pointers when forming APValues."Arthur Eubanks1-1/+1
This reverts commit 9dcd96f728863d40d6f5922ed52732fdd728fb5f. See https://crbug.com/1134762.
2020-09-27Canonicalize declaration pointers when forming APValues.Richard Smith1-1/+1
References to different declarations of the same entity aren't different values, so shouldn't have different representations. Recommit of e6393ee813178e9d3306b8e3c6949a4f32f8a2cb with fixed handling for weak declarations. We now look for attributes on the most recent declaration when determining whether a declaration is weak. (Second recommit with further fixes for mishandling of weak declarations. Our behavior here is fundamentally unsound -- see PR47663 -- but this approach attempts to not make things worse.)
2020-09-22Revert "Canonicalize declaration pointers when forming APValues."Leonard Chan1-1/+1
This reverts commit 905b9ca26c94fa86339451a528cedde5004fc1bb. Reverting because this strips `weak` attributes off function declarations, leading to the linker error we see at https://ci.chromium.org/p/fuchsia/builders/ci/clang_toolchain.fuchsia-arm64-debug-subbuild/b8868932035091473008. See https://reviews.llvm.org/rG905b9ca26c94 for reproducer details.
2020-09-16Canonicalize declaration pointers when forming APValues.Richard Smith1-1/+1
References to different declarations of the same entity aren't different values, so shouldn't have different representations. Recommit of e6393ee813178e9d3306b8e3c6949a4f32f8a2cb with fixed handling for weak declarations. We now look for attributes on the most recent declaration when determining whether a declaration is weak.
2020-08-26[clang] Exclude invalid destructors from lookups.Adam Czachorowski1-0/+7
This fixes a crash when declaring a destructor with a wrong name, then writing result to pch file and loading it again. The PCH storage uses DeclarationNameKey as key and it is the same key for both the invalid destructor and the implicit one that was created because the other one was invalid. When querying for the Foo::~Foo we end up getting Foo::~Bar, which is then rejected and we end up with nullptr in CXXRecordDecl::GetDestructor(). Fixes https://bugs.llvm.org/show_bug.cgi?id=47270 Differential Revision: https://reviews.llvm.org/D86624
2020-07-09PR46648: Do not eagerly instantiate default arguments for a genericRichard Smith1-1/+3
lambda when instantiating a call operator specialization. We previously incorrectly thought that such substitution was happening in the context of substitution into a local scope, which is a context where we should perform eager default argument instantiation.
2020-06-23DR458: Search template parameter scopes in the right order.Richard Smith1-1/+1
C++ unqualified name lookup searches template parameter scopes immediately after finishing searching the entity the parameters belong to. (Eg, for a class template, you search the template parameter scope after looking in that class template and its base classes and before looking in the scope containing the class template.) This is complicated by the fact that scope lookup within a template parameter scope looks in a different sequence of places prior to reaching the end of the declarator-id in the template declaration. We used to approximate the proper lookup rule with a hack in the scope / decl context walk inside name lookup. Now we instead compute the lookup parent for each template parameter scope. In order to get this right, we now make sure to enter a distinct Scope for each template parameter scope, and make sure to re-enter the enclosing class scopes properly when handling delay-parsed regions within a class.
2020-06-22Fix rejects-valid when referencing an implicit operator== from within aRichard Smith1-1/+33
templated class. When a defaulted operator<=> results in the injection of a defaulted operator==, that operator== can be named by unqualified name within the same class, even if the class is templated. To make this work, perform the transform from defaulted operator<=> to defaulted operator== in the template definition context instead of the template instantiation context. This results in our substituting into a declaration from a context where we don't have a full list of template arguments (or indeed any), for which we are now more careful to not spuriously instantiate declarations that are not dependent on the arguments we're substituting.
2020-06-17Revert "Fix rejects-valid when referencing an implicit operator== from within a"Richard Smith1-33/+1
This change may have caused some self-host failures. Reverting while investigating. This reverts commit c7fbe2191b8b9cd64570ed3906d1bed1dd5fff8e.
2020-06-17Fix rejects-valid when referencing an implicit operator== from within aRichard Smith1-1/+33
templated class. When a defaulted operator<=> results in the injection of a defaulted operator==, that operator== can be named by unqualified name within the same class, even if the class is templated. To make this work, perform the transform from defaulted operator<=> to defaulted operator== in the template definition context instead of the template instantiation context. This results in our substituting into a declaration from a context where we don't have a full list of template arguments (or indeed any), for which we are now more careful to not spuriously instantiate declarations that are not dependent on the arguments we're substituting.
2020-06-16Revert "DR458: Search template parameter scopes in the right order."Richard Smith1-1/+1
We weren't re-entering template scopes in the right order, causing this to break self-host with -fdelayed-template-parsing. This reverts commit 237c2a23b6d4fa953f5ae910dccf492db61bb959.
2020-06-16DR458: Search template parameter scopes in the right order.Richard Smith1-1/+1
C++ unqualified name lookup searches template parameter scopes immediately after finishing searching the entity the parameters belong to. (Eg, for a class template, you search the template parameter scope after looking in that class template and its base classes and before looking in the scope containing the class template.) This is complicated by the fact that scope lookup within a template parameter scope looks in a different sequence of places prior to reaching the end of the declarator-id in the template declaration. We used to approximate the proper lookup rule with a hack in the scope / decl context walk inside name lookup. Now we instead compute the lookup parent for each template parameter scope. This gets the right answer and as a bonus is substantially simpler and more uniform. In order to get this right, we now make sure to enter a distinct Scope for each template parameter scope. (The fact that we didn't before was already a bug, but not really observable most of the time, since template parameters can't shadow each other.)
2020-04-22PR45000: Let Sema::SubstParmVarDecl handle default args of lambdas in ↵Aaron Puchert1-1/+4
initializers Summary: We extend the behavior for local functions and methods of local classes to lambdas in variable initializers. The initializer is not a separate scope, but we treat it as such. We also remove the (faulty) instantiation of default arguments in TreeTransform::TransformLambdaExpr, because it doesn't do proper initialization, and if it did, we would do it twice (and thus also emit eventual errors twice). Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D76038
2020-04-15Rework how UuidAttr, CXXUuidofExpr, and GUID template arguments and ↵Richard Smith1-0/+1
constants are represented. Summary: Previously, we treated CXXUuidofExpr as quite a special case: it was the only kind of expression that could be a canonical template argument, it could be a constant lvalue base object, and so on. In addition, we represented the UUID value as a string, whose source form we did not preserve faithfully, and that we partially parsed in multiple different places. With this patch, we create an MSGuidDecl object to represent the implicit object of type 'struct _GUID' created by a UuidAttr. Each UuidAttr holds a pointer to its 'struct _GUID' and its original (as-written) UUID string. A non-value-dependent CXXUuidofExpr behaves like a DeclRefExpr denoting that MSGuidDecl object. We cache an APValue representation of the GUID on the MSGuidDecl and use it from constant evaluation where needed. This allows removing a lot of the special-case logic to handle these expressions. Unfortunately, many parts of Clang assume there are only a couple of interesting kinds of ValueDecl, so the total amount of special-case logic is not really reduced very much. This fixes a few bugs and issues: * PR38490: we now support reading from GUID objects returned from __uuidof during constant evaluation. * Our Itanium mangling for a non-instantiation-dependent template argument involving __uuidof no longer depends on which CXXUuidofExpr template argument we happened to see first. * We now predeclare ::_GUID, and permit use of __uuidof without any header inclusion, better matching MSVC's behavior. We do not predefine ::__s_GUID, though; that seems like a step too far. * Our IR representation for GUID constants now uses the correct IR type wherever possible. We will still fall back to using the {i32, i16, i16, [8 x i8]} layout if a definition of struct _GUID is not available. This is not ideal: in principle the two layouts could have different padding. Reviewers: rnk, jdoerfert Subscribers: arphaman, cfe-commits, aeubanks Tags: #clang Differential Revision: https://reviews.llvm.org/D78171
2020-04-15[AST] Fix recovery-expr crash on invalid aligned attr.Haojian Wu1-2/+4
Summary: crash stack: ``` lang: tools/clang/include/clang/AST/AttrImpl.inc:1490: unsigned int clang::AlignedAttr::getAlignment(clang::ASTContext &) const: Assertion `!isAlignmentDependent()' failed. PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: ./bin/clang -cc1 -std=c++1y -ast-dump -frecovery-ast -fcxx-exceptions /tmp/t4.cpp 1. /tmp/t4.cpp:3:31: current parser token ';' #0 0x0000000002530cff llvm::sys::PrintStackTrace(llvm::raw_ostream&) llvm-project/llvm/lib/Support/Unix/Signals.inc:564:13 #1 0x000000000252ee30 llvm::sys::RunSignalHandlers() llvm-project/llvm/lib/Support/Signals.cpp:69:18 #2 0x000000000253126c SignalHandler(int) llvm-project/llvm/lib/Support/Unix/Signals.inc:396:3 #3 0x00007f86964d0520 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13520) #4 0x00007f8695f9ff61 raise /build/glibc-oCLvUT/glibc-2.29/signal/../sysdeps/unix/sysv/linux/raise.c:51:1 #5 0x00007f8695f8b535 abort /build/glibc-oCLvUT/glibc-2.29/stdlib/abort.c:81:7 #6 0x00007f8695f8b40f _nl_load_domain /build/glibc-oCLvUT/glibc-2.29/intl/loadmsgcat.c:1177:9 #7 0x00007f8695f98b92 (/lib/x86_64-linux-gnu/libc.so.6+0x32b92) #8 0x0000000004503d9f llvm::APInt::getZExtValue() const llvm-project/llvm/include/llvm/ADT/APInt.h:1623:5 #9 0x0000000004503d9f clang::AlignedAttr::getAlignment(clang::ASTContext&) const llvm-project/build/tools/clang/include/clang/AST/AttrImpl.inc:1492:0 ``` Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D78085
2020-04-06[AST] Remove DeclCXX.h dep on ASTContext.hReid Kleckner1-0/+6
Saves only 36 includes of ASTContext.h and related headers. There are two deps on ASTContext.h: - C++ method overrides iterator types (TinyPtrVector) - getting LangOptions For #1, duplicate the iterator type, which is TinyPtrVector<>::const_iterator. For #2, add an out-of-line accessor to get the language options. Getting the ASTContext from a Decl is already an out of line method that loops over the parent DeclContexts, so if it is ever performance critical, the proper fix is to pass the context (or LangOpts) into the predicate in question. Other changes are just header fixups.
2020-03-17[Clang] Undef attribute for global variablesJon Chesterfield1-1/+4
Summary: [Clang] Attribute to allow defining undef global variables Initializing global variables is very cheap on hosted implementations. The C semantics of zero initializing globals work very well there. It is not necessarily cheap on freestanding implementations. Where there is no loader available, code must be emitted near the start point to write the appropriate values into memory. At present, external variables can be declared in C++ and definitions provided in assembly (or IR) to achive this effect. This patch provides an attribute in order to remove this reason for writing assembly for performance sensitive freestanding implementations. A close analogue in tree is LDS memory for amdgcn, where the kernel is responsible for initializing the memory after it starts executing on the gpu. Uninitalized variables in LDS are observably cheaper than zero initialized. Patch is loosely based on the cuda __shared__ and opencl __local variable implementation which also produces undef global variables. Reviewers: kcc, rjmccall, rsmith, glider, vitalybuka, pcc, eugenis, vlad.tsyrklevich, jdoerfert, gregrodgers, jfb, aaron.ballman Reviewed By: rjmccall, aaron.ballman Subscribers: Anastasia, aaron.ballman, davidb, Quuxplusone, dexonsmith, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D74361
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-2/+2
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-19[Concepts] Requires ExpressionsSaar Raz1-0/+2
Implement support for C++2a requires-expressions. Re-commit after compilation failure on some platforms due to alignment issues with PointerIntPair. Differential Revision: https://reviews.llvm.org/D50360
2020-01-18Revert "[Concepts] Requires Expressions"Saar Raz1-2/+0
This reverts commit 027931899763409e2c61a84bdee6057b5e838ffa. There have been some failing tests on some platforms, reverting while investigating.
2020-01-18[Concepts] Requires ExpressionsSaar Raz1-0/+2
Implement support for C++2a requires-expressions. Differential Revision: https://reviews.llvm.org/D50360