16 Commits

Author SHA1 Message Date
Matheus Izvekov
2bde13cda1
[clang] NFCI: use TemplateArgumentLoc for NTTP DefaultArgument (#92852)
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-22 12:18:44 -03:00
Matheus Izvekov
e42b799bb2
[clang] NFCI: use TemplateArgumentLoc for type-param DefaultArgument (#92854)
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-05-21 20:27:50 -03:00
cor3ntin
e90e43fb9c
[Clang][NFC] Rename CXXMethodDecl::isPure -> is VirtualPure (#78463)
To avoid any possible confusion with the notion of pure function and the
gnu::pure attribute.
2024-01-18 15:30:58 +01:00
Vlad Serebrennikov
aaba3761db [clang][NFC] Refactor ObjCMethodDecl::ImplementationControl
This patch moves `ObjCMethodDecl::ImplementationControl` to a DeclBase.h so that it's complete at the point where corresponsing bit-field is declared. This patch also converts it to a scoped enum `clang::ObjCImplementationControl`.
2023-11-01 13:40:11 +03:00
Corentin Jabot
47ccfd7a89 [Clang] Implement P2741R3 - user-generated static_assert messages
Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D154290
2023-07-20 08:33:19 +02:00
Volodymyr Sapsai
18530e5d07
[ODRHash] Stop hashing ObjCMethodDecl::isOverriding as it doesn't capture inherent method quality.
`isOverriding` depends on the surrounding code and not on the method
itself. That's why it can be different in different modules. And
mismatches shouldn't be an error.

rdar://109481753

Differential Revision: https://reviews.llvm.org/D154459
2023-07-05 18:04:32 -07:00
Richard Smith
bc73ef0031 PR60985: Fix merging of lambda closure types across modules.
Previously, distinct lambdas would get merged, and multiple definitions
of the same lambda would not get merged, because we attempted to
identify lambdas by their ordinal position within their lexical
DeclContext. This failed for lambdas within namespace-scope variables
and within variable templates, where the lexical position in the context
containing the variable didn't uniquely identify the lambda.

In this patch, we instead identify lambda closure types by index within
their context declaration, which does uniquely identify them in a way
that's consistent across modules.

This change causes a deserialization cycle between the type of a
variable with deduced type and a lambda appearing as the initializer of
the variable -- reading the variable's type requires reading and merging
the lambda, and reading the lambda requires reading and merging the
variable. This is addressed by deferring loading the deduced type of a
variable until after we finish recursive deserialization.

This also exposes a pre-existing subtle issue where loading a
variable declaration would trigger immediate loading of its initializer,
which could recursively refer back to properties of the variable. This
particularly causes problems if the initializer contains a
lambda-expression, but can be problematic in general. That is addressed
by switching to lazily loading the initializers of variables rather than
always loading them with the variable declaration. As well as fixing a
deserialization cycle, that should improve laziness of deserialization
in general.

LambdaDefinitionData had 63 spare bits in it, presumably caused by an
off-by-one-error in some previous change. This change claims 32 of those bits
as a counter for the lambda within its context. We could probably move the
numbering to separate storage, like we do for the device-side mangling number,
to optimize the likely-common case where all three numbers (host-side mangling
number, device-side mangling number, and index within the context declaration)
are zero, but that's not done in this change.

Fixes #60985.

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D145737
2023-03-30 14:22:40 -07:00
Volodymyr Sapsai
ed7a46a8de [modules] Allow parsing a duplicate Obj-C interface if a previous one comes from a hidden [sub]module.
Instead of emitting a redefinition error, check that definitions are
equivalent and allow such scenario.

A few non-obvious implementation details:
* to avoid multiple definitions in the redeclaration chain we just drop
  the new definition after checking for equivalence;
* for checking definition equivalence use ODR hash instead of
  ASTStructuralEquivalence because it avoids excessive recursive
  deserialization. Though after detecting a mismatch we do deserialize
  multiple entities to provide a better error message.

rdar://82908223

Differential Revision: https://reviews.llvm.org/D124286
2023-01-20 10:18:18 -06:00
Volodymyr Sapsai
6ba4afb4d6 [ODRHash] Hash ObjCInterfaceDecl and diagnose discovered mismatches.
When two modules contain interfaces with the same name, check the
definitions are equivalent and diagnose if they are not.

Differential Revision: https://reviews.llvm.org/D140073
2023-01-20 10:18:18 -06:00
Volodymyr Sapsai
160bc160b9 [ODRHash] Hash RecordDecl and diagnose discovered mismatches.
When two modules contain struct/union with the same name, check the
definitions are equivalent and diagnose if they are not. This is similar
to `CXXRecordDecl` where we already discover and diagnose mismatches.

rdar://problem/56764293

Differential Revision: https://reviews.llvm.org/D71734
2023-01-19 15:57:48 -06:00
Volodymyr Sapsai
a65d5309d5 [ODRHash] Detect duplicate ObjCProtocolDecl ODR mismatches during parsing.
When during parsing we encountered a duplicate `ObjCProtocolDecl`, we
were always emitting an error. With this change we accept
* when a previous `ObjCProtocolDecl` is in a hidden [sub]module;
* parsed `ObjCProtocolDecl` is the same as the previous one.

And in case of mismatches we provide more detailed error messages.

rdar://93069080

Differential Revision: https://reviews.llvm.org/D130327
2022-11-17 18:31:32 -08:00
Volodymyr Sapsai
dcb71b5e1d [ODRHash] Hash ObjCPropertyDecl and diagnose discovered mismatches.
Differential Revision: https://reviews.llvm.org/D130326
2022-11-17 17:22:03 -08:00
Volodymyr Sapsai
2662009c87 [ODRHash] Hash ObjCMethodDecl and diagnose discovered mismatches.
Differential Revision: https://reviews.llvm.org/D130325
2022-10-17 18:48:24 -07:00
Volodymyr Sapsai
37fdca21f7 [ODRHash] Rename isDeclToBeProcessed to isSubDeclToBeProcessed. NFC intended.
The method is used only for sub-Decls, so reflect that in the name.
2022-10-17 18:24:44 -07:00
Volodymyr Sapsai
9c79eab7fd [ODRHash] Hash ObjCProtocolDecl and diagnose discovered mismatches.
Differential Revision: https://reviews.llvm.org/D130324
2022-10-17 16:29:52 -07:00
Volodymyr Sapsai
3e7350f317 [ODRHash diagnostics] Move ODRDiagsEmitter to libAST in separate files. NFC.
Intend to use `ODRDiagsEmitter` during parsing to diagnose a parsed
definition differing from a definition with the same name from a hidden
[sub]module.

Differential Revision: https://reviews.llvm.org/D128695
2022-09-07 14:40:37 -07:00