Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
thetruestblue authored Jan 23, 2025
2 parents 576a920 + 7a831eb commit 2154683
Show file tree
Hide file tree
Showing 903 changed files with 47,751 additions and 31,585 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
prepare:
name: Prepare to build binaries
runs-on: ${{ inputs.runs-on }}
if: github.repository == 'llvm/llvm-project'
if: github.repository_owner == 'llvm'
outputs:
release-version: ${{ steps.vars.outputs.release-version }}
ref: ${{ steps.vars.outputs.ref }}
Expand Down Expand Up @@ -177,7 +177,7 @@ jobs:
build-release-package:
name: "Build Release Package"
needs: prepare
if: github.repository == 'llvm/llvm-project'
if: github.repository_owner == 'llvm'
runs-on: ${{ needs.prepare.outputs.build-runs-on }}
steps:

Expand Down Expand Up @@ -327,7 +327,7 @@ jobs:
- prepare
- build-release-package
if: >-
github.repository == 'llvm/llvm-project'
github.repository_owner == 'llvm'
runs-on: ${{ needs.prepare.outputs.test-runs-on }}
steps:
- name: Checkout Actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Lex/Lexer.h"

using namespace clang::ast_matchers;
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/modularize/CoverageChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ CoverageChecker::collectUmbrellaHeaderHeaders(StringRef UmbrellaHeaderName) {
sys::fs::current_path(PathBuf);

// Create the compilation database.
std::unique_ptr<CompilationDatabase> Compilations;
Compilations.reset(new FixedCompilationDatabase(Twine(PathBuf), CommandLine));
FixedCompilationDatabase Compilations(Twine(PathBuf), CommandLine);

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

// Create the tool and run the compilation.
ClangTool Tool(*Compilations, HeaderPath);
int HadErrors = Tool.run(new CoverageCheckerFrontendActionFactory(*this));
ClangTool Tool(Compilations, HeaderPath);
CoverageCheckerFrontendActionFactory ActionFactory(*this);
int HadErrors = Tool.run(&ActionFactory);

// If we had errors, exit early.
return !HadErrors;
Expand Down
9 changes: 8 additions & 1 deletion clang/docs/BoundsSafety.rst
Original file line number Diff line number Diff line change
Expand Up @@ -996,4 +996,11 @@ and the soundness of the type system. This may incur significant code size
overhead in unoptimized builds and leaving some of the adoption mistakes to be
caught only at run time. This is not a fundamental limitation, however, because
incrementally adding necessary static analysis will allow us to catch issues
early on and remove unnecessary bounds checks in unoptimized builds.
early on and remove unnecessary bounds checks in unoptimized builds.

Try it out
==========

Your feedback on the programming model is valuable. You may want to follow the
instruction in :doc:`BoundsSafetyAdoptionGuide` to play with ``-fbounds-safety``
and please send your feedback to `Yeoul Na <mailto:[email protected]>`_.
90 changes: 90 additions & 0 deletions clang/docs/BoundsSafetyAdoptionGuide.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
======================================
Adoption Guide for ``-fbounds-safety``
======================================

.. contents::
:local:

Where to get ``-fbounds-safety``
================================

The open sourcing to llvm.org's ``llvm-project`` is still on going and the
feature is not available yet. In the mean time, the preview implementation is
available
`here <https://github.com/swiftlang/llvm-project/tree/stable/20240723>`_ in a
fork of ``llvm-project``. Please follow
`Building LLVM with CMake <https://llvm.org/docs/CMake.html>`_ to build the
compiler.

Feature flag
============

Pass ``-fbounds-safety`` as a Clang compilation flag for the C file that you
want to adopt. We recommend adopting the model file by file, because adoption
requires some effort to add bounds annotations and fix compiler diagnostics.

Include ``ptrcheck.h``
======================

``ptrcheck.h`` is a Clang toolchain header to provide definition of the bounds
annotations such as ``__counted_by``, ``__counted_by_or_null``, ``__sized_by``,
etc. In the LLVM source tree, the header is located in
``llvm-project/clang/lib/Headers/ptrcheck.h``.


Add bounds annotations on pointers as necessary
===============================================

Annotate pointers on struct fields and function parameters if they are pointing
to an array of object, with appropriate bounds annotations. Please see
:doc:`BoundsSafety` to learn what kind of bounds annotations are available and
their semantics. Note that local pointer variables typically don't need bounds
annotations because they are implicitely a wide pointer (``__bidi_indexable``)
that automatically carries the bounds information.

Address compiler diagnostics
============================

Once you pass ``-fbounds-safety`` to compiler a C file, you will see some new
compiler warnings and errors, which guide adoption of ``-fbounds-safety``.
Consider the following example:

.. code-block:: c
#include <ptrcheck.h>
void init_buf(int *p, int n) {
for (int i = 0; i < n; ++i)
p[i] = 0; // error: array subscript on single pointer 'p' must use a constant index of 0 to be in bounds
}
The parameter ``int *p`` doesn't have a bounds annotation, so the compiler will
complain about the code indexing into it (``p[i]``) as it assumes that ``p`` is
pointing to a single ``int`` object or null. To address the diagnostics, you
should add a bounds annotation on ``int *p`` so that the compiler can reason
about the safety of the array subscript. In the following example, ``p`` is now
``int *__counted_by(n)``, so the compiler will allow the array subscript with
additional run-time checks as necessary.

.. code-block:: c
#include <ptrcheck.h>
void init_buf(int *__counted_by(n) p, int n) {
for (int i = 0; i < n; ++i)
p[i] = 0; // ok; `p` is now has a type with bounds annotation.
}
Run test suites to fix new run-time traps
=========================================

Adopting ``-fbounds-safety`` may cause your program to trap if it violates
bounds safety or it has incorrect adoption. Thus, it is necessary to perform
run-time testing of your program to gain confidence that it won't trap at
run time.

Repeat the process for each remaining file
==========================================

Once you've done with adopting a single C file, please repeat the same process
for each remaining C file that you want to adopt.
35 changes: 32 additions & 3 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ C++ Language Changes
C++2c Feature Support
^^^^^^^^^^^^^^^^^^^^^

- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
`P2647R1 A trait for implicit lifetime types <https://wg21.link/p2674r1>`_

- Add ``__builtin_is_virtual_base_of`` intrinsic, which supports
`P2985R0 A type trait for detecting virtual base classes <https://wg21.link/p2985r0>`_

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

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

- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports
`P2674R1 A trait for implicit lifetime types <https://wg21.link/p2674r1>`_

- Add support for `P2280R4 Using unknown pointers and references in constant expressions <https://wg21.link/P2280R4>`_. (#GH63139)

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

- Respect constructor constraints during CTAD.
(`CWG2628: Implicit deduction guides should propagate constraints <https://cplusplus.github.io/CWG/issues/2628.html>`_).

- Clang now diagnoses a space in the first production of a ``literal-operator-id``
by default.
(`CWG2521: User-defined literals and reserved identifiers <https://cplusplus.github.io/CWG/issues/2521.html>`_).
Expand Down Expand Up @@ -804,6 +807,8 @@ Improvements to Clang's diagnostics

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

- Clang now diagnoses the use of attribute names reserved by the C++ standard (#GH92196).

Improvements to Clang's time-trace
----------------------------------

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

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -1131,6 +1139,20 @@ Windows Support
LoongArch Support
^^^^^^^^^^^^^^^^^

- Types of parameters and return value of ``__builtin_lsx_vorn_v`` and ``__builtin_lasx_xvorn_v``
are changed from ``signed char`` to ``unsigned char``. (#GH114514)

- ``-mrelax`` and ``-mno-relax`` are supported now on LoongArch that can be used
to enable / disable the linker relaxation optimization. (#GH123587)

- Fine-grained la64v1.1 options are added including ``-m{no-,}frecipe``, ``-m{no-,}lam-bh``,
``-m{no-,}ld-seq-sa``, ``-m{no-,}div32``, ``-m{no-,}lamcas`` and ``-m{no-,}scq``.

- Two options ``-m{no-,}annotate-tablejump`` are added to enable / disable
annotating table jump instruction to correlate it with the jump table. (#GH102411)

- FreeBSD support is added for LoongArch64 and has been tested by building kernel-toolchain. (#GH119191)

RISC-V Support
^^^^^^^^^^^^^^

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


Code Completion
---------------

- Use ``HeuristicResolver`` (upstreamed from clangd) to improve code completion results
in dependent code

Static Analyzer
---------------

Expand Down
1 change: 1 addition & 0 deletions clang/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Using Clang as a Compiler
SanitizerStats
SanitizerSpecialCaseList
BoundsSafety
BoundsSafetyAdoptionGuide
BoundsSafetyImplPlans
ControlFlowIntegrity
LTOVisibility
Expand Down
16 changes: 14 additions & 2 deletions clang/include/clang/AST/ASTNodeTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ class ASTNodeTraverser
ConstStmtVisitor<Derived>::Visit(S);

// Some statements have custom mechanisms for dumping their children.
if (isa<DeclStmt>(S) || isa<GenericSelectionExpr>(S) ||
isa<RequiresExpr>(S) || isa<OpenACCWaitConstruct>(S))
if (isa<DeclStmt, GenericSelectionExpr, RequiresExpr,
OpenACCWaitConstruct, SYCLKernelCallStmt>(S))
return;

if (Traversal == TK_IgnoreUnlessSpelledInSource &&
Expand Down Expand Up @@ -585,6 +585,12 @@ class ASTNodeTraverser

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

void VisitOutlinedFunctionDecl(const OutlinedFunctionDecl *D) {
for (const ImplicitParamDecl *Parameter : D->parameters())
Visit(Parameter);
Visit(D->getBody());
}

void VisitCapturedDecl(const CapturedDecl *D) { Visit(D->getBody()); }

void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) {
Expand Down Expand Up @@ -815,6 +821,12 @@ class ASTNodeTraverser
Visit(Node->getCapturedDecl());
}

void VisitSYCLKernelCallStmt(const SYCLKernelCallStmt *Node) {
Visit(Node->getOriginalStmt());
if (Traversal != TK_IgnoreUnlessSpelledInSource)
Visit(Node->getOutlinedFunctionDecl());
}

void VisitOMPExecutableDirective(const OMPExecutableDirective *Node) {
for (const auto *C : Node->clauses())
Visit(C);
Expand Down
14 changes: 4 additions & 10 deletions clang/include/clang/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class Attr : public AttributeCommonInfo {
unsigned IsLateParsed : 1;
LLVM_PREFERRED_TYPE(bool)
unsigned InheritEvenIfAlreadyPresent : 1;
LLVM_PREFERRED_TYPE(bool)
unsigned DeferDeserialization : 1;

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

protected:
Attr(ASTContext &Context, const AttributeCommonInfo &CommonInfo,
attr::Kind AK, bool IsLateParsed, bool DeferDeserialization = false)
attr::Kind AK, bool IsLateParsed)
: AttributeCommonInfo(CommonInfo), AttrKind(AK), Inherited(false),
IsPackExpansion(false), Implicit(false), IsLateParsed(IsLateParsed),
InheritEvenIfAlreadyPresent(false),
DeferDeserialization(DeferDeserialization) {}
InheritEvenIfAlreadyPresent(false) {}

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

bool shouldDeferDeserialization() const { return DeferDeserialization; }

// Clone this attribute.
Attr *clone(ASTContext &C) const;

Expand Down Expand Up @@ -151,9 +146,8 @@ class InheritableAttr : public Attr {
protected:
InheritableAttr(ASTContext &Context, const AttributeCommonInfo &CommonInfo,
attr::Kind AK, bool IsLateParsed,
bool InheritEvenIfAlreadyPresent,
bool DeferDeserialization = false)
: Attr(Context, CommonInfo, AK, IsLateParsed, DeferDeserialization) {
bool InheritEvenIfAlreadyPresent)
: Attr(Context, CommonInfo, AK, IsLateParsed) {
this->InheritEvenIfAlreadyPresent = InheritEvenIfAlreadyPresent;
}

Expand Down
Loading

0 comments on commit 2154683

Please sign in to comment.