6624 Commits

Author SHA1 Message Date
Oliver Hunt
467f72d8e2
[clang][Sema] Fix the continue and break scope for while loops
Make sure we don't push the break and continue scope for a while
loop until after we have evaluated the condition.
2025-08-07 15:31:35 -07:00
Oliver Hunt
c548c47476
[clang] Fix crash in dynamic_cast final class optimization (#152076)
This corrects the codegen for the final class optimization to
correct handle the case where there is no path to perform the
cast, and also corrects the codegen to handle ptrauth protected
vtable pointers.

As part of this fix we separate out the path computation as
that makes it easier to reason about the failure code paths
and more importantly means we can know what the type of the
this object is during the cast.

The allows us to use the GetVTablePointer interface which
correctly performs the authentication operations required when
pointer authentication is enabled. This still leaves incorrect
authentication behavior in the multiple inheritance case but
currently the optimization is disabled entirely if pointer
authentication is enabled.

Fixes #137518
2025-08-06 09:52:34 -07:00
Vincent
3339a0045d
[clang] Respect [[gnu::error]] on functions passed to [[gnu::cleanup]] (#152082)
Forward SourceLocation to `EmitCall` so that clang triggers an error
when a function inside `[[gnu::cleanup(func)]]` is annotated with
`[[gnu::error("some message")]]`.

resolves #146520
2025-08-05 21:21:36 -07:00
Peter Collingbourne
813e477155 Mention MTE in the HWASan design doc. 2025-08-05 17:49:05 -07:00
Peter Collingbourne
ab209cafdc Add link to CFI design doc to the documentation index. 2025-08-05 17:31:15 -07:00
keinflue
81ed75679d
[clang] Fix constant evaluation of member pointer access into sibling class. (#150829)
HandleMemberPointerAccess considered whether the lvalue path in a member
pointer access matched the bases of the containing class of the member,
but neglected to check the same for the containing class of the member
itself, thereby ignoring access attempts to members in direct sibling
classes.

Fixes #150705.
Fixes #150709.
2025-08-05 14:44:15 -07:00
Aaron Danen
2444c4a698
[clang-repl] add %help, documentation, and tests for %commands (#150348)
1. Added %commands to documentation
2. Added %help command to clang repl
3. Expanded parsing to throw unique errors in the case of users entering
an invalid %command or using %lib without an argument
4. Added tests to check the behvaior of %help, %lib, and bad %commands
2025-08-05 14:50:48 +01:00
Matt
2e404d1f80
clang: Make the type_info builtin declaration a singleton (#151277)
This fixes an ambiguous type type_info when you try and reference the
`type_info` type while using clang modulemaps with `-fms-compatibility`
enabled

Fixes #38400
2025-08-04 06:44:10 -07:00
Endre Fülöp
a3d0c541eb
[clang][analyzer] Add StoreToImmutable checker (#150417)
This adds alpha.core.StoreToImmutable, a new alpha checker that detects
writes
to immutable memory regions, implementing part of SEI CERT Rule ENV30-C.
The
original proposal only handled global const variables, but this
implementation
extends it to also detect writes to:
- Local const variables
- String literals
- Const parameters and struct members
- Const arrays and pointers to const data

This checker is the continuation of the work started by zukatsinadze.
Discussion: https://reviews.llvm.org/D124244
2025-08-04 14:56:33 +02:00
Aaron Ballman
19b4258d65
[Docs] Some updates to the Clang user's manual (#151702)
* Fills out the terminology section
* Removes the basic usage section (we should bring it back someday
though!)
* Updates the list of supported language versions
* Adds information about what versions of Clang are officially supported
* Moves some extensions into the intentionally unsupported extensions
section.

There are likely far more updates that could be done, but this seemed
worth posting just to get things moving.
2025-08-04 07:15:48 -04:00
Gergely Futo
1454db130a
[RISCV] Support resumable non-maskable interrupt handlers (#148134)
The `rnmi` interrupt attribute value has been added for the `Smrnmi`
extension.

---------

Co-authored-by: Sam Elliott <sam@lenary.co.uk>
2025-08-04 10:54:50 +02:00
Kazu Hirata
d729076245
[clang] Proofread LanguageExtensions.rst (#151802) 2025-08-02 08:09:48 -07:00
Iris Shi
eefc3d275f
[clang][diagnostics] Fix fix-it hint parenthesis placement for fold expressions (#151790)
- Closes #151787

Insert the right parenthesis one token later to correctly enclose the
expression.

---------

Co-authored-by: Corentin Jabot <corentinjabot@gmail.com>
2025-08-02 16:53:06 +08:00
Aaron Ballman
17327482f0
[Analyzer] No longer crash with VLA operands to unary type traits (#151719)
sizeof was handled correctly, but __datasizeof and _Countof were not.

Fixes #151711
2025-08-01 12:31:56 -04:00
Iris Shi
f9088f1eb5
[static analyzer] Fix crash on parenthesized expression in assume attribute (#151682)
- Closes #151529

`ParenExpr` should be ignored before reaching `ExprEngine::Visit`.
Failing to do so triggers the assertion.
2025-08-01 19:29:06 +08:00
bd1976bris
c129d65995
[DTLTO][Clang][Docs] Update for COFF support (#149988)
As the COFF linker is usually invoked independently, update the Clang
DTLTO section to show an example. This follows what is done earlier in
the document.

Also some minor fixes and improvements:
- Use generic distributor names to avoid implying anything about what an
Incredibuild distributor may or should support.
- Use subheadings for readability.
- Correct a mis-cased hyperlink.
2025-08-01 09:16:22 +01:00
Kazu Hirata
666874a4bd
[clang] Proofread InternalsManual.rst (#151626) 2025-08-01 00:24:32 -07:00
Venkata Ramanaiah Nalamothu
523b4b0312
[Docs] Fix typo in shadow call stack option name (#151474)
Fix typo in shadow call stack option name mentioned in
'ShadowCallStack.rst'.
2025-07-31 21:31:23 +05:30
Kazu Hirata
5bb59e4716
[llvm] Proofread LangRef.rst (#151443) 2025-07-31 07:31:23 -07:00
Donát Nagy
6540c93aa9
[NFC][analyzer] Update docs of CodeChecker --ctu-ast-mode (#144901)
The documentation of the cross translation unit analysis mentioned a
certain flag of `CodeChecker` (an external open source tool that can be
used to drive the static analysis), but the information about it was
obsolete: apparently the name of the flag, the names of the possible
values, and the default value were all changed.

Currently `CodeChecker analyze --help` displays this flag as
```
--ctu-ast-mode {load-from-pch,parse-on-demand}
  Choose the way ASTs are loaded during CTU analysis. Only available if
  CTU mode is enabled. Mode 'load-from-pch' generates PCH format
  serialized ASTs during the 'collect' phase. Mode 'parse-on-demand'
  only generates the invocations needed to parse the ASTs. Mode 'load-
  from-pch' can use significant disk-space for the serialized ASTs,
  while mode 'parse-on-demand' can incur some runtime CPU overhead in
  the second phase of the analysis. (default: parse-on-demand)
```
and I tried to follow this in the commands that I adjusted.

Note that this documentation file probably contains other obsolete
details as well, but I didn't try to find or fix them.
2025-07-31 11:47:03 +02:00
M. Zeeshan Siddiqui
70471f08ee
[Sema] Fix -Wunreachable-code false negative when operands differ only by implicit casts (#149972)
## Motivation  
`-Wunreachable-code` missed—or in rare cases crashed on—tautological
comparisons such as

```cpp
x != 0 || x != 1.0   // always true
x == 0 && x == 1.0   // always false
```

when the *same* variable appears on both sides but one operand goes
through a floating‑rank promotion that is target‑dependent. On back‑ends
with **native half‑precision** (`_Float16` / `__fp16`) such as
AArch64 `+fullfp16`, no promotion occurs, so the cast stacks between the
two operands differ and the existing heuristic bails out.

## Technical description 
* **Extends `Expr::isSameComparisonOperand()`** – the helper now ignores
parentheses **and value‑preserving implicit casts**
(`CK_LValueToRValue`, floating‑rank `CK_FloatingCast`) before comparing
the underlying operands. This prevents floating‑rank promotions and
lvalue‑to‑rvalue conversions from blocking the unreachable‑code
diagnostic on targets with native FP16.
*No change needed in `CheckIncorrectLogicOperator`; it simply benefits
from the improved helper.*
* **Regression test** – `warn-unreachable_crash.cpp` updated to cover
both the promoted case (x86‑64) and the native‑half case
(AArch64 `+fullfp16`).
* **Docs** – release‑note bullet added under *Bug Fixes in This
Version*.

@ziqingluo-90 @yronglin Could you please review promptly? (feel free to
also merge it on my behalf) Thanks!

Fixes #149967

Co-authored-by: Zeeshan Siddiqui <mzs@ntdev.microsoft.com>
2025-07-31 09:21:59 +08:00
Yanzuo Liu
b39160ddfb
[Clang][Sema] Expression in assumption attribute should be full expression (#150814)
Add missing `ActOnFinishFullExpr` to `BuildCXXAssumeExpr`. We did it
during template instantiation but forgot non-template case.
2025-07-29 11:53:02 +08:00
Nick Sarnie
0efcb83626
[Clang] Reland '__has_builtin should return false for aux triple builtins' (#126324)
Reland https://github.com/llvm/llvm-project/pull/121839 based on the
results of the Discourse discussion
[here](https://discourse.llvm.org/t/rfc-has-builtin-behavior-on-offloading-targets/84964).

---------

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-07-28 17:54:52 +00:00
Tomer Shafir
5f20518f5b
[Clang][Docs] Fix typo in clang.rst (#150907) 2025-07-29 00:13:46 +08:00
Baghirov Feyruz
f0c90dfcd8
Rename 'free' in warning messages to 'release' (#150935)
Changed the warning message:

- **From**: 'Attempt to free released memory'
   **To**: 'Attempt to release already released memory'
- **From**: 'Attempt to free non-owned memory'
   **To**: 'Attempt to release non-owned memory'
- **From**: 'Use of memory after it is freed' 
   **To**: 'Use of memory after it is released'

All connected tests and their expectations have been changed
accordingly.

Inspired by [this
PR](https://github.com/llvm/llvm-project/pull/147542#discussion_r2195197922)
2025-07-28 18:02:56 +02:00
halbi2
a63bbf2f1e
[clang] Diagnose [[nodiscard]] return types in Objective-C++ (#142541)
My solution was to copy-paste getUnusedResultAttr and
hasUnusedResultAttr from CallExpr into ObjCMessageExpr too.

Fixes #141504
2025-07-28 09:26:28 -04:00
Anthony Tran
29992cfd62
[Clang][CodeGen] Emit “trap reasons” on UBSan traps (#145967)
This patch adds a human readable trap category and message to UBSan
traps. The category and message are encoded in a fake frame in the debug
info where the function is a fake inline function where the name encodes
the trap category and message. This is the same mechanism used by
Clang’s `__builtin_verbose_trap()`.

This change allows consumers of binaries built with trapping UBSan to
more easily identify the reason for trapping. In particular LLDB already
has a frame recognizer that recognizes the fake function names emitted
in debug info by this patch. A patch testing this behavior in LLDB will
be added in a separately.

The human readable trap messages are based on the messages currently
emitted by the userspace runtime for UBSan in compiler-rt. Note the
wording is not identical because the userspace UBSan runtime has access
to dynamic information that is not available during Clang’s codegen.

Test cases for each UBSan trap kind are included.

This complements the [`-fsanitize-annotate-debug-info`
feature](https://github.com/llvm/llvm-project/pull/141997). While
`-fsanitize-annotate-debug-info` attempts to annotate all UBSan-added
instructions, this feature (`-fsanitize-debug-trap-reasons`) only
annotates the final trap instruction using SanitizerHandler information.

This work is part of a GSoc 2025 project.
2025-07-26 08:50:25 -07:00
CatherineMoore
af17541eab
Update development status for OpenMP 6.0 (#150700) 2025-07-25 16:15:11 -05:00
gui martins
e77230424f
[clang-format] fix typo in docs (#150658)
Closes #150533
2025-07-25 21:30:25 +02:00
Harald van Dijk
2228b4b46c
clang: Handle deleting pointers to incomplete array types (#150359)
CodeGenFunction::EmitCXXDeleteExpr contains logic to go from a pointer
to an array to a pointer to the first element of the array using a
getelementptr LLVM IR instruction. This was done for pointers that were
not variable length arrays, as pointers to variable length arrays never
existed in LLVM IR, but rather than checking for arrays that were not
variable length arrays, it checked for arrays that had a constant bound.
This caused incomplete arrays to be inadvertently omitted.

This getelementptr was necessary back when LLVM IR used typed pointers,
but they have been gone for a while, a gep with a constant zero offset
does nothing now, so we can simplify the code by removing that.
2025-07-24 18:43:17 +01:00
Owen Pan
97c953406d
[clang-format] Add AfterNot to SpaceBeforeParensOptions (#150367)
Closes #149971
2025-07-24 09:38:43 -07:00
Donát Nagy
baa19c05a3
[NFC][analyzer] Document optin.portability.UnixAPI (#150005)
This commit provides a brief documentation for the checker
optin.portability.UnixAPI.

Unfortunately the name of this checker is meaninglessly vague and its
functionality is very closely related to unix.Malloc, so it should be
eventually "rebranded" to a more user-friendly presentation.
2025-07-24 14:53:34 +02:00
Aaron Ballman
db8a389f88 [Docs] Add back lost release notes; NFC
When release notes were cleared on ``main``, there were some notes lost
because the changes happened after the branch point for 21.x. This
restores the lost notes.
2025-07-24 07:12:54 -04:00
Tobias Hieta
3d8db8ef50 Clear release notes on main for LLVM 22 2025-07-24 11:36:11 +02:00
Shashi Shankar
31db0f0a7a
[Clang] Suppress deprecated field warnings in implicit functions definitions (#147400)
Do not warn on deprecated member used in an implicit definition (such as a defaulted special member function).

Co-authored-by: Corentin Jabot <corentinjabot@gmail.com>

Fixes #147293
2025-07-24 08:48:27 +02:00
David Pagan
45d99c26c3
[clang][OpenMP] In 6.0, can omit length in array section (#148048)
In OpenMP 6.0 specification, section 5.2.5 Array Sections, page 166,
lines 28-28:

When the length is absent and the size of the dimension is not known,
the array section is an assumed-size array.

Testing
- Updated LIT test
- check-all
- OpenMP_VV (formerly sollve) test case
tests/6.0/target/test_target_assumed_array_size.c
2025-07-23 10:53:38 -07:00
Fazlay Rabbi
5daaaf8d7d
[OpenMP 6.0] Allow only byref arguments with need_device_addr modifier on adjust_args clause (#149586)
If the need_device_addr adjust-op modifier is present, each list item
that appears in the clause must refer to an argument in the declaration
of the function variant that has a reference type.

Reference:
OpenMP 6.0 [Sec 9.6.2, page 332, line 31-33, adjust_args clause,
Restrictions]
2025-07-23 09:38:13 -07:00
Alex Voicu
01e23c3d62
[HIPSTDPAR] Add support for globals (#146813)
This (mostly) removes one of the largest remaining limitations of
`hipstdpar` based algorithm acceleration, by adding support for global
variable usage in offloaded algorithms. It is mean to compose with a run
time component that will live in the support library, and fires iff a
special variable is provided by the latter. In short, things work as
follows:

- We replace uses some global `G` with an indirect access via an
implicitly created anonymous global `F`, which is of pointer type and is
expected to hold the program-wide address of `G`;
- We append 'F', alongside 'G''s name, to an table structure;
- At run-time, the support library uses the table to look-up the
program-wide address of a contained symbol based on its name, and then
stores the address via the paired pointer.

This doesn't handle internal linkage symbols (`static foo` or `namespace
{ foo }`) if they are not unique i.e. if there's a name clash that is
solved by the linker, as the resolution would not be visible. Also,
initially we will only support "true" globals in RDC mode. Things would
be much simpler if we had direct access to the accelerator loader, but
since the expectation is to compose at the HIP RT level we have to jump
through additional hoops.
2025-07-23 13:55:46 +01:00
Wenju He
e0dd22fab1
[Clang] Add elementwise maximumnum/minimumnum builtin functions (#149775)
Addresses https://github.com/llvm/llvm-project/issues/112164. minimumnum
and maximumnum intrinsics were added in 5bf81e53dbea.

The new built-ins can be used for implementing OpenCL math function fmax
and fmin in #128506.
2025-07-23 08:34:35 +08:00
Volodymyr Sapsai
dbc41dd5d8
[clang][deps] Add a release note for fixing crashes in clang-scan-deps. (#149857) 2025-07-22 20:15:54 -04:00
yronglin
44a6e0099b
[clang] Check empty macro name in #pragma push_macro("") or #pragma pop_macro("") (#149982)
Fixes https://github.com/llvm/llvm-project/issues/149762.

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2025-07-22 22:57:34 +08:00
Owen Pan
739e76454f [Tooling][Inclusions][NFC] Reformat C++ code 2025-07-21 21:37:48 -07:00
Devon Loehr
dcffa3d05c
Fix indendation in StandardCPlusPlusModules.rst (#149901)
The CI is complaining about unexpected indentation. It seems multiple-line list entries must start at the beginning of each line.
2025-07-21 17:12:53 -04:00
Kazu Hirata
afdd30d712
[clang] Proofread UsersManual.rst (NFC) (#149763) 2025-07-21 07:24:07 -07:00
Chuanqi Xu
255a163e51 [C++20] [Modules] Enable reduced BMI by default
As documented in 20.x, we'd like to keep reduced BMI off by default for
1~2 versions. And now we're in 22.x.

I rarely receive bug reports for reduced BMI. I am not sure about the
reason. Maybe not a lot of people are using it. Or it is really stable
enough.

And also, we've been enabling the reduced BMI internally for roughly half a
year.

So I think it's the time to move on. See the document changes for other
information.
2025-07-21 18:57:38 +08:00
Kazu Hirata
1b8defddf4
[clang] Proofread LanguageExtensions.rst (#149729) 2025-07-20 20:42:24 -07:00
Manas
54492c231c
[clang][docs] Add all clang-tools-extra to 'ClangTools.rst' (#148622)
The 'Extra Clang Tools' section does not mention any other clang tool
except clang-tidy. This adds all missing extra tools to sync
documentation between this page and the main page of Extra Clang Tools.

Fixes #148538
2025-07-20 01:18:24 +03:00
YexuanXiao
7c402b8b81
Reland [Clang] Make the SizeType, SignedSizeType and PtrdiffType be named sugar types (#149613)
The checks for the 'z' and 't' format specifiers added in the original
PR #143653 had some issues and were overly strict, causing some build
failures and were consequently reverted at
4c85bf2fe8.

In the latest commit
27c58629ec,
I relaxed the checks for the 'z' and 't' format specifiers, so warnings
are now only issued when they are used with mismatched types.

The original intent of these checks was to diagnose code that assumes
the underlying type of `size_t` is `unsigned` or `unsigned long`, for
example:

```c
printf("%zu", 1ul); // Not portable, but not an error when size_t is unsigned long
```  

However, it produced a significant number of false positives. This was
partly because Clang does not treat the `typedef` `size_t` and
`__size_t` as having a common "sugar" type, and partly because a large
amount of existing code either assumes `unsigned` (or `unsigned long`)
is `size_t`, or they define the equivalent of size_t in their own way
(such as
sanitizer_internal_defs.h).2e67dcfdcd/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h (L203)
2025-07-19 03:44:14 -03:00
Oleksandr T.
cda28e203d
[analyzer] Support parenthesized list initialization (CXXParenListInitExpr) (#148988)
This patch addresses the lack of support for parenthesized
initialization in the Clang Static Analyzer's `ExprEngine`. Previously,
initializations such as `V v(1, 2);` were not modeled properly, which
could lead to false negatives in analyses like `DivideZero`.

```cpp
struct A {
  int x;
  A(int v) : x(v) {}
};

int t() {
  A a(42);
  return 1 / (a.x - 42); // expected-warning {{Division by zero}}
}
```

Fixes #148875
2025-07-18 09:34:15 +02:00
Younan Zhang
beec840822
[Clang] Ensure correct parameters are in the scope for constraint equivalence checking (#149264)
This is another case where untransformed constraint expressions led to
inconsistent transforms.

We did fix some of those issues by looking at parent scopes, however the
parent instantiation scope is not always available because we could also
reach here after the parents get instantiated.

Fixes #146614
2025-07-18 15:23:32 +08:00