aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ComputeDependence.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-16/+10
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-04[Clang] Initial support for P2841 (Variable template and concept template ↵Corentin Jabot1-1/+1
parameters) (#150823) This is a first pass at implementing [P2841R7](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2841r7.pdf). The implementation is far from complete; however, I'm aiming to do that in chunks, to make our lives easier. In particular, this does not implement - Subsumption - Mangling - Satisfaction checking is minimal as we should focus on #141776 first (note that I'm currently very stuck) FTM, release notes, status page, etc, will be updated once the feature is more mature. Given the state of the feature, it is not yet allowed in older language modes. Of note: - Mismatches between template template arguments and template template parameters are a bit wonky. This is addressed by #130603 - We use `UnresolvedLookupExpr` to model template-id. While this is pre-existing, I have been wondering if we want to introduce a different OverloadExpr subclass for that. I did not make the change in this patch.
2025-06-23[NFC][Clang][AST] Drop `llvm::` in front of `ArrayRef`/`MutableArrayRef` ↵Rahul Joshi1-5/+4
(#145207)
2025-04-03[clang] NFC: introduce UnsignedOrNone as a replacement for ↵Matheus Izvekov1-1/+1
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.
2024-11-25[Clang] Preserve partially substituted pack indexing type/expressions (#116782)Younan Zhang1-2/+1
Substituting into pack indexing types/expressions can still result in unexpanded types/expressions, such as `PackIndexingType` or `PackIndexingExpr`. To handle these cases correctly, we should defer the pack size checks to the next round of transformation, when the patterns can be fully expanded. To that end, the `FullySubstituted` flag is now necessary for computing the dependencies of `PackIndexingExprs`. Conveniently, this flag can also represent the prior `ExpandsToEmpty` status with an additional emptiness check. Therefore, I converted all stored flags to use `FullySubstituted`. Fixes https://github.com/llvm/llvm-project/issues/116105
2024-10-11[Clang] [Sema] Don't crash on unexpanded pack in invalid block literal (#110762)Sirraide1-1/+4
Consider #109148: ```c++ template <typename ...Ts> void f() { [] { (^Ts); }; } ``` When we encounter `^Ts`, we try to parse a block and subsequently call `DiagnoseUnexpandedParameterPack()` (in `ActOnBlockArguments()`), which sees `Ts` and sets `ContainsUnexpandedParameterPack` to `true` in the `LambdaScopeInfo` of the enclosing lambda. However, the entire block is subsequently discarded entirely because it isn’t even syntactically well-formed. As a result, `ContainsUnexpandedParameterPack` is `true` despite the lambda’s body no longer containing any unexpanded packs, which causes an assertion the next time `DiagnoseUnexpandedParameterPack()` is called. This pr moves handling of unexpanded parameter packs into `CapturingScopeInfo` instead so that the same logic is used for both blocks and lambdas. This fixes this issue since the `ContainsUnexpandedParameterPack` flag is now part of the block (and before that, its `CapturingScopeInfo`) and no longer affects the surrounding lambda directly when the block is parsed. Moreover, this change makes blocks actually usable with pack expansion. This fixes #109148.
2024-10-03[OpenACC] Implement 'tile' attribute AST (#110999)Erich Keane1-0/+6
The 'tile' clause shares quite a bit of the rules with 'collapse', so a followup patch will add those tests/behaviors. This patch deals with adding the AST node. The 'tile' clause takes a series of integer constant expressions, or *. The asterisk is now represented by a new OpenACCAsteriskSizeExpr node, else this clause is very similar to others.
2024-08-28[NFC] Comment fix: "does specify state that" -> "does specify that" (#106338)Michael Park1-1/+1
2024-05-14[Clang] Fix dependency computation for pack indexing expression (#91933)cor3ntin1-3/+10
Given `foo...[idx]` if idx is value dependent, the expression is type dependent. Fixes #91885 Fixes #91884
2024-04-25[NFC] Generalize ArraySections to work for OpenACC in the future (#89639)Erich Keane1-1/+6
OpenACC is going to need an array sections implementation that is a simpler version/more restrictive version of the OpenMP version. This patch moves `OMPArraySectionExpr` to `Expr.h` and renames it `ArraySectionExpr`, then adds an enum to choose between the two. This also fixes a couple of 'drive-by' issues that I discovered on the way, but leaves the OpenACC Sema parts reasonably unimplemented (no semantic analysis implementation), as that will be a followup patch.
2024-04-09[Clang] [Sema] Fix dependence of DREs in lambdas with an explicit object ↵Sirraide1-0/+10
parameter (#84473) This fixes some problems wrt dependence of captures in lambdas with an explicit object parameter. [temp.dep.expr] states that > An id-expression is type-dependent if [...] its terminal name is > - associated by name lookup with an entity captured by copy > ([expr.prim.lambda.capture]) in a lambda-expression that has > an explicit object parameter whose type is dependent [dcl.fct]. There were several issues with our implementation of this: 1. we were treating by-reference captures as dependent rather than by-value captures; 2. tree transform wasn't checking whether referring to such a by-value capture should make a DRE dependent; 3. when checking whether a DRE refers to such a by-value capture, we were only looking at the immediately enclosing lambda, and not at any parent lambdas; 4. we also forgot to check for implicit by-value captures; 5. lastly, we were attempting to determine whether a lambda has an explicit object parameter by checking the `LambdaScopeInfo`'s `ExplicitObjectParameter`, but it seems that that simply wasn't set (yet) by the time we got to the check. All of these should be fixed now. This fixes #70604, #79754, #84163, #84425, #86054, #86398, and #86399.
2024-04-02[Clang][AST][NFC] Move template argument dependence computations for ↵Krystian Stasiowski1-1/+3
MemberExpr to computeDependence (#86682) (This patch depends on #86678) Pretty straightforward change, addresses the FIXME's in `computeDependence(MemberExpr*)` and `MemberExpr::Create` by moving the template argument dependence computations to `computeDependence`.
2024-01-27[Clang][C++26] Implement Pack Indexing (P2662R3). (#72644)cor3ntin1-0/+15
Implements https://isocpp.org/files/papers/P2662R3.pdf The feature is exposed as an extension in older language modes. Mangling is not yet supported and that is something we will have to do before release.
2024-01-05[clang] Accept recursive non-dependent calls to functions with deduced ↵Mariya Podchishchaeva1-0/+2
return type (#75456) Treat such calls as dependent since it is much easier to implement. Fixes https://github.com/llvm/llvm-project/issues/71015
2023-10-02[C++] Implement "Deducing this" (P0847R7)Corentin Jabot1-0/+9
This patch implements P0847R7 (partially), CWG2561 and CWG2653. Reviewed By: aaron.ballman, #clang-language-wg Differential Revision: https://reviews.llvm.org/D140828
2023-07-11[clang][AST] Propagate the contains-errors bit to DeclRefExpr from VarDecl's ↵Haojian Wu1-8/+8
initializer. Similar to the https://reviews.llvm.org/D86048 (it only sets the bit for C++ code), we propagate the contains-errors bit for C-code path. Fixes https://github.com/llvm/llvm-project/issues/50236 Fixes https://github.com/llvm/llvm-project/issues/50243 Fixes https://github.com/llvm/llvm-project/issues/48636 Fixes https://github.com/llvm/llvm-project/issues/50320 Differential Revision: https://reviews.llvm.org/D154861
2023-07-10[clang] Correct calculation of MemberExpr's dependenceMariya Podchishchaeva1-10/+16
Due to incorrect calculation false positive diagnostics were emitted. Fixes https://github.com/llvm/llvm-project/issues/48731 Reviewed By: shafik, cor3ntin Differential Revision: https://reviews.llvm.org/D154689
2023-06-05[C] Support _Generic expressions with a type operandAaron Ballman1-1/+6
_Generic accepts an expression operand whose type is matched against a list of associations. The expression operand is unevaluated, but the type matched is the type after lvalue conversion. This conversion loses type information, which makes it more difficult to match against qualified or incomplete types. This extension allows _Generic to accept a type operand instead of an expression operand. The type operand form does not undergo any conversions and is matched directly against the association list. This extension is also supported in C++ as we already supported _Generic selection expressions there. The RFC for this extension can be found at: https://discourse.llvm.org/t/rfc-generic-selection-expression-with-a-type-operand/70388 Differential Revision: https://reviews.llvm.org/D149904
2023-05-19[clang][AST] Propagate the value-dependent bit for VAArgExpr.Haojian Wu1-1/+1
Fixes https://github.com/llvm/llvm-project/issues/62711 We never set the value-dependent bit for the VAArgExpr before this patch, this was fine becase the dependent-type TypoExpr was always resolved before checking the operands (see https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaExpr.cpp#L21173-L21180) Now we have enabled the dependence by default for C, the typo expr is not early resolved before checking rather than delayed (share the same codepath with C++). The fix is to propagate the value-dependent bit for VAArgExpr where it contains a TypoExpr, so that the AST node can be handled properly. Differential Revision: https://reviews.llvm.org/D150955
2023-04-24[NFC][clang] Fix Coverity bugs with AUTO_CAUSES_COPYManna, Soumi1-1/+1
Reported by Coverity: AUTO_CAUSES_COPY Unnecessary object copies can affect performance. 1. Inside "ExtractAPIVisitor.h" file, in clang::extractapi::impl::ExtractAPIVisitorBase<<unnamed>::BatchExtractAPIVisitor>::VisitFunctionDecl(clang::FunctionDecl const *): Using the auto keyword without an & causes the copy of an object of type DynTypedNode. 2. Inside "NeonEmitter.cpp" file, in <unnamed>::Intrinsic::Intrinsic(llvm::Record *, llvm::StringRef, llvm::StringRef, <unnamed>::TypeSpec, <unnamed>::TypeSpec, <unnamed>::ClassKind, llvm::ListInit *, <unnamed>::NeonEmitter &, llvm::StringRef, llvm::StringRef, bool, bool): Using the auto keyword without an & causes the copy of an object of type Type. 3. Inside "MicrosoftCXXABI.cpp" file, in <unnamed>::MSRTTIBuilder::getClassHierarchyDescriptor(): Using the auto keyword without an & causes the copy of an object of type MSRTTIClass. 4. Inside "CGGPUBuiltin.cpp" file, in clang::CodeGen::CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(clang::CallExpr const *): Using the auto keyword without an & causes the copy of an object of type CallArg. 5. Inside "SemaDeclAttr.cpp" file, in threadSafetyCheckIsSmartPointer(clang::Sema &, clang::RecordType const *): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier. 6. Inside "ComputeDependence.cpp" file, in clang::computeDependence(clang::DesignatedInitExpr *): Using the auto keyword without an & causes the copy of an object of type Designator. 7. Inside "Format.cpp" file, In clang::format::affectsRange(llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned int): Using the auto keyword without an & causes the copy of an object of type Range. Reviewed By: tahonermann Differential Revision: https://reviews.llvm.org/D149074
2023-04-23[NFC][clang] Fix static analyzer concernsManna, Soumi1-2/+2
Reported by Coverity: AUTO_CAUSES_COPY Unnecessary object copies can affect performance. 1. Inside "SemaDeclCXX.cpp" file, in <unnamed>::DiagnoseUninitializedFields(clang::Sema &, clang::CXXConstructorDecl const *): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier. 2. Inside "ClangAttrEmitter.cpp" file, in clang::EmitClangAttrParsedAttrImpl(llvm::RecordKeeper &, llvm::raw_ostream &): Using the auto keyword without an & causes the copy of an object of type pair. 3. Inside "Marshallers.h" file, in clang::ast_matchers::dynamic::internal::MapAnyOfBuilderDescriptor::buildMatcherCtor(clang::ast_matchers::dynamic::SourceRange, llvm::ArrayRef<clang::ast_matchers::dynamic::ParserValue>, clang::ast_matchers::dynamic::Diagnostics *): Using the auto keyword without an & causes the copy of an object of type ParserValue. 4. Inside "CGVTables.cpp" file, in clang::CodeGen::CodeGenModule::GetVCallVisibilityLevel(clang::CXXRecordDecl const *, llvm::DenseSet<clang::CXXRecordDecl const *, llvm::DenseMapInfo<clang::CXXRecordDecl const *, void>> &): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier. 5. Inside "ASTContext.cpp" file, in hasTemplateSpecializationInEncodedString(clang::Type const *, bool): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier. 6. Inside "ComputeDependence.cpp" file, in clang::computeDependence(clang::DependentScopeDeclRefExpr *): Using the auto keyword without an & causes the copy of an object of type TemplateArgumentLoc. Reviewed By: tahonermann, erichkeane Differential Revision: https://reviews.llvm.org/D148812
2023-04-05[NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copyManna, Soumi1-1/+1
Reported by Coverity: AUTO_CAUSES_COPY Unnecessary object copies can affect performance Inside FrontendActions.cpp file, In clang::DumpModuleInfoAction::ExecuteAction(): Using the auto keyword without an & causes the copy of an object of type pair. Inside ComputeDependence.cpp file, In clang::computeDependence(clang::OverloadExpr *, bool, bool, bool): Using the auto keyword without an & causes the copy of an object of type TemplateArgumentLoc. Reviewed By: erichkeane, aaron.ballman Differential Revision: https://reviews.llvm.org/D147574
2023-01-12[clang] Reland parenthesized aggregate init patchesAlan Zhao1-0/+7
This commit relands the patches for implementing P0960R3 and P1975R0, which describe initializing aggregates via a parenthesized list. The relanded commits are: * 40c52159d3ee - P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values * c77a91bb7ba7 - Remove overly restrictive aggregate paren init logic * 32d7aae04fdb - Fix a clang crash on invalid code in C++20 mode This patch also fixes a crash in the original implementation. Previously, if the input tried to call an implicitly deleted copy or move constructor of a union, we would then try to initialize the union by initializing it's first element with a reference to a union. This behavior is incorrect (we should fail to initialize) and if the type of the first element has a constructor with a single template typename parameter, then Clang will explode. This patch fixes that issue by checking that constructor overload resolution did not result in a deleted function before attempting parenthesized aggregate initialization. Additionally, this patch also includes D140159, which contains some minor fixes made in response to code review comments in the original implementation that were made after that patch was submitted. Co-authored-by: Sheng <ox59616e@gmail.com> Fixes #54040, Fixes #59675 Reviewed By: ilya-biryukov Differential Revision: https://reviews.llvm.org/D141546
2023-01-09Move from llvm::makeArrayRef to ArrayRef deduction guides - clang/ partserge-sans-paille1-3/+3
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141139
2023-01-04[clang] Revert parentesized aggregate initalization patchesAlan Zhao1-7/+0
This feature causes clang to crash when compiling Chrome - see https://crbug.com/1405031 and https://github.com/llvm/llvm-project/issues/59675 Revert "[clang] Fix a clang crash on invalid code in C++20 mode." This reverts commit 32d7aae04fdb58e65a952f281ff2f2c3f396d98f. Revert "[clang] Remove overly restrictive aggregate paren init logic" This reverts commit c77a91bb7ba793ec3a6a5da3743ed55056291658. Revert "[clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values" This reverts commit 40c52159d3ee337dbed14e4c73b5616ea354c337.
2022-12-14[clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a ↵Alan Zhao1-0/+7
parenthesized list of values This patch implements P0960R3, which allows initialization of aggregates via parentheses. As an example: ``` struct S { int i, j; }; S s1(1, 1); int arr1[2](1, 2); ``` This patch also implements P1975R0, which fixes the wording of P0960R3 for single-argument parenthesized lists so that statements like the following are allowed: ``` S s2(1); S s3 = static_cast<S>(1); S s4 = (S)1; int (&&arr2)[] = static_cast<int[]>(1); int (&&arr3)[2] = static_cast<int[2]>(1); ``` This patch was originally authored by @0x59616e and completed by @ayzhao. Fixes #54040, Fixes #54041 Co-authored-by: Sheng <ox59616e@gmail.com> Full write up : https://discourse.llvm.org/t/c-20-rfc-suggestion-desired-regarding-the-implementation-of-p0960r3/63744 Reviewed By: ilya-biryukov Differential Revision: https://reviews.llvm.org/D129531
2022-10-31[clang] Improve error recovery for pack expansion of expressionsMatheus Izvekov1-1/+1
Closes #58673. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D136962
2022-09-26Reapply "[Concepts] Recover properly from a RecoveryExpr in a concept"Erich Keane1-1/+4
This reverts commit 192d69f7e65a625e344421841e731e39f80595f5. This fixes the condition to check whether this is a situation where we are in a recovery-expr'ed concept a little better, so we don't access an inactive member of a union, which should make the bots happy. Differential Revision: https://reviews.llvm.org/D134542
2022-09-26Revert "[Concepts] Recover properly from a RecoveryExpr in a concept"Erich Keane1-4/+1
This reverts commit e3d14bee238b672a7a112311eefee55e142eaefc. There are apparently a large number of crashes in libcxx and some JSON Parser thing, so clearly this has some sort of serious issue. Reverting so I can take some time to figure out what is going on.
2022-09-26[Concepts] Recover properly from a RecoveryExpr in a conceptErich Keane1-1/+4
Discovered by reducing a different problem, we currently assert because we failed to make the constraint expressions not dependent, since a RecoveryExpr cannot be transformed. This patch fixes that, and gets reasonably nice diagnostics by introducing a concept (hah!) of "ContainsErrors" to the Satisfaction types, which causes us to treat the candidate as non-viable. However, just making THAT candidate non-viable would result in choosing the 'next best' canddiate, which can result in awkward errors, where we start evaluating a candidate that is not intended to be selected. Because of this, and to make diagnostics more relevant, we now just cause the entire lookup to result in a 'no-viable-candidates'. This means we will only emit the list of candidates, rather than any cascading failures.
2022-06-20[clang] Don't use Optional::hasValue (NFC)Kazu Hirata1-1/+1
2022-03-31An expression should only contain an unexpanded parameter pack if itRichard Smith1-56/+93
lexically contains a mention of the pack. Systematically distinguish between syntactic and semantic references to packs, especially when propagating dependence from a type into an expression. We should consult the type-as-written when computing syntactic dependence and should consult the semantic type when computing semantic dependence. Fixes #54402.
2021-06-10[clang] Make CXXDefaultArgExpr inherit dependence from the inner ExprAdam Czachorowski1-0/+4
Before this change, CXXDefaultArgExpr would always have ExprDependence::None. This can lead to issues when, for example, the inner expression is RecoveryExpr and yet containsErrors() on the default expression is false. Differential Revision: https://reviews.llvm.org/D103982
2021-05-27Reimplement __builtin_unique_stable_name-Erich Keane1-0/+4
The original version of this was reverted, and @rjmcall provided some advice to architect a new solution. This is that solution. This implements a builtin to provide a unique name that is stable across compilations of this TU for the purposes of implementing the library component of the unnamed kernel feature of SYCL. It does this by running the Itanium mangler with a few modifications. Because it is somewhat common to wrap non-kernel-related lambdas in macros that aren't present on the device (such as for logging), this uniquely generates an ID for all lambdas involved in the naming of a kernel. It uses the lambda-mangling number to do this, except replaces this with its own number (starting at 10000 for readabililty reasons) for lambdas used to name a kernel. Additionally, this implements itself as constexpr with a slight catch: if a name would be invalidated by the use of this lambda in a later kernel invocation, it is diagnosed as an error (see the Sema tests). Differential Revision: https://reviews.llvm.org/D103112
2021-01-20Revert "Following up on PR48517, fix handling of template arguments that refer"Hans Wennborg1-11/+2
Combined with 'da98651 - Revert "DR2064: decltype(E) is only a dependent', this change (5a391d3) caused verifier errors when building Chromium. See https://crbug.com/1168494#c1 for a reproducer. Additionally it reverts changes that were dependent on this one, see below. > Following up on PR48517, fix handling of template arguments that refer > to dependent declarations. > > Treat an id-expression that names a local variable in a templated > function as being instantiation-dependent. > > This addresses a language defect whereby a reference to a dependent > declaration can be formed without any construct being value-dependent. > Fixing that through value-dependence turns out to be problematic, so > instead this patch takes the approach (proposed on the core reflector) > of allowing the use of pointers or references to (but not values of) > dependent declarations inside value-dependent expressions, and instead > treating template arguments as dependent if they evaluate to a constant > involving such dependent declarations. > > This ends up affecting a bunch of OpenMP tests, due to OpenMP > imprecisely handling instantiation-dependent constructs, bailing out > early instead of processing dependent constructs to the extent possible > when handling the template. > > Previously committed as 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e, and > reverted because a dependency commit was reverted. This reverts commit 5a391d38ac6c561ba908334d427f26124ed9132e. It also restores clang/test/SemaCXX/coroutines.cpp to its state before da986511fb9da1a46a0ca4dba2e49e2426036303. Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type." > Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and > reverted because a dependency commit was reverted. This incorporates the > following follow-on commits that were also reverted: > > 7e84aa1b81e72d44bcc58ffe1731bfc7abb73ce0 by Simon Pilgrim > ed13d8c66781b50ff007cb089c5905f9bb9e8af2 by me > 95c7b6cadbc9a3d4376ef44edbeb3c8bb5b8d7fc by Sam McCall > 430d5d8429473c2b10b109991d7577a3cea41140 by Dave Zarzycki This reverts commit 4b574008aef5a7235c1f894ab065fe300d26e786. Revert "[msabi] Mangle a template argument referring to array-to-pointer decay" > [msabi] Mangle a template argument referring to array-to-pointer decay > applied to an array the same as the array itself. > > This follows MS ABI, and corrects a regression from the implementation > of generalized non-type template parameters, where we "forgot" how to > mangle this case. This reverts commit 18e093faf726d15f210ab4917142beec51848258.
2021-01-18Following up on PR48517, fix handling of template arguments that referRichard Smith1-2/+11
to dependent declarations. Treat an id-expression that names a local variable in a templated function as being instantiation-dependent. This addresses a language defect whereby a reference to a dependent declaration can be formed without any construct being value-dependent. Fixing that through value-dependence turns out to be problematic, so instead this patch takes the approach (proposed on the core reflector) of allowing the use of pointers or references to (but not values of) dependent declarations inside value-dependent expressions, and instead treating template arguments as dependent if they evaluate to a constant involving such dependent declarations. This ends up affecting a bunch of OpenMP tests, due to OpenMP imprecisely handling instantiation-dependent constructs, bailing out early instead of processing dependent constructs to the extent possible when handling the template. Previously committed as 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e, and reverted because a dependency commit was reverted.
2020-12-22Revert "Following up on PR48517, fix handling of template arguments that refer"Arthur Eubanks1-11/+2
This reverts commit 8c1f2d15b826591cdf6bd6b468b8a7d23377b29e. This is part of 5 commits being reverted due to https://crbug.com/1161059. See bug for repro.
2020-12-17Following up on PR48517, fix handling of template arguments that referRichard Smith1-2/+11
to dependent declarations. Treat an id-expression that names a local variable in a templated function as being instantiation-dependent. This addresses a language defect whereby a reference to a dependent declaration can be formed without any construct being value-dependent. Fixing that through value-dependence turns out to be problematic, so instead this patch takes the approach (proposed on the core reflector) of allowing the use of pointers or references to (but not values of) dependent declarations inside value-dependent expressions, and instead treating template arguments as dependent if they evaluate to a constant involving such dependent declarations. This ends up affecting a bunch of OpenMP tests, due to OpenMP imprecisely handling instantiation-dependent constructs, bailing out early instead of processing dependent constructs to the extent possible when handling the template.
2020-12-15DR1413 and part of P1815R2: Minor improvements to Clang's determinationRichard Smith1-37/+52
of type- and value-dependency. A static data member initialized to a constant inside a class template is no longer considered value-dependent, per DR1413. A const but not constexpr variable of literal type (other than integer or enumeration) is no longer considered value-dependent, per P1815R2.
2020-12-15DR2100: &expr is value-dependent if expr constant-evaluates to aRichard Smith1-3/+32
dependent declaration.
2020-10-08PR47175: Ensure type-dependent function-style casts have dependentRichard Smith1-2/+0
types. Previously, a type-dependent cast to a deduced class template specialization type would end up with a non-dependent class template specialization type, leading to confusion downstream.
2020-10-05[AST][RecoveryExpr] Popagate the error-bit from a VarDecl's initializer to ↵Haojian Wu1-3/+5
DeclRefExpr. The error-bit was missing, if a DeclRefExpr (which refers to a VarDecl with a contains-errors initializer). It could cause different violations in clang -- the DeclRefExpr is value-dependent, but not contains-errors, `ABC<DeclRefExpr>` could produce a non-error and non-dependent type in non-template context, which will lead to crashes in constexpr evaluation. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D86048
2020-09-21[AST] Fix dependence-bits for CXXDefaultInitExpr.Haojian Wu1-0/+4
Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D87382
2020-07-21[clang] Set the error-bit for ill-formed semantic InitListExpr.Haojian Wu1-1/+1
When a semantic checking fails on a syntactic InitListExpr, we will get an ill-formed semantic InitListExpr (e.g. some inits are nullptr), using this semantic InitListExpr in clang (without setting the err-bits) is crashy. Differential Revision: https://reviews.llvm.org/D84140
2020-07-13[clang][RecoveryExpr] Clarify the dependence-bits documentation.Haojian Wu1-5/+8
The expr dependent-bits described that the expression somehow depends on a template paramter. With RecoveryExpr, we have generalized it to "the expression depends on a template parameter, or an error". This patch updates/cleanups all related comments of dependence-bits. Differential Revision: https://reviews.llvm.org/D83213
2020-06-08[AST][RecoveryExpr] Populate the dependence bits from CompoundStmt result ↵Haojian Wu1-4/+8
expr to StmtExpr. Summary: We lost errorBit for StmtExpr if a recoveryExpr is the result expr of a CompoundStmt, which will lead to crashes. ``` // `-StmtExpr // `-CompoundStmt // `-RecoveryExp ({ invalid(); }); ``` Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D81154
2020-06-01[Matrix] Implement matrix index expressions ([][]).Florian Hahn1-0/+6
This patch implements matrix index expressions (matrix[RowIdx][ColumnIdx]). It does so by introducing a new MatrixSubscriptExpr(Base, RowIdx, ColumnIdx). MatrixSubscriptExprs are built in 2 steps in ActOnMatrixSubscriptExpr. First, if the base of a subscript is of matrix type, we create a incomplete MatrixSubscriptExpr(base, idx, nullptr). Second, if the base is an incomplete MatrixSubscriptExpr, we create a complete MatrixSubscriptExpr(base->getBase(), base->getRowIdx(), idx) Similar to vector elements, it is not possible to take the address of a MatrixSubscriptExpr. For CodeGen, a new MatrixElt type is added to LValue, which is very similar to VectorElt. The only difference is that we may need to cast the type of the base from an array to a vector type when accessing it. Reviewers: rjmccall, anemet, Bigcheese, rsmith, martong Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D76791
2020-05-11[AST] Preserve the type in RecoveryExprs for broken function calls.Haojian Wu1-1/+5
RecoveryExprs are modeled as dependent type to prevent bogus diagnostics and crashes in clang. This patch allows to preseve the type for broken calls when the RecoveryEprs have a known type, e.g. a broken non-overloaded call, a overloaded call when the all candidates have the same return type, so that more features (code completion still work on "take2args(x).^") still work. However, adding the type is risky, which may result in more clang code being affected leading to new crashes and hurt diagnostic, and it requires large effort to minimize the affect (update all sites in clang to handle errorDepend case), so we add a new flag (off by default) to allow us to develop/test them incrementally. This patch also has some trivial fixes to suppress diagnostics (to prevent regressions). Tested: all existing tests are passed (when both "-frecovery-ast", "-frecovery-ast-type" flags are flipped on); Reviewed By: sammccall Subscribers: rsmith, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D79160
2020-04-15[AST] Fix recovery-expr crash on invalid aligned attr.Haojian Wu1-1/+3
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-02[OPENMP50]Add initial support for OpenMP 5.0 iterator.Alexey Bataev1-0/+16
Added basic parsing/semantic analysis/(de)serialization support for iterator expression introduced in OpenMP 5.0.