Skip to content

Commit e11da05

Browse files
committed
rebase
Created using spr 1.3.4
2 parents 50ab70c + 6a97897 commit e11da05

File tree

741 files changed

+45217
-30211
lines changed

Some content is hidden

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

741 files changed

+45217
-30211
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: 30 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>`_).
@@ -971,6 +974,9 @@ 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)
978+
- Fixed assertions or false compiler diagnostics in the case of C++ modules for
979+
lambda functions or inline friend functions defined inside templates (#GH122493).
974980

975981
Bug Fixes to AST Handling
976982
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1131,6 +1137,20 @@ Windows Support
11311137
LoongArch Support
11321138
^^^^^^^^^^^^^^^^^
11331139

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

@@ -1254,6 +1274,13 @@ libclang
12541274
- Added ``clang_getOffsetOfBase``, which allows computing the offset of a base
12551275
class in a class's layout.
12561276

1277+
1278+
Code Completion
1279+
---------------
1280+
1281+
- Use ``HeuristicResolver`` (upstreamed from clangd) to improve code completion results
1282+
in dependent code
1283+
12571284
Static Analyzer
12581285
---------------
12591286

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,

0 commit comments

Comments
 (0)