Skip to content

Commit 9567f08

Browse files
committed
Merge remote-tracking branch 'upstream/release/15.x' into rustc/15.0-2022-08-09
2 parents 670e5f6 + 77ff99c commit 9567f08

File tree

154 files changed

+2537
-817
lines changed

Some content is hidden

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

154 files changed

+2537
-817
lines changed

Diff for: .github/workflows/version-check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def get_version_from_tag(tag):
1212
# We have an rc tag.
1313
return m.group(1,2,3)
1414
# We have a final release tag.
15-
return (m.group(1), m.group(2), int(m.group(3)) + 1)
15+
return (m.group(1), m.group(2), str(int(m.group(3)) + 1))
1616

1717
m = re.match('llvmorg-([0-9]+)-init', tag)
1818
if m:

Diff for: clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
1313
#include "clang/ASTMatchers/ASTMatchers.h"
1414

15-
#include <iostream>
16-
1715
using namespace clang::ast_matchers;
1816

1917
namespace clang {
@@ -132,6 +130,12 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
132130
VC = VariableCategory::Reference;
133131
if (Variable->getType()->isPointerType())
134132
VC = VariableCategory::Pointer;
133+
if (Variable->getType()->isArrayType()) {
134+
if (const auto *ArrayT = dyn_cast<ArrayType>(Variable->getType())) {
135+
if (ArrayT->getElementType()->isPointerType())
136+
VC = VariableCategory::Pointer;
137+
}
138+
}
135139

136140
// Each variable can only be in one category: Value, Pointer, Reference.
137141
// Analysis can be controlled for every category.

Diff for: clang-tools-extra/clangd/CompileCommands.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,13 @@ void CommandMangler::adjust(std::vector<std::string> &Cmd,
220220
ArgList = OptTable.ParseArgs(
221221
llvm::makeArrayRef(OriginalArgs).drop_front(), IgnoredCount, IgnoredCount,
222222
/*FlagsToInclude=*/
223-
IsCLMode ? (driver::options::CLOption | driver::options::CoreOption)
223+
IsCLMode ? (driver::options::CLOption | driver::options::CoreOption |
224+
driver::options::CLDXCOption)
224225
: /*everything*/ 0,
225226
/*FlagsToExclude=*/driver::options::NoDriverOption |
226-
(IsCLMode ? 0 : driver::options::CLOption));
227+
(IsCLMode
228+
? 0
229+
: (driver::options::CLOption | driver::options::CLDXCOption)));
227230

228231
llvm::SmallVector<unsigned, 1> IndicesToDrop;
229232
// Having multiple architecture options (e.g. when building fat binaries)

Diff for: clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,19 @@ TEST(CommandMangler, EmptyArgs) {
415415
// Make sure we don't crash.
416416
Mangler.adjust(Args, "foo.cc");
417417
}
418+
419+
TEST(CommandMangler, PathsAsPositional) {
420+
const auto Mangler = CommandMangler::forTests();
421+
std::vector<std::string> Args = {
422+
"clang",
423+
"--driver-mode=cl",
424+
"-I",
425+
"foo",
426+
};
427+
// Make sure we don't crash.
428+
Mangler.adjust(Args, "a.cc");
429+
EXPECT_THAT(Args, Contains("foo"));
430+
}
418431
} // namespace
419432
} // namespace clangd
420433
} // namespace clang

Diff for: clang-tools-extra/docs/ReleaseNotes.rst

+2-9
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ Extra Clang Tools |release| |ReleaseNotesTitle|
88

99
Written by the `LLVM Team <https://llvm.org/>`_
1010

11-
.. only:: PreRelease
12-
13-
.. warning::
14-
These are in-progress notes for the upcoming Extra Clang Tools |version| release.
15-
Release notes for previous releases can be found on
16-
`the Download Page <https://releases.llvm.org/download.html>`_.
17-
1811
Introduction
1912
============
2013

@@ -259,12 +252,12 @@ Changes in existing checks
259252

260253
- Fixed a false positive in :doc:`misc-unused-parameters
261254
<clang-tidy/checks/misc/unused-parameters>`
262-
where invalid parameters were implicitly being treated as being unused.
255+
where invalid parameters were implicitly being treated as being unused.
263256
This fixes `Issue 56152 <https://github.com/llvm/llvm-project/issues/56152>`_.
264257

265258
- Fixed false positives in :doc:`misc-unused-using-decls
266259
<clang-tidy/checks/misc/unused-using-decls>` where `using` statements bringing
267-
operators into the scope where incorrectly marked as unused.
260+
operators into the scope where incorrectly marked as unused.
268261
This fixes `issue 55095 <https://github.com/llvm/llvm-project/issues/55095>`_.
269262

270263
- Fixed a false positive in :doc:`modernize-deprecated-headers

Diff for: clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst

+80-32
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ misc-const-correctness
44
======================
55

66
This check implements detection of local variables which could be declared as
7-
``const``, but are not. Declaring variables as ``const`` is required or recommended by many
7+
``const`` but are not. Declaring variables as ``const`` is required or recommended by many
88
coding guidelines, such as:
99
`CppCoreGuidelines ES.25 <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es25-declare-an-object-const-or-constexpr-unless-you-want-to-modify-its-value-later-on>`_
1010
and `AUTOSAR C++14 Rule A7-1-1 (6.7.1 Specifiers) <https://www.autosar.org/fileadmin/user_upload/standards/adaptive/17-03/AUTOSAR_RS_CPP14Guidelines.pdf>`_.
1111

12-
Please note that this analysis is type-based only. Variables that are not modified
12+
Please note that this check's analysis is type-based only. Variables that are not modified
1313
but used to create a non-const handle that might escape the scope are not diagnosed
1414
as potential ``const``.
1515

@@ -18,44 +18,50 @@ as potential ``const``.
1818
// Declare a variable, which is not ``const`` ...
1919
int i = 42;
2020
// but use it as read-only. This means that `i` can be declared ``const``.
21-
int result = i * i;
21+
int result = i * i; // Before transformation
22+
int const result = i * i; // After transformation
2223

23-
The check can analyzes values, pointers and references but not (yet) pointees:
24+
The check can analyze values, pointers and references but not (yet) pointees:
2425

2526
.. code-block:: c++
2627

2728
// Normal values like built-ins or objects.
28-
int potential_const_int = 42; // 'const int potential_const_int = 42' suggestion.
29+
int potential_const_int = 42; // Before transformation
30+
int const potential_const_int = 42; // After transformation
2931
int copy_of_value = potential_const_int;
3032

31-
MyClass could_be_const; // 'const MyClass could_be_const' suggestion;
33+
MyClass could_be_const; // Before transformation
34+
MyClass const could_be_const; // After transformation
3235
could_be_const.const_qualified_method();
3336

3437
// References can be declared const as well.
35-
int &reference_value = potential_const_int; // 'const int &reference_value' suggestion.
38+
int &reference_value = potential_const_int; // Before transformation
39+
int const& reference_value = potential_const_int; // After transformation
3640
int another_copy = reference_value;
3741

3842
// The similar semantics of pointers are not (yet) analyzed.
39-
int *pointer_variable = &potential_const_int; // Not 'const int *pointer_variable' suggestion.
43+
int *pointer_variable = &potential_const_int; // _NO_ 'const int *pointer_variable' suggestion.
4044
int last_copy = *pointer_variable;
4145
4246
The automatic code transformation is only applied to variables that are declared in single
4347
declarations. You may want to prepare your code base with
4448
`readability-isolate-declaration <readability-isolate-declaration.html>`_ first.
4549

4650
Note that there is the check
47-
`cppcoreguidelines-avoid-non-const-global-variables <cppcoreguidelines-avoid-non-const-global-variables.html>`_
51+
`cppcoreguidelines-avoid-non-const-global-variables <../cppcoreguidelines/avoid-non-const-global-variables.html>`_
4852
to enforce ``const`` correctness on all globals.
4953

5054
Known Limitations
5155
-----------------
5256

57+
The check does not run on `C` code.
58+
5359
The check will not analyze templated variables or variables that are instantiation dependent.
5460
Different instantiations can result in different ``const`` correctness properties and in general it
55-
is not possible to find all instantiations of a template. It might be used differently in an
56-
independent translation unit.
61+
is not possible to find all instantiations of a template. The template might be used differently in
62+
an independent translation unit.
5763

58-
Pointees can not be analyzed for constness yet. The following code is shows this limitation.
64+
Pointees can not be analyzed for constness yet. The following code shows this limitation.
5965

6066
.. code-block:: c++
6167

@@ -74,44 +80,72 @@ This limitation affects the capability to add ``const`` to methods which is not
7480
Options
7581
-------
7682

77-
.. option:: AnalyzeValues (default = 1)
83+
.. option:: AnalyzeValues (default = true)
7884

7985
Enable or disable the analysis of ordinary value variables, like ``int i = 42;``
8086

81-
.. option:: AnalyzeReferences (default = 1)
87+
.. code-block:: c++
88+
89+
// Warning
90+
int i = 42;
91+
// No warning
92+
int const i = 42;
93+
94+
// Warning
95+
int a[] = {42, 42, 42};
96+
// No warning
97+
int const a[] = {42, 42, 42};
98+
99+
.. option:: AnalyzeReferences (default = true)
82100

83101
Enable or disable the analysis of reference variables, like ``int &ref = i;``
84102

85-
.. option:: WarnPointersAsValues (default = 0)
103+
.. code-block:: c++
104+
105+
int i = 42;
106+
// Warning
107+
int& ref = i;
108+
// No warning
109+
int const& ref = i;
110+
111+
.. option:: WarnPointersAsValues (default = false)
86112

87113
This option enables the suggestion for ``const`` of the pointer itself.
88114
Pointer values have two possibilities to be ``const``, the pointer
89115
and the value pointing to.
90116

91117
.. code-block:: c++
92118

93-
const int value = 42;
94-
const int * const pointer_variable = &value;
119+
int value = 42;
95120

96-
// The following operations are forbidden for `pointer_variable`.
97-
// *pointer_variable = 44;
98-
// pointer_variable = nullptr;
121+
// Warning
122+
const int * pointer_variable = &value;
123+
// No warning
124+
const int *const pointer_variable = &value;
99125
100-
.. option:: TransformValues (default = 1)
126+
.. option:: TransformValues (default = true)
101127

102-
Provides fixit-hints for value types that automatically adds ``const`` if its a single declaration.
128+
Provides fixit-hints for value types that automatically add ``const`` if its a single declaration.
103129

104130
.. code-block:: c++
105131

106-
// Emits a hint for 'value' to become 'const int value = 42;'.
132+
// Before
107133
int value = 42;
134+
// After
135+
int const value = 42;
136+
137+
// Before
138+
int a[] = {42, 42, 42};
139+
// After
140+
int const a[] = {42, 42, 42};
141+
108142
// Result is modified later in its life-time. No diagnostic and fixit hint will be emitted.
109143
int result = value * 3;
110144
result -= 10;
111145

112-
.. option:: TransformReferences (default = 1)
146+
.. option:: TransformReferences (default = true)
113147

114-
Provides fixit-hints for reference types that automatically adds ``const`` if its a single
148+
Provides fixit-hints for reference types that automatically add ``const`` if its a single
115149
declaration.
116150

117151
.. code-block:: c++
@@ -120,31 +154,45 @@ Options
120154
// it, it can not be transformed (yet).
121155
int value = 42;
122156
// The reference 'ref_value' is not modified and can be made 'const int &ref_value = value;'
157+
// Before
123158
int &ref_value = value;
159+
// After
160+
int const &ref_value = value;
124161

125162
// Result is modified later in its life-time. No diagnostic and fixit hint will be emitted.
126163
int result = ref_value * 3;
127164
result -= 10;
128165

129-
.. option:: TransformPointersAsValues (default = 0)
166+
.. option:: TransformPointersAsValues (default = false)
130167

131168
Provides fixit-hints for pointers if their pointee is not changed. This does not analyze if the
132169
value-pointed-to is unchanged!
133170

134-
Requires 'WarnPointersAsValues' to be 1.
171+
Requires 'WarnPointersAsValues' to be 'true'.
135172

136173
.. code-block:: c++
137174

138175
int value = 42;
139-
// Emits a hint that 'ptr_value' may become 'int *const ptr_value = &value' because its pointee
140-
// is not changed.
176+
177+
// Before
178+
const int * pointer_variable = &value;
179+
// After
180+
const int *const pointer_variable = &value;
181+
182+
// Before
183+
const int * a[] = {&value, &value};
184+
// After
185+
const int *const a[] = {&value, &value};
186+
187+
// Before
141188
int *ptr_value = &value;
189+
// After
190+
int *const ptr_value = &value;
142191
143-
int result = 100 * (*ptr_value);
144-
// This modification of the pointee is still allowed and not analyzed/diagnosed.
192+
int result = 100 * (*ptr_value); // Does not modify the pointer itself.
193+
// This modification of the pointee is still allowed and not diagnosed.
145194
*ptr_value = 0;
146195
147196
// The following pointer may not become a 'int *const'.
148197
int *changing_pointee = &value;
149198
changing_pointee = &result;
150-

Diff for: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,65 @@ void potential_const_pointer() {
1010
double *p_local0 = &np_local0[1];
1111
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double *' can be declared 'const'
1212
// CHECK-FIXES: double *const p_local0
13+
14+
using doublePtr = double*;
15+
using doubleArray = double[15];
16+
doubleArray np_local1;
17+
doublePtr p_local1 = &np_local1[0];
18+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'doublePtr' (aka 'double *') can be declared 'const'
19+
// CHECK-FIXES: doublePtr const p_local1
20+
}
21+
22+
void range_for() {
23+
int np_local0[2] = {1, 2};
24+
int *p_local0[2] = {&np_local0[0], &np_local0[1]};
25+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int *[2]' can be declared 'const'
26+
// CHECK-FIXES: int *const p_local0[2]
27+
for (const int *p_local1 : p_local0) {
28+
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: variable 'p_local1' of type 'const int *' can be declared 'const'
29+
// CHECK-FIXES: for (const int *const p_local1 : p_local0)
30+
}
31+
32+
int *p_local2[2] = {nullptr, nullptr};
33+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local2' of type 'int *[2]' can be declared 'const'
34+
// CHECK-FIXES: int *const p_local2[2]
35+
for (const auto *con_ptr : p_local2) {
36+
}
37+
38+
}
39+
40+
template <typename T>
41+
struct SmallVectorBase {
42+
T data[4];
43+
void push_back(const T &el) {}
44+
int size() const { return 4; }
45+
T *begin() { return data; }
46+
const T *begin() const { return data; }
47+
T *end() { return data + 4; }
48+
const T *end() const { return data + 4; }
49+
};
50+
51+
template <typename T>
52+
struct SmallVector : SmallVectorBase<T> {};
53+
54+
template <class T>
55+
void EmitProtocolMethodList(T &&Methods) {
56+
// Note: If the template is uninstantiated the analysis does not figure out,
57+
// that p_local0 could be const. Not sure why, but probably bails because
58+
// some expressions are type-dependent.
59+
SmallVector<const int *> p_local0;
60+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'SmallVector<const int *>' can be declared 'const'
61+
// CHECK-FIXES: SmallVector<const int *> const p_local0
62+
SmallVector<const int *> np_local0;
63+
for (const auto *I : Methods) {
64+
if (I == nullptr)
65+
np_local0.push_back(I);
66+
}
67+
p_local0.size();
68+
}
69+
void instantiate() {
70+
int *p_local0[4] = {nullptr, nullptr, nullptr, nullptr};
71+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int *[4]' can be declared 'const'
72+
// CHECK-FIXES: int *const p_local0[4]
73+
EmitProtocolMethodList(p_local0);
1374
}

0 commit comments

Comments
 (0)