Skip to content

Commit 2154683

Browse files
Merge branch 'main' into main
2 parents 576a920 + 7a831eb commit 2154683

File tree

903 files changed

+47751
-31585
lines changed

Some content is hidden

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

903 files changed

+47751
-31585
lines changed

.github/workflows/release-binaries.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
prepare:
5050
name: Prepare to build binaries
5151
runs-on: ${{ inputs.runs-on }}
52-
if: github.repository == 'llvm/llvm-project'
52+
if: github.repository_owner == 'llvm'
5353
outputs:
5454
release-version: ${{ steps.vars.outputs.release-version }}
5555
ref: ${{ steps.vars.outputs.ref }}
@@ -177,7 +177,7 @@ jobs:
177177
build-release-package:
178178
name: "Build Release Package"
179179
needs: prepare
180-
if: github.repository == 'llvm/llvm-project'
180+
if: github.repository_owner == 'llvm'
181181
runs-on: ${{ needs.prepare.outputs.build-runs-on }}
182182
steps:
183183

@@ -327,7 +327,7 @@ jobs:
327327
- prepare
328328
- build-release-package
329329
if: >-
330-
github.repository == 'llvm/llvm-project'
330+
github.repository_owner == 'llvm'
331331
runs-on: ${{ needs.prepare.outputs.test-runs-on }}
332332
steps:
333333
- name: Checkout Actions

clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/AST/Decl.h"
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
1314
#include "clang/Lex/Lexer.h"
1415

1516
using namespace clang::ast_matchers;

clang-tools-extra/modularize/CoverageChecker.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,15 @@ CoverageChecker::collectUmbrellaHeaderHeaders(StringRef UmbrellaHeaderName) {
278278
sys::fs::current_path(PathBuf);
279279

280280
// Create the compilation database.
281-
std::unique_ptr<CompilationDatabase> Compilations;
282-
Compilations.reset(new FixedCompilationDatabase(Twine(PathBuf), CommandLine));
281+
FixedCompilationDatabase Compilations(Twine(PathBuf), CommandLine);
283282

284283
std::vector<std::string> HeaderPath;
285284
HeaderPath.push_back(std::string(UmbrellaHeaderName));
286285

287286
// Create the tool and run the compilation.
288-
ClangTool Tool(*Compilations, HeaderPath);
289-
int HadErrors = Tool.run(new CoverageCheckerFrontendActionFactory(*this));
287+
ClangTool Tool(Compilations, HeaderPath);
288+
CoverageCheckerFrontendActionFactory ActionFactory(*this);
289+
int HadErrors = Tool.run(&ActionFactory);
290290

291291
// If we had errors, exit early.
292292
return !HadErrors;

clang/docs/BoundsSafety.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,4 +996,11 @@ and the soundness of the type system. This may incur significant code size
996996
overhead in unoptimized builds and leaving some of the adoption mistakes to be
997997
caught only at run time. This is not a fundamental limitation, however, because
998998
incrementally adding necessary static analysis will allow us to catch issues
999-
early on and remove unnecessary bounds checks in unoptimized builds.
999+
early on and remove unnecessary bounds checks in unoptimized builds.
1000+
1001+
Try it out
1002+
==========
1003+
1004+
Your feedback on the programming model is valuable. You may want to follow the
1005+
instruction in :doc:`BoundsSafetyAdoptionGuide` to play with ``-fbounds-safety``
1006+
and please send your feedback to `Yeoul Na <mailto:[email protected]>`_.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
======================================
2+
Adoption Guide for ``-fbounds-safety``
3+
======================================
4+
5+
.. contents::
6+
:local:
7+
8+
Where to get ``-fbounds-safety``
9+
================================
10+
11+
The open sourcing to llvm.org's ``llvm-project`` is still on going and the
12+
feature is not available yet. In the mean time, the preview implementation is
13+
available
14+
`here <https://github.com/swiftlang/llvm-project/tree/stable/20240723>`_ in a
15+
fork of ``llvm-project``. Please follow
16+
`Building LLVM with CMake <https://llvm.org/docs/CMake.html>`_ to build the
17+
compiler.
18+
19+
Feature flag
20+
============
21+
22+
Pass ``-fbounds-safety`` as a Clang compilation flag for the C file that you
23+
want to adopt. We recommend adopting the model file by file, because adoption
24+
requires some effort to add bounds annotations and fix compiler diagnostics.
25+
26+
Include ``ptrcheck.h``
27+
======================
28+
29+
``ptrcheck.h`` is a Clang toolchain header to provide definition of the bounds
30+
annotations such as ``__counted_by``, ``__counted_by_or_null``, ``__sized_by``,
31+
etc. In the LLVM source tree, the header is located in
32+
``llvm-project/clang/lib/Headers/ptrcheck.h``.
33+
34+
35+
Add bounds annotations on pointers as necessary
36+
===============================================
37+
38+
Annotate pointers on struct fields and function parameters if they are pointing
39+
to an array of object, with appropriate bounds annotations. Please see
40+
:doc:`BoundsSafety` to learn what kind of bounds annotations are available and
41+
their semantics. Note that local pointer variables typically don't need bounds
42+
annotations because they are implicitely a wide pointer (``__bidi_indexable``)
43+
that automatically carries the bounds information.
44+
45+
Address compiler diagnostics
46+
============================
47+
48+
Once you pass ``-fbounds-safety`` to compiler a C file, you will see some new
49+
compiler warnings and errors, which guide adoption of ``-fbounds-safety``.
50+
Consider the following example:
51+
52+
.. code-block:: c
53+
54+
#include <ptrcheck.h>
55+
56+
void init_buf(int *p, int n) {
57+
for (int i = 0; i < n; ++i)
58+
p[i] = 0; // error: array subscript on single pointer 'p' must use a constant index of 0 to be in bounds
59+
}
60+
61+
The parameter ``int *p`` doesn't have a bounds annotation, so the compiler will
62+
complain about the code indexing into it (``p[i]``) as it assumes that ``p`` is
63+
pointing to a single ``int`` object or null. To address the diagnostics, you
64+
should add a bounds annotation on ``int *p`` so that the compiler can reason
65+
about the safety of the array subscript. In the following example, ``p`` is now
66+
``int *__counted_by(n)``, so the compiler will allow the array subscript with
67+
additional run-time checks as necessary.
68+
69+
.. code-block:: c
70+
71+
#include <ptrcheck.h>
72+
73+
void init_buf(int *__counted_by(n) p, int n) {
74+
for (int i = 0; i < n; ++i)
75+
p[i] = 0; // ok; `p` is now has a type with bounds annotation.
76+
}
77+
78+
Run test suites to fix new run-time traps
79+
=========================================
80+
81+
Adopting ``-fbounds-safety`` may cause your program to trap if it violates
82+
bounds safety or it has incorrect adoption. Thus, it is necessary to perform
83+
run-time testing of your program to gain confidence that it won't trap at
84+
run time.
85+
86+
Repeat the process for each remaining file
87+
==========================================
88+
89+
Once you've done with adopting a single C file, please repeat the same process
90+
for each remaining C file that you want to adopt.

clang/docs/ReleaseNotes.rst

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,6 @@ C++ Language Changes
294294
C++2c Feature Support
295295
^^^^^^^^^^^^^^^^^^^^^
296296

297-
- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
298-
`P2647R1 A trait for implicit lifetime types <https://wg21.link/p2674r1>`_
299-
300297
- Add ``__builtin_is_virtual_base_of`` intrinsic, which supports
301298
`P2985R0 A type trait for detecting virtual base classes <https://wg21.link/p2985r0>`_
302299

@@ -318,6 +315,9 @@ C++23 Feature Support
318315

319316
- ``__cpp_explicit_this_parameter`` is now defined. (#GH82780)
320317

318+
- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
319+
`P2674R1 A trait for implicit lifetime types <https://wg21.link/p2674r1>`_
320+
321321
- Add support for `P2280R4 Using unknown pointers and references in constant expressions <https://wg21.link/P2280R4>`_. (#GH63139)
322322

323323
C++20 Feature Support
@@ -363,6 +363,9 @@ Resolutions to C++ Defect Reports
363363
- Clang now allows trailing requires clause on explicit deduction guides.
364364
(`CWG2707: Deduction guides cannot have a trailing requires-clause <https://cplusplus.github.io/CWG/issues/2707.html>`_).
365365

366+
- Respect constructor constraints during CTAD.
367+
(`CWG2628: Implicit deduction guides should propagate constraints <https://cplusplus.github.io/CWG/issues/2628.html>`_).
368+
366369
- Clang now diagnoses a space in the first production of a ``literal-operator-id``
367370
by default.
368371
(`CWG2521: User-defined literals and reserved identifiers <https://cplusplus.github.io/CWG/issues/2521.html>`_).
@@ -804,6 +807,8 @@ Improvements to Clang's diagnostics
804807

805808
- Clang now emits a ``-Wignored-qualifiers`` diagnostic when a base class includes cv-qualifiers (#GH55474).
806809

810+
- Clang now diagnoses the use of attribute names reserved by the C++ standard (#GH92196).
811+
807812
Improvements to Clang's time-trace
808813
----------------------------------
809814

@@ -971,6 +976,9 @@ Bug Fixes to C++ Support
971976
- Fixed canonicalization of pack indexing types - Clang did not always recognized identical pack indexing. (#GH123033)
972977
- Fixed a nested lambda substitution issue for constraint evaluation. (#GH123441)
973978
- Fixed various false diagnostics related to the use of immediate functions. (#GH123472)
979+
- Fix immediate escalation not propagating through inherited constructors. (#GH112677)
980+
- Fixed assertions or false compiler diagnostics in the case of C++ modules for
981+
lambda functions or inline friend functions defined inside templates (#GH122493).
974982

975983
Bug Fixes to AST Handling
976984
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1131,6 +1139,20 @@ Windows Support
11311139
LoongArch Support
11321140
^^^^^^^^^^^^^^^^^
11331141

1142+
- Types of parameters and return value of ``__builtin_lsx_vorn_v`` and ``__builtin_lasx_xvorn_v``
1143+
are changed from ``signed char`` to ``unsigned char``. (#GH114514)
1144+
1145+
- ``-mrelax`` and ``-mno-relax`` are supported now on LoongArch that can be used
1146+
to enable / disable the linker relaxation optimization. (#GH123587)
1147+
1148+
- Fine-grained la64v1.1 options are added including ``-m{no-,}frecipe``, ``-m{no-,}lam-bh``,
1149+
``-m{no-,}ld-seq-sa``, ``-m{no-,}div32``, ``-m{no-,}lamcas`` and ``-m{no-,}scq``.
1150+
1151+
- Two options ``-m{no-,}annotate-tablejump`` are added to enable / disable
1152+
annotating table jump instruction to correlate it with the jump table. (#GH102411)
1153+
1154+
- FreeBSD support is added for LoongArch64 and has been tested by building kernel-toolchain. (#GH119191)
1155+
11341156
RISC-V Support
11351157
^^^^^^^^^^^^^^
11361158

@@ -1254,6 +1276,13 @@ libclang
12541276
- Added ``clang_getOffsetOfBase``, which allows computing the offset of a base
12551277
class in a class's layout.
12561278

1279+
1280+
Code Completion
1281+
---------------
1282+
1283+
- Use ``HeuristicResolver`` (upstreamed from clangd) to improve code completion results
1284+
in dependent code
1285+
12571286
Static Analyzer
12581287
---------------
12591288

clang/docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Using Clang as a Compiler
4040
SanitizerStats
4141
SanitizerSpecialCaseList
4242
BoundsSafety
43+
BoundsSafetyAdoptionGuide
4344
BoundsSafetyImplPlans
4445
ControlFlowIntegrity
4546
LTOVisibility

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ class ASTNodeTraverser
158158
ConstStmtVisitor<Derived>::Visit(S);
159159

160160
// Some statements have custom mechanisms for dumping their children.
161-
if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S) ||
162-
isa<RequiresExpr>(S) || isa<OpenACCWaitConstruct>(S))
161+
if (isa<DeclStmt, GenericSelectionExpr, RequiresExpr,
162+
OpenACCWaitConstruct, SYCLKernelCallStmt>(S))
163163
return;
164164

165165
if (Traversal == TK_IgnoreUnlessSpelledInSource &&
@@ -585,6 +585,12 @@ class ASTNodeTraverser
585585

586586
void VisitTopLevelStmtDecl(const TopLevelStmtDecl *D) { Visit(D->getStmt()); }
587587

588+
void VisitOutlinedFunctionDecl(const OutlinedFunctionDecl *D) {
589+
for (const ImplicitParamDecl *Parameter : D->parameters())
590+
Visit(Parameter);
591+
Visit(D->getBody());
592+
}
593+
588594
void VisitCapturedDecl(const CapturedDecl *D) { Visit(D->getBody()); }
589595

590596
void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
@@ -815,6 +821,12 @@ class ASTNodeTraverser
815821
Visit(Node->getCapturedDecl());
816822
}
817823

824+
void VisitSYCLKernelCallStmt(const SYCLKernelCallStmt *Node) {
825+
Visit(Node->getOriginalStmt());
826+
if (Traversal != TK_IgnoreUnlessSpelledInSource)
827+
Visit(Node->getOutlinedFunctionDecl());
828+
}
829+
818830
void VisitOMPExecutableDirective(const OMPExecutableDirective *Node) {
819831
for (const auto *C : Node->clauses())
820832
Visit(C);

clang/include/clang/AST/Attr.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ class Attr : public AttributeCommonInfo {
6060
unsigned IsLateParsed : 1;
6161
LLVM_PREFERRED_TYPE(bool)
6262
unsigned InheritEvenIfAlreadyPresent : 1;
63-
LLVM_PREFERRED_TYPE(bool)
64-
unsigned DeferDeserialization : 1;
6563

6664
void *operator new(size_t bytes) noexcept {
6765
llvm_unreachable("Attrs cannot be allocated with regular 'new'.");
@@ -82,11 +80,10 @@ class Attr : public AttributeCommonInfo {
8280

8381
protected:
8482
Attr(ASTContext &Context, const AttributeCommonInfo &CommonInfo,
85-
attr::Kind AK, bool IsLateParsed, bool DeferDeserialization = false)
83+
attr::Kind AK, bool IsLateParsed)
8684
: AttributeCommonInfo(CommonInfo), AttrKind(AK), Inherited(false),
8785
IsPackExpansion(false), Implicit(false), IsLateParsed(IsLateParsed),
88-
InheritEvenIfAlreadyPresent(false),
89-
DeferDeserialization(DeferDeserialization) {}
86+
InheritEvenIfAlreadyPresent(false) {}
9087

9188
public:
9289
attr::Kind getKind() const { return static_cast<attr::Kind>(AttrKind); }
@@ -108,8 +105,6 @@ class Attr : public AttributeCommonInfo {
108105
void setPackExpansion(bool PE) { IsPackExpansion = PE; }
109106
bool isPackExpansion() const { return IsPackExpansion; }
110107

111-
bool shouldDeferDeserialization() const { return DeferDeserialization; }
112-
113108
// Clone this attribute.
114109
Attr *clone(ASTContext &C) const;
115110

@@ -151,9 +146,8 @@ class InheritableAttr : public Attr {
151146
protected:
152147
InheritableAttr(ASTContext &Context, const AttributeCommonInfo &CommonInfo,
153148
attr::Kind AK, bool IsLateParsed,
154-
bool InheritEvenIfAlreadyPresent,
155-
bool DeferDeserialization = false)
156-
: Attr(Context, CommonInfo, AK, IsLateParsed, DeferDeserialization) {
149+
bool InheritEvenIfAlreadyPresent)
150+
: Attr(Context, CommonInfo, AK, IsLateParsed) {
157151
this->InheritEvenIfAlreadyPresent = InheritEvenIfAlreadyPresent;
158152
}
159153

0 commit comments

Comments
 (0)