Skip to content

Commit

Permalink
Merge branch 'main' into cmake_cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari authored Jun 21, 2024
2 parents b0dd6d6 + 5d6d2fc commit 5604e76
Show file tree
Hide file tree
Showing 1,209 changed files with 34,299 additions and 19,246 deletions.
1 change: 1 addition & 0 deletions bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <functional>
#include <limits>
#include <numeric>
#include <stack>
#include <string>

#define DEBUG_TYPE "bolt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "RedundantStrcatCallsCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include <deque>

using namespace clang::ast_matchers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "clang/Lex/MacroArgs.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
#include <stack>

namespace clang::tidy::bugprone {

Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <deque>
#include <mutex>
#include <optional>
#include <string>
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/Selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "clang/AST/PrettyPrinter.h"
#include "clang/Tooling/Syntax/Tokens.h"
#include "llvm/ADT/SmallVector.h"
#include <stack>

namespace clang {
namespace clangd {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/unittests/ASTTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
namespace std
{
template<class _E>
class [[initializer_list]] {};
class [[initializer_list]] { const _E *a, *b; };
}
^auto i = {1,2};
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/unittests/HoverTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,7 @@ TEST(Hover, All) {
namespace std
{
template<class _E>
class initializer_list {};
class initializer_list { const _E *a, *b; };
}
void foo() {
^[[auto]] i = {1,2};
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/unittests/InlayHintTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ TEST(ParameterHints, ConstructorStdInitList) {
// Do not show hints for std::initializer_list constructors.
assertParameterHints(R"cpp(
namespace std {
template <typename> class initializer_list {};
template <typename E> class initializer_list { const E *a, *b; };
}
struct S {
S(std::initializer_list<int> param);
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/unittests/XRefsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ TEST(LocateSymbol, All) {
namespace std
{
template<class _E>
class [[initializer_list]] {};
class [[initializer_list]] { const _E *a, *b; };
}
^auto i = {1,2};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ TEST(WalkAST, Enums) {
TEST(WalkAST, InitializerList) {
testWalk(R"cpp(
namespace std {
template <typename T> struct $implicit^initializer_list {};
template <typename T> struct $implicit^initializer_list { const T *a, *b; };
})cpp",
R"cpp(
const char* s = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ T max(T a, T b) {
namespace std {
template< class T >
struct initializer_list {
const T *a, *b;
initializer_list()=default;
initializer_list(T*,int){}
const T* begin() const {return nullptr;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
// RUN: true}}"

namespace std {
template <typename>
template <typename E>
class initializer_list
{
public:
const E *a, *b;
initializer_list() noexcept {}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
// RUN: '::std::make_pair; ::std::make_tuple; ::test::MakeSingle'}}"

namespace std {
template <typename>
template <typename E>
class initializer_list {
public:
const E *a, *b;
initializer_list() noexcept {}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace std {

typedef int size_t;
typedef decltype(sizeof 0) size_t;

template<class E> class initializer_list {
public:
Expand All @@ -15,6 +15,8 @@ template<class E> class initializer_list {
using size_type = size_t;
using iterator = const E*;
using const_iterator = const E*;
iterator p;
size_t sz;
initializer_list();
size_t size() const; // number of elements
const E* begin() const; // first element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct SomeClass {

namespace std {
template <typename T>
class initializer_list {};
class initializer_list { const T *a, *b; };

template <typename T>
class vector {
Expand Down
9 changes: 9 additions & 0 deletions clang-tools-extra/test/pp-trace/pp-trace-macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ X
// CHECK: MacroNameTok: __STDC_UTF_32__
// CHECK-NEXT: MacroDirective: MD_Define
// CHECK: - Callback: MacroDefined
// CHECK-NEXT: MacroNameTok: __STDC_EMBED_NOT_FOUND__
// CHECK-NEXT: MacroDirective: MD_Define
// CHECK: - Callback: MacroDefined
// CHECK-NEXT: MacroNameTok: __STDC_EMBED_FOUND__
// CHECK-NEXT: MacroDirective: MD_Define
// CHECK: - Callback: MacroDefined
// CHECK-NEXT: MacroNameTok: __STDC_EMBED_EMPTY__
// CHECK-NEXT: MacroDirective: MD_Define
// CHECK: - Callback: MacroDefined
// CHECK: - Callback: MacroDefined
// CHECK-NEXT: MacroNameTok: MACRO
// CHECK-NEXT: MacroDirective: MD_Define
Expand Down
7 changes: 4 additions & 3 deletions clang/docs/BoundsSafety.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
Overview
========

**NOTE:** This is a design document and the feature is not available for users yet.
Please see :doc:`BoundsSafetyImplPlans` for more details.

``-fbounds-safety`` is a C extension to enforce bounds safety to prevent
out-of-bounds (OOB) memory accesses, which remain a major source of security
vulnerabilities in C. ``-fbounds-safety`` aims to eliminate this class of bugs
Expand Down Expand Up @@ -55,9 +58,7 @@ adopt, offering these properties that make it widely adoptable in practice:
* It has a relatively low adoption cost.

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

subject to be actively updated with a more detailed specification.

Programming Model
=================
Expand Down
65 changes: 32 additions & 33 deletions clang/docs/BoundsSafetyImplPlans.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,39 @@ Implementation plans for ``-fbounds-safety``
.. contents::
:local:

Gradual updates with experimental flag
======================================

The feature will be implemented as a series of smaller PRs and we will guard our
implementation with an experimental flag ``-fexperimental-bounds-safety`` until
the usable model is fully available. Once the model is ready for use, we will
expose the flag ``-fbounds-safety``.

Possible patch sets
-------------------

* External bounds annotations and the (late) parsing logic.
* Internal bounds annotations (wide pointers) and their parsing logic.
* Clang code generation for wide pointers with debug information.
* Pointer cast semantics involving bounds annotations (this could be divided
into multiple sub-PRs).
* CFG analysis for pairs of related pointer and count assignments and the likes.
* Bounds check expressions in AST and the Clang code generation (this could also
be divided into multiple sub-PRs).

Proposed implementation
=======================

External bounds annotations
===========================
---------------------------

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

New sugar types
===============
---------------

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

Late parsing for C
==================
------------------

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

Internal bounds annotations
===========================
---------------------------

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

Default bounds annotations
==========================
--------------------------

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

Promotion expression
====================
--------------------

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

Bounds check expression
=======================
-----------------------

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

Paired assignment check
=======================
-----------------------

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

Bounds check optimizations
==========================
--------------------------

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

``-fbounds-safety`` is not currently supported in C++, but we believe the
general approach would be applicable for future efforts.

Upstreaming plan
================

Gradual updates with experimental flag
--------------------------------------

The upstreaming will take place as a series of smaller PRs and we will guard our
implementation with an experimental flag ``-fexperimental-bounds-safety`` until
the usable model is fully upstreamed. Once the model is ready for use, we will
expose the flag ``-fbounds-safety``.

Possible patch sets
-------------------

* External bounds annotations and the (late) parsing logic.
* Internal bounds annotations (wide pointers) and their parsing logic.
* Clang code generation for wide pointers with debug information.
* Pointer cast semantics involving bounds annotations (this could be divided
into multiple sub-PRs).
* CFG analysis for pairs of related pointer and count assignments and the likes.
* Bounds check expressions in AST and the Clang code generation (this could also
be divided into multiple sub-PRs).

24 changes: 24 additions & 0 deletions clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ Attributes on Structured Bindings __cpp_structured_bindings C+
Designated initializers (N494) C99 C89
Array & element qualification (N2607) C23 C89
Attributes (N2335) C23 C89
``#embed`` (N3017) C23 C89, C++
============================================ ================================ ============= =============

Type Trait Primitives
Expand Down Expand Up @@ -5664,3 +5665,26 @@ Compiling different TUs depending on these flags (including use of
``std::hardware_destructive_interference``) with different compilers, macro
definitions, or architecture flags will lead to ODR violations and should be
avoided.

``#embed`` Parameters
=====================

``clang::offset``
-----------------
The ``clang::offset`` embed parameter may appear zero or one time in the
embed parameter sequence. Its preprocessor argument clause shall be present and
have the form:

..code-block: text

( constant-expression )

and shall be an integer constant expression. The integer constant expression
shall not evaluate to a value less than 0. The token ``defined`` shall not
appear within the constant expression.

The offset will be used when reading the contents of the embedded resource to
specify the starting offset to begin embedding from. The resources is treated
as being empty if the specified offset is larger than the number of bytes in
the resource. The offset will be applied *before* any ``limit`` parameters are
applied.
36 changes: 36 additions & 0 deletions clang/docs/PointerAuthentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,23 @@ be done in a single instruction with an immediate integer.
``pointer`` must have pointer type, and ``integer`` must have integer type. The
result has type ``ptrauth_extra_data_t``.

``ptrauth_string_discriminator``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: c
ptrauth_string_discriminator(string)
Compute a constant discriminator from the given string.

``string`` must be a string literal of ``char`` character type. The result has
type ``ptrauth_extra_data_t``.

The result value is never zero and always within range for both the
``__ptrauth`` qualifier and ``ptrauth_blend_discriminator``.

This can be used in constant expressions.

``ptrauth_strip``
^^^^^^^^^^^^^^^^^

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

``ptrauth_sign_constant``
^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: c
ptrauth_sign_constant(pointer, key, discriminator)
Return a signed pointer for a constant address in a manner which guarantees
a non-attackable sequence.

``pointer`` must be a constant expression of pointer type which evaluates to
a non-null pointer.
``key`` must be a constant expression of type ``ptrauth_key``.
``discriminator`` must be a constant expression of pointer or integer type;
if an integer, it will be coerced to ``ptrauth_extra_data_t``.
The result will have the same type as ``pointer``.

This can be used in constant expressions.

``ptrauth_sign_unauthenticated``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Loading

0 comments on commit 5604e76

Please sign in to comment.