Skip to content

Commit c72c6f2

Browse files
authored
Merge branch 'main' into users/junlarsen/codegen_replace_pointertype_getunqual_type_with_opaque_pointer_version_nfc_
2 parents 22a0782 + d21b2e6 commit c72c6f2

File tree

557 files changed

+42583
-12868
lines changed

Some content is hidden

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

557 files changed

+42583
-12868
lines changed

bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s

Lines changed: 25 additions & 99 deletions
Large diffs are not rendered by default.

bolt/test/binary-analysis/AArch64/gs-pacret-multi-bb.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ f_crossbb1:
1515
1:
1616
ret
1717
.size f_crossbb1, .-f_crossbb1
18-
// CHECK-LABEL: GS-PACRET: non-protected ret found in function f_crossbb1, basic block .L{{[^,]+}}, at address
18+
// CHECK-LABEL: GS-PACRET: non-protected ret found in function f_crossbb1, basic block {{[^,]+}}, at address
1919
// CHECK-NEXT: The return instruction is {{[0-9a-f]+}}: ret
2020
// CHECK-NEXT: The 2 instructions that write to the return register after any authentication are:
2121
// CHECK-NEXT: 1. {{[0-9a-f]+}}: ldp x29, x30, [sp], #0x10
@@ -37,7 +37,7 @@ f_mergebb1:
3737
1:
3838
ret
3939
.size f_mergebb1, .-f_mergebb1
40-
// CHECK-LABEL: GS-PACRET: non-protected ret found in function f_mergebb1, basic block .L{{[^,]+}}, at address
40+
// CHECK-LABEL: GS-PACRET: non-protected ret found in function f_mergebb1, basic block {{[^,]+}}, at address
4141
// CHECK-NEXT: The return instruction is {{[0-9a-f]+}}: ret
4242
// CHECK-NEXT: The 1 instructions that write to the return register after any authentication are:
4343
// CHECK-NEXT: 1. {{[0-9a-f]+}}: ldp x29, x30, [sp], #0x10

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ clang_target_link_libraries(clangTidyBugproneModule
117117
clangASTMatchers
118118
clangBasic
119119
clangLex
120+
clangSema
120121
clangTooling
121122
clangTransformer
122123
)

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "clang/Basic/Diagnostic.h"
2121
#include "clang/Basic/SourceLocation.h"
2222
#include "clang/Lex/Lexer.h"
23+
#include "clang/Sema/HeuristicResolver.h"
2324
#include "llvm/ADT/STLExtras.h"
2425
#include "llvm/ADT/SmallVector.h"
2526
#include "llvm/Support/Casting.h"
@@ -125,8 +126,8 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) {
125126
DeclarationName Name =
126127
Context.DeclarationNames.getIdentifier(&Context.Idents.get("clear"));
127128

128-
auto Candidates = MemberCall->getRecordDecl()->lookupDependentName(
129-
Name, [](const NamedDecl *ND) {
129+
auto Candidates = HeuristicResolver(Context).lookupDependentName(
130+
MemberCall->getRecordDecl(), Name, [](const NamedDecl *ND) {
130131
return isa<CXXMethodDecl>(ND) &&
131132
llvm::cast<CXXMethodDecl>(ND)->getMinRequiredArguments() ==
132133
0 &&
@@ -174,8 +175,8 @@ void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) {
174175
DeclarationName Name =
175176
Context.DeclarationNames.getIdentifier(&Context.Idents.get("clear"));
176177

177-
auto Candidates =
178-
ArgRecordDecl->lookupDependentName(Name, [](const NamedDecl *ND) {
178+
auto Candidates = HeuristicResolver(Context).lookupDependentName(
179+
ArgRecordDecl, Name, [](const NamedDecl *ND) {
179180
return isa<CXXMethodDecl>(ND) &&
180181
llvm::cast<CXXMethodDecl>(ND)->getMinRequiredArguments() ==
181182
0 &&

clang/Maintainers.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ Clang static analyzer
136136
137137
| Balázs Benics
138138
| benicsbalazs\@gmail.com (email), steakhal (Phabricator), steakhal (GitHub)
139+
| balazs.benics\@sonarsource.com (email), balazs-benics-sonarsource (GitHub)
139140
140141
Compiler options
141142
~~~~~~~~~~~~~~~~

clang/docs/ReleaseNotes.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,50 @@ Attribute Changes in Clang
132132
This forces the global to be considered small or large in regards to the
133133
x86-64 code model, regardless of the code model specified for the compilation.
134134

135+
- There is a new ``format_matches`` attribute to complement the existing
136+
``format`` attribute. ``format_matches`` allows the compiler to verify that
137+
a format string argument is equivalent to a reference format string: it is
138+
useful when a function accepts a format string without its accompanying
139+
arguments to format. For instance:
140+
141+
.. code-block:: c
142+
143+
static int status_code;
144+
static const char *status_string;
145+
146+
void print_status(const char *fmt) {
147+
fprintf(stderr, fmt, status_code, status_string);
148+
// ^ warning: format string is not a string literal [-Wformat-nonliteral]
149+
}
150+
151+
void stuff(void) {
152+
print_status("%s (%#08x)\n");
153+
// order of %s and %x is swapped but there is no diagnostic
154+
}
155+
156+
Before the introducion of ``format_matches``, this code cannot be verified
157+
at compile-time. ``format_matches`` plugs that hole:
158+
159+
.. code-block:: c
160+
161+
__attribute__((format_matches(printf, 1, "%x %s")))
162+
void print_status(const char *fmt) {
163+
fprintf(stderr, fmt, status_code, status_string);
164+
// ^ `fmt` verified as if it was "%x %s" here; no longer triggers
165+
// -Wformat-nonliteral, would warn if arguments did not match "%x %s"
166+
}
167+
168+
void stuff(void) {
169+
print_status("%s (%#08x)\n");
170+
// warning: format specifier 's' is incompatible with 'x'
171+
// warning: format specifier 'x' is incompatible with 's'
172+
}
173+
174+
Like with ``format``, the first argument is the format string flavor and the
175+
second argument is the index of the format string parameter.
176+
``format_matches`` accepts an example valid format string as its third
177+
argument. For more information, see the Clang attributes documentation.
178+
135179
Improvements to Clang's diagnostics
136180
-----------------------------------
137181

clang/docs/analyzer/checkers.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,6 +3668,51 @@ Here are some examples of situations that we warn about as they *might* be poten
36683668
RefCountable* uncounted = counted.get(); // warn
36693669
}
36703670
3671+
alpha.webkit.UnretainedLocalVarsChecker
3672+
"""""""""""""""""""""""""""""""""""""""
3673+
The goal of this rule is to make sure that any NS or CF local variable is backed by a RetainPtr with lifetime that is strictly larger than the scope of the unretained local variable. To be on the safe side we require the scope of an unretained variable to be embedded in the scope of Retainptr object that backs it.
3674+
3675+
The rules of when to use and not to use RetainPtr are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
3676+
3677+
These are examples of cases that we consider safe:
3678+
3679+
.. code-block:: cpp
3680+
3681+
void foo1() {
3682+
RetainPtr<NSObject> retained;
3683+
// The scope of unretained is EMBEDDED in the scope of retained.
3684+
{
3685+
NSObject* unretained = retained.get(); // ok
3686+
}
3687+
}
3688+
3689+
void foo2(RetainPtr<NSObject> retained_param) {
3690+
NSObject* unretained = retained_param.get(); // ok
3691+
}
3692+
3693+
void FooClass::foo_method() {
3694+
NSObject* unretained = this; // ok
3695+
}
3696+
3697+
Here are some examples of situations that we warn about as they *might* be potentially unsafe. The logic is that either we're able to guarantee that a local variable is safe or it's considered unsafe.
3698+
3699+
.. code-block:: cpp
3700+
3701+
void foo1() {
3702+
NSObject* unretained = [[NSObject alloc] init]; // warn
3703+
}
3704+
3705+
NSObject* global_unretained;
3706+
void foo2() {
3707+
NSObject* unretained = global_unretained; // warn
3708+
}
3709+
3710+
void foo3() {
3711+
RetainPtr<NSObject> retained;
3712+
// The scope of unretained is not EMBEDDED in the scope of retained.
3713+
NSObject* unretained = retained.get(); // warn
3714+
}
3715+
36713716
Debug Checkers
36723717
---------------
36733718

clang/include/clang/AST/DeclCXX.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,14 +1720,6 @@ class CXXRecordDecl : public RecordDecl {
17201720
/// static analysis, or similar.
17211721
bool hasMemberName(DeclarationName N) const;
17221722

1723-
/// Performs an imprecise lookup of a dependent name in this class.
1724-
///
1725-
/// This function does not follow strict semantic rules and should be used
1726-
/// only when lookup rules can be relaxed, e.g. indexing.
1727-
std::vector<const NamedDecl *>
1728-
lookupDependentName(DeclarationName Name,
1729-
llvm::function_ref<bool(const NamedDecl *ND)> Filter);
1730-
17311723
/// Renders and displays an inheritance diagram
17321724
/// for this C++ class and all of its base classes (transitively) using
17331725
/// GraphViz.

clang/include/clang/AST/FormatString.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class ArgType {
292292
};
293293

294294
private:
295-
const Kind K;
295+
Kind K;
296296
QualType T;
297297
const char *Name = nullptr;
298298
bool Ptr = false;
@@ -338,6 +338,7 @@ class ArgType {
338338
}
339339

340340
MatchKind matchesType(ASTContext &C, QualType argTy) const;
341+
MatchKind matchesArgType(ASTContext &C, const ArgType &other) const;
341342

342343
QualType getRepresentativeType(ASTContext &C) const;
343344

clang/include/clang/Basic/Attr.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,16 @@ def Format : InheritableAttr {
18341834
let Documentation = [FormatDocs];
18351835
}
18361836

1837+
def FormatMatches : InheritableAttr {
1838+
let Spellings = [GCC<"format_matches">];
1839+
let Args = [IdentifierArgument<"Type">, IntArgument<"FormatIdx">, ExprArgument<"ExpectedFormat">];
1840+
let AdditionalMembers = [{
1841+
StringLiteral *getFormatString() const;
1842+
}];
1843+
let Subjects = SubjectList<[ObjCMethod, Block, HasFunctionProto]>;
1844+
let Documentation = [FormatMatchesDocs];
1845+
}
1846+
18371847
def FormatArg : InheritableAttr {
18381848
let Spellings = [GCC<"format_arg">];
18391849
let Args = [ParamIdxArgument<"FormatIdx">];

0 commit comments

Comments
 (0)