7170 Commits

Author SHA1 Message Date
Alexandre Ganea
410a1341b5 [clang][bytecode] Silence unused variable warning 2025-08-20 14:10:05 -04:00
Yanzuo Liu
a6da68ed36
[Clang][ASTMatchers] Make hasConditionVariableStatement support for loop, while loop and switch statements (#154298)
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-08-20 23:57:30 +08:00
Samira Bakon
ffe21f1cd7
[clang][dataflow] Transfer more cast expressions. (#153066)
Transfer all casts by kind as we currently do implicit casts. This
obviates the need for specific handling of static casts.

Also transfer CK_BaseToDerived and CK_DerivedToBase and add tests for
these and missing tests for already-handled cast types.

Ensure that CK_BaseToDerived casts result in modeling of the fields of the derived class.
2025-08-20 11:40:06 -04:00
Anutosh Bhat
ea634fef56
[clang-repl] Fix InstantiateTemplate & Value test while building against emscripten (#154513)
Building with assertions flag (-sAssertions=2) gives me these 

```
[ RUN ] InterpreterTest.InstantiateTemplate Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueWithAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Error in loading dynamic library incr_module_3.wasm: RuntimeError: Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueWithAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Could not load dynamic lib: incr_module_3.wasm RuntimeError: Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueWithAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment)
[ RUN ] InterpreterTest.InstantiateTemplate Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueNoAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Error in loading dynamic library incr_module_3.wasm: RuntimeError: Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueNoAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Could not load dynamic lib: incr_module_3.wasm RuntimeError: Aborted(Assertion failed: undefined symbol '__clang_Interpreter_SetValueNoAlloc'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment)
[ RUN ] InterpreterTest.InstantiateTemplate Aborted(Assertion failed: undefined symbol '_ZnwmPv26__clang_Interpreter_NewTag'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Error in loading dynamic library incr_module_23.wasm: RuntimeError: Aborted(Assertion failed: undefined symbol '_ZnwmPv26__clang_Interpreter_NewTag'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Could not load dynamic lib: incr_module_23.wasm RuntimeError: Aborted(Assertion failed: undefined symbol '_ZnwmPv26__clang_Interpreter_NewTag'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment)
[ RUN ] InterpreterTest.Value Aborted(Assertion failed: undefined symbol '_Z9getGlobalv'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Error in loading dynamic library incr_module_36.wasm: RuntimeError: Aborted(Assertion failed: undefined symbol '_Z9getGlobalv'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Could not load dynamic lib: incr_module_36.wasm
[ RUN ] InterpreterTest.Value Aborted(Assertion failed: undefined symbol '_Z9getGlobalv'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Error in loading dynamic library incr_module_36.wasm: RuntimeError: Aborted(Assertion failed: undefined symbol '_Z9setGlobali'. perhaps a side module was not linked in? if this global was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment) Could not load dynamic lib: incr_module_36.wasm
```

**So we have some symbols missing here that are needed by the side
modules being created here.**

First 2 are needed by both tests 
Last 3 are needed for these lines accordingly in the Value test.


dc23869f98/clang/unittests/Interpreter/InterpreterTest.cpp (L355)

dc23869f98/clang/unittests/Interpreter/InterpreterTest.cpp (L364)

dc23869f98/clang/unittests/Interpreter/InterpreterTest.cpp (L365)

Everything should work as expected after this 
```
[----------] 9 tests from InterpreterTest
[ RUN      ] InterpreterTest.Sanity
[       OK ] InterpreterTest.Sanity (18 ms)
[ RUN      ] InterpreterTest.IncrementalInputTopLevelDecls
[       OK ] InterpreterTest.IncrementalInputTopLevelDecls (45 ms)
[ RUN      ] InterpreterTest.Errors
[       OK ] InterpreterTest.Errors (29 ms)
[ RUN      ] InterpreterTest.DeclsAndStatements
[       OK ] InterpreterTest.DeclsAndStatements (34 ms)
[ RUN      ] InterpreterTest.UndoCommand
/Users/anutosh491/work/llvm-project/clang/unittests/Interpreter/InterpreterTest.cpp:156: Skipped
Test fails for Emscipten builds

[  SKIPPED ] InterpreterTest.UndoCommand (0 ms)
[ RUN      ] InterpreterTest.FindMangledNameSymbol
[       OK ] InterpreterTest.FindMangledNameSymbol (85 ms)
[ RUN      ] InterpreterTest.InstantiateTemplate
[       OK ] InterpreterTest.InstantiateTemplate (127 ms)
[ RUN      ] InterpreterTest.Value
[       OK ] InterpreterTest.Value (608 ms)
[ RUN      ] InterpreterTest.TranslationUnit_CanonicalDecl
[       OK ] InterpreterTest.TranslationUnit_CanonicalDecl (64 ms)
[----------] 9 tests from InterpreterTest (1014 ms total)
```

This is similar to how we need to take care of some symbols while
building side modules during running cppinterop's test suite !
2025-08-20 14:14:19 +00:00
Timm Baeder
e16ced3ef4
[clang][bytecode] Diagnose one-past-end reads from global arrays (#154484)
Fixes #154312
2025-08-20 10:34:44 +02:00
Damyan Pepper
cc49f3b3e1
[NFC][HLSL] Remove confusing enum aliases / duplicates (#153909)
Remove:

* DescriptorType enum - this almost exactly shadowed the ResourceClass
enum
* ClauseType aliased ResourceClass

Although these were introduced to make the HLSL root signature handling
code a bit cleaner, they were ultimately causing confusion as they
appeared to be unique enums that needed to be converted between each
other.

Closes #153890
2025-08-18 08:58:33 -07:00
Yitzhak Mandelbaum
3ecfc0330d
[clang][dataflow] Add support for serialization and deserialization. (#152487)
Adds support for compact serialization of Formulas, and a corresponding
parse function. Extends Environment and AnalysisContext with necessary
functions for serializing and deserializing all formula-related parts of
the environment.
2025-08-18 11:55:12 -04:00
Utkarsh Saxena
673750feea
[LifetimeSafety] Implement a basic use-after-free diagnostic (#149731)
Implement use-after-free detection in the lifetime safety analysis with two warning levels.

- Added a `LifetimeSafetyReporter` interface for reporting lifetime safety issues
- Created two warning levels:
    - Definite errors (reported with `-Wexperimental-lifetime-safety-permissive`)
    - Potential errors (reported with `-Wexperimental-lifetime-safety-strict`)
- Implemented a `LifetimeChecker` class that analyzes loan propagation and expired loans to detect use-after-free issues.
- Added tracking of use sites through a new `UseFact` class.
- Enhanced the `ExpireFact` to track the expressions where objects are destroyed.
- Added test cases for both definite and potential use-after-free scenarios.

The implementation now tracks pointer uses and can determine when a pointer is dereferenced after its loan has been expired, with appropriate diagnostics.

The two warning levels provide flexibility - definite errors for high-confidence issues and potential errors for cases that depend on control flow.
2025-08-18 13:46:43 +02:00
yronglin
e6e874ce8f
[clang] Allow trivial pp-directives before C++ module directive (#153641)
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 <yronglin777@gmail.com>
2025-08-18 14:17:35 +08:00
owenca
6cfedea492
[clang-format] Add SpaceInEmptyBraces option (#153765)
Also set it to SIEB_Always for WebKit style.

Closes #85525.
Closes #93635.
2025-08-17 12:56:22 -07:00
owenca
a21d17f1d7
[clang-format] Fix a bug in breaking before FunctionDeclarationName (#153924)
Fixes #153891
2025-08-17 12:54:48 -07:00
owenca
5e57a10f50
[clang-format] Allow breaking before bit-field colons (#153529)
Fixes #153448
2025-08-17 12:54:23 -07:00
owenca
9a692e0f94
[clang-format] Don't annotate class property specifiers as StartOfName (#153525)
Fixes #153443
2025-08-17 12:53:57 -07:00
mcbarton
b24b8a5bb4
Enable running ClangReplInterpreterTests in an Emscripten environment (#150977)
@vgvassilev @anutosh491 This is what it took for me to enable running
ClangReplInterpreterTests in an Emscripten environment. When I ran this
patch for llvm 20 we could run InterpreterTest.InstantiateTemplate , but
now it crashes gtest when running in node. Let me know what you think.
2025-08-14 14:07:13 +05:30
Abhinav Kumar
a02444fb69
Revert "[clang-repl] Enable extending launchExecutor (#152562)" (#153180)
Reverts #152562.

Seems to be causing test failures on Solaris bot.

Co-authored-by: kr-2003 <kumar.kr.abhinav@gmail.com>
2025-08-12 20:56:02 +02:00
owenca
3d38a92c8a
[clang-format] Add functionality of getting info about numeric literals (#152878) 2025-08-11 09:24:28 -07:00
Matheus Izvekov
91cdd35008
[clang] Improve nested name specifier AST representation (#147835)
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-09 05:06:53 -03:00
Endre Fülöp
4f2ed926db
[analyzer][NFCi] Pass if bind is to a Decl or not to checkBind (#152137)
Binding a value to location can happen when a new value is created or
when and existing value is updated. This modification exposes whether
the value binding happens at a declaration.
This helps simplify the hacky logic of the BindToImmutable checker.
2025-08-08 19:16:47 +02:00
Kazu Hirata
1bc49c0c97
[AST] Remove an unused local variable (NFC) (#152647) 2025-08-08 07:45:22 -07:00
Abhinav Kumar
eccc6e22f8
[clang-repl] Enable extending launchExecutor (#152562)
This patch introduces the ability to customize the fork process with an external lambda function. This is useful for downstream clients where they want to do stream redirection.
2025-08-08 08:54:34 +03:00
Michael Buch
cd8f348c69
[clang][Attr] Remove 'literal label' form of AsmLabelAttr (#151858)
This was added purely for the needs of LLDB. However, starting with
https://github.com/llvm/llvm-project/pull/151355 and
https://github.com/llvm/llvm-project/pull/148877 we no longer create
literal AsmLabels in LLDB either. So this is unused and we can get rid
of it.

In the near future LLDB will want to add special support for mangling
`AsmLabel`s (specifically
https://github.com/llvm/llvm-project/pull/149827).
2025-08-04 14:34:45 +01:00
Utkarsh Saxena
f9be391dd7
[LifetimeSafety] Handle pruned-edges (null blocks) in dataflow (#150670)
Fix a crash in the lifetime safety dataflow analysis when handling null CFG blocks.

Added a null check for adjacent blocks in the dataflow analysis algorithm to prevent dereferencing null pointers. This occurs when processing CFG blocks with unreachable successors or predecessors.

Original crash: https://compiler-explorer.com/z/qfzfqG5vM

Fixes https://github.com/llvm/llvm-project/issues/150095
2025-08-03 21:45:36 +02:00
Connector Switch
8b7f81f2de
[NFC] Fix assignment typo. (#151864) 2025-08-03 22:32:00 +08:00
Mythreya Kuricheti
c76a9afe24
[clang][Tooling] Choose header insertion location in global module fragment (#151624)
Ensures that headers are inserted after `module;` declaration by
updating minimum offset.
2025-08-03 03:20:25 -04:00
James Y Knight
4205da0f13
NFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151782)
This commit handles the following types:
- clang::ExternalASTSource
- clang::TargetInfo
- clang::ASTContext
- clang::SourceManager
- clang::FileManager

Part of cleanup #151026
2025-08-01 22:23:30 -04:00
Steven Wu
3c08498fe2
[clang][CodeGen] Remove CWD fallback in compilation directory (#150130)
CWD is queried in clang driver and passed to clang cc1 via flags when
needed. Respect the cc1 flags and do not repeated checking current
working directory in CodeGen.
2025-07-31 16:32:44 -07:00
James Y Knight
c7f3437507
NFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151545)
Handles clang::DiagnosticsEngine and clang::DiagnosticIDs.

For DiagnosticIDs, this mostly migrates from `new DiagnosticIDs` to
convenience method `DiagnosticIDs::create()`.

Part of cleanup https://github.com/llvm/llvm-project/issues/151026
2025-07-31 15:07:35 -04:00
James Y Knight
9ddbb478ce
NFC: Clean up construction of IntrusiveRefCntPtr from raw pointers for llvm::vfs::FileSystem. (#151407)
This switches to `makeIntrusiveRefCnt<FileSystem>` where creating a new
object, and to passing/returning by `IntrusiveRefCntPtr<FileSystem>`
instead of `FileSystem*` or `FileSystem&`, when dealing with existing
objects.

Part of cleanup #151026.
2025-07-31 09:57:13 -04:00
Owen Pan
5fc482cfc0
[clang-format] Disable IntegerLiteralSeparator for C++ before c++14 (#151273)
Fixes #151102
2025-07-30 09:43:46 -07:00
Owen Pan
3d99446809
[clang-format] Fix a bug in DerivePointerAlignment: true (#150744)
This effectively reverts a4d4859dc70c046ad928805ddeaf8fa101793394 which
didn't fix the problem that `int*,` was not counted as "Left" alignment.

Fixes #150327
2025-07-28 00:44:12 -07:00
James Y Knight
9281797a57
[clang-format] Google Style: disable DerivePointerAlignment. (#149602)
The [Google C++ Style
Guide](https://google.github.io/styleguide/cppguide.html#Pointer_and_Reference_Expressions)
is being changed to specify that spaces should go after the
asterisk/ampersand, rather than permitting either before or after on a
file-by-file basis.

The new requirement is:
> When referring to a pointer or reference (variable declarations or
> definitions, arguments, return types, template parameters, etc.),
> you must not place a space before the asterisk/ampersand. Use a
> space to separate the type from the declared name (if present).

The [Google ObjC
style](https://google.github.io/styleguide/objcguide.html) is silent on
this matter, but the de-facto style is not being modified at this time.
So, keep DerivePointerAlignment enabled for ObjC language mode.
2025-07-25 11:55:50 -04:00
Finn Plummer
77524bcf26
[NFC][HLSL] Let RootSignatureParser own the references (#150310)
- this is a clean up from a review comment that we should let the parser
own the constructed `RootSignatureElement`s

Original comment here:
https://github.com/llvm/llvm-project/pull/147115#discussion_r2192999527.
2025-07-24 16:04:27 -07:00
Owen Pan
a4d4859dc7
[clang-format] Fix a bug in DerivePointerAlignment: true (#150387)
Fixes #150327
2025-07-24 09:41:22 -07:00
Owen Pan
97c953406d
[clang-format] Add AfterNot to SpaceBeforeParensOptions (#150367)
Closes #149971
2025-07-24 09:38:43 -07:00
Eric Li
531cf8298b
[clang-format] Stop ctor initializer from being inlined (#150361)
The colon in a constructor's initializer list triggers the inlining of a
nested block as if it was a conditional operator expression. This
prevents line breaks under certain circumstances when the initializer
list contains braced initializers, which in turn prevents the line
formatter from finding a solution.

In this commit we exclude colons that are a constructor initializer
colon from consideration of nested block inlining.

Fixes #97242.
Fixes #81822.
2025-07-24 04:06:03 -04:00
Utkarsh Saxena
ffdada1666
[LifetimeSafety] Add loan expiry analysis (#148712)
This PR adds the `ExpiredLoansAnalysis` class to track which loans have expired. The analysis uses a dataflow lattice (`ExpiredLattice`) to maintain the set of expired loans at each program point.

This is a very light weight dataflow analysis and is expected to reach fixed point in ~2 iterations.
In principle, this does not need a dataflow analysis but is used for convenience in favour of lean code.
2025-07-23 12:14:29 +02:00
Aaron Danen
c295f05063
[clang-repl] Improve error message on failed undos (#149396)
Updated error message logic for undo function. Throws different errors
for the case of there being nothing to undo, and for the case of
requesting more undos than there are operations to undo.

Fixes https://github.com/llvm/llvm-project/issues/143668
2025-07-23 10:13:11 +01:00
Utkarsh Saxena
58be6226eb Reapply "[LifetimeSafety] Revamp test suite using unittests (#149158)"
This reverts commit 54b50681ca0fd1c0c6ddb059c88981a45e2f1b19.
2025-07-22 13:34:44 +00:00
Utkarsh Saxena
54b50681ca Revert "[LifetimeSafety] Revamp test suite using unittests (#149158)"
This reverts commit 688ea048affe8e79221ea1a8c376bcf20ef8f3bb.
2025-07-22 12:10:47 +00:00
Donát Nagy
a807e8ea9f
[analyzer] Prettify checker registration and unittest code (#147797)
This commit tweaks the interface of `CheckerRegistry::addChecker` to
make it more practical for plugins and tests:
- The parameter `IsHidden` now defaults to `false` even in the
  non-templated overload (because setting it to true is unusual,
  especially in plugins).
- The parameter `DocsUri` defaults to the dummy placeholder string
  `"NoDocsUri"` because (as of now) nothing queries its value from the
  checker registry (it's only used by the logic that generates the
  clang-tidy documentation, but that loads it directly from `Checkers.td`
  without involving the `CheckerRegistry`), so there is no reason to
  demand specifying this value.

In addition to propagating these changes, this commit clarifies,
corrects and extends lots of comments and performs various minor code
quality improvements in the code of unit tests and example plugins.

I originally wrote the bulk of this commit when I was planning to add an
extra parameter to `addChecker` in order to implement some technical
details of the CheckerFamily framework. At the end I decided against
adding that extra parameter, so this cleanup was left out of the PR
https://github.com/llvm/llvm-project/pull/139256 and I'm merging it now
as a separate commit (after minor tweaks).

This commit is mostly NFC: the only functional change is that the
analyzer will be compatible with plugins that rely on the default
argument values and don't specify `IsHidden` or `DocsUri`. (But existing
plugin code will remain valid as well.)
2025-07-22 13:36:58 +02:00
Utkarsh Saxena
688ea048af
[LifetimeSafety] Revamp test suite using unittests (#149158)
Refactor the Lifetime Safety Analysis infrastructure to support unit testing.

- Created a public API class `LifetimeSafetyAnalysis` that encapsulates the analysis functionality
- Added support for test points via a special `TestPointFact` that can be used to mark specific program points
- Added unit tests that verify loan propagation in various code patterns
2025-07-22 12:32:06 +02:00
Owen Pan
4d48996ff0
[clang-format][NFC] Clean up around StringRef initializations (#149765)
Consistently use `constexpr StringRef Code("string literal");`.
2025-07-21 19:11:17 -07:00
sstwcw
12a3afe47d
[clang-format] Remove code related to trigraphs (#148640)
When reviewing #147156, the reviewers pointed out that we didn't need to
support the trigraph. The code never handled it right.

In the debug build, this kind of input caused the assertion in the
function `countLeadingWhitespace` to fail. The release build without
assertions outputted `?` `?` `/` separated by spaces.

```C
#define A ??/
  int i;
```

This is because the code in `countLeadingWhitespace` assumed that the
underlying lexer recognized the entire `??/` sequence as a single token.
In fact, the lexer recognized it as 3 separate tokens. The flag to make
the lexer recognize trigraphs was never enabled.

This patch enables the flag in the underlying lexer. This way, the
program now either turns the trigraph into a single `\` or removes it
altogether if the line is short enough. There are operators like the
`??=` in C#. So the flag is not enabled for all input languages. Instead
the check for the token size is moved from the assert line into the if
line.

The problem was introduced by my own patch 370bee480139 from about 3
years ago. I added code to count the number of characters in the escape
sequence probably just because the block of code used to have a comment
saying someone should add the feature. Maybe I forgot to enable
assertions when I ran the code. I found the problem because reviewing
pull request 145243 made me look at the code again.
2025-07-21 15:40:28 +00:00
Owen Pan
f3a3270dbc [clang-format][NFC] Delete redundant type names after FormatStyle:: 2025-07-20 20:27:37 -07:00
Owen Pan
06ed4d2c92
[clang-format] Fix a bug in BreakBeforeBinaryOperators: All (#149695)
Fixes #149520
2025-07-20 19:01:46 -07:00
Vassil Vassilev
6163b66e0a [clang-repl] Another try on system-z.
This patch should make msan happy as it found a real bug where we always try to
read an unsigned long long without respecting the underlying enum type.

Another follow-up on llvm/llvm-project#102858
2025-07-20 08:23:47 +00:00
Vassil Vassilev
0a463bd43e [clang-repl] Mark asan and systemz as unsupported for now.
While waiting for the bot owners it seems that this is not a major issue due
to the big endianness of the systemz platform. Instead it looks like we are not
modelling something well for enum types. Probably `va_arg` has a bug for that
platform or similar.

The asan failure seems to be a crash in asan and maybe related to the issues
we've mentioned in llvm/llvm-project#102858.

This patch should appease the bots that were broken by llvm/llvm-project#148701
2025-07-19 17:45:56 +00:00
Naveen Seth Hanig
6855b9c598
[clang][deps] Properly capture the global module and '\n' for all module directives (#148685)
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.
2025-07-19 09:47:37 +02:00
Vassil Vassilev
9bf7d04c43
[clang-repl] Lay the basic infrastructure for pretty printing of types (#148701)
The idea is to store a type-value pair in clang::Value which is updated
by the interpreter runtime. The class copies builtin types and boxes
non-builtin types to provide some lifetime control.

The patch enables default printers for C and C++ using a very
minimalistic approach. We handle enums, arrays and user types. Once we
land this we can focus on enabling user-defined pretty-printers which
take control over printing of types

The work started as part of https://reviews.llvm.org/D146809, then we
created a giant in https://github.com/llvm/llvm-project/pull/84769
2025-07-19 09:25:27 +03:00
Owen Pan
a8f5e9ed6b
[clang-format] Fix a regression of annotating PointerOrReference (#149039)
Fixes #149010
2025-07-17 21:43:43 -07:00