<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/clang/lib/Lex/Preprocessor.cpp, branch main</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.
</subtitle>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/'/>
<entry>
<title>[Lex] Use a range-based for loop (NFC) (#169174)</title>
<updated>2025-11-22T23:30:51+00:00</updated>
<author>
<name>Kazu Hirata</name>
<email>kazu@google.com</email>
</author>
<published>2025-11-22T23:30:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=c5939937a4d1b7da4477762389dee0afa756bd9c'/>
<id>c5939937a4d1b7da4477762389dee0afa756bd9c</id>
<content type='text'>
Identified with modernize-loop-convert.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Identified with modernize-loop-convert.</pre>
</div>
</content>
</entry>
<entry>
<title>[clang] Allow trivial pp-directives before C++ module directive (#153641)</title>
<updated>2025-08-18T06:17:35+00:00</updated>
<author>
<name>yronglin</name>
<email>yronglin777@gmail.com</email>
</author>
<published>2025-08-18T06:17:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=e6e874ce8f055f5b8c5d7f8c7fb0afe764d1d350'/>
<id>e6e874ce8f055f5b8c5d7f8c7fb0afe764d1d350</id>
<content type='text'>
Consider the following code:

```cpp
# 1 __FILE__ 1 3
export module a;
```

According to the wording in
[P1857R3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1857r3.html):
```
A module directive may only appear as the first preprocessing tokens in a file (excluding the global module fragment.)
```

and the wording in
[[cpp.pre]](https://eel.is/c++draft/cpp.pre#nt:module-file)
```
module-file:
    pp-global-module-fragment[opt] pp-module group[opt] pp-private-module-fragment[opt]
```

`#` is the first pp-token in the translation unit, and it was rejected
by clang, but they really should be exempted from this rule. The goal is
to not allow any preprocessor conditionals or most state changes, but
these don't fit that.

State change would mean most semantically observable preprocessor state,
particularly anything that is order dependent. Global flags like being a
system header/module shouldn't matter.

We should exempt a brunch of directives, even though it violates the
current standard wording.

In this patch, we introduce a `TrivialDirectiveTracer` to trace the
**State change** that described above and propose to exempt the
following kind of directive: `#line`, GNU line marker, `#ident`,
`#pragma comment`, `#pragma mark`, `#pragma detect_mismatch`, `#pragma
clang __debug`, `#pragma message`, `#pragma GCC warning`, `#pragma GCC
error`, `#pragma gcc diagnostic`, `#pragma OPENCL EXTENSION`, `#pragma
warning`, `#pragma execution_character_set`, `#pragma clang
assume_nonnull` and builtin macro expansion.

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

---------

Signed-off-by: yronglin &lt;yronglin777@gmail.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Consider the following code:

```cpp
# 1 __FILE__ 1 3
export module a;
```

According to the wording in
[P1857R3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1857r3.html):
```
A module directive may only appear as the first preprocessing tokens in a file (excluding the global module fragment.)
```

and the wording in
[[cpp.pre]](https://eel.is/c++draft/cpp.pre#nt:module-file)
```
module-file:
    pp-global-module-fragment[opt] pp-module group[opt] pp-private-module-fragment[opt]
```

`#` is the first pp-token in the translation unit, and it was rejected
by clang, but they really should be exempted from this rule. The goal is
to not allow any preprocessor conditionals or most state changes, but
these don't fit that.

State change would mean most semantically observable preprocessor state,
particularly anything that is order dependent. Global flags like being a
system header/module shouldn't matter.

We should exempt a brunch of directives, even though it violates the
current standard wording.

In this patch, we introduce a `TrivialDirectiveTracer` to trace the
**State change** that described above and propose to exempt the
following kind of directive: `#line`, GNU line marker, `#ident`,
`#pragma comment`, `#pragma mark`, `#pragma detect_mismatch`, `#pragma
clang __debug`, `#pragma message`, `#pragma GCC warning`, `#pragma GCC
error`, `#pragma gcc diagnostic`, `#pragma OPENCL EXTENSION`, `#pragma
warning`, `#pragma execution_character_set`, `#pragma clang
assume_nonnull` and builtin macro expansion.

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

---------

Signed-off-by: yronglin &lt;yronglin777@gmail.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>  [clang][deps] Properly capture the global module and '\n' for all module directives (#148685)</title>
<updated>2025-07-19T07:47:37+00:00</updated>
<author>
<name>Naveen Seth Hanig</name>
<email>naveen.hanig@outlook.com</email>
</author>
<published>2025-07-19T07:47:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=6855b9c598b3258e8c0e3edffe5458630a0b0105'/>
<id>6855b9c598b3258e8c0e3edffe5458630a0b0105</id>
<content type='text'>
Previously, the newline after a module directive was not properly
captured and printed by `clang::printDependencyDirectivesAsSource`.

According to P1857R3, each directive must, after skipping horizontal
whitespace, appear at the start of a logical line. Because the newline
after module directives was missing, this invalidated the following
line.
This fixes tests that were previously in violation of P1857R3,
including for Objective-C directives, which should also comply with
P1857R3.

This also ensures that the global module fragment `module;` is captured
by the dependency directives scanner.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Previously, the newline after a module directive was not properly
captured and printed by `clang::printDependencyDirectivesAsSource`.

According to P1857R3, each directive must, after skipping horizontal
whitespace, appear at the start of a logical line. Because the newline
after module directives was missing, this invalidated the following
line.
This fixes tests that were previously in violation of P1857R3,
including for Objective-C directives, which should also comply with
P1857R3.

This also ensures that the global module fragment `module;` is captured
by the dependency directives scanner.</pre>
</div>
</content>
</entry>
<entry>
<title>[clang] NFC: Add alias for std::pair&lt;FileID, unsigned&gt; used in SourceLocation (#145711)</title>
<updated>2025-06-26T12:12:51+00:00</updated>
<author>
<name>Haojian Wu</name>
<email>hokein.wu@gmail.com</email>
</author>
<published>2025-06-26T12:12:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=0b6ddb02efdcbdac9426e8d857499ea0580303cd'/>
<id>0b6ddb02efdcbdac9426e8d857499ea0580303cd</id>
<content type='text'>
Introduce a type alias for the commonly used `std::pair&lt;FileID,
unsigned&gt;` to improve code readability, and make it easier for future
updates (64-bit source locations).</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Introduce a type alias for the commonly used `std::pair&lt;FileID,
unsigned&gt;` to improve code readability, and make it easier for future
updates (64-bit source locations).</pre>
</div>
</content>
</entry>
<entry>
<title>[clang][Preprocessor] Handle the first pp-token in EnterMainSourceFile (#145244)</title>
<updated>2025-06-26T00:49:43+00:00</updated>
<author>
<name>yronglin</name>
<email>yronglin777@gmail.com</email>
</author>
<published>2025-06-26T00:49:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=0529a346007cecab95c6820a60cb3e4e36f34990'/>
<id>0529a346007cecab95c6820a60cb3e4e36f34990</id>
<content type='text'>
Depends on [[clang][Preprocessor] Add peekNextPPToken, makes look ahead
next token without
side-effects](https://github.com/llvm/llvm-project/pull/143898).

This PR fix the performance regression that introduced in
https://github.com/llvm/llvm-project/pull/144233.
The original PR(https://github.com/llvm/llvm-project/pull/144233) handle
the first pp-token in the main source file in the macro
definition/expansion and `Lexer::Lex`, but the lexer is almost always on
the hot path, we may hit a performance regression. In this PR, we handle
the first pp-token in `Preprocessor::EnterMainSourceFile`.

---------

Signed-off-by: yronglin &lt;yronglin777@gmail.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Depends on [[clang][Preprocessor] Add peekNextPPToken, makes look ahead
next token without
side-effects](https://github.com/llvm/llvm-project/pull/143898).

This PR fix the performance regression that introduced in
https://github.com/llvm/llvm-project/pull/144233.
The original PR(https://github.com/llvm/llvm-project/pull/144233) handle
the first pp-token in the main source file in the macro
definition/expansion and `Lexer::Lex`, but the lexer is almost always on
the hot path, we may hit a performance regression. In this PR, we handle
the first pp-token in `Preprocessor::EnterMainSourceFile`.

---------

Signed-off-by: yronglin &lt;yronglin777@gmail.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>[NFC][Clang][Preprocessor] Refine the implementation of isNextPPTokenOneOf (#145546)</title>
<updated>2025-06-25T17:38:37+00:00</updated>
<author>
<name>yronglin</name>
<email>yronglin777@gmail.com</email>
</author>
<published>2025-06-25T17:38:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=585ed213a8594c15324ea4bffc3ea2128eac50c8'/>
<id>585ed213a8594c15324ea4bffc3ea2128eac50c8</id>
<content type='text'>
This PR follow the
suggestion(https://github.com/llvm/llvm-project/pull/143898#discussion_r2164253141)
to refine the implementation of `Preprocessor::isNextPPToken`, also use
C++ fold expression to refine `Token::isOneOf`. We don't need `bool
isOneOf(tok::TokenKind K1, tok::TokenKind K2) const` anymore.

In order to reduce the impact, specificed `TokenKind` is still passed to
`Token::isOneOf` and `Preprocessor::isNextPPTokenOneOf` as function
parameters.

---------

Signed-off-by: yronglin &lt;yronglin777@gmail.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This PR follow the
suggestion(https://github.com/llvm/llvm-project/pull/143898#discussion_r2164253141)
to refine the implementation of `Preprocessor::isNextPPToken`, also use
C++ fold expression to refine `Token::isOneOf`. We don't need `bool
isOneOf(tok::TokenKind K1, tok::TokenKind K2) const` anymore.

In order to reduce the impact, specificed `TokenKind` is still passed to
`Token::isOneOf` and `Preprocessor::isNextPPTokenOneOf` as function
parameters.

---------

Signed-off-by: yronglin &lt;yronglin777@gmail.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>[clang][Preprocessor] Add peekNextPPToken, makes look ahead next token without side-effects (#143898)</title>
<updated>2025-06-24T10:55:21+00:00</updated>
<author>
<name>yronglin</name>
<email>yronglin777@gmail.com</email>
</author>
<published>2025-06-24T10:55:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=e8976e92f655f8c358081ffae01e10ea159cd37d'/>
<id>e8976e92f655f8c358081ffae01e10ea159cd37d</id>
<content type='text'>
This PR introduce a new function `peekNextPPToken`. It's an extension of
`isNextPPTokenLParen` and can makes look ahead one token in preprocessor
without side-effects.

It's also the 1st part of
https://github.com/llvm/llvm-project/pull/107168 and it was used to look
ahead next token then determine whether current lexing pp directive is
one of pp-import or pp-module directive.

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
    - &lt;, ", or : (but not ::) pp tokens for import, or
    - ; for module
Otherwise the token is treated as an identifier.

---------

Signed-off-by: yronglin &lt;yronglin777@gmail.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This PR introduce a new function `peekNextPPToken`. It's an extension of
`isNextPPTokenLParen` and can makes look ahead one token in preprocessor
without side-effects.

It's also the 1st part of
https://github.com/llvm/llvm-project/pull/107168 and it was used to look
ahead next token then determine whether current lexing pp directive is
one of pp-import or pp-module directive.

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
    - &lt;, ", or : (but not ::) pp tokens for import, or
    - ; for module
Otherwise the token is treated as an identifier.

---------

Signed-off-by: yronglin &lt;yronglin777@gmail.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>[C++][Modules] A module directive may only appear as the first preprocessing tokens in a file (#144233)</title>
<updated>2025-06-21T10:58:56+00:00</updated>
<author>
<name>yronglin</name>
<email>yronglin777@gmail.com</email>
</author>
<published>2025-06-21T10:58:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=ea321392ebc487c1000e43576f44af99edf28a5f'/>
<id>ea321392ebc487c1000e43576f44af99edf28a5f</id>
<content type='text'>
This PR is 2nd part of
[P1857R3](https://github.com/llvm/llvm-project/pull/107168)
implementation, and mainly implement the restriction `A module directive
may only appear as the first preprocessing tokens in a file (excluding
the global module fragment.)`:
[cpp.pre](https://eel.is/c++draft/cpp.pre):
```
module-file:
    pp-global-module-fragment[opt] pp-module group[opt] pp-private-module-fragment[opt]
```

We also refine tests use `split-file` instead of conditional macro.

Signed-off-by: yronglin &lt;yronglin777@gmail.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This PR is 2nd part of
[P1857R3](https://github.com/llvm/llvm-project/pull/107168)
implementation, and mainly implement the restriction `A module directive
may only appear as the first preprocessing tokens in a file (excluding
the global module fragment.)`:
[cpp.pre](https://eel.is/c++draft/cpp.pre):
```
module-file:
    pp-global-module-fragment[opt] pp-module group[opt] pp-private-module-fragment[opt]
```

We also refine tests use `split-file` instead of conditional macro.

Signed-off-by: yronglin &lt;yronglin777@gmail.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>[clang] Use *Map::try_emplace (NFC) (#140477)</title>
<updated>2025-05-19T13:19:53+00:00</updated>
<author>
<name>Kazu Hirata</name>
<email>kazu@google.com</email>
</author>
<published>2025-05-19T13:19:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=325281631a3b5c089dd732d9ca10704431447859'/>
<id>325281631a3b5c089dd732d9ca10704431447859</id>
<content type='text'>
We can simplify the code with *Map::try_emplace where we need
default-constructed values while avoding calling constructors when
keys are already present.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We can simplify the code with *Map::try_emplace where we need
default-constructed values while avoding calling constructors when
keys are already present.</pre>
</div>
</content>
</entry>
<entry>
<title>[Clang][Lex][NFC] Assert getExternalSource() in updateOutOfDateIdentifier (#140137)</title>
<updated>2025-05-16T13:26:56+00:00</updated>
<author>
<name>Shafik Yaghmour</name>
<email>shafik.yaghmour@intel.com</email>
</author>
<published>2025-05-16T13:26:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=dd32ad1c3787c51e72d496c03ab7948c98f93e06'/>
<id>dd32ad1c3787c51e72d496c03ab7948c98f93e06</id>
<content type='text'>
Static analysis flagged the unconditional access of getExternalSource().
We don't initialize ExternalSource during construction but via
setExternalSource(). If this is not set it will violate the invariant
covered by the assert.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Static analysis flagged the unconditional access of getExternalSource().
We don't initialize ExternalSource during construction but via
setExternalSource(). If this is not set it will violate the invariant
covered by the assert.</pre>
</div>
</content>
</entry>
</feed>
