Skip to content

Commit d83a968

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/96043
2 parents c982465 + 39048b6 commit d83a968

File tree

1,010 files changed

+29315
-17786
lines changed

Some content is hidden

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

1,010 files changed

+29315
-17786
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <functional>
4646
#include <limits>
4747
#include <numeric>
48+
#include <stack>
4849
#include <string>
4950

5051
#define DEBUG_TYPE "bolt"

clang-tools-extra/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "RedundantStrcatCallsCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include <deque>
1213

1314
using namespace clang::ast_matchers;
1415

clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "clang/Lex/MacroArgs.h"
1313
#include "clang/Lex/PPCallbacks.h"
1414
#include "clang/Lex/Preprocessor.h"
15+
#include <stack>
1516

1617
namespace clang::tidy::bugprone {
1718

clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <atomic>
3131
#include <chrono>
3232
#include <condition_variable>
33+
#include <deque>
3334
#include <mutex>
3435
#include <optional>
3536
#include <string>

clang-tools-extra/clangd/Selection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "clang/AST/PrettyPrinter.h"
4646
#include "clang/Tooling/Syntax/Tokens.h"
4747
#include "llvm/ADT/SmallVector.h"
48+
#include <stack>
4849

4950
namespace clang {
5051
namespace clangd {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
8080
namespace std
8181
{
8282
template<class _E>
83-
class [[initializer_list]] {};
83+
class [[initializer_list]] { const _E *a, *b; };
8484
}
8585
8686
^auto i = {1,2};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2284,7 +2284,7 @@ TEST(Hover, All) {
22842284
namespace std
22852285
{
22862286
template<class _E>
2287-
class initializer_list {};
2287+
class initializer_list { const _E *a, *b; };
22882288
}
22892289
void foo() {
22902290
^[[auto]] i = {1,2};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ TEST(ParameterHints, ConstructorStdInitList) {
945945
// Do not show hints for std::initializer_list constructors.
946946
assertParameterHints(R"cpp(
947947
namespace std {
948-
template <typename> class initializer_list {};
948+
template <typename E> class initializer_list { const E *a, *b; };
949949
}
950950
struct S {
951951
S(std::initializer_list<int> param);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ TEST(LocateSymbol, All) {
771771
namespace std
772772
{
773773
template<class _E>
774-
class [[initializer_list]] {};
774+
class [[initializer_list]] { const _E *a, *b; };
775775
}
776776
777777
^auto i = {1,2};

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ TEST(WalkAST, Enums) {
534534
TEST(WalkAST, InitializerList) {
535535
testWalk(R"cpp(
536536
namespace std {
537-
template <typename T> struct $implicit^initializer_list {};
537+
template <typename T> struct $implicit^initializer_list { const T *a, *b; };
538538
})cpp",
539539
R"cpp(
540540
const char* s = "";

clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ T max(T a, T b) {
1111
namespace std {
1212
template< class T >
1313
struct initializer_list {
14+
const T *a, *b;
1415
initializer_list()=default;
1516
initializer_list(T*,int){}
1617
const T* begin() const {return nullptr;}

clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace-ignore-implicit-constructors.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
// RUN: true}}"
55

66
namespace std {
7-
template <typename>
7+
template <typename E>
88
class initializer_list
99
{
1010
public:
11+
const E *a, *b;
1112
initializer_list() noexcept {}
1213
};
1314

clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
// RUN: '::std::make_pair; ::std::make_tuple; ::test::MakeSingle'}}"
99

1010
namespace std {
11-
template <typename>
11+
template <typename E>
1212
class initializer_list {
1313
public:
14+
const E *a, *b;
1415
initializer_list() noexcept {}
1516
};
1617

clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-vector-operation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace std {
77

8-
typedef int size_t;
8+
typedef decltype(sizeof 0) size_t;
99

1010
template<class E> class initializer_list {
1111
public:
@@ -15,6 +15,8 @@ template<class E> class initializer_list {
1515
using size_type = size_t;
1616
using iterator = const E*;
1717
using const_iterator = const E*;
18+
iterator p;
19+
size_t sz;
1820
initializer_list();
1921
size_t size() const; // number of elements
2022
const E* begin() const; // first element

clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration-cxx17.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct SomeClass {
3131

3232
namespace std {
3333
template <typename T>
34-
class initializer_list {};
34+
class initializer_list { const T *a, *b; };
3535

3636
template <typename T>
3737
class vector {

clang/docs/BoundsSafety.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
Overview
99
========
1010

11+
**NOTE:** This is a design document and the feature is not available for users yet.
12+
Please see :doc:`BoundsSafetyImplPlans` for more details.
13+
1114
``-fbounds-safety`` is a C extension to enforce bounds safety to prevent
1215
out-of-bounds (OOB) memory accesses, which remain a major source of security
1316
vulnerabilities in C. ``-fbounds-safety`` aims to eliminate this class of bugs
@@ -55,9 +58,7 @@ adopt, offering these properties that make it widely adoptable in practice:
5558
* It has a relatively low adoption cost.
5659

5760
This document discusses the key designs of ``-fbounds-safety``. The document is
58-
subject to be actively updated with a more detailed specification. The
59-
implementation plan can be found in :doc:`BoundsSafetyImplPlans`.
60-
61+
subject to be actively updated with a more detailed specification.
6162

6263
Programming Model
6364
=================

clang/docs/BoundsSafetyImplPlans.rst

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,39 @@ Implementation plans for ``-fbounds-safety``
55
.. contents::
66
:local:
77

8+
Gradual updates with experimental flag
9+
======================================
10+
11+
The feature will be implemented as a series of smaller PRs and we will guard our
12+
implementation with an experimental flag ``-fexperimental-bounds-safety`` until
13+
the usable model is fully available. Once the model is ready for use, we will
14+
expose the flag ``-fbounds-safety``.
15+
16+
Possible patch sets
17+
-------------------
18+
19+
* External bounds annotations and the (late) parsing logic.
20+
* Internal bounds annotations (wide pointers) and their parsing logic.
21+
* Clang code generation for wide pointers with debug information.
22+
* Pointer cast semantics involving bounds annotations (this could be divided
23+
into multiple sub-PRs).
24+
* CFG analysis for pairs of related pointer and count assignments and the likes.
25+
* Bounds check expressions in AST and the Clang code generation (this could also
26+
be divided into multiple sub-PRs).
27+
28+
Proposed implementation
29+
=======================
30+
831
External bounds annotations
9-
===========================
32+
---------------------------
1033

1134
The bounds annotations are C type attributes appertaining to pointer types. If
1235
an attribute is added to the position of a declaration attribute, e.g., ``int
1336
*ptr __counted_by(size)``, the attribute appertains to the outermost pointer
1437
type of the declaration (``int *``).
1538

1639
New sugar types
17-
===============
40+
---------------
1841

1942
An external bounds annotation creates a type sugar of the underlying pointer
2043
types. We will introduce a new sugar type, ``DynamicBoundsPointerType`` to
@@ -29,7 +52,7 @@ overloading. However, this design requires a separate logic to walk through the
2952
entire type hierarchy to check type compatibility of bounds annotations.
3053

3154
Late parsing for C
32-
==================
55+
------------------
3356

3457
A bounds annotation such as ``__counted_by(count)`` can be added to type of a
3558
struct field declaration where count is another field of the same struct
@@ -43,7 +66,7 @@ same logic. This requires introducing late parsing logic for C/C++ type
4366
attributes.
4467

4568
Internal bounds annotations
46-
===========================
69+
---------------------------
4770

4871
``__indexable`` and ``__bidi_indexable`` alter pointer representations to be
4972
equivalent to a struct with the pointer and the corresponding bounds fields.
@@ -65,7 +88,7 @@ operations returning wide pointers. Alternatively, a new ``TEK`` and an
6588
expression emitter dedicated to wide pointers could be introduced.
6689

6790
Default bounds annotations
68-
==========================
91+
--------------------------
6992

7093
The model may implicitly add ``__bidi_indexable`` or ``__single`` depending on
7194
the context of the declaration that has the pointer type. ``__bidi_indexable``
@@ -79,7 +102,7 @@ This also requires the parser to reset the type of the declaration with the
79102
newly created type with the right default attribute.
80103

81104
Promotion expression
82-
====================
105+
--------------------
83106

84107
A new expression will be introduced to represent the conversion from a pointer
85108
with an external bounds annotation, such as ``__counted_by``, to
@@ -88,7 +111,7 @@ CastExprs because it requires an extra subexpression(s) to provide the bounds
88111
information necessary to create a wide pointer.
89112

90113
Bounds check expression
91-
=======================
114+
-----------------------
92115

93116
Bounds checks are part of semantics defined in the ``-fbounds-safety`` language
94117
model. Hence, exposing the bounds checks and other semantic actions in the AST
@@ -98,7 +121,7 @@ and has the additional sub-expressions that are necessary to perform the check
98121
according to the kind.
99122

100123
Paired assignment check
101-
=======================
124+
-----------------------
102125

103126
``-fbounds-safety`` enforces that variables or fields related with the same
104127
external bounds annotation (e.g., ``buf`` and ``count`` related with
@@ -123,7 +146,7 @@ provides a linear view of statements within each ``CFGBlock`` (Clang
123146
``CFGBlock`` represents a single basic block in a source-level CFG).
124147

125148
Bounds check optimizations
126-
==========================
149+
--------------------------
127150

128151
In ``-fbounds-safety``, the Clang frontend emits run-time checks for every
129152
memory dereference if the type system or analyses in the frontend couldn’t
@@ -229,27 +252,3 @@ solution.
229252

230253
``-fbounds-safety`` is not currently supported in C++, but we believe the
231254
general approach would be applicable for future efforts.
232-
233-
Upstreaming plan
234-
================
235-
236-
Gradual updates with experimental flag
237-
--------------------------------------
238-
239-
The upstreaming will take place as a series of smaller PRs and we will guard our
240-
implementation with an experimental flag ``-fexperimental-bounds-safety`` until
241-
the usable model is fully upstreamed. Once the model is ready for use, we will
242-
expose the flag ``-fbounds-safety``.
243-
244-
Possible patch sets
245-
-------------------
246-
247-
* External bounds annotations and the (late) parsing logic.
248-
* Internal bounds annotations (wide pointers) and their parsing logic.
249-
* Clang code generation for wide pointers with debug information.
250-
* Pointer cast semantics involving bounds annotations (this could be divided
251-
into multiple sub-PRs).
252-
* CFG analysis for pairs of related pointer and count assignments and the likes.
253-
* Bounds check expressions in AST and the Clang code generation (this could also
254-
be divided into multiple sub-PRs).
255-

clang/docs/PointerAuthentication.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,23 @@ be done in a single instruction with an immediate integer.
328328
``pointer`` must have pointer type, and ``integer`` must have integer type. The
329329
result has type ``ptrauth_extra_data_t``.
330330

331+
``ptrauth_string_discriminator``
332+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
333+
334+
.. code-block:: c
335+
336+
ptrauth_string_discriminator(string)
337+
338+
Compute a constant discriminator from the given string.
339+
340+
``string`` must be a string literal of ``char`` character type. The result has
341+
type ``ptrauth_extra_data_t``.
342+
343+
The result value is never zero and always within range for both the
344+
``__ptrauth`` qualifier and ``ptrauth_blend_discriminator``.
345+
346+
This can be used in constant expressions.
347+
331348
``ptrauth_strip``
332349
^^^^^^^^^^^^^^^^^
333350

@@ -339,6 +356,25 @@ Given that ``signedPointer`` matches the layout for signed pointers signed with
339356
the given key, extract the raw pointer from it. This operation does not trap
340357
and cannot fail, even if the pointer is not validly signed.
341358

359+
``ptrauth_sign_constant``
360+
^^^^^^^^^^^^^^^^^^^^^^^^^
361+
362+
.. code-block:: c
363+
364+
ptrauth_sign_constant(pointer, key, discriminator)
365+
366+
Return a signed pointer for a constant address in a manner which guarantees
367+
a non-attackable sequence.
368+
369+
``pointer`` must be a constant expression of pointer type which evaluates to
370+
a non-null pointer.
371+
``key`` must be a constant expression of type ``ptrauth_key``.
372+
``discriminator`` must be a constant expression of pointer or integer type;
373+
if an integer, it will be coerced to ``ptrauth_extra_data_t``.
374+
The result will have the same type as ``pointer``.
375+
376+
This can be used in constant expressions.
377+
342378
``ptrauth_sign_unauthenticated``
343379
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
344380

0 commit comments

Comments
 (0)