6037 Commits

Author SHA1 Message Date
Nikita Popov
1295aa2e81
[Clang] Add -fwrapv-pointer flag (#122486)
GCC supports three flags related to overflow behavior:
 * `-fwrapv`: Makes signed integer overflow well-defined.
 * `-fwrapv-pointer`: Makes pointer overflow well-defined.
* `-fno-strict-overflow`: Implies `-fwrapv -fwrapv-pointer`, making both
signed integer overflow and pointer overflow well-defined.

Clang currently only supports `-fno-strict-overflow` and `-fwrapv`, but
not `-fwrapv-pointer`.

This PR proposes to introduce `-fwrapv-pointer` and adjust the semantics
of `-fwrapv` to match GCC.

This allows signed integer overflow and pointer overflow to be
controlled independently, while `-fno-strict-overflow` still exists to
control both at the same time (and that option is consistent across GCC
and Clang).
2025-01-28 09:57:00 +01:00
Gedare Bloom
d50ebd47ae
[clang-format] Add style option PenaltyBreakBeforeMemberAccess (#118409)
The penalty for breaking before a member access is hard-coded to 150.
Add a configuration option to allow setting it.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2025-01-27 21:40:17 -08:00
Aidan Goldfarb
7fd58339b4
[clang] Add __nullptr as a keyword to C (#123119)
This PR resolves #121503. 

---------

Co-authored-by: Aidan <aidan.goldfarb@mail.mcgill.ca>
Co-authored-by: Erich Keane <ekeane@nvidia.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-01-27 18:12:50 -05:00
cor3ntin
0e372c3ea3
Revert "[Clang] call HandleImmediateInvocation before checking for immediate escacalating expressions" (#124646)
Reverts llvm/llvm-project#124414

Turns out to be an important compile time regression, I'll come up with
a less disruptive approach
2025-01-27 23:51:19 +01:00
cor3ntin
5815a31105
[Clang] call HandleImmediateInvocation before checking for immediate escacalating expressions (#124414)
HandleImmediateInvocation can call MarkExpressionAsImmediateEscalating
and should always be called before
CheckImmediateEscalatingFunctionDefinition.

However, we were not doing that in `ActFunctionBody`.

We simply move CheckImmediateEscalatingFunctionDefinition to
PopExpressionEvaluationContext.

Fixes #119046
2025-01-27 22:21:48 +01:00
André Brand
e734f01bff
[clang] Prevent duplicated instantiation of enumerators of unscoped member enumerations (#124407)
This commit addresses a bug occurring when an unscoped member enumeration
of a class template is introduced with an opaque-enum-declaration and later
redeclared with an enum-specifier (per C++23 [class.mem] p6).
Previously, the enumerators, or EnumConstantDecl, of the enum-specifier
were instantiated at both declarations, leading to different issues:
* erroneous ambiguities when referencing the enumerators,
* duplicated diagnostics in the enumerator-list.

The issue is resolved by ensuring that enumerators are instantiated only
at the first instantiated declaration, analogous to nested classes.

Fixes #124405
2025-01-27 21:42:33 +01:00
cor3ntin
561132e71b
[Clang] Fix immediate escalation of template function specializations. (#124404)
We record whether an expression is immediate escalating in the
FunctionScope.
However, that only happen when parsing or transforming an expression.
This might not happen when transforming a non dependent expression.

This patch fixes that by considering a function immediate when
instantiated from an immediate function.

Fixes #123405
2025-01-27 15:50:51 +01:00
Dipesh Sharma
54928a10c8
[clang] __STDC_NO_THREADS__ is no longer necessary for VS 2022 1939 and above (#117149)
Since `__STDC_NO_THREADS__` is a reserved identifier,
- If `MSVC version < 17.9`
- C version < C11(201112L)
- When `<threads.h>` is unavailable `!__has_include(<threads.h>)` is
`__has_include` is defined.

Closes #115529
2025-01-27 09:30:53 -05:00
Robert Dazi
ddbfe6f7d2
[Sema] Fix __array_rank instantiation (#124491)
The type being queried was left as a template type parameter, making the
whole expression as dependent and thus not eligible to static_assert.

Fixes #123498

Co-authored-by: v01dxyz <v01dxyz@v01d.xyz>
Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2025-01-27 12:43:37 +01:00
Manuel Sainz de Baranda y Goñi
33ad474c45
[Clang] Add predefined macros for integer constants (#123514)
This adds predefined macros for integer constants to implement section 7.18.4 of ISO/IEC 9899:1999 in `<stdint.h>` in a safe way:

```
__INT8_C(c)
__INT16_C(c)
__INT32_C(c)
__INT64_C(c)
__INTMAX_C(c)
__UINT8_C(c)
__UINT16_C(c)
__UINT32_C(c)
__UINT64_C(c)
__UINTMAX_C(c)
```

Which improves compatibility with GCC and makes it trivial to implement
section 7.18.4 of ISO/IEC 9899:1999.

Clang defines `__INT<N>_C_SUFFIX__`, `__UINT<N>_C_SUFFIX__`,
`__INTAX_C_SUFFIX__` and `__UINTMAX_C_SUFFIX__`, but these macros are
useless for this purpose.

Let's say, for example, that `__INT64_C_SUFFIX__` expands to `L` or
`LL`. If the user defines them as a macros, the compiler will produce
errors if `INT64_C` is implemented in `<stdint.h>` using
`__INT64_C_SUFFIX__`:

**minimal-test.c:**
```cpp
#if defined(__clang__) & !defined(__INT64_C)
#	pragma clang diagnostic push
#	pragma clang diagnostic ignored "-Wreserved-identifier"
#	define __PSTDC_INT_C_(literal, suffix) literal##suffix
#	define __PSTDC_INT_C(literal, suffix) __PSTDC_INT_C_(literal, suffix)
#	define INT64_C(literal) __PSTDC_INT_C(literal, __INT64_C_SUFFIX__)
#	pragma clang diagnostic pop
#elif defined(__GNUC__)
#	define INT64_C __INT64_C
#endif

typedef __INT64_TYPE__ int64_t;

#define L  "Make Clang produce an error"
#define LL "Make Clang produce an error"

int main(int argc, char **argv)
	{
	(void)argc; (void)argv;
	int64_t v = INT64_C(9223372036854775807);
	(void)v;
	return 0;
	}

```

<img width="697" alt="imagen"
src="https://github.com/user-attachments/assets/6df97af6-7cfd-4cf9-85b7-d7c854509325"
/>

**test.c:**
```cpp
#if defined(__clang__) && !defined(__INT8_C)
#	pragma clang diagnostic push
#	pragma clang diagnostic ignored "-Wreserved-identifier"

#	define __PSTDC_INT_C_(literal, suffix) literal##suffix
#	define __PSTDC_INT_C(literal, suffix) __PSTDC_INT_C_(literal, suffix)

#	define INT8_C(literal)    __PSTDC_INT_C(literal, __INT8_C_SUFFIX__)
#	define INT16_C(literal)   __PSTDC_INT_C(literal, __INT16_C_SUFFIX__)
#	define INT32_C(literal)   __PSTDC_INT_C(literal, __INT32_C_SUFFIX__)
#	define INT64_C(literal)   __PSTDC_INT_C(literal, __INT64_C_SUFFIX__)
#	define INTMAX_C(literal)  __PSTDC_INT_C(literal, __INTMAX_C_SUFFIX__)
#	define UINT8_C(literal)   __PSTDC_INT_C(literal, __UINT8_C_SUFFIX__)
#	define UINT16_C(literal)  __PSTDC_INT_C(literal, __UINT16_C_SUFFIX__)
#	define UINT32_C(literal)  __PSTDC_INT_C(literal, __UINT32_C_SUFFIX__)
#	define UINT64_C(literal)  __PSTDC_INT_C(literal, __UINT64_C_SUFFIX__)
#	define UINTMAX_C(literal) __PSTDC_INT_C(literal, __UINTMAX_C_SUFFIX__)

#	pragma clang diagnostic pop

#else
#	define INT8_C    __INT8_C
#	define INT16_C   __INT16_C
#	define INT32_C   __INT32_C
#	define INT64_C   __INT64_C
#	define INTMAX_C  __INTMAX_C
#	define UINT8_C   __UINT8_C
#	define UINT16_C  __UINT16_C
#	define UINT32_C  __UINT32_C
#	define UINT64_C  __UINT64_C
#	define UINTMAX_C __UINTMAX_C
#endif

typedef __INT8_TYPE__    int8_t;
typedef __INT16_TYPE__   int16_t;
typedef __INT32_TYPE__   int32_t;
typedef __INT64_TYPE__   int64_t;
typedef __INTMAX_TYPE__  intmax_t;
typedef __UINT8_TYPE__   uint8_t;
typedef __UINT16_TYPE__  uint16_t;
typedef __UINT32_TYPE__  uint32_t;
typedef __UINT64_TYPE__  uint64_t;
typedef __UINTMAX_TYPE__ uintmax_t;

#define L   "Make Clang produce an error"
#define LL  "Make Clang produce an error"
#define U   "Make Clang produce an error"
#define UL  "Make Clang produce an error"
#define ULL "Make Clang produce an error"

int main(int argc, char **argv)
	{
	(void)argc; (void)argv;

	int8_t    a = INT8_C   (127);
	int16_t   b = INT16_C  (32767);
	int32_t   c = INT32_C  (2147483647);
	int64_t   d = INT64_C  (9223372036854775807);
	intmax_t  e = INTMAX_C (9223372036854775807);
	uint8_t   f = UINT8_C  (255);
	uint16_t  g = UINT16_C (65535);
	uint32_t  h = UINT32_C (4294967295);
	uint64_t  i = UINT64_C (18446744073709551615);
	uintmax_t j = UINTMAX_C(18446744073709551615);

	(void)a; (void)b; (void)c; (void)d; (void)e;
	(void)f; (void)g; (void)h; (void)i; (void)j;
	return 0;
	}
```
2025-01-26 16:48:42 +01:00
cor3ntin
e4514293f9
[Clang] Correctly determine constexprness of dependent lambdas. (#124468)
We skipped checking if a lambda is constexpr if the parent context was
dependent, even if the lambda itself wasn't (and there is no other
opportunity to establish constexprness)


Fixes #114234
Fixes #97958
2025-01-26 16:17:21 +01:00
Valentyn Yukhymenko
f607e3fd23
[Clang][Sema] Reject declaring an alias template with the same name as its template parameter. (#123533)
The issue occurred because the template parameter scope was skipped
too early, before diagnosing the alias name shadowing.

To fix this, the patch moves it to after LookupName, such that the behavior
remains consistent with the typedef implementation.

Fixes llvm#123423
2025-01-25 15:01:40 +08:00
Timm Baeder
e4009ed3d6
[clang][docs] Update bytecode interpreter docs (#124252)
Just a light update, not adding a lot of new information.
2025-01-24 19:17:51 +01:00
Matheus Izvekov
28ad8978ee
Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (#124137)
This patch relands the following PRs:
* #111711
* #107350
* #111457

All of these patches were reverted due to an issue reported in
https://github.com/llvm/llvm-project/pull/111711#issuecomment-2406491485,
due to interdependencies.

---
[clang] Finish implementation of P0522

This finishes the clang implementation of P0522, getting rid
of the fallback to the old, pre-P0522 rules.

Before this patch, when partial ordering template template parameters,
we would perform, in order:
* If the old rules would match, we would accept it. Otherwise, don't
  generate diagnostics yet.
* If the new rules would match, just accept it. Otherwise, don't
  generate any diagnostics yet again.
* Apply the old rules again, this time with diagnostics.

This situation was far from ideal, as we would sometimes:
* Accept some things we shouldn't.
* Reject some things we shouldn't.
* Only diagnose rejection in terms of the old rules.

With this patch, we apply the P0522 rules throughout.

This needed to extend template argument deduction in order
to accept the historial rule for TTP matching pack parameter to non-pack
arguments.
This change also makes us accept some combinations of historical and P0522
allowances we wouldn't before.

It also fixes a bunch of bugs that were documented in the test suite,
which I am not sure there are issues already created for them.

This causes a lot of changes to the way these failures are diagnosed,
with related test suite churn.

The problem here is that the old rules were very simple and
non-recursive, making it easy to provide customized diagnostics,
and to keep them consistent with each other.

The new rules are a lot more complex and rely on template argument
deduction, substitutions, and they are recursive.

The approach taken here is to mostly rely on existing diagnostics,
and create a new instantiation context that keeps track of this context.

So for example when a substitution failure occurs, we use the error
produced there unmodified, and just attach notes to it explaining
that it occurred in the context of partial ordering this template
argument against that template parameter.

This diverges from the old diagnostics, which would lead with an
error pointing to the template argument, explain the problem
in subsequent notes, and produce a final note pointing to the parameter.

---
[clang] CWG2398: improve overload resolution backwards compat

With this change, we discriminate if the primary template and which partial
specializations would have participated in overload resolution prior to
P0522 changes.

We collect those in an initial set. If this set is not empty, or the
primary template would have matched, we proceed with this set as the
candidates for overload resolution.

Otherwise, we build a new overload set with everything else, and proceed
as usual.

---
[clang] Implement TTP 'reversed' pack matching for deduced function template calls.

Clang previously missed implementing P0522 pack matching
for deduced function template calls.
2025-01-23 20:37:33 -03:00
Oleksandr T.
4018317407
[Clang] restrict use of attribute names reserved by the C++ standard (#106036)
Fixes #92196

https://eel.is/c++draft/macro.names#2
> A translation unit shall not #define or #undef names lexically
identical to keywords, to the identifiers listed in Table
[4](https://eel.is/c++draft/lex.name#tab:lex.name.special), or to the
[attribute-token](https://eel.is/c++draft/dcl.attr.grammar#nt:attribute-token)s
described in [[dcl.attr]](https://eel.is/c++draft/dcl.attr), except that
the names likely and unlikely may be defined as function-like macros
([[cpp.replace]](https://eel.is/c++draft/cpp.replace))[.](https://eel.is/c++draft/macro.names#2.sentence-1)
2025-01-23 21:16:59 +02:00
cor3ntin
17756aa9c9
[Clang] [Release Notes] Implicit lifetimes are a C++23 feature 2025-01-23 12:19:52 +01:00
Dmitry Polukhin
cad6bbade0
[C++20][Modules] Fix crash/compiler error due broken AST links (#123648)
Summary:
This PR fixes bugreport
https://github.com/llvm/llvm-project/issues/122493 The root problem is
the same as before lambda function and DeclRefExpr references a variable
that does not belong to the same module as the enclosing function body.
Therefore iteration over the function body doesn’t visit the VarDecl.
Before this change RelatedDeclsMap was created only for canonical decl
but in reality it has to be done for the definition of the function that
does not always match the canonical decl.

Test Plan: check-clang
2025-01-23 10:35:58 +00:00
Nathan Ridge
ba17485520
[clang][CodeComplete] Use HeuristicResolver to resolve DependentNameTypes (#123818)
Fixes https://github.com/clangd/clangd/issues/1249
2025-01-23 01:43:44 -05:00
Weining Lu
3c7a878d91 [LoongArch] Summary clang20 release notes 2025-01-23 12:38:04 +08:00
Younan Zhang
b46fcb9fa3
[Clang] Implement CWG 2628 "Implicit deduction guides should propagate constraints" (#111143)
Closes https://github.com/llvm/llvm-project/issues/98592
2025-01-23 10:53:00 +08:00
Yeoul Na
64360899c7
[BoundsSafety][Doc] Add BoundsSafetyAdoptionGuide.rst (#120674)
This adds an instruction to adopt `-fbounds-safety` using the preview
implementation available in the fork of llvm-project.
2025-01-22 15:41:59 -08:00
cor3ntin
213e03ca11
[Clang] Fix handling of immediate escalation for inherited constructors (#112860)
Fixes #112677
2025-01-22 22:00:17 +01:00
Shafik Yaghmour
0a9c08c59b
[Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (#95474)
P2280R4 allows the use of references in pointers of unknown origins in a
constant expression context but only in specific cases that could be
constant expressions.

We track whether a variable is a constexpr unknown in a constant
expression by setting a flag in either APValue or LValue and using this
flag to prevent using unknown values in places where it is not allowed.

Fixes: https://github.com/llvm/llvm-project/issues/63139 https://github.com/llvm/llvm-project/issues/63117
2025-01-22 09:28:08 +01:00
Younan Zhang
69d0c4c167
[Clang] SubstituteConstraintExpressionWithoutSatisfaction needs an unevaluated context (#123883)
It turns out that the substitution for expression comparing also needs
an unevaluated context, otherwise any reference to immediate functions
might not be properly handled.

As a fallout, this also guards the VLA transformation under unevaluated
context
with `InConditionallyConstantEvaluateContext` to avoid duplicate
diagnostics.

Fixes https://github.com/llvm/llvm-project/issues/123472

---------

Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2025-01-22 16:08:19 +08:00
Vinicius Tadeu Zein
6ab9dafec8
[clang] Implement #pragma clang section on COFF targets (#112714)
This patch implements the directive #pragma clang section on COFF targets
with the exact same features available on ELF and Mach-O.
2025-01-21 16:12:58 -08:00
Oleksandr T.
cac67d3936
[Clang] emit -Wignored-qualifiers diagnostic for cv-qualified base classes (#121419)
Fixes #55474
2025-01-21 22:49:24 +02:00
Sirraide
33656932b0
[clang-format] Rename ExportBlockIndentation -> IndentExportBlock (#123493)
This renames the `ExportBlockIndentation` option and adds a config parse
test, as requested in #110381.
2025-01-21 14:13:13 +01:00
Younan Zhang
f07e5162d0
[Clang] Delegate part of SetupConstraintScope's job to LambdaScopeForCallOperatorInstantiationRAII (#123687)
Now that the RAII object has a dedicate logic for handling nested
lambdas, where the inner lambda could reference any
captures/variables/parameters from the outer lambda, we can shift the
responsibility for managing lambdas away from SetupConstraintScope().

I think this also makes the structure clearer.

Fixes https://github.com/llvm/llvm-project/issues/123441
2025-01-21 14:16:17 +08:00
Yaxun (Sam) Liu
e87b843811 Reland [OffloadBundler] Compress bundles over 4GB (#122307)
Reland the patch after fixing the lit test.
2025-01-20 21:17:21 -05:00
Yaxun (Sam) Liu
72c560da4b Revert "[OffloadBundler] Compress bundles over 4GB (#122307)"
revert due to failure in buildbot

 https://lab.llvm.org/buildbot/#/builders/144/builds/16114

This reverts commit 4e2efc3bd500836d0fa977d6e257ffee2c92e178.
2025-01-20 20:58:05 -05:00
Yaxun (Sam) Liu
4e2efc3bd5
[OffloadBundler] Compress bundles over 4GB (#122307)
Added initial support for version 3 of the compressed offload bundle
format, which uses 64-bit fields for Total File Size and Uncompressed
Binary Size. This enables support for files larger than 4GB. The support
is currently experimental and can be enabled by setting the environment
variable `COMPRESSED_BUNDLE_FORMAT_VERSION=3`.
2025-01-20 20:17:30 -05:00
Amr Hesham
e5992b686b
[Clang] Fix warning for non std functions with name infinity (#123417)
Fix reporting diagnostic for non std functions that has the name
`infinity`

Fixes: #123231
2025-01-20 22:21:48 +01:00
Nikolas Klauser
c248fc1880
[Clang] Document some of the implementation-defined keywords (#84591) 2025-01-20 17:58:16 +01:00
Arseniy Zaostrovnykh
d049db8362
[clang] Fix false warning on reinterpret_casting unknown template type (#109430)
After 1595988ee6f9732e7ea79928af8a470ad5ef7dbe
diag::warn_undefined_reinterpret_cast started raising on
non-instantiated template functions without sufficient knowledge whether
the reinterpret_cast is indeed UB.
2025-01-20 10:02:57 +01:00
Younan Zhang
6f0a627dd3
[Clang] Correctly propagate type aliases' unexpanded flags up to lambda (#122875)
We should have been checking desugar() for the type of the right-hand
side of a typedef declaration, instead of using getCanonicalType(),
which points to the end of the type alias chain.

Fixes https://github.com/llvm/llvm-project/issues/122417
2025-01-20 16:56:04 +08:00
DeNiCoN
293dbea8b0
Fix some typos (#123506)
Fixes some typos in the documentation
2025-01-19 16:53:39 +01:00
Nikolas Klauser
0cb2fe5183
[Clang] Deprecate __is_referenceable (#123185)
`__is_referenceable` is almost unused in the wild, and the few cases I
was able to find had checks around them. Since The places in the
standard library where `__is_referenceable` is used have bespoke
builtins, it doesn't make a ton of sense to keep this builtin around.

See #123078
2025-01-19 10:28:38 +01:00
Sirraide
106c483a10
[clang-format] Improve brace wrapping and add an option to control indentation of export { ... } (#110381)
`export { ... }` blocks can get a bit long, so I thought it would make
sense to have an option that makes it so their contents are not indented
(basically the same argument as for namespaces).

This is based on the `NamespaceIndentation` option, except that there is
no option to control the behaviour of `export` blocks when nested because
nesting them doesn’t really make sense.

Additionally, brace wrapping of short `export { ... }` blocks is now controlled by the
`AllowShortBlocksOnASingleLine` option. There is no separate option just for `export`
blocks because you can just write e.g. `export int x;` instead of `export { int x; }`.

This closes #121723.
2025-01-19 00:26:40 +01:00
Chuanqi Xu
c5e4afe673
[C++20] [Modules] Support module level lookup (#122887) (#123281)
Close https://github.com/llvm/llvm-project/issues/90154

This patch is also an optimization to the lookup process to utilize the
information provided by `export` keyword.

Previously, in the lookup process, the `export` keyword only takes part
in the check part, it doesn't get involved in the lookup process. That
said, previously, in a name lookup for 'name', we would load all of
declarations with the name 'name' and check if these declarations are
valid or not. It works well. But it is inefficient since it may load
declarations that may not be wanted.

Note that this patch actually did a trick in the lookup process instead
of bring module information to DeclarationName or considering module
information when deciding if two declarations are the same. So it may
not be a surprise to me if there are missing cases. But it is not a
regression. It should be already the case. Issue reports are welcomed.

In this patch, I tried to split the big lookup table into a lookup table
as before and a module local lookup table, which takes a combination of
the ID of the DeclContext and hash value of the primary module name as
the key. And refactored `DeclContext::lookup()` method to take the
module information. So that a lookup in a DeclContext won't load
declarations that are local to **other** modules.

And also I think it is already beneficial to split the big lookup table
since it may reduce the conflicts during lookups in the hash table.

BTW, this patch introduced a **regression** for a reachability rule in
C++20 but it was false-negative. See
'clang/test/CXX/module/module.interface/p7.cpp' for details.

This patch is not expected to introduce any other
regressions for non-c++20-modules users since the module local lookup
table should be empty for them.
2025-01-17 13:41:44 +08:00
Oleksandr T.
d49a2d2bc9
[Clang] disallow the use of asterisks preceding constructor and destructor names (#122621)
Fixes #121706
2025-01-16 13:00:41 -08:00
cor3ntin
b311ab0f89
[Clang] Fix canonicalization of pack indexing types (#123209)
A canonicalized pack indexing should refer to a canonicalized pattern

Fixes #123033
2025-01-16 17:50:31 +01:00
Victor Campos
226a9d73ee
Add documentation for Multilib custom flags (#114998)
This patch is the fourth step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as --target, -mcpu, -mfpu, -mbranch-protection.
However, some library variants are particular to features that do not
correspond to any command-line options. Examples include variants for
multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch updates the
documentation.
2025-01-16 09:53:04 +00:00
Younan Zhang
fd4f94ddbf
[Clang] Correct the order of substituted arguments in CTAD alias guides (#123022)
We missed a case of type constraints referencing deduced template
parameters when constructing a deduction guide for the type alias. This
patch fixes the issue by swapping the order of constructing 'template
arguments not appearing in the type alias parameters' and 'template
arguments that are not yet deduced'.

Fixes https://github.com/llvm/llvm-project/issues/122134
2025-01-16 16:37:57 +08:00
Chuanqi Xu
731db2a03e Revert "[C++20] [Modules] Support module level lookup (#122887)"
This reverts commit 7201cae106260aeb3e9bbbb7d5291ff30f05076a.
2025-01-16 10:23:11 +08:00
Erich Keane
bf17016a92
Add 'enum_select' diagnostic selection to clang. (#122505)
This causes us to generate an enum to go along with the select
diagnostic, which allows for clearer diagnostic error emit lines.

The syntax for this is:

%enum_select<EnumerationName>{%OptionalEnumeratorName{Text}|{Text2}}0

Where the curley brackets around the select-text are only required if an
Enumerator name is provided.

The TableGen here emits this as a normal 'select' to the frontend, which
permits us to reuse all of the existing 'select' infrastructure.
Documentation is the same as well.

---------

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-01-15 12:59:08 -08:00
Chuanqi Xu
7201cae106
[C++20] [Modules] Support module level lookup (#122887)
Close https://github.com/llvm/llvm-project/issues/90154

This patch is also an optimization to the lookup process to utilize the
information provided by `export` keyword.

Previously, in the lookup process, the `export` keyword only takes part
in the check part, it doesn't get involved in the lookup process. That
said, previously, in a name lookup for 'name', we would load all of
declarations with the name 'name' and check if these declarations are
valid or not. It works well. But it is inefficient since it may load
declarations that may not be wanted.

Note that this patch actually did a trick in the lookup process instead
of bring module information to DeclarationName or considering module
information when deciding if two declarations are the same. So it may
not be a surprise to me if there are missing cases. But it is not a
regression. It should be already the case. Issue reports are welcomed.

In this patch, I tried to split the big lookup table into a lookup table
as before and a module local lookup table, which takes a combination of
the ID of the DeclContext and hash value of the primary module name as
the key. And refactored `DeclContext::lookup()` method to take the
module information. So that a lookup in a DeclContext won't load
declarations that are local to **other** modules.

And also I think it is already beneficial to split the big lookup table
since it may reduce the conflicts during lookups in the hash table.

BTW, this patch introduced a **regression** for a reachability rule in
C++20 but it was false-negative. See
'clang/test/CXX/module/module.interface/p7.cpp' for details.

This patch is not expected to introduce any other
regressions for non-c++20-modules users since the module local lookup
table should be empty for them.

---

On the API side, this patch unfortunately add a maybe-confusing argument
`Module *NamedModule` to
`ExternalASTSource::FindExternalVisibleDeclsByName()`. People may think
we can get the information from the first argument `const DeclContext
*DC`. But sadly there are declarations (e.g., namespace) can appear in
multiple different modules as a single declaration. So we have to add
additional information to indicate this.
2025-01-15 15:15:35 +08:00
Eli Friedman
1682deed0f
[libclang] Add API to query more information about base classes. (#120300)
The first API is clang_visitCXXBaseClasses: this allows visiting the
base classes without going through the generic child visitor (which is
awkward, and doesn't work for template instantiations).

The second API is clang_getOffsetOfBase; this allows computing the
offset of a base in the class layout, the same way
clang_Cursor_getOffsetOfField computes the offset of a field.

Also, add a Python binding for the existing function
clang_isVirtualBase.
2025-01-14 13:57:44 -08:00
Sander de Smalen
97cf5aa1b2
[Clang] Add AArch64 SME changes to release notes (NFC) (#122899) 2025-01-14 16:21:58 +00:00
Jonathan Thackray
e4e85e04c3
[NFC][AArch64] Add relnote saying SVE2.1 and SME2.1 now fully implemented by ACLE (#122705) 2025-01-14 08:34:39 +00:00
David Pagan
ad38e24eb7
[clang][OpenMP] Add 'align' modifier for 'allocate' clause (#121814)
The 'align' modifier is now accepted in the 'allocate' clause. Added LIT
tests covering codegen, PCH, template handling, and serialization for
'align' modifier.

Added support for align-modifier to release notes.

Testing
- New allocate modifier LIT tests.
- OpenMP LIT tests.
- check-all
2025-01-13 05:44:48 -08:00