2221 Commits

Author SHA1 Message Date
Qiongsi Wu
f7aa1cdc9b
[clang] Canonicalizing -include-pch input in the Frontend (#180065)
This patch adds logic to canonicalize `-include-pch`'s input in the
frontend. This way, the `ASTWriter` always serializes the canonicalized
path to the included pch file whether the input is an absolute path or a
relative path.

Fixes rdar://168596546.
2026-02-06 14:41:45 -08:00
Jan Svoboda
4c05ff11ff
[clang][modules] Support every import syntax in single-module-parse-mode (#179610)
Previously, `-fmodules-single-module-parse-mode` only prevented module
compilation/loading when initiated from an `#include` or `#import`
directive. This PR does the same for `@import`, `#pragma clang module
import` and `#pragma clang module load`. This is done by sinking the
logic down into `CompilerInstance::loadModule()`.
2026-02-05 12:38:53 -08:00
Chuanqi Xu
013b345af9
[Serialization] Stop demote var definition as declaration (#172430) (#177117)
Close https://github.com/llvm/llvm-project/issues/172241 
Close https://github.com/llvm/llvm-project/issues/64034 
Close https://github.com/llvm/llvm-project/issues/149404
 Close https://github.com/llvm/llvm-project/issues/174858

After this patch, we (the clang dev) no longer assumes there are at most
one definition in a redeclaration chain.

See


https://discourse.llvm.org/t/rfc-clang-not-assuming-there-is-at-most-one-definition-in-a-redeclaration-chain/89360
for details.

---

Update since last commit:

Previously I remove the code to update visibility accidently. This is
the root cause of the failure.
2026-02-02 15:23:57 +08:00
Chuanqi Xu
56ad5241c9 [NFC] [C++20] [Modules] Make sure we can use named module with module map 2026-01-28 14:05:32 +08:00
Chuanqi Xu
772b15b3be
[C++20] [Modules] Set ManglingContextDecl when we need to mangle a lambda but it's nullptr (#177899)
Close https://github.com/llvm/llvm-project/issues/177385

The root cause of the problem is, when we decide to mangle a lamdba in a
module interface while the ManglingContextDecl is nullptr, we didn't
update ManglingContextDecl. So that the following use of
ManglingContextDecl is an invalid value.
2026-01-26 06:11:25 +00:00
Ian Anderson
aea6a19d78
[test][NFC] Add more keys to test SDKSettings files (#177538)
Every time DarwinSDKInfo reads a new key out of SDKSettings, a boatload
of test SDKSettings files need to be updated across several repositories
and forks and branches. It’s tedious to be careful to update those with
real values so that the tests are properly regression testing older
SDKs. It’s important to be careful so that the tests are accurate, e.g.
to prevent the scenario where DarwinSDKInfo starts reading a new key out
of SDKSettings and assumes that it’s always available everywhere, when
in reality it was only added a few releases ago and will break with
older SDKs. If the test SDKSettings files continue to be updated ad hoc,
it’s going to be really easy to copy/paste a default value everywhere,
and then clients will see incorrect behaviors with the real SDKs, or
even compiler crashes if the key is unconditionally read. Preemptively
add all of the maybe-possibly-compiler relevant keys to the test
SDKSettings files from the real SDKs so that the test files are an
accurate representation and shouldn't need to be touched in the future.
Where the test SDKSettings have intentionally doctored data, add a
Comments key explaining what is changed from the real SDK, and alter the
SDK name with a tag indicating the change.
2026-01-23 23:04:25 -08:00
Michael Park
688b01ad52
[C++20][Modules] Improve namespace look-up performance for modules. (Attempt #2) (#177255) 2026-01-21 18:19:02 -08:00
yronglin
1da403937e
Reapply "[C++20][Modules] Implement P1857R3 Modules Dependency Discovery" (#173130)" (#173789)
The patch reapply https://github.com/llvm/llvm-project/pull/173130.

This patch implement the following papers:
[P1857R3 Modules Dependency Discovery](https://wg21.link/p1857r3).
[P3034R1 Module Declarations Shouldn’t be
Macros](https://wg21.link/P3034R1).
[CWG2947](https://cplusplus.github.io/CWG/issues/2947.html).

At the start of phase 4 an import or module token is treated as starting
a directive and are converted to their respective keywords iff:

 - After skipping horizontal whitespace are
    - at the start of a logical line, or
    - preceded by an export at the start of the logical line.
- Are followed by an identifier pp token (before macro expansion), or
    - <, ", or : (but not ::) pp tokens for import, or
    - ; for module
Otherwise the token is treated as an identifier.

Additionally:

- The entire import or module directive (including the closing ;) must
be on a single logical line and for module must not come from an
#include.
- The expansion of macros must not result in an import or module
directive introducer that was not there prior to macro expansion.
- A module directive may only appear as the first preprocessing tokens
in a file (excluding the global module fragment.)
- Preprocessor conditionals shall not span a module declaration.

After this patch, we handle C++ module-import and module-declaration as
a real pp-directive in preprocessor. Additionally, we refactor module
name lexing, remove the complex state machine and read full module name
during module/import directive handling. Possibly we can introduce a
tok::annot_module_name token in the future, avoid duplicatly parsing
module name in both preprocessor and parser, but it's makes error
recovery much diffcult(eg. import a; import b; in same line).

This patch also introduce 2 new keyword `__preprocessed_module` and
`__preprocessed_import`. These 2 keyword was generated during `-E` mode.
This is useful to avoid confusion with `module` and `import` keyword in
preprocessed output:
```cpp
export module m;
struct import {};
#define EMPTY
EMPTY import foo;
```

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

The previous patch has an use-after-free issue in
Lexer::LexTokenInternal function. Since C++20, the `export`, `import`
and `module` identifiers may be an introducer of a C++ module
declaration/importing directive, and the directive will handled in
`LexIdentifierContinue`. Unfortunately, the EOF may be encountered in
`LexIdentifierContinue` and `CurLexer` might be destructed in
`HandleEndOfFile`, If the code after `LexIdentifierContinue` try to
access `LangOps` or other class members in this Lexer, it will hit
undefined behavior.

This patch also fix the use-after-free issue in Lexer by introduce a
mechanism to delay the destruction of `CurLexer` in `Preprocessor`
class.

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2026-01-20 17:42:46 +08:00
Qiongsi Wu
ca153a65e9
Revert "[clang][Modules] Fix unexpected warnings triggered by a PCH a… (#176499)
…nd a module with config macros (#174034)"

This reverts commit 71925cbdf80d4fc88ef844e726f89aa71c64bceb.

The test case is causing test failures on downstream Swift forks. This
PR reverts the commit to avoid failing the test case on Linux.

rdar://168174041
2026-01-19 12:02:05 -08:00
Jordan Rupprecht
42065cfd74
Revert "[Serialization] Stop demote var definition as declaration" (#176441)
Reverts #172430 (c560f1cf03aa06c0bdd00c5a9b558c16d882af6f).

Causes some failures like `error: static assertion expression is not an
integral constant expression` and `error: substitution into constraint
expression resulted in a non-constant expression` in modules builds.
Repro TBD.
2026-01-16 13:19:07 -06:00
Jan Svoboda
f94afdd0b7
[clang][modules] Unify "context hash" and "specific module cache path" (#176215)
This PR unifies the terminology for:
* "context hash" - previously ambiguously referred to as "module hash"
or as overly specific "module context hash"
* "specific module cache path" - previously referred to as just "module
cache path" - hard to distinguish from the command-line-provided module
cache path without the context hash

NFCI
2026-01-15 12:02:31 -08:00
Chuanqi Xu
c560f1cf03
[Serialization] Stop demote var definition as declaration (#172430)
Close https://github.com/llvm/llvm-project/issues/172241
Close https://github.com/llvm/llvm-project/issues/64034
Close https://github.com/llvm/llvm-project/issues/149404
Close https://github.com/llvm/llvm-project/issues/174858

After this patch, we (the clang dev) no longer assumes there are at
most one definition in a redeclaration chain.

See

https://discourse.llvm.org/t/rfc-clang-not-assuming-there-is-at-most-one-definition-in-a-redeclaration-chain/89360
for details.
2026-01-14 02:54:03 +00:00
Chuanqi Xu
b4ed102b1e
[C++20] [Modules] Avoid infinite loop when checking TU local exposures (#174704)
Close https://github.com/llvm/llvm-project/issues/174543

The root cause of the problem is that the recursion in the code pattern
triggers infinite loop in the checking process for TU local exposure.
2026-01-07 07:24:13 +00:00
Chuanqi Xu
2451172df7
[C++20] [Modules] Don't update MarkAsUsed information for decls from named modules (#174687)
Declarations from named modules are used naturally. Thet are
declarations in other TU. We don't need to record the information for
updating them.
2026-01-07 06:57:40 +00:00
Ian Anderson
33275d0a08
[clang][driver][darwin] Base the platform prefix on the SDK, not the target (#171970)
The search path prefix is really a property of the SDK, and not the
target triple. The target is just being used as a proxy for the SDK.
That's problematic when the SDK being used doesn't match the target
assumption, and the prefix should be taken from the SDK rather than hard
coded.

Parse the SupportedTargets, which is what holds the platform prefix, in
DarwinSDKInfo. SupportedTargets contains an entry for the SDK's
canonical name, and that entry holds a valid OS value so use that
instead of the hard coded map. Include the environment which is also
relevant in some situations, and the vendor and object format in case
they're useful later. Skip architectures because they typically aren't
used for doing platform matching.
2026-01-05 23:42:32 +00:00
Qiongsi Wu
71925cbdf8
[clang][Modules] Fix unexpected warnings triggered by a PCH and a module with config macros (#174034)
When a PCH is compiled with macro definitions on the command line, such
as `-DCONFIG1`, an unexpected warning can occur if the macro definitions
happen to belong to an imported module's config macros. The warning may
look like the following:
```
definition of configuration macro 'CONFIG1' has no effect on the import of 'Mod1'; pass '-DCONFIG1=...' on the command line to configure the module
```
while `-DCONFIG1` is clearly on the command line when `clang` compiles
the source that uses the PCH and the module.

The reason this can happen is a combination of two things:
1. The logic that checks for config macros is not aware of any command
line macros passed through the PCH
([here](7976ac9900/clang/lib/Frontend/CompilerInstance.cpp (L1562))).
2. `clang` _replaces_ the predefined macros on the command line with the
predefined macros from the PCH, which does not include any builtins
([here](7976ac9900/clang/lib/Frontend/CompilerInstance.cpp (L679))).

This PR teaches the preprocessor to recognize the command line macro
definitions passed transitively through the PCH, so that the error check
does not miss these definitions by mistake. The config macro itself
works fine, and it is only the error check that needs fixing.

rdar://95261458
2026-01-05 14:41:22 -08:00
Cyndy Ishida
5089f63460
[clang][modules] Diagnose config mismatches more generally from precompiled files (#174260)
PCHs (but also modules generated from several implicit invocations like
swiftc) previously reported a confusing diagnostic about module caches
being mismatched by subdir. This is an implementation detail of the
module machinery, and not very useful to the end user. Instead, report
this case as a configuration mismatch when the compiler can confirm the
module cache was passed the same between the current TU & previously
compiled products.

Ideally, each argument that could result in this error would be uniquely
reported (e.g., O3), but as a starting point, providing something more
general is strictly better than pointing the user to the module cache.

This patch also includes NFCs for renaming variable names from Module to
AST and formatting cleanup in related areas.

resolves: rdar://167453135
2026-01-05 12:06:24 -08:00
Chuanqi Xu
50351218b3
[C++20] [Modules] Fix incorrect read of TULocalOffset for delayed namespace (#174365)
Close https://github.com/llvm/llvm-project/issues/158321

The root cause of the problem is a mismatch in an initializer.
2026-01-05 07:14:54 +00:00
yronglin
71bba12587
Revert "Reapply "[C++20][Modules] Implement P1857R3 Modules Dependency Discovery" (#173130)" (#173549)
This reverts commit 0d1c396ce8178baf05f277b16bf41b8a6b847d6d.

Co-authored-by: Yihan Wang <yihwang@nvidia.com>
2025-12-25 19:55:40 +08:00
yronglin
0d1c396ce8
Reapply "[C++20][Modules] Implement P1857R3 Modules Dependency Discovery" (#173130)
This PR reapply https://github.com/llvm/llvm-project/pull/107168.

---------

Signed-off-by: Wang, Yihan <yronglin777@gmail.com>
Signed-off-by: yronglin <yronglin777@gmail.com>
2025-12-25 18:55:44 +08:00
Aiden Grossman
d140068f1f
[Clang] Remove remaining REQUIRES: shell statements (#173335)
Now that the internal shell is enabled everywhere by default, the shell
feature makes little sense and essentially only implies windows is
unsupported. These tests all already require specific POSIX systems, so
the feature is no-op. Remove them to eventually remove the shell feature
from lit.
2025-12-22 23:24:26 -08:00
Cyndy Ishida
36c27c63af
[clang][modules] print mtime of input files when recorded in "module-file-info" (#173120)
When debugging issues related to invalidation for implicit module
compilations, it can be helpful to consult the PCM to see what the saved
mtime was.
2025-12-19 16:54:57 -08:00
Paul Kirth
2b8b305d46
Revert "[C++20][Modules] Implement P1857R3 Modules Dependency Discovery" (#173118)
Reverts llvm/llvm-project#107168

This patch broke on bots:
- https://lab.llvm.org/buildbot/#/builders/190/builds/33105
- https://lab.llvm.org/buildbot/#/builders/94/builds/13727
- https://lab.llvm.org/buildbot/#/builders/169/builds/18192

and on mac-aarch64 builds.
see
https://github.com/llvm/llvm-project/pull/107168#issuecomment-3675990781
2025-12-19 15:17:31 -08:00
yronglin
d2e62d9024
[C++20][Modules] Implement P1857R3 Modules Dependency Discovery (#107168)
This PR implement the following papers:
[P1857R3 Modules Dependency Discovery](https://wg21.link/p1857r3).
[P3034R1 Module Declarations Shouldn’t be
Macros](https://wg21.link/P3034R1).
[CWG2947](https://cplusplus.github.io/CWG/issues/2947.html).

At the start of phase 4 an import or module token is treated as starting
a directive and are converted to their respective keywords iff:

 - After skipping horizontal whitespace are
    - at the start of a logical line, or
    - preceded by an export at the start of the logical line.
- Are followed by an identifier pp token (before macro expansion), or
    - <, ", or : (but not ::) pp tokens for import, or
    - ; for module
Otherwise the token is treated as an identifier.

Additionally:

- The entire import or module directive (including the closing ;) must
be on a single logical line and for module must not come from an
#include.
- The expansion of macros must not result in an import or module
directive introducer that was not there prior to macro expansion.
- A module directive may only appear as the first preprocessing tokens
in a file (excluding the global module fragment.)
- Preprocessor conditionals shall not span a module declaration.

After this patch, we handle C++ module-import and module-declaration as
a real pp-directive in preprocessor. Additionally, we refactor module
name lexing, remove the complex state machine and read full module name
during module/import directive handling. Possibly we can introduce a
tok::annot_module_name token in the future, avoid duplicatly parsing
module name in both preprocessor and parser, but it's makes error
recovery much diffcult(eg. import a; import b; in same line).

This patch also introduce 2 new keyword `__preprocessed_module` and
`__preprocessed_import`. These 2 keyword was generated during `-E` mode.
This is useful to avoid confusion with `module` and `import` keyword in
preprocessed output:
```cpp
export module m;
struct import {};
#define EMPTY
EMPTY import foo;
```

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

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
Signed-off-by: Wang, Yihan <yronglin777@gmail.com>
2025-12-19 23:29:17 +08:00
Chuanqi Xu
8994d399fa [NFC] [C++20] [Modules] Add a test for issue 149404
Close https://github.com/llvm/llvm-project/issues/149404 and add its
reproducer
2025-12-19 16:47:19 +08:00
Chuanqi Xu
c6cccbfe08 [NFC] [C++20] [Modules] Add test for issue 137533
Close https://github.com/llvm/llvm-project/issues/137533

This may be fixed by other PR before. Adding a test for avoid further regression.
2025-12-19 16:08:05 +08:00
Chuanqi Xu
04638a76c1 [NFC] [C++20] [Modules] Adding test for typeinfo
Complained by https://github.com/llvm/llvm-project/issues/162758
but failed to reproduce.

Adding the reproducer as a test since I feel testing are always good.
2025-12-19 15:52:27 +08:00
Chuanqi Xu
5937d7f907 [C++20] [Modules] Correct the behavior for adding mangling for lambda in modules
Close https://github.com/llvm/llvm-project/issues/130080
Close https://github.com/llvm/llvm-project/issues/116087

The common pattern of the problem is the lambda is somehow leaked from a
non-inline non-internal function in module purview, and we need to
define a mangling for it by the discuss from
https://github.com/itanium-cxx-abi/cxx-abi/issues/186

The root cause of the issue is a mismatch that give up too quickly when
ManglingContextDecl is nullptr. But we can still get the context
information from DC.
2025-12-19 15:44:34 +08:00
Mariya Podchishchaeva
b512c19716
[clang][win] Fix size passed to delete[] in vector deleting destructors (#172513)
Due to missing parameters to `EmitDeleteCall` only size of a single
array element was passed to `delete[]`.

Reported by
https://github.com/llvm/llvm-project/pull/170337#issuecomment-3660304812
2025-12-17 10:20:49 +01:00
Chuanqi Xu
e60471d9fd [NFC] [C++20] [Modules] Add a test for module local template instantiation in namespace
This was found when debugging
https://github.com/llvm/llvm-project/issues/164466

I think more tests are always good. So I want to land this as a
regression check.
2025-12-16 17:37:53 +08:00
Jan Svoboda
faf879abbb
[clang][lex] Introduce new single-module-parse mode (#135813)
This PR introduces new single-module preprocessing mode. It is very
similar to single-file-parse mode, but has the following differences:
* Single-file mode skips over all inclusion directives, while the
single-module mode skips only over import directives and does resolve
textual inclusion directives.
* Single-file mode enters all branches of a conditional directive with
an undefined identifier, while the single-module enters none of them.

This will be used from the dependency scanner to quickly discover a
subset of modular dependencies of a TU/module. The dependencies aren't
being imported in this mode, but the file-inclusion preprocessor
callback does get invoked.
2025-12-15 16:41:13 -08:00
Mariya Podchishchaeva
d714a6c210
Reland [MS][clang] Add support for vector deleting destructors (#170337)
This reverts commit
54a4da9df6.

MSVC supports an extension allowing to delete an array of objects via
pointer whose static type doesn't match its dynamic type. This is done
via generation of special destructors - vector deleting destructors.
MSVC's virtual tables always contain a pointer to the vector deleting
destructor for classes with virtual destructors, so not having this
extension implemented causes clang to generate code that is not
compatible with the code generated by MSVC, because clang always puts a
pointer to a scalar deleting destructor to the vtable. As a bonus the
deletion of an array of polymorphic object will work just like it does
with MSVC - no memory leaks and correct destructors are called.

This patch will cause clang to emit code that is compatible with code
produced by MSVC but not compatible with code produced with clang of
older versions, so the new behavior can be disabled via passing
-fclang-abi-compat=21 (or lower).

Fixes https://github.com/llvm/llvm-project/issues/19772
2025-12-12 09:54:32 +01:00
Jonas Hahnfeld
5ee6cff90b
[clang] Propagate definition data to all redecls (#170090)
Fix the propagation added in commit 0d490ae55f to include all redecls,
not only previous ones. This fixes another instance of the assertion
"Cannot get layout of forward declarations" in getASTRecordLayout().

Kudos to Alexander Kornienko for providing an initial version of the
reproducer that I further simplified.

Fixes #170084
2025-12-03 09:10:56 +01:00
Chuanqi Xu
93ebe63f2e [C++20] [Modules] Fix ADL for friend in modules
Close https://github.com/llvm/llvm-project/issues/170235

The cause of the issue is it didn't check friendness for decls
in ordinary namespace if it isn't visible.

It is fine for code before modules, since everything is visible.
But it is not true after modules came in. This patch adjusts this.

Note that this doesn't change the control flow for non-modules codes,
as the decls in ordinary namespace is always visible then it won't never
fall in following friendness check.
2025-12-03 10:29:52 +08:00
Zequan Wu
54a4da9df6
Revert "Reland [MS][clang] Add support for vector deleting destructors" (#169116)
This reverts 4d10c1165442cbbbc0017b48fcdd7dae1ccf3678 and its two
dependent commits: e6b9805b574bb5c90263ec7fbcb94df76d2807a4 and
c243406a695ca056a07ef4064b0f9feee7685320, see discussion in
https://github.com/llvm/llvm-project/pull/165598#issuecomment-3563825509.
2025-11-21 17:14:34 -08:00
Michael Buch
bb1b82af39
[clang][TypePrinter] Replace AppendScope with printNestedNameSpecifier (#168534)
In debug-info we soon have the need to print names using the full scope
of the entity (see discussion in
https://github.com/llvm/llvm-project/pull/159592). Particularly, when a
structure is scoped inside a function, we'd like to emit the name as
`func()::foo`. `CGDebugInfo` uses the `TypePrinter` to print type names
into debug-info. However, `TypePrinter` stops (and ignores)
`DeclContext`s that are functions. I.e., it would just print `foo`.
Ideally it would behave the same way `printNestedNameSpecifier` does.
The FIXME in
47c1aa4cef/clang/lib/AST/TypePrinter.cpp (L1520-L1521)
motivated this patch.

See https://github.com/llvm/llvm-project/pull/168533 for how this will
be used by `CGDebugInfo`. The plan is to introduce a new
`PrintingPolicy` that prints anonymous entities using their full scope
(including function/anonymous scopes) and the mangling number.
2025-11-21 19:31:35 +09:00
Chuanqi Xu
cc5185bd14 [C++20] [Modules] Check TULocal entity within exported entities
See the attached test for example.
2025-11-21 13:57:41 +08:00
Mariya Podchishchaeva
4d10c11654
Reland [MS][clang] Add support for vector deleting destructors (#165598)
MSVC supports an extension allowing to delete an array of objects via
pointer whose static type doesn't match its dynamic type. This is done
via generation of special destructors - vector deleting destructors.
MSVC's virtual tables always contain a pointer to the vector deleting
destructor for classes with virtual destructors, so not having this
extension implemented causes clang to generate code that is not
compatible with the code generated by MSVC, because clang always puts a
pointer to a scalar deleting destructor to the vtable. As a bonus the
deletion of an array of polymorphic object will work just like it does
with MSVC - no memory leaks and correct destructors are called.

This patch will cause clang to emit code that is compatible with code
produced by MSVC but not compatible with code produced with clang of
older versions, so the new behavior can be disabled via passing
-fclang-abi-compat=21 (or lower).

This is yet another attempt to land vector deleting destructors support
originally implemented by
https://github.com/llvm/llvm-project/pull/133451.

This PR contains fixes for issues reported in the original PR as well as
fixes for issues related to operator delete[] search reported in several
issues like

https://github.com/llvm/llvm-project/pull/133950#issuecomment-2787510484
https://github.com/llvm/llvm-project/issues/134265

Fixes https://github.com/llvm/llvm-project/issues/19772
2025-11-13 10:32:03 +01:00
Chuanqi Xu
3cda32d590
[clang] [Serialization] No transitive change for MacroID and PreprocessedEntityID (#166346)
Similar to previous no transitive changes to decls, types, identifiers
and source locations (
https://github.com/llvm/llvm-project/pull/92083
https://github.com/llvm/llvm-project/pull/92085
https://github.com/llvm/llvm-project/pull/92511
https://github.com/llvm/llvm-project/pull/86912
)

This patch does the same thing for MacroID and PreprocessedEntityID.

---

### Some background

Previously we record different IDs linearly. That is, when writing a
module, if we have 17 decls in imported modules, the ID of decls in the
module will start from 18. This makes the contents of the BMI changes if
the we add/remove any decls, types, identifiers and source locations in
the imported modules.

This makes it hard for us to reduce recompilations with modules. We want
to skip recompilations as we think the modules can help us to remove
fake dependencies. This can be done by split the ID into <ModuleIndex,
LocalIndex> pairs.
This is ALREADY done for several different ID above. We call it
non-casacading changes
(https://clang.llvm.org/docs/StandardCPlusPlusModules.html#experimental-non-cascading-changes).
Our internal users have already used this feature and it works well for
years.

Now we want to extend this to MacroID and PreprocessedEntityID. This is
helpful for us in the downstream as we allowed named modules to export
macros. But I believe this is also helpful for header-like modules if
you'd like to explore the area.

And also I think this is a nice cleanup too.

---

Given the use of MacroID and PreprocessedEntityID are not as complicated
as other IDs in the above series, I feel the patch itself should be
good. I hope the vendors can test the patch to make sure it won't affect
existing users.
2025-11-13 09:45:52 +08:00
Chuanqi Xu
ae2b303391
[C++20] [Modules] Don't import initializer/pending implicit instantiations from other named module (#167468)
Close https://github.com/llvm/llvm-project/issues/166068

The cause of the problem is that we would import initializers and
pending implicit instantiations from other named module. This is very
bad and it may waste a lot of time.

And we didn't observe it as the weak symbols can live together and the
strong symbols would be removed by other mechanism. So we didn't observe
the bad behavior for a long time. But it indeeds waste compilation time.
2025-11-12 13:37:36 +08:00
Chuanqi Xu
905ee4424d [NFC] [C++20] [Modules] Test that we can avoid adding more specializations in reduced BMI 2025-11-12 11:14:01 +08:00
Qiongsi Wu
be0aa7b6c7
[clang][DependencyScanning] Implementation of CompilerInstanceWithContext to Improve By-Name Queries (#164345)
This PR implements `CompilerInstanceWithContext` to improve by-name
dependency queries.

Cases exist where we query the dependency of different names, with
otherwise identical working directory and compile command line inputs.
In these cases, we can create one `CompilerInstance`, whose lifetime is
the same as the dependency scanning worker, and reuse the same compiler
instance to complete the queries. This way we reduce the amount of
header search we need to perform per query, since the already completed
header search results are cached in the compiler instance.

Using a microbenchmark on a prototype of this implementation, we are
seeing a scanning performance improvement of about 20%. The
microbenchmark scans a Swift file that imports everything importable.
When measuring against a set of internal project builds, the geo mean of
total build time improvement is around 1.02x to 1.04x depending on
whether the module caches are populated or not.

Part of work for rdar://136303612.
2025-11-07 12:58:56 -08:00
Naveen Seth Hanig
bc08e69959
[clang][modules] Fix crash in enum visibility lookup for C++20 header units (#166272)
Fixes #165445.

Fixes a crash when `ASTWriter::GenerateNameLookupTable` processes enum
constants from C++20 header units.

The special handling for enum constants, introduced in fccc6ee, doesn't
account for declarations whose owning module is a C++20 header unit. It
calls `isNamedModule()` on the result of
`getTopLevelOwningNamedModule()`, which returns null for header units,
causing a null pointer dereference.
2025-11-04 09:54:56 +08:00
Michael Spencer
9ff31be2f2
[clang][builtins] Add stdckdint.h to the modulemap. (#166230)
All builtin Clang headers need to be covered by the modulemap.

This fixes https://github.com/llvm/llvm-project/issues/166173
2025-11-03 13:12:55 -08:00
Aiden Grossman
42bba7fc7a
[Clang] Reenable Tests on SystemZ/AIX Using env -u (#164816)
These were disabled when adjusting tests to work with the internal shell
because the implementation on these systems of env did not support the
-u option. Now that we have switched to the internal shell and env -u is
implemented internally, these tests should work again.
2025-10-25 21:08:45 -07:00
Ian Anderson
38473c5d35
[clang][headers] Need a way for math.h to share the definitions of INIFINITY and NAN with float.h (#164348)
In C23 mode, both float.h and math.h are required to define INIFINITY
and NAN. However, with clang modules, there needs to be a single owner
for the declarations. Let that be float.h since that's the suggested
true owner in Annex F.2.2 of ISO/IEC 9899:2024, and introduce
`__need_infinity_nan` so that math.h can pick up the compiler
definitions.
2025-10-23 10:15:00 -07:00
Jan Svoboda
1ab6c0d60c
[clang] Make explicitly-built modules independent of the CWD (#164840)
PR https://github.com/llvm/llvm-project/pull/150123 changed how we
normalize the modules cache path. Unfortunately, empty path would get
normalized to the current working directory. This means that even
explicitly-built PCMs that don't rely on the CWD now embed it, leading
to surprising behavior. This PR fixes that by normalizing an empty
modules cache path to an empty string.
2025-10-23 10:09:50 -07:00
Aiden Grossman
04fc1aee56 [Clang] Explicitly invoke bash to run shell scripts
Otherwise these tests run into an exec format error when attempting to run
them with the internal shell. This is similar to other patches that have
done the same for similar tests.
2025-10-20 03:09:39 +00:00
Jan Svoboda
ce8abef25e
[clang][modules] Derive mtime from PCM timestamps, not PCM files (#162965)
#137363 was supposed to be NFC for the `CrossProcessModuleCache` (a.k.a
normal implicit module builds), but accidentally passed the wrong path
to `sys::fs::status`. Then, #141358 removed the correct path that
should've been passed instead. (The variable was flagged as unused.)
None of our existing tests caught this regression, we only found out due
to a SourceKit-LSP benchmark getting slower.

This PR re-implements the original behavior, adds new remark to Clang
for PCM input file validation, and uses it to create more reliable tests
of the `-fmodules-validate-once-per-build-session` flag.
2025-10-13 13:38:38 -07:00
Jonas Hahnfeld
a9dafc9bdc
[Sema] Compare canonical conversion function (#154158)
With lazy template loading, it is possible to find non-canonical
FunctionDecls, depending on when redecl chains are completed. This
is a problem for templated conversion operators that would allow to
call either the copy assignment or the move assignment operator.
This ambiguity is resolved by isBetterReferenceBindingKind (called
from CompareStandardConversionSequences) ranking rvalue refs over
lvalue refs.
    
Unfortunately, this fix is hard to test in isolation without the
changes in https://github.com/llvm/llvm-project/pull/133057 that
make lazy template loading more likely to complete redecl chains
at "inconvenient" times. The added reproducer passes before and
after this commit, but would have failed with the proposed changes
of the linked PR.
    
Kudos to Maksim Ivanov for providing an initial version of the
reproducer that I further simplified.
2025-10-06 10:34:49 +02:00