Skip to content

Commit d21dbbb

Browse files
committed
[AutoBump] Merge with 08195f3 (Jan 23)
2 parents a28ff29 + 08195f3 commit d21dbbb

File tree

337 files changed

+18372
-6700
lines changed

Some content is hidden

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

337 files changed

+18372
-6700
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/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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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>`_).
@@ -971,6 +974,7 @@ Bug Fixes to C++ Support
971974
- Fixed canonicalization of pack indexing types - Clang did not always recognized identical pack indexing. (#GH123033)
972975
- Fixed a nested lambda substitution issue for constraint evaluation. (#GH123441)
973976
- Fixed various false diagnostics related to the use of immediate functions. (#GH123472)
977+
- Fix immediate escalation not propagating through inherited constructors. (#GH112677)
974978

975979
Bug Fixes to AST Handling
976980
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1131,6 +1135,20 @@ Windows Support
11311135
LoongArch Support
11321136
^^^^^^^^^^^^^^^^^
11331137

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

@@ -1254,6 +1272,13 @@ libclang
12541272
- Added ``clang_getOffsetOfBase``, which allows computing the offset of a base
12551273
class in a class's layout.
12561274

1275+
1276+
Code Completion
1277+
---------------
1278+
1279+
- Use ``HeuristicResolver`` (upstreamed from clangd) to improve code completion results
1280+
in dependent code
1281+
12571282
Static Analyzer
12581283
---------------
12591284

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/Decl.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4688,6 +4688,83 @@ class BlockDecl : public Decl, public DeclContext {
46884688
}
46894689
};
46904690

4691+
/// Represents a partial function definition.
4692+
///
4693+
/// An outlined function declaration contains the parameters and body of
4694+
/// a function independent of other function definition concerns such
4695+
/// as function name, type, and calling convention. Such declarations may
4696+
/// be used to hold a parameterized and transformed sequence of statements
4697+
/// used to generate a target dependent function definition without losing
4698+
/// association with the original statements. See SYCLKernelCallStmt as an
4699+
/// example.
4700+
class OutlinedFunctionDecl final
4701+
: public Decl,
4702+
public DeclContext,
4703+
private llvm::TrailingObjects<OutlinedFunctionDecl, ImplicitParamDecl *> {
4704+
private:
4705+
/// The number of parameters to the outlined function.
4706+
unsigned NumParams;
4707+
4708+
/// The body of the outlined function.
4709+
llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4710+
4711+
explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);
4712+
4713+
ImplicitParamDecl *const *getParams() const {
4714+
return getTrailingObjects<ImplicitParamDecl *>();
4715+
}
4716+
4717+
ImplicitParamDecl **getParams() {
4718+
return getTrailingObjects<ImplicitParamDecl *>();
4719+
}
4720+
4721+
public:
4722+
friend class ASTDeclReader;
4723+
friend class ASTDeclWriter;
4724+
friend TrailingObjects;
4725+
4726+
static OutlinedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
4727+
unsigned NumParams);
4728+
static OutlinedFunctionDecl *
4729+
CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams);
4730+
4731+
Stmt *getBody() const override;
4732+
void setBody(Stmt *B);
4733+
4734+
bool isNothrow() const;
4735+
void setNothrow(bool Nothrow = true);
4736+
4737+
unsigned getNumParams() const { return NumParams; }
4738+
4739+
ImplicitParamDecl *getParam(unsigned i) const {
4740+
assert(i < NumParams);
4741+
return getParams()[i];
4742+
}
4743+
void setParam(unsigned i, ImplicitParamDecl *P) {
4744+
assert(i < NumParams);
4745+
getParams()[i] = P;
4746+
}
4747+
4748+
// Range interface to parameters.
4749+
using parameter_const_iterator = const ImplicitParamDecl *const *;
4750+
using parameter_const_range = llvm::iterator_range<parameter_const_iterator>;
4751+
parameter_const_range parameters() const {
4752+
return {param_begin(), param_end()};
4753+
}
4754+
parameter_const_iterator param_begin() const { return getParams(); }
4755+
parameter_const_iterator param_end() const { return getParams() + NumParams; }
4756+
4757+
// Implement isa/cast/dyncast/etc.
4758+
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4759+
static bool classofKind(Kind K) { return K == OutlinedFunction; }
4760+
static DeclContext *castToDeclContext(const OutlinedFunctionDecl *D) {
4761+
return static_cast<DeclContext *>(const_cast<OutlinedFunctionDecl *>(D));
4762+
}
4763+
static OutlinedFunctionDecl *castFromDeclContext(const DeclContext *DC) {
4764+
return static_cast<OutlinedFunctionDecl *>(const_cast<DeclContext *>(DC));
4765+
}
4766+
};
4767+
46914768
/// Represents the body of a CapturedStmt, and serves as its DeclContext.
46924769
class CapturedDecl final
46934770
: public Decl,

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "clang/AST/StmtObjC.h"
3838
#include "clang/AST/StmtOpenACC.h"
3939
#include "clang/AST/StmtOpenMP.h"
40+
#include "clang/AST/StmtSYCL.h"
4041
#include "clang/AST/TemplateBase.h"
4142
#include "clang/AST/TemplateName.h"
4243
#include "clang/AST/Type.h"
@@ -1581,6 +1582,11 @@ DEF_TRAVERSE_DECL(BlockDecl, {
15811582
ShouldVisitChildren = false;
15821583
})
15831584

1585+
DEF_TRAVERSE_DECL(OutlinedFunctionDecl, {
1586+
TRY_TO(TraverseStmt(D->getBody()));
1587+
ShouldVisitChildren = false;
1588+
})
1589+
15841590
DEF_TRAVERSE_DECL(CapturedDecl, {
15851591
TRY_TO(TraverseStmt(D->getBody()));
15861592
ShouldVisitChildren = false;
@@ -2904,6 +2910,14 @@ DEF_TRAVERSE_STMT(SEHFinallyStmt, {})
29042910
DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
29052911
DEF_TRAVERSE_STMT(CapturedStmt, { TRY_TO(TraverseDecl(S->getCapturedDecl())); })
29062912

2913+
DEF_TRAVERSE_STMT(SYCLKernelCallStmt, {
2914+
if (getDerived().shouldVisitImplicitCode()) {
2915+
TRY_TO(TraverseStmt(S->getOriginalStmt()));
2916+
TRY_TO(TraverseDecl(S->getOutlinedFunctionDecl()));
2917+
ShouldVisitChildren = false;
2918+
}
2919+
})
2920+
29072921
DEF_TRAVERSE_STMT(CXXOperatorCallExpr, {})
29082922
DEF_TRAVERSE_STMT(CXXRewrittenBinaryOperator, {
29092923
if (!getDerived().shouldVisitImplicitCode()) {

0 commit comments

Comments
 (0)