Skip to content

Commit 290c27c

Browse files
committed
Merge from 'main' to 'sycl-web' (27 commits)
CONFLICT (content): Merge conflict in clang/lib/Driver/ToolChains/AMDGPU.cpp CONFLICT (content): Merge conflict in clang/lib/Driver/ToolChains/HIPAMD.cpp
2 parents 957154e + b68b4f6 commit 290c27c

File tree

91 files changed

+2464
-753
lines changed

Some content is hidden

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

91 files changed

+2464
-753
lines changed

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

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,32 @@ void UnsafeFunctionsCheck::registerMatchers(MatchFinder *Finder) {
256256
.bind(CustomFunctionNamesId)))
257257
.bind(DeclRefId),
258258
this);
259+
// C++ member calls do not contain a DeclRefExpr to the function decl.
260+
// Instead, they contain a MemberExpr that refers to the decl.
261+
Finder->addMatcher(memberExpr(member(functionDecl(CustomFunctionsMatcher)
262+
.bind(CustomFunctionNamesId)))
263+
.bind(DeclRefId),
264+
this);
259265
}
260266
}
261267

262268
void UnsafeFunctionsCheck::check(const MatchFinder::MatchResult &Result) {
263-
const auto *DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>(DeclRefId);
264-
const auto *FuncDecl = cast<FunctionDecl>(DeclRef->getDecl());
265-
assert(DeclRef && FuncDecl && "No valid matched node in check()");
269+
const Expr *SourceExpr;
270+
const FunctionDecl *FuncDecl;
271+
272+
if (const auto *DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>(DeclRefId)) {
273+
SourceExpr = DeclRef;
274+
FuncDecl = cast<FunctionDecl>(DeclRef->getDecl());
275+
} else if (const auto *Member =
276+
Result.Nodes.getNodeAs<MemberExpr>(DeclRefId)) {
277+
SourceExpr = Member;
278+
FuncDecl = cast<FunctionDecl>(Member->getMemberDecl());
279+
} else {
280+
llvm_unreachable("No valid matched node in check()");
281+
return;
282+
}
283+
284+
assert(SourceExpr && FuncDecl && "No valid matched node in check()");
266285

267286
// Only one of these are matched at a time.
268287
const auto *AnnexK = Result.Nodes.getNodeAs<FunctionDecl>(
@@ -286,14 +305,15 @@ void UnsafeFunctionsCheck::check(const MatchFinder::MatchResult &Result) {
286305
Entry.Reason.empty() ? "is marked as unsafe" : Entry.Reason.c_str();
287306

288307
if (Entry.Replacement.empty()) {
289-
diag(DeclRef->getExprLoc(), "function %0 %1; it should not be used")
308+
diag(SourceExpr->getExprLoc(),
309+
"function %0 %1; it should not be used")
290310
<< FuncDecl << Reason << Entry.Replacement
291-
<< DeclRef->getSourceRange();
311+
<< SourceExpr->getSourceRange();
292312
} else {
293-
diag(DeclRef->getExprLoc(),
313+
diag(SourceExpr->getExprLoc(),
294314
"function %0 %1; '%2' should be used instead")
295315
<< FuncDecl << Reason << Entry.Replacement
296-
<< DeclRef->getSourceRange();
316+
<< SourceExpr->getSourceRange();
297317
}
298318

299319
return;
@@ -323,9 +343,9 @@ void UnsafeFunctionsCheck::check(const MatchFinder::MatchResult &Result) {
323343
if (!ReplacementFunctionName)
324344
return;
325345

326-
diag(DeclRef->getExprLoc(), "function %0 %1; '%2' should be used instead")
346+
diag(SourceExpr->getExprLoc(), "function %0 %1; '%2' should be used instead")
327347
<< FuncDecl << getRationaleFor(FunctionName)
328-
<< ReplacementFunctionName.value() << DeclRef->getSourceRange();
348+
<< ReplacementFunctionName.value() << SourceExpr->getSourceRange();
329349
}
330350

331351
void UnsafeFunctionsCheck::registerPPCallbacks(

clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class UnsafeFunctionsCheck : public ClangTidyCheck {
4343
private:
4444
const std::vector<CheckedFunction> CustomFunctions;
4545

46-
// If true, the default set of functions are reported.
46+
/// If true, the default set of functions are reported.
4747
const bool ReportDefaultFunctions;
4848
/// If true, additional functions from widely used API-s (such as POSIX) are
4949
/// added to the list of reported functions.

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ New check aliases
9797
Changes in existing checks
9898
^^^^^^^^^^^^^^^^^^^^^^^^^^
9999

100+
- Improved :doc:`bugprone-unsafe-functions
101+
<clang-tidy/checks/bugprone/unsafe-functions>` check to allow specifying
102+
additional C++ member functions to match.
103+
100104
Removed checks
101105
^^^^^^^^^^^^^^
102106

clang-tools-extra/docs/clang-tidy/checks/bugprone/unsafe-functions.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ qualified name (i.e. ``std::original``), otherwise the regex is matched against
114114
If the regular expression starts with `::` (or `^::`), it is matched against the
115115
fully qualified name (``::std::original``).
116116

117+
.. note::
118+
119+
Fully qualified names can contain template parameters on certain C++ classes, but not on C++ functions.
120+
Type aliases are resolved before matching.
121+
122+
As an example, the member function ``open`` in the class ``std::ifstream``
123+
has a fully qualified name of ``::std::basic_ifstream<char>::open``.
124+
125+
The example could also be matched with the regex ``::std::basic_ifstream<[^>]*>::open``, which matches all potential
126+
template parameters, but does not match nested template classes.
127+
117128
Options
118129
-------
119130

clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions-custom-regex.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
// RUN: %check_clang_tidy -check-suffix=NON-STRICT-REGEX %s bugprone-unsafe-functions %t --\
2-
// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.CustomFunctions: '::name_match,replacement,is a qualname match;^::prefix_match,,is matched on qualname prefix'}}"
2+
// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.CustomFunctions: '::name_match,replacement,is a qualname match;^::prefix_match,,is matched on qualname prefix;^::S::member_match_,,is matched on a C++ class member'}}"
33
// RUN: %check_clang_tidy -check-suffix=STRICT-REGEX %s bugprone-unsafe-functions %t --\
4-
// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.CustomFunctions: '^name_match$,replacement,is matched on function name only;^::prefix_match$,,is a full qualname match'}}"
4+
// RUN: -config="{CheckOptions: {bugprone-unsafe-functions.CustomFunctions: '^name_match$,replacement,is matched on function name only;^::prefix_match$,,is a full qualname match;^::S::member_match_1$,,is matched on a C++ class member'}}"
55

66
void name_match();
77
void prefix_match();
88

9+
struct S {
10+
static void member_match_1() {}
11+
void member_match_2() {}
12+
};
13+
14+
void member_match_1() {}
15+
void member_match_unmatched() {}
16+
917
namespace regex_test {
1018
void name_match();
1119
void prefix_match();
@@ -42,3 +50,25 @@ void f1() {
4250
// CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'prefix_match_regex' is matched on qualname prefix; it should not be used
4351
// no-warning STRICT-REGEX
4452
}
53+
54+
void f2() {
55+
S s;
56+
57+
S::member_match_1();
58+
// CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:3: warning: function 'member_match_1' is matched on a C++ class member; it should not be used
59+
// CHECK-MESSAGES-STRICT-REGEX: :[[@LINE-2]]:3: warning: function 'member_match_1' is matched on a C++ class member; it should not be used
60+
61+
s.member_match_1();
62+
// CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:5: warning: function 'member_match_1' is matched on a C++ class member; it should not be used
63+
// CHECK-MESSAGES-STRICT-REGEX: :[[@LINE-2]]:5: warning: function 'member_match_1' is matched on a C++ class member; it should not be used
64+
65+
s.member_match_2();
66+
// CHECK-MESSAGES-NON-STRICT-REGEX: :[[@LINE-1]]:5: warning: function 'member_match_2' is matched on a C++ class member; it should not be used
67+
// no-warning STRICT-REGEX
68+
69+
member_match_1();
70+
// no-warning
71+
72+
member_match_unmatched();
73+
// no-warning
74+
}

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ Bug Fixes to Attribute Support
128128
Bug Fixes to C++ Support
129129
^^^^^^^^^^^^^^^^^^^^^^^^
130130

131-
- Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
132-
133131
Bug Fixes to AST Handling
134132
^^^^^^^^^^^^^^^^^^^^^^^^^
135133

clang/include/clang/AST/Decl.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,13 +2299,6 @@ class FunctionDecl : public DeclaratorDecl,
22992299
FunctionDeclBits.IsLateTemplateParsed = ILT;
23002300
}
23012301

2302-
bool isInstantiatedFromMemberTemplate() const {
2303-
return FunctionDeclBits.IsInstantiatedFromMemberTemplate;
2304-
}
2305-
void setInstantiatedFromMemberTemplate(bool Val = true) {
2306-
FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val;
2307-
}
2308-
23092302
/// Whether this function is "trivial" in some specialized C++ senses.
23102303
/// Can only be true for default constructors, copy constructors,
23112304
/// copy assignment operators, and destructors. Not meaningful until

clang/include/clang/AST/DeclBase.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,8 +1777,6 @@ class DeclContext {
17771777
uint64_t HasImplicitReturnZero : 1;
17781778
LLVM_PREFERRED_TYPE(bool)
17791779
uint64_t IsLateTemplateParsed : 1;
1780-
LLVM_PREFERRED_TYPE(bool)
1781-
uint64_t IsInstantiatedFromMemberTemplate : 1;
17821780

17831781
/// Kind of contexpr specifier as defined by ConstexprSpecKind.
17841782
LLVM_PREFERRED_TYPE(ConstexprSpecKind)
@@ -1829,7 +1827,7 @@ class DeclContext {
18291827
};
18301828

18311829
/// Number of inherited and non-inherited bits in FunctionDeclBitfields.
1832-
enum { NumFunctionDeclBits = NumDeclContextBits + 32 };
1830+
enum { NumFunctionDeclBits = NumDeclContextBits + 31 };
18331831

18341832
/// Stores the bits used by CXXConstructorDecl. If modified
18351833
/// NumCXXConstructorDeclBits and the accessor
@@ -1840,12 +1838,12 @@ class DeclContext {
18401838
LLVM_PREFERRED_TYPE(FunctionDeclBitfields)
18411839
uint64_t : NumFunctionDeclBits;
18421840

1843-
/// 19 bits to fit in the remaining available space.
1841+
/// 20 bits to fit in the remaining available space.
18441842
/// Note that this makes CXXConstructorDeclBitfields take
18451843
/// exactly 64 bits and thus the width of NumCtorInitializers
18461844
/// will need to be shrunk if some bit is added to NumDeclContextBitfields,
18471845
/// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
1848-
uint64_t NumCtorInitializers : 16;
1846+
uint64_t NumCtorInitializers : 17;
18491847
LLVM_PREFERRED_TYPE(bool)
18501848
uint64_t IsInheritingConstructor : 1;
18511849

@@ -1859,7 +1857,7 @@ class DeclContext {
18591857
};
18601858

18611859
/// Number of inherited and non-inherited bits in CXXConstructorDeclBitfields.
1862-
enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 19 };
1860+
enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 20 };
18631861

18641862
/// Stores the bits used by ObjCMethodDecl.
18651863
/// If modified NumObjCMethodDeclBits and the accessor

clang/include/clang/AST/DeclTemplate.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,15 +1011,6 @@ class FunctionTemplateDecl : public RedeclarableTemplateDecl {
10111011
return getTemplatedDecl()->isThisDeclarationADefinition();
10121012
}
10131013

1014-
bool isCompatibleWithDefinition() const {
1015-
return getTemplatedDecl()->isInstantiatedFromMemberTemplate() ||
1016-
isThisDeclarationADefinition();
1017-
}
1018-
void setInstantiatedFromMemberTemplate(FunctionTemplateDecl *D) {
1019-
getTemplatedDecl()->setInstantiatedFromMemberTemplate();
1020-
RedeclarableTemplateDecl::setInstantiatedFromMemberTemplate(D);
1021-
}
1022-
10231014
/// Return the specialization with the provided arguments if it exists,
10241015
/// otherwise return the insertion point.
10251016
FunctionDecl *findSpecialization(ArrayRef<TemplateArgument> Args,

clang/lib/AST/Decl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3069,7 +3069,6 @@ FunctionDecl::FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC,
30693069
FunctionDeclBits.IsIneligibleOrNotSelected = false;
30703070
FunctionDeclBits.HasImplicitReturnZero = false;
30713071
FunctionDeclBits.IsLateTemplateParsed = false;
3072-
FunctionDeclBits.IsInstantiatedFromMemberTemplate = false;
30733072
FunctionDeclBits.ConstexprKind = static_cast<uint64_t>(ConstexprKind);
30743073
FunctionDeclBits.BodyContainsImmediateEscalatingExpression = false;
30753074
FunctionDeclBits.InstantiationIsPending = false;

0 commit comments

Comments
 (0)