Skip to content

Commit 7071026

Browse files
[AutoBump] Merge with 1533682 (Feb 01) (10) (#899)
2 parents 570aaba + 25f7602 commit 7071026

307 files changed

Lines changed: 6768 additions & 5045 deletions

File tree

Some content is hidden

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

.github/new-prs-labeler.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,9 @@ llvm:regalloc:
730730
lldb:
731731
- lldb/**
732732

733+
lldb-dap:
734+
- lldb/tools/lldb-dap/**
735+
733736
backend:AMDGPU:
734737
- '**/*amdgpu*'
735738
- '**/*AMDGPU*'

.github/workflows/premerge.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ jobs:
139139
group: ${{ github.workflow }}-macos-${{ github.event.pull_request.number || github.sha }}
140140
cancel-in-progress: true
141141
if: >-
142+
github.repository_owner == 'llvm' &&
142143
(startswith(github.ref_name, 'release/') ||
143-
startswith(github.base_ref, 'refs/heads/release/'))
144+
startswith(github.base_ref, 'release/'))
144145
steps:
145146
- name: Checkout LLVM
146147
uses: actions/checkout@v4

bolt/test/X86/dynamic-relocs-on-entry.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
# RUN: %clang %cflags -fPIC -pie %s -o %t.exe -nostdlib -Wl,-q
66
# RUN: llvm-bolt %t.exe -o %t.bolt > %t.out.txt
7-
# RUN: readelf -r %t.bolt >> %t.out.txt
7+
# RUN: llvm-readelf -r %t.bolt >> %t.out.txt
88
# RUN: llvm-objdump --disassemble-symbols=chain %t.bolt >> %t.out.txt
99
# RUN: FileCheck %s --input-file=%t.out.txt
1010

1111
## Check if the new address in `chain` is correctly updated by BOLT
12-
# CHECK: Relocation section '.rela.dyn' at offset 0x{{.*}} contains 1 entry:
12+
# CHECK: Relocation section '.rela.dyn' at offset 0x{{.*}} contains 1 entries:
1313
# CHECK: {{.*}} R_X86_64_RELATIVE [[#%x,ADDR:]]
1414
# CHECK: [[#ADDR]]: c3 retq
1515
.text
@@ -29,4 +29,4 @@ _start:
2929

3030
.data
3131
.Lfoo:
32-
.quad Label
32+
.quad Label

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "clang/AST/Type.h"
2323
#include "clang/AST/TypeLoc.h"
2424
#include "clang/Basic/IdentifierTable.h"
25+
#include "clang/Basic/OperatorKinds.h"
2526
#include "clang/Basic/SourceLocation.h"
2627
#include "clang/Basic/Specifiers.h"
2728
#include "llvm/ADT/STLExtras.h"
@@ -32,6 +33,11 @@
3233

3334
namespace clang::include_cleaner {
3435
namespace {
36+
bool isOperatorNewDelete(OverloadedOperatorKind OpKind) {
37+
return OpKind == OO_New || OpKind == OO_Delete || OpKind == OO_Array_New ||
38+
OpKind == OO_Array_Delete;
39+
}
40+
3541
using DeclCallback =
3642
llvm::function_ref<void(SourceLocation, NamedDecl &, RefType)>;
3743

@@ -158,7 +164,15 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
158164
// the container decl instead, which is preferred as it'll handle
159165
// aliases/exports properly.
160166
if (!FD->isCXXClassMember() && !llvm::isa<EnumConstantDecl>(FD)) {
161-
report(DRE->getLocation(), FD);
167+
// Global operator new/delete [] is available implicitly in every
168+
// translation unit, even without including any explicit headers. So treat
169+
// those as ambigious to not force inclusion in TUs that transitively
170+
// depend on those.
171+
RefType RT =
172+
isOperatorNewDelete(FD->getDeclName().getCXXOverloadedOperator())
173+
? RefType::Ambiguous
174+
: RefType::Explicit;
175+
report(DRE->getLocation(), FD, RT);
162176
return true;
163177
}
164178
// If the ref is without a qualifier, and is a member, ignore it. As it is

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,55 @@ TEST_F(AnalyzeTest, SpellingIncludesWithSymlinks) {
397397
}
398398
}
399399

400+
// Make sure that the references to implicit operator new/delete are reported as
401+
// ambigious.
402+
TEST_F(AnalyzeTest, ImplicitOperatorNewDeleteNotMissing) {
403+
ExtraFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
404+
ExtraFS->addFile("header.h",
405+
/*ModificationTime=*/{},
406+
llvm::MemoryBuffer::getMemBufferCopy(guard(R"cpp(
407+
void* operator new(decltype(sizeof(int)));
408+
)cpp")));
409+
ExtraFS->addFile("wrapper.h",
410+
/*ModificationTime=*/{},
411+
llvm::MemoryBuffer::getMemBufferCopy(guard(R"cpp(
412+
#include "header.h"
413+
)cpp")));
414+
415+
Inputs.Code = R"cpp(
416+
#include "wrapper.h"
417+
void bar() {
418+
operator new(3);
419+
})cpp";
420+
TestAST AST(Inputs);
421+
std::vector<Decl *> DeclsInTU;
422+
for (auto *D : AST.context().getTranslationUnitDecl()->decls())
423+
DeclsInTU.push_back(D);
424+
auto Results = analyze(DeclsInTU, {}, PP.Includes, &PI, AST.preprocessor());
425+
EXPECT_THAT(Results.Missing, testing::IsEmpty());
426+
}
427+
428+
TEST_F(AnalyzeTest, ImplicitOperatorNewDeleteNotUnused) {
429+
ExtraFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
430+
ExtraFS->addFile("header.h",
431+
/*ModificationTime=*/{},
432+
llvm::MemoryBuffer::getMemBufferCopy(guard(R"cpp(
433+
void* operator new(decltype(sizeof(int)));
434+
)cpp")));
435+
436+
Inputs.Code = R"cpp(
437+
#include "header.h"
438+
void bar() {
439+
operator new(3);
440+
})cpp";
441+
TestAST AST(Inputs);
442+
std::vector<Decl *> DeclsInTU;
443+
for (auto *D : AST.context().getTranslationUnitDecl()->decls())
444+
DeclsInTU.push_back(D);
445+
auto Results = analyze(DeclsInTU, {}, PP.Includes, &PI, AST.preprocessor());
446+
EXPECT_THAT(Results.Unused, testing::IsEmpty());
447+
}
448+
400449
TEST(FixIncludes, Basic) {
401450
llvm::StringRef Code = R"cpp(#include "d.h"
402451
#include "a.h"

clang/docs/ReleaseNotes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ Resolutions to C++ Defect Reports
8383
C Language Changes
8484
------------------
8585

86+
- Clang now allows an ``inline`` specifier on a typedef declaration of a
87+
function type in Microsoft compatibility mode. #GH124869
88+
8689
C2y Feature Support
8790
^^^^^^^^^^^^^^^^^^^
8891

@@ -216,6 +219,10 @@ Code Completion
216219
Static Analyzer
217220
---------------
218221

222+
- Clang currently support extending lifetime of object bound to
223+
reference members of aggregates in CFG and ExprEngine, that are
224+
created from default member initializer.
225+
219226
New features
220227
^^^^^^^^^^^^
221228

clang/docs/analyzer/user-docs/Annotations.rst

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ recognized by GCC. Their use can be conditioned using preprocessor macros
2323
.. contents::
2424
:local:
2525

26-
Annotations to Enhance Generic Checks
27-
_____________________________________
26+
General Purpose Annotations
27+
___________________________
2828

2929
Null Pointer Checking
3030
#####################
@@ -79,15 +79,15 @@ implemented with a macro, with the macro performing a check for the assertion
7979
condition and, when the check fails, calling an assertion handler. For
8080
example, consider the following code fragment:
8181

82-
.. code-block: c
82+
.. code-block:: c
8383
8484
void foo(int *p) {
8585
assert(p != NULL);
8686
}
8787
8888
When this code is preprocessed on Mac OS X it expands to the following:
8989

90-
.. code-block: c
90+
.. code-block:: c
9191
9292
void foo(int *p) {
9393
(__builtin_expect(!(p != NULL), 0) ? __assert_rtn(__func__, "t.c", 4, "p != NULL") : (void)0);
@@ -131,7 +131,7 @@ return.
131131
On Mac OS X, the function prototype for ``__assert_rtn`` (declared in
132132
``assert.h``) is specifically annotated with the 'noreturn' attribute:
133133

134-
.. code-block: c
134+
.. code-block:: c
135135
136136
void __assert_rtn(const char *, const char *, int, const char *) __attribute__((__noreturn__));
137137
@@ -151,7 +151,7 @@ the use of preprocessor macros.
151151

152152
**Example**
153153

154-
.. code-block: c
154+
.. code-block:: c
155155
156156
#ifndef CLANG_ANALYZER_NORETURN
157157
#if __has_feature(attribute_analyzer_noreturn)
@@ -163,6 +163,43 @@ the use of preprocessor macros.
163163
164164
void my_assert_rtn(const char *, const char *, int, const char *) CLANG_ANALYZER_NORETURN;
165165
166+
Dynamic Memory Modeling Annotations
167+
###################################
168+
169+
If a project uses custom functions for dynamic memory management (that e.g. act as wrappers around ``malloc``/``free`` or ``new``/``delete`` in C++) and the analyzer cannot "see" the _definitions_ of these functions, it's possible to annotate their declarations to let the analyzer model their behavior. (Otherwise the analyzer cannot know that the opaque ``my_free()`` is basically equivalent to a standard ``free()`` call.)
170+
171+
.. note::
172+
**This page only provides a brief list of these annotations.** For a full documentation, see the main `Attributes in Clang <../../AttributeReference.html#ownership-holds-ownership-returns-ownership-takes-clang-static-analyzer>`_ page.
173+
174+
Attribute 'ownership_returns' (Clang-specific)
175+
----------------------------------------------
176+
177+
Use this attribute to mark functions that return dynamically allocated memory. Takes a single argument, the type of the allocation (e.g. ``malloc`` or ``new``).
178+
179+
.. code-block:: c
180+
181+
void __attribute((ownership_returns(malloc))) *my_malloc(size_t);
182+
183+
Attribute 'ownership_takes' (Clang-specific)
184+
--------------------------------------------
185+
186+
Use this attribute to mark functions that deallocate memory. Takes two arguments: the type of the allocation (e.g. ``malloc`` or ``new``) and the index of the parameter that is being deallocated (counting from 1).
187+
188+
.. code-block:: c
189+
190+
void __attribute((ownership_takes(malloc, 1))) my_free(void *);
191+
192+
Attribute 'ownership_holds' (Clang-specific)
193+
--------------------------------------------
194+
195+
Use this attribute to mark functions that take ownership of memory and will deallocate it at some unspecified point in the future. Takes two arguments: the type of the allocation (e.g. ``malloc`` or ``new``) and the index of the parameter that is being held (counting from 1).
196+
197+
.. code-block:: c
198+
199+
void __attribute((ownership_holds(malloc, 2))) store_in_table(int key, record_t *val);
200+
201+
The annotations ``ownership_takes`` and ``ownership_holds`` both prevent memory leak reports (concerning the specified argument); the difference between them is that using taken memory is a use-after-free error, while using held memory is assumed to be legitimate.
202+
166203
Mac OS X API Annotations
167204
________________________
168205

@@ -207,7 +244,7 @@ functions allows the analyzer to perform extra checking.
207244

208245
**Example**
209246

210-
.. code-block: objc
247+
.. code-block:: objc
211248
212249
#import <Foundation/Foundation.h>;
213250
@@ -597,7 +634,6 @@ returned object.
597634
LIBKERN_RETURNS_NOT_RETAINED OSObject *myFieldGetter();
598635
}
599636
600-
601637
// Note that the annotation only has to be applied to the function declaration.
602638
OSObject * MyClass::myFieldGetter() {
603639
return f;

0 commit comments

Comments
 (0)