Skip to content

Commit 9dbaac6

Browse files
authored
Merge branch 'main' into clang-abi-ver
2 parents a5f6dcf + 1eaf736 commit 9dbaac6

File tree

455 files changed

+16650
-5896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

455 files changed

+16650
-5896
lines changed

.github/workflows/libc-fullbuild-tests.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,37 @@ jobs:
2121
- os: ubuntu-24.04
2222
build_type: Debug
2323
ccache-variant: sccache
24-
c_compiler: clang-20
25-
cpp_compiler: clang++-20
24+
c_compiler: clang-22
25+
cpp_compiler: clang++-22
2626
target: x86_64-unknown-linux-llvm
2727
include_scudo: ON
2828
- os: ubuntu-24.04
2929
build_type: Release
3030
ccache-variant: sccache
31-
c_compiler: clang-20
32-
cpp_compiler: clang++-20
31+
c_compiler: clang-22
32+
cpp_compiler: clang++-22
3333
target: x86_64-unknown-linux-llvm
3434
include_scudo: ON
3535
- os: ubuntu-24.04
3636
build_type: MinSizeRel
3737
ccache-variant: sccache
38-
c_compiler: clang-20
39-
cpp_compiler: clang++-20
38+
c_compiler: clang-22
39+
cpp_compiler: clang++-22
4040
target: x86_64-unknown-linux-llvm
4141
include_scudo: ON
4242
# TODO: remove ccache logic when https://github.com/hendrikmuhs/ccache-action/issues/279 is resolved.
4343
- os: ubuntu-24.04-arm
4444
build_type: Debug
4545
ccache-variant: ccache
46-
c_compiler: clang-20
47-
cpp_compiler: clang++-20
46+
c_compiler: clang-22
47+
cpp_compiler: clang++-22
4848
target: aarch64-unknown-linux-llvm
4949
include_scudo: ON
5050
- os: ubuntu-24.04
5151
build_type: Debug
5252
ccache-variant: ccache
53-
c_compiler: clang-20
54-
cpp_compiler: clang++-20
53+
c_compiler: clang-22
54+
cpp_compiler: clang++-22
5555
target: x86_64-unknown-uefi-llvm
5656
include_scudo: OFF
5757
# TODO: add back gcc build when it is fixed
@@ -81,7 +81,7 @@ jobs:
8181
run: |
8282
wget https://apt.llvm.org/llvm.sh
8383
chmod +x llvm.sh
84-
sudo ./llvm.sh 20
84+
sudo ./llvm.sh 22
8585
sudo apt-get update
8686
sudo apt-get install -y libmpfr-dev libgmp-dev libmpc-dev ninja-build linux-libc-dev
8787
sudo ln -sf /usr/include/$(uname -p)-linux-gnu/asm /usr/include/asm

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -859,17 +859,47 @@ std::vector<DocumentLink> getDocumentLinks(ParsedAST &AST) {
859859
for (auto &Inc : AST.getIncludeStructure().MainFileIncludes) {
860860
if (Inc.Resolved.empty())
861861
continue;
862+
863+
// Get the location of the # symbole of the "#include ..." statement
862864
auto HashLoc = SM.getComposedLoc(SM.getMainFileID(), Inc.HashOffset);
865+
866+
// get the # Token itself, std::next to get the "include" token and the
867+
// first token after (aka "File Token")
863868
const auto *HashTok = AST.getTokens().spelledTokenContaining(HashLoc);
864869
assert(HashTok && "got inclusion at wrong offset");
865870
const auto *IncludeTok = std::next(HashTok);
866871
const auto *FileTok = std::next(IncludeTok);
867-
// FileTok->range is not sufficient here, as raw lexing wouldn't yield
868-
// correct tokens for angled filenames. Hence we explicitly use
869-
// Inc.Written's length.
870-
auto FileRange =
871-
syntax::FileRange(SM, FileTok->location(), Inc.Written.length())
872-
.toCharRange(SM);
872+
873+
// The File Token can either be of kind :
874+
// "less" if using the "#include <h-char-sequence> new-line" syntax
875+
// "string_literal" if using the "#include "q-char-sequence" new-line"
876+
// syntax something else (most likely "identifier") if using the "#include
877+
// pp-tokens new-line" syntax (#include with macro argument)
878+
879+
CharSourceRange FileRange;
880+
881+
if (FileTok->kind() == tok::TokenKind::less) {
882+
// FileTok->range would only include the '<' char. Hence we explicitly use
883+
// Inc.Written's length.
884+
FileRange =
885+
syntax::FileRange(SM, FileTok->location(), Inc.Written.length())
886+
.toCharRange(SM);
887+
} else if (FileTok->kind() == tok::TokenKind::string_literal) {
888+
// FileTok->range includes the quotes for string literals so just return
889+
// it.
890+
FileRange = FileTok->range(SM).toCharRange(SM);
891+
} else {
892+
// FileTok is the first Token of a macro spelling
893+
894+
// Report the range of the first token (as it should be the macro
895+
// identifier)
896+
// We could use the AST to find the last spelled token of the macro and
897+
// report a range spanning the full macro expression, but it would require
898+
// using token-buffers that are deemed too unstable and crash-prone
899+
// due to optimizations in cland
900+
901+
FileRange = FileTok->range(SM).toCharRange(SM);
902+
}
873903

874904
Result.push_back(
875905
DocumentLink({halfOpenToRange(SM, FileRange),

clang-tools-extra/clangd/unittests/XRefsTests.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,14 +2784,24 @@ TEST(GetNonLocalDeclRefs, All) {
27842784

27852785
TEST(DocumentLinks, All) {
27862786
Annotations MainCpp(R"cpp(
2787+
#define HEADER_AA "faa.h"
2788+
#define HEADER_BB "fbb.h"
2789+
#define GET_HEADER(X) HEADER_ ## X
2790+
27872791
#/*comments*/include /*comments*/ $foo[["foo.h"]] //more comments
27882792
int end_of_preamble = 0;
27892793
#include $bar[[<bar.h>]]
2794+
#include $AA[[GET_HEADER]](AA) // Some comment !
2795+
# /* What about */ \
2796+
include /* multiple line */ \
2797+
$BB[[GET_HEADER]]( /* statements ? */ \
2798+
BB /* :) */ )
27902799
)cpp");
27912800

27922801
TestTU TU;
27932802
TU.Code = std::string(MainCpp.code());
2794-
TU.AdditionalFiles = {{"foo.h", ""}, {"bar.h", ""}};
2803+
TU.AdditionalFiles = {
2804+
{"faa.h", ""}, {"fbb.h", ""}, {"foo.h", ""}, {"bar.h", ""}};
27952805
TU.ExtraArgs = {"-isystem."};
27962806
auto AST = TU.build();
27972807

@@ -2801,7 +2811,11 @@ TEST(DocumentLinks, All) {
28012811
DocumentLink({MainCpp.range("foo"),
28022812
URIForFile::canonicalize(testPath("foo.h"), "")}),
28032813
DocumentLink({MainCpp.range("bar"),
2804-
URIForFile::canonicalize(testPath("bar.h"), "")})));
2814+
URIForFile::canonicalize(testPath("bar.h"), "")}),
2815+
DocumentLink({MainCpp.range("AA"),
2816+
URIForFile::canonicalize(testPath("faa.h"), "")}),
2817+
DocumentLink({MainCpp.range("BB"),
2818+
URIForFile::canonicalize(testPath("fbb.h"), "")})));
28052819
}
28062820

28072821
} // namespace

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ Bug Fixes in This Version
144144

145145
Bug Fixes to Compiler Builtins
146146
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147+
- Fix an ambiguous reference to the builtin `type_info` (available when using
148+
`-fms-compatibility`) with modules. (#GH38400)
147149

148150
Bug Fixes to Attribute Support
149151
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -198,6 +200,9 @@ LoongArch Support
198200
RISC-V Support
199201
^^^^^^^^^^^^^^
200202

203+
- Add support for `__attribute__((interrupt("rnmi")))` to be used with the `Smrnmi` extension.
204+
With this the `Smrnmi` extension is fully supported.
205+
201206
CUDA/HIP Language Changes
202207
^^^^^^^^^^^^^^^^^^^^^^^^^
203208

clang/docs/UsersManual.rst

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ which includes :ref:`C <c>`, :ref:`Objective-C <objc>`, :ref:`C++ <cxx>`, and
3535
language-specific information, please see the corresponding language
3636
specific section:
3737

38-
- :ref:`C Language <c>`: K&R C, ANSI C89, ISO C90, ISO C94 (C89+AMD1), ISO
39-
C99 (+TC1, TC2, TC3).
38+
- :ref:`C Language <c>`: K&R C, ANSI C89, ISO C90, C94 (C89+AMD1), C99 (+TC1,
39+
TC2, TC3), C11, C17, C23, and C2y.
4040
- :ref:`Objective-C Language <objc>`: ObjC 1, ObjC 2, ObjC 2.1, plus
4141
variants depending on base language.
42-
- :ref:`C++ Language <cxx>`
42+
- :ref:`C++ Language <cxx>`: C++98, C++03, C++11, C++14, C++17, C++20, C++23,
43+
and C++26.
4344
- :ref:`Objective C++ Language <objcxx>`
4445
- :ref:`OpenCL Kernel Language <opencl>`: OpenCL C 1.0, 1.1, 1.2, 2.0, 3.0,
4546
and C++ for OpenCL 1.0 and 2021.
@@ -60,29 +61,55 @@ features that depend on what CPU architecture or operating system is
6061
being compiled for. Please see the :ref:`Target-Specific Features and
6162
Limitations <target_features>` section for more details.
6263

63-
The rest of the introduction introduces some basic :ref:`compiler
64-
terminology <terminology>` that is used throughout this manual and
65-
contains a basic :ref:`introduction to using Clang <basicusage>` as a
66-
command line compiler.
67-
6864
.. _terminology:
6965

7066
Terminology
7167
-----------
68+
* Lexer -- the part of the compiler responsible for converting source code into
69+
abstract representations called tokens.
70+
* Preprocessor -- the part of the compiler responsible for in-place textual
71+
replacement of source constructs. When the lexer is required to produce a
72+
token, it will run the preprocessor while determining which token to produce.
73+
In other words, when the lexer encounters something like `#include` or a macro
74+
name, the preprocessor will be used to perform the inclusion or expand the
75+
macro name into its replacement list, and return the resulting non-preprocessor
76+
token.
77+
* Parser -- the part of the compiler responsible for determining syntactic
78+
correctness of the source code. The parser will request tokens from the lexer
79+
and after performing semantic analysis of the production, generates an
80+
abstract representation of the source called an AST.
81+
* Sema -- the part of the compiler responsible for determining semantic
82+
correctness of the source code. It is closely related to the parser and is
83+
where many diagnostics are produced.
84+
* Diagnostic -- a message to the user about properties of the source code. For
85+
example, errors or warnings and their associated notes.
86+
* Undefined behavior -- behavior for which the standard imposes no requirements
87+
on how the code behaves. Generally speaking, undefined behavior is a bug in
88+
the user's code. However, it can also be a place for the compiler to define
89+
the behavior, called an extension.
90+
* Optimizer -- the part of the compiler responsible for transforming code to
91+
have better performance characteristics without changing the semantics of how
92+
the code behaves. Note, the optimizer assumes the code has no undefined
93+
behavior, so if the code does contain undefined behavior, it will often behave
94+
differently depending on which optimization level is enabled.
95+
* Frontend -- the Lexer, Preprocessor, Parser, Sema, and LLVM IR code generation
96+
parts of the compiler.
97+
* Middle-end -- a term used for the of the subset of the backend that does
98+
(typically not target specific) optimizations prior to assembly code
99+
generation.
100+
* Backend -- the parts of the compiler which run after LLVM IR code generation,
101+
such as the optimizer and generation of assembly code.
102+
103+
See the :doc:`InternalsManual` for more details about the internal construction
104+
of the compiler.
105+
106+
Support
107+
-------
108+
Clang releases happen roughly `every six months <https://llvm.org/docs/HowToReleaseLLVM.html#annual-release-schedule>`_.
109+
Only the current public release is officially supported. Bug-fix releases for
110+
the current release will be produced on an as-needed basis, but bug fixes are
111+
not backported to releases older than the current one.
72112

73-
Front end, parser, backend, preprocessor, undefined behavior,
74-
diagnostic, optimizer
75-
76-
.. _basicusage:
77-
78-
Basic Usage
79-
-----------
80-
81-
Intro to how to use a C compiler for newbies.
82-
83-
compile + link compile then link debug info enabling optimizations
84-
picking a language to use, defaults to C17 by default. Autosenses based
85-
on extension. using a makefile
86113

87114
Command Line Options
88115
====================
@@ -3797,8 +3824,8 @@ This environment variable does not affect the options added by the config files.
37973824
C Language Features
37983825
===================
37993826

3800-
The support for standard C in clang is feature-complete except for the
3801-
C99 floating-point pragmas.
3827+
The support for standard C in Clang is mostly feature-complete, see the `C
3828+
status page <https://clang.llvm.org/c_status.html>`_ for more details.
38023829

38033830
Extensions supported by clang
38043831
-----------------------------
@@ -3883,23 +3910,10 @@ GCC extensions not implemented yet
38833910
----------------------------------
38843911

38853912
clang tries to be compatible with gcc as much as possible, but some gcc
3886-
extensions are not implemented yet:
3913+
extensions are not implemented:
38873914

38883915
- clang does not support decimal floating point types (``_Decimal32`` and
38893916
friends) yet.
3890-
- clang does not support nested functions; this is a complex feature
3891-
which is infrequently used, so it is unlikely to be implemented
3892-
anytime soon. In C++11 it can be emulated by assigning lambda
3893-
functions to local variables, e.g:
3894-
3895-
.. code-block:: cpp
3896-
3897-
auto const local_function = [&](int parameter) {
3898-
// Do something
3899-
};
3900-
...
3901-
local_function(1);
3902-
39033917
- clang only supports global register variables when the register specified
39043918
is non-allocatable (e.g. the stack pointer). Support for general global
39053919
register variables is unlikely to be implemented soon because it requires
@@ -3914,18 +3928,13 @@ extensions are not implemented yet:
39143928
that because clang pretends to be like GCC 4.2, and this extension
39153929
was introduced in 4.3, the glibc headers will not try to use this
39163930
extension with clang at the moment.
3917-
- clang does not support the gcc extension for forward-declaring
3918-
function parameters; this has not shown up in any real-world code
3919-
yet, though, so it might never be implemented.
39203931

39213932
This is not a complete list; if you find an unsupported extension
3922-
missing from this list, please send an e-mail to cfe-dev. This list
3923-
currently excludes C++; see :ref:`C++ Language Features <cxx>`. Also, this
3924-
list does not include bugs in mostly-implemented features; please see
3925-
the `bug
3926-
tracker <https://bugs.llvm.org/buglist.cgi?quicksearch=product%3Aclang+component%3A-New%2BBugs%2CAST%2CBasic%2CDriver%2CHeaders%2CLLVM%2BCodeGen%2Cparser%2Cpreprocessor%2CSemantic%2BAnalyzer>`_
3927-
for known existing bugs (FIXME: Is there a section for bug-reporting
3928-
guidelines somewhere?).
3933+
missing from this list, please file a `feature request <https://github.com/llvm/llvm-project/issues/>`_.
3934+
This list currently excludes C++; see :ref:`C++ Language Features <cxx>`. Also,
3935+
this list does not include bugs in mostly-implemented features; please see the
3936+
`issues list <https://github.com/llvm/llvm-project/issues/>`_ for known existing
3937+
bugs.
39293938

39303939
Intentionally unsupported GCC extensions
39313940
----------------------------------------
@@ -3944,6 +3953,20 @@ Intentionally unsupported GCC extensions
39443953
variable) will likely never be accepted by Clang.
39453954
- clang does not support ``__builtin_apply`` and friends; this extension
39463955
is extremely obscure and difficult to implement reliably.
3956+
- clang does not support the gcc extension for forward-declaring
3957+
function parameters.
3958+
- clang does not support nested functions; this is a complex feature which is
3959+
infrequently used, so it is unlikely to be implemented. In C++11 it can be
3960+
emulated by assigning lambda functions to local variables, e.g:
3961+
3962+
.. code-block:: cpp
3963+
3964+
auto const local_function = [&](int parameter) {
3965+
// Do something
3966+
};
3967+
...
3968+
local_function(1);
3969+
39473970
39483971
.. _c_ms:
39493972

@@ -3983,7 +4006,7 @@ C++ Language Features
39834006

39844007
clang fully implements all of standard C++98 except for exported
39854008
templates (which were removed in C++11), all of standard C++11,
3986-
C++14, and C++17, and most of C++20.
4009+
C++14, and C++17, and most of C++20 and C++23.
39874010

39884011
See the `C++ support in Clang <https://clang.llvm.org/cxx_status.html>`_ page
39894012
for detailed information on C++ feature support across Clang versions.

clang/docs/analyzer/checkers.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,6 +3086,23 @@ Either the comparison is useless or there is division by zero.
30863086
if (x == 0) { } // warn
30873087
}
30883088
3089+
.. _alpha-core-StoreToImmutable:
3090+
3091+
alpha.core.StoreToImmutable (C, C++)
3092+
""""""""""""""""""""""""""""""""""""
3093+
Check for writes to immutable memory regions. This implements part of SEI CERT Rule ENV30-C.
3094+
3095+
This checker detects attempts to write to memory regions that are marked as immutable,
3096+
including const variables, string literals, and other const-qualified memory.
3097+
3098+
.. literalinclude:: checkers/storetoimmutable_example.cpp
3099+
:language: cpp
3100+
3101+
**Solution**
3102+
3103+
Avoid writing to const-qualified memory regions. If you need to modify the data,
3104+
remove the const qualifier from the original declaration or use a mutable copy.
3105+
30893106
alpha.cplusplus
30903107
^^^^^^^^^^^^^^^
30913108
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const int global_const = 42;
2+
3+
struct TestStruct {
4+
const int x;
5+
int y;
6+
};
7+
8+
void immutable_violation_examples() {
9+
*(int *)&global_const = 100; // warn: Trying to write to immutable memory
10+
11+
const int local_const = 42;
12+
*(int *)&local_const = 43; // warn: Trying to write to immutable memory
13+
14+
// NOTE: The following is reported in C++, but not in C, as the analyzer
15+
// treats string literals as non-const char arrays in C mode.
16+
char *ptr_to_str_literal = (char *)"hello";
17+
ptr_to_str_literal[0] = 'H'; // warn: Trying to write to immutable memory
18+
19+
TestStruct s = {1, 2};
20+
*(int *)&s.x = 10; // warn: Trying to write to immutable memory
21+
}

0 commit comments

Comments
 (0)