Skip to content

Commit ccb85fc

Browse files

File tree

63 files changed

+1838
-261
lines changed

Some content is hidden

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

63 files changed

+1838
-261
lines changed

bolt/test/X86/dwarf4-ftypes-dwp-input-dwo-output.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# UNSUPPORTED: system-linux
21
; RUN: rm -rf %t
32
; RUN: mkdir %t
43
; RUN: cd %t

clang-tools-extra/clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,26 @@ void MacroUsageCheck::registerPPCallbacks(const SourceManager &SM,
8282
void MacroUsageCheck::warnMacro(const MacroDirective *MD, StringRef MacroName) {
8383
const MacroInfo *Info = MD->getMacroInfo();
8484
StringRef Message;
85+
bool MacroBodyExpressionLike;
86+
if (Info->getNumTokens() > 0) {
87+
const Token &Tok = Info->getReplacementToken(0);
88+
// Now notice that keywords like `__attribute` cannot be a leading
89+
// token in an expression.
90+
MacroBodyExpressionLike = !Tok.is(tok::kw___attribute);
91+
} else {
92+
MacroBodyExpressionLike = true;
93+
}
8594

8695
if (llvm::all_of(Info->tokens(), std::mem_fn(&Token::isLiteral)))
8796
Message = "macro '%0' used to declare a constant; consider using a "
8897
"'constexpr' constant";
8998
// A variadic macro is function-like at the same time. Therefore variadic
9099
// macros are checked first and will be excluded for the function-like
91100
// diagnostic.
92-
else if (Info->isVariadic())
101+
else if (Info->isVariadic() && MacroBodyExpressionLike)
93102
Message = "variadic macro '%0' used; consider using a 'constexpr' "
94103
"variadic template function";
95-
else if (Info->isFunctionLike())
104+
else if (Info->isFunctionLike() && MacroBodyExpressionLike)
96105
Message = "function-like macro '%0' used; consider a 'constexpr' template "
97106
"function";
98107

clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ void UseScopedLockCheck::diagOnSingleLock(
217217

218218
// Create Fix-its only if we can find the constructor call to properly handle
219219
// 'std::lock_guard l(m, std::adopt_lock)' case.
220-
const auto *CtorCall = dyn_cast<CXXConstructExpr>(LockGuard->getInit());
220+
const auto *CtorCall =
221+
dyn_cast_if_present<CXXConstructExpr>(LockGuard->getInit());
221222
if (!CtorCall)
222223
return;
223224

clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,18 @@ namespace readability {
8383
m(Member) \
8484
m(ClassConstant) \
8585
m(ClassMember) \
86+
m(ClassConstexpr) \
87+
m(GlobalConstexprVariable) \
8688
m(GlobalConstant) \
8789
m(GlobalConstantPointer) \
8890
m(GlobalPointer) \
8991
m(GlobalVariable) \
92+
m(LocalConstexprVariable) \
9093
m(LocalConstant) \
9194
m(LocalConstantPointer) \
9295
m(LocalPointer) \
9396
m(LocalVariable) \
97+
m(StaticConstexprVariable) \
9498
m(StaticConstant) \
9599
m(StaticVariable) \
96100
m(Constant) \
@@ -1497,8 +1501,22 @@ StyleKind IdentifierNamingCheck::findStyleKindForField(
14971501
StyleKind IdentifierNamingCheck::findStyleKindForVar(
14981502
const VarDecl *Var, QualType Type,
14991503
ArrayRef<std::optional<NamingStyle>> NamingStyles) const {
1500-
if (Var->isConstexpr() && NamingStyles[SK_ConstexprVariable])
1501-
return SK_ConstexprVariable;
1504+
if (Var->isConstexpr()) {
1505+
if (Var->isStaticDataMember() && NamingStyles[SK_ClassConstexpr])
1506+
return SK_ClassConstexpr;
1507+
1508+
if (Var->isFileVarDecl() && NamingStyles[SK_GlobalConstexprVariable])
1509+
return SK_GlobalConstexprVariable;
1510+
1511+
if (Var->isStaticLocal() && NamingStyles[SK_StaticConstexprVariable])
1512+
return SK_StaticConstexprVariable;
1513+
1514+
if (Var->isLocalVarDecl() && NamingStyles[SK_LocalConstexprVariable])
1515+
return SK_LocalConstexprVariable;
1516+
1517+
if (NamingStyles[SK_ConstexprVariable])
1518+
return SK_ConstexprVariable;
1519+
}
15021520

15031521
if (!Type.isNull() && Type.isConstQualified()) {
15041522
if (Var->isStaticDataMember() && NamingStyles[SK_ClassConstant])

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ Changes in existing checks
325325
<clang-tidy/checks/cppcoreguidelines/init-variables>` check by fixing the
326326
insertion location for function pointers with multiple parameters.
327327

328+
- Improved :doc:`cppcoreguidelines-macro-usage
329+
<clang-tidy/checks/cppcoreguidelines/macro-usage>` check by excluding macro
330+
bodies that starts with ``__attribute__((..))`` keyword.
331+
Such a macro body is unlikely a proper expression and so suggesting users
332+
an impossible rewrite into a template function should be avoided.
333+
328334
- Improved :doc:`cppcoreguidelines-prefer-member-initializer
329335
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
330336
avoid false positives on inherited members in class templates.
@@ -380,6 +386,11 @@ Changes in existing checks
380386
on Windows when the check was enabled with a 32-bit :program:`clang-tidy`
381387
binary.
382388

389+
- Improved :doc:`modernize-use-scoped-lock
390+
<clang-tidy/checks/modernize/use-scoped-lock>` check by fixing a crash
391+
on malformed code (common when using :program:`clang-tidy` through
392+
:program:`clangd`).
393+
383394
- Improved :doc:`modernize-use-std-format
384395
<clang-tidy/checks/modernize/use-std-format>` check to correctly match
385396
when the format string is converted to a different type by an implicit
@@ -416,7 +427,8 @@ Changes in existing checks
416427
- Improved :doc:`readability-identifier-naming
417428
<clang-tidy/checks/readability/identifier-naming>` check by ignoring
418429
declarations and macros in system headers. The documentation is also improved
419-
to differentiate the general options from the specific ones.
430+
to differentiate the general options from the specific ones. Options for
431+
fine-grained control over ``constexpr`` variables were added.
420432

421433
- Improved :doc:`readability-implicit-bool-conversion
422434
<clang-tidy/checks/readability/implicit-bool-conversion>` check by correctly

clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The available options are summarized below:
5959

6060
- :option:`AbstractClassCase`, :option:`AbstractClassPrefix`, :option:`AbstractClassSuffix`, :option:`AbstractClassIgnoredRegexp`, :option:`AbstractClassHungarianPrefix`
6161
- :option:`ClassCase`, :option:`ClassPrefix`, :option:`ClassSuffix`, :option:`ClassIgnoredRegexp`, :option:`ClassHungarianPrefix`
62+
- :option:`ClassConstexprCase`, :option:`ClassConstexprPrefix`, :option:`ClassConstexprSuffix`, :option:`ClassConstexprIgnoredRegexp`, :option:`ClassConstexprHungarianPrefix`
6263
- :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, :option:`ClassConstantSuffix`, :option:`ClassConstantIgnoredRegexp`, :option:`ClassConstantHungarianPrefix`
6364
- :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, :option:`ClassMemberSuffix`, :option:`ClassMemberIgnoredRegexp`, :option:`ClassMemberHungarianPrefix`
6465
- :option:`ClassMethodCase`, :option:`ClassMethodPrefix`, :option:`ClassMethodSuffix`, :option:`ClassMethodIgnoredRegexp`
@@ -73,12 +74,14 @@ The available options are summarized below:
7374
- :option:`EnumCase`, :option:`EnumPrefix`, :option:`EnumSuffix`, :option:`EnumIgnoredRegexp`
7475
- :option:`EnumConstantCase`, :option:`EnumConstantPrefix`, :option:`EnumConstantSuffix`, :option:`EnumConstantIgnoredRegexp`, :option:`EnumConstantHungarianPrefix`
7576
- :option:`FunctionCase`, :option:`FunctionPrefix`, :option:`FunctionSuffix`, :option:`FunctionIgnoredRegexp`
77+
- :option:`GlobalConstexprVariableCase`, :option:`GlobalConstexprVariablePrefix`, :option:`GlobalConstexprVariableSuffix`, :option:`GlobalConstexprVariableIgnoredRegexp`, :option:`GlobalConstexprVariableHungarianPrefix`
7678
- :option:`GlobalConstantCase`, :option:`GlobalConstantPrefix`, :option:`GlobalConstantSuffix`, :option:`GlobalConstantIgnoredRegexp`, :option:`GlobalConstantHungarianPrefix`
7779
- :option:`GlobalConstantPointerCase`, :option:`GlobalConstantPointerPrefix`, :option:`GlobalConstantPointerSuffix`, :option:`GlobalConstantPointerIgnoredRegexp`, :option:`GlobalConstantPointerHungarianPrefix`
7880
- :option:`GlobalFunctionCase`, :option:`GlobalFunctionPrefix`, :option:`GlobalFunctionSuffix`, :option:`GlobalFunctionIgnoredRegexp`
7981
- :option:`GlobalPointerCase`, :option:`GlobalPointerPrefix`, :option:`GlobalPointerSuffix`, :option:`GlobalPointerIgnoredRegexp`, :option:`GlobalPointerHungarianPrefix`
8082
- :option:`GlobalVariableCase`, :option:`GlobalVariablePrefix`, :option:`GlobalVariableSuffix`, :option:`GlobalVariableIgnoredRegexp`, :option:`GlobalVariableHungarianPrefix`
8183
- :option:`InlineNamespaceCase`, :option:`InlineNamespacePrefix`, :option:`InlineNamespaceSuffix`, :option:`InlineNamespaceIgnoredRegexp`
84+
- :option:`LocalConstexprVariableCase`, :option:`LocalConstexprVariablePrefix`, :option:`LocalConstexprVariableSuffix`, :option:`LocalConstexprVariableIgnoredRegexp`, :option:`LocalConstexprVariableHungarianPrefix`
8285
- :option:`LocalConstantCase`, :option:`LocalConstantPrefix`, :option:`LocalConstantSuffix`, :option:`LocalConstantIgnoredRegexp`, :option:`LocalConstantHungarianPrefix`
8386
- :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, :option:`LocalConstantPointerSuffix`, :option:`LocalConstantPointerIgnoredRegexp`, :option:`LocalConstantPointerHungarianPrefix`
8487
- :option:`LocalPointerCase`, :option:`LocalPointerPrefix`, :option:`LocalPointerSuffix`, :option:`LocalPointerIgnoredRegexp`, :option:`LocalPointerHungarianPrefix`
@@ -97,6 +100,7 @@ The available options are summarized below:
97100
- :option:`PublicMemberCase`, :option:`PublicMemberPrefix`, :option:`PublicMemberSuffix`, :option:`PublicMemberIgnoredRegexp`, :option:`PublicMemberHungarianPrefix`
98101
- :option:`PublicMethodCase`, :option:`PublicMethodPrefix`, :option:`PublicMethodSuffix`, :option:`PublicMethodIgnoredRegexp`
99102
- :option:`ScopedEnumConstantCase`, :option:`ScopedEnumConstantPrefix`, :option:`ScopedEnumConstantSuffix`, :option:`ScopedEnumConstantIgnoredRegexp`
103+
- :option:`StaticConstexprVariableCase`, :option:`StaticConstexprVariablePrefix`, :option:`StaticConstexprVariableSuffix`, :option:`StaticConstexprVariableIgnoredRegexp`, :option:`StaticConstexprVariableHungarianPrefix`
100104
- :option:`StaticConstantCase`, :option:`StaticConstantPrefix`, :option:`StaticConstantSuffix`, :option:`StaticConstantIgnoredRegexp`, :option:`StaticConstantHungarianPrefix`
101105
- :option:`StaticVariableCase`, :option:`StaticVariablePrefix`, :option:`StaticVariableSuffix`, :option:`StaticVariableIgnoredRegexp`, :option:`StaticVariableHungarianPrefix`
102106
- :option:`StructCase`, :option:`StructPrefix`, :option:`StructSuffix`, :option:`StructIgnoredRegexp`
@@ -307,6 +311,58 @@ After:
307311
~pre_foo_post();
308312
};
309313

314+
.. option:: ClassConstexprCase
315+
316+
When defined, the check will ensure class ``constexpr`` names conform to
317+
the selected casing.
318+
319+
.. option:: ClassConstexprPrefix
320+
321+
When defined, the check will ensure class ``constexpr`` names will add the
322+
prefixed with the given value (regardless of casing).
323+
324+
.. option:: ClassConstexprIgnoredRegexp
325+
326+
Identifier naming checks won't be enforced for class ``constexpr`` names
327+
matching this regular expression.
328+
329+
.. option:: ClassConstexprSuffix
330+
331+
When defined, the check will ensure class ``constexpr`` names will add the
332+
suffix with the given value (regardless of casing).
333+
334+
.. option:: ClassConstexprHungarianPrefix
335+
336+
When enabled, the check ensures that the declared identifier will have a
337+
Hungarian notation prefix based on the declared type.
338+
339+
For example using values of:
340+
341+
- ClassConstexprCase of ``lower_case``
342+
- ClassConstexprPrefix of ``pre_``
343+
- ClassConstexprSuffix of ``_post``
344+
- ClassConstexprHungarianPrefix of ``On``
345+
346+
Identifies and/or transforms class ``constexpr`` variable names as follows:
347+
348+
Before:
349+
350+
.. code-block:: c++
351+
352+
class FOO {
353+
public:
354+
static constexpr int CLASS_CONSTEXPR;
355+
};
356+
357+
After:
358+
359+
.. code-block:: c++
360+
361+
class FOO {
362+
public:
363+
static const int pre_class_constexpr_post;
364+
};
365+
310366
.. option:: ClassConstantCase
311367

312368
When defined, the check will ensure class constant names conform to the
@@ -950,6 +1006,52 @@ After:
9501006
different style.
9511007
Default value is `true`.
9521008

1009+
.. option:: GlobalConstexprVariableCase
1010+
1011+
When defined, the check will ensure global ``constexpr`` variable names
1012+
conform to the selected casing.
1013+
1014+
.. option:: GlobalConstexprVariablePrefix
1015+
1016+
When defined, the check will ensure global ``constexpr`` variable names
1017+
will add the prefixed with the given value (regardless of casing).
1018+
1019+
.. option:: GlobalConstexprVariableIgnoredRegexp
1020+
1021+
Identifier naming checks won't be enforced for global ``constexpr``
1022+
variable names matching this regular expression.
1023+
1024+
.. option:: GlobalConstexprVariableSuffix
1025+
1026+
When defined, the check will ensure global ``constexpr`` variable names
1027+
will add the suffix with the given value (regardless of casing).
1028+
1029+
.. option:: GlobalConstexprVariableHungarianPrefix
1030+
1031+
When enabled, the check ensures that the declared identifier will have a
1032+
Hungarian notation prefix based on the declared type.
1033+
1034+
For example using values of:
1035+
1036+
- GlobalConstexprVariableCase of ``lower_case``
1037+
- GlobalConstexprVariablePrefix of ``pre_``
1038+
- GlobalConstexprVariableSuffix of ``_post``
1039+
- GlobalConstexprVariableHungarianPrefix of ``On``
1040+
1041+
Identifies and/or transforms global ``constexpr`` variable names as follows:
1042+
1043+
Before:
1044+
1045+
.. code-block:: c++
1046+
1047+
constexpr unsigned ImportantValue = 69;
1048+
1049+
After:
1050+
1051+
.. code-block:: c++
1052+
1053+
constexpr unsigned pre_important_value_post = 69;
1054+
9531055
.. option:: GlobalConstantCase
9541056

9551057
When defined, the check will ensure global constant names conform to the
@@ -1228,6 +1330,52 @@ After:
12281330
}
12291331
} // namespace FOO_NS
12301332

1333+
.. option:: LocalConstexprVariableCase
1334+
1335+
When defined, the check will ensure local ``constexpr`` variable names
1336+
conform to the selected casing.
1337+
1338+
.. option:: LocalConstexprVariablePrefix
1339+
1340+
When defined, the check will ensure local ``constexpr`` variable names will
1341+
add the prefixed with the given value (regardless of casing).
1342+
1343+
.. option:: LocalConstexprVariableIgnoredRegexp
1344+
1345+
Identifier naming checks won't be enforced for local ``constexpr`` variable
1346+
names matching this regular expression.
1347+
1348+
.. option:: LocalConstexprVariableSuffix
1349+
1350+
When defined, the check will ensure local ``constexpr`` variable names will
1351+
add the suffix with the given value (regardless of casing).
1352+
1353+
.. option:: LocalConstexprVariableHungarianPrefix
1354+
1355+
When enabled, the check ensures that the declared identifier will have a
1356+
Hungarian notation prefix based on the declared type.
1357+
1358+
For example using values of:
1359+
1360+
- LocalConstexprVariableCase of ``lower_case``
1361+
- LocalConstexprVariablePrefix of ``pre_``
1362+
- LocalConstexprVariableSuffix of ``_post``
1363+
- LocalConstexprVariableHungarianPrefix of ``On``
1364+
1365+
Identifies and/or transforms local ``constexpr`` variable names as follows:
1366+
1367+
Before:
1368+
1369+
.. code-block:: c++
1370+
1371+
void foo() { int const local_Constexpr = 420; }
1372+
1373+
After:
1374+
1375+
.. code-block:: c++
1376+
1377+
void foo() { int const pre_local_constexpr_post = 420; }
1378+
12311379
.. option:: LocalConstantCase
12321380

12331381
When defined, the check will ensure local constant names conform to the
@@ -2077,6 +2225,52 @@ After:
20772225

20782226
enum class FOO { pre_One_post, pre_Two_post, pre_Three_post };
20792227

2228+
.. option:: StaticConstexprVariableCase
2229+
2230+
When defined, the check will ensure static ``constexpr`` variable names
2231+
conform to the selected casing.
2232+
2233+
.. option:: StaticConstexprVariablePrefix
2234+
2235+
When defined, the check will ensure static ``constexpr`` variable names
2236+
will add the prefixed with the given value (regardless of casing).
2237+
2238+
.. option:: StaticConstexprVariableIgnoredRegexp
2239+
2240+
Identifier naming checks won't be enforced for static ``constexpr``
2241+
variable names matching this regular expression.
2242+
2243+
.. option:: StaticConstexprVariableSuffix
2244+
2245+
When defined, the check will ensure static ``constexpr`` variable names
2246+
will add the suffix with the given value (regardless of casing).
2247+
2248+
.. option:: StaticConstexprVariableHungarianPrefix
2249+
2250+
When enabled, the check ensures that the declared identifier will have a
2251+
Hungarian notation prefix based on the declared type.
2252+
2253+
For example using values of:
2254+
2255+
- StaticConstexprVariableCase of ``lower_case``
2256+
- StaticConstexprVariablePrefix of ``pre_``
2257+
- StaticConstexprVariableSuffix of ``_post``
2258+
- StaticConstexprVariableHungarianPrefix of ``On``
2259+
2260+
Identifies and/or transforms static ``constexpr`` variable names as follows:
2261+
2262+
Before:
2263+
2264+
.. code-block:: c++
2265+
2266+
static unsigned constexpr MyConstexprStatic_array[] = {1, 2, 3};
2267+
2268+
After:
2269+
2270+
.. code-block:: c++
2271+
2272+
static unsigned constexpr pre_my_constexpr_static_array_post[] = {1, 2, 3};
2273+
20802274
.. option:: StaticConstantCase
20812275

20822276
When defined, the check will ensure static constant names conform to the

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/macro-usage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@
4747
#define DLLEXPORTS __declspec(dllimport)
4848
#endif
4949

50+
#define ATTRIBUTE_MACRO(...) __attribute__(__VA_ARGS__)
51+
5052
#endif
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %check_clang_tidy -std=c++17-or-later -expect-clang-tidy-error %s modernize-use-scoped-lock %t -- -- -isystem %clang_tidy_headers
2+
3+
#include <mutex>
4+
5+
void f() {
6+
std::lock_guard<std::mutex> dont_crash {some_nonexistant_variable};
7+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'std::scoped_lock' instead of 'std::lock_guard' [modernize-use-scoped-lock]
8+
// CHECK-MESSAGES: :[[@LINE-2]]:43: error: use of undeclared identifier 'some_nonexistant_variable' [clang-diagnostic-error]
9+
}

0 commit comments

Comments
 (0)