Skip to content

Commit 3376c14

Browse files
committed
Merge commit '8b7cc93e9dc7e4e3b3a5cb014fa8d047c47f4818' into llvmspirv_pulldown
2 parents 4346e1e + 8b7cc93 commit 3376c14

File tree

181 files changed

+20104
-2624
lines changed

Some content is hidden

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

181 files changed

+20104
-2624
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,29 @@ namespace clang {
1919
namespace tidy {
2020
namespace cppcoreguidelines {
2121

22+
AST_MATCHER(CXXRecordDecl, hasPublicVirtualOrProtectedNonVirtualDestructor) {
23+
// We need to call Node.getDestructor() instead of matching a
24+
// CXXDestructorDecl. Otherwise, tests will fail for class templates, since
25+
// the primary template (not the specialization) always gets a non-virtual
26+
// CXXDestructorDecl in the AST. https://bugs.llvm.org/show_bug.cgi?id=51912
27+
const CXXDestructorDecl *Destructor = Node.getDestructor();
28+
if (!Destructor)
29+
return false;
30+
31+
return (((Destructor->getAccess() == AccessSpecifier::AS_public) &&
32+
Destructor->isVirtual()) ||
33+
((Destructor->getAccess() == AccessSpecifier::AS_protected) &&
34+
!Destructor->isVirtual()));
35+
}
36+
2237
void VirtualClassDestructorCheck::registerMatchers(MatchFinder *Finder) {
2338
ast_matchers::internal::Matcher<CXXRecordDecl> InheritsVirtualMethod =
2439
hasAnyBase(hasType(cxxRecordDecl(has(cxxMethodDecl(isVirtual())))));
2540

2641
Finder->addMatcher(
2742
cxxRecordDecl(
2843
anyOf(has(cxxMethodDecl(isVirtual())), InheritsVirtualMethod),
29-
unless(anyOf(
30-
has(cxxDestructorDecl(isPublic(), isVirtual())),
31-
has(cxxDestructorDecl(isProtected(), unless(isVirtual()))))))
44+
unless(hasPublicVirtualOrProtectedNonVirtualDestructor()))
3245
.bind("ProblematicClassOrStruct"),
3346
this);
3447
}

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-virtual-class-destructor.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,73 @@ struct NonOverridingDerivedStruct : ProtectedNonVirtualBaseStruct {
202202
void m();
203203
};
204204
// inherits virtual method
205+
206+
namespace Bugzilla_51912 {
207+
// Fixes https://bugs.llvm.org/show_bug.cgi?id=51912
208+
209+
// Forward declarations
210+
// CHECK-MESSAGES-NOT: :[[@LINE+1]]:8: warning: destructor of 'ForwardDeclaredStruct' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
211+
struct ForwardDeclaredStruct;
212+
213+
struct ForwardDeclaredStruct : PublicVirtualBaseStruct {
214+
};
215+
216+
// Normal Template
217+
// CHECK-MESSAGES-NOT: :[[@LINE+2]]:8: warning: destructor of 'TemplatedDerived' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
218+
template <typename T>
219+
struct TemplatedDerived : PublicVirtualBaseStruct {
220+
};
221+
222+
TemplatedDerived<int> InstantiationWithInt;
223+
224+
// Derived from template, base has virtual dtor
225+
// CHECK-MESSAGES-NOT: :[[@LINE+2]]:8: warning: destructor of 'DerivedFromTemplateVirtualBaseStruct' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
226+
template <typename T>
227+
struct DerivedFromTemplateVirtualBaseStruct : T {
228+
virtual void foo();
229+
};
230+
231+
DerivedFromTemplateVirtualBaseStruct<PublicVirtualBaseStruct> InstantiationWithPublicVirtualBaseStruct;
232+
233+
// Derived from template, base has *not* virtual dtor
234+
// CHECK-MESSAGES: :[[@LINE+8]]:8: warning: destructor of 'DerivedFromTemplateNonVirtualBaseStruct' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
235+
// CHECK-MESSAGES: :[[@LINE+7]]:8: note: make it public and virtual
236+
// CHECK-MESSAGES: :[[@LINE+6]]:8: warning: destructor of 'DerivedFromTemplateNonVirtualBaseStruct<PublicNonVirtualBaseStruct>' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
237+
// CHECK-FIXES: struct DerivedFromTemplateNonVirtualBaseStruct : T {
238+
// CHECK-FIXES-NEXT: virtual ~DerivedFromTemplateNonVirtualBaseStruct() = default;
239+
// CHECK-FIXES-NEXT: virtual void foo();
240+
// CHECK-FIXES-NEXT: };
241+
template <typename T>
242+
struct DerivedFromTemplateNonVirtualBaseStruct : T {
243+
virtual void foo();
244+
};
245+
246+
DerivedFromTemplateNonVirtualBaseStruct<PublicNonVirtualBaseStruct> InstantiationWithPublicNonVirtualBaseStruct;
247+
248+
// Derived from template, base has virtual dtor, to be used in a typedef
249+
// CHECK-MESSAGES-NOT: :[[@LINE+2]]:8: warning: destructor of 'DerivedFromTemplateVirtualBaseStruct2' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
250+
template <typename T>
251+
struct DerivedFromTemplateVirtualBaseStruct2 : T {
252+
virtual void foo();
253+
};
254+
255+
using DerivedFromTemplateVirtualBaseStruct2Typedef = DerivedFromTemplateVirtualBaseStruct2<PublicVirtualBaseStruct>;
256+
DerivedFromTemplateVirtualBaseStruct2Typedef InstantiationWithPublicVirtualBaseStruct2;
257+
258+
// Derived from template, base has *not* virtual dtor, to be used in a typedef
259+
// CHECK-MESSAGES: :[[@LINE+8]]:8: warning: destructor of 'DerivedFromTemplateNonVirtualBaseStruct2' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
260+
// CHECK-MESSAGES: :[[@LINE+7]]:8: note: make it public and virtual
261+
// CHECK-MESSAGES: :[[@LINE+6]]:8: warning: destructor of 'DerivedFromTemplateNonVirtualBaseStruct2<PublicNonVirtualBaseStruct>' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]
262+
// CHECK-FIXES: struct DerivedFromTemplateNonVirtualBaseStruct2 : T {
263+
// CHECK-FIXES-NEXT: virtual ~DerivedFromTemplateNonVirtualBaseStruct2() = default;
264+
// CHECK-FIXES-NEXT: virtual void foo();
265+
// CHECK-FIXES-NEXT: };
266+
template <typename T>
267+
struct DerivedFromTemplateNonVirtualBaseStruct2 : T {
268+
virtual void foo();
269+
};
270+
271+
using DerivedFromTemplateNonVirtualBaseStruct2Typedef = DerivedFromTemplateNonVirtualBaseStruct2<PublicNonVirtualBaseStruct>;
272+
DerivedFromTemplateNonVirtualBaseStruct2Typedef InstantiationWithPublicNonVirtualBaseStruct2;
273+
274+
} // namespace Bugzilla_51912

clang/docs/ReleaseNotes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ Attribute Changes in Clang
110110
attribute is handled instead, e.g. in ``handleDeclAttribute``.
111111
(This was changed in order to better support attributes in code completion).
112112

113+
- __has_cpp_attribute, __has_c_attribute, __has_attribute, and __has_declspec
114+
will now macro expand their argument. This causes a change in behavior for
115+
code using ``__has_cpp_attribute(__clang__::attr)`` (and same for
116+
``__has_c_attribute``) where it would previously expand to ``0`` for all
117+
attributes, but will now issue an error due to the expansion of the
118+
predefined ``__clang__`` macro.
119+
113120
Windows Support
114121
---------------
115122

@@ -122,6 +129,9 @@ Windows Support
122129
C Language Changes in Clang
123130
---------------------------
124131

132+
- The value of ``__STDC_VERSION__`` has been bumped to ``202000L`` when passing
133+
``-std=c2x`` so that it can be distinguished from C17 mode. This value is
134+
expected to change again when C23 is published.
125135
- Wide multi-characters literals such as ``L'ab'`` that would previously be interpreted as ``L'b'``
126136
are now ill-formed in all language modes. The motivation for this change is outlined in
127137
`P2362 <wg21.link/P2362>`_.

clang/include/clang/ASTMatchers/ASTMatchersInternal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ class BoundNodesTreeBuilder {
312312

313313
template <typename ExcludePredicate>
314314
bool removeBindings(const ExcludePredicate &Predicate) {
315-
Bindings.erase(std::remove_if(Bindings.begin(), Bindings.end(), Predicate),
316-
Bindings.end());
315+
llvm::erase_if(Bindings, Predicate);
317316
return !Bindings.empty();
318317
}
319318

clang/include/clang/Analysis/Analyses/Dominators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ struct ChildrenGetterTy<clang::CFGBlock, IsPostDom> {
202202

203203
auto Children = children<OrderedNodeTy>(N);
204204
ChildrenTy Ret{Children.begin(), Children.end()};
205-
Ret.erase(std::remove(Ret.begin(), Ret.end(), nullptr), Ret.end());
205+
llvm::erase_value(Ret, nullptr);
206206
return Ret;
207207
}
208208
};

clang/include/clang/Analysis/CloneDetection.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ class CloneConstraint {
235235
static void filterGroups(
236236
std::vector<CloneDetector::CloneGroup> &CloneGroups,
237237
llvm::function_ref<bool(const CloneDetector::CloneGroup &)> Filter) {
238-
CloneGroups.erase(
239-
std::remove_if(CloneGroups.begin(), CloneGroups.end(), Filter),
240-
CloneGroups.end());
238+
llvm::erase_if(CloneGroups, Filter);
241239
}
242240

243241
/// Splits the given CloneGroups until the given Compare function returns true

clang/include/clang/Basic/DiagnosticCommonKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ def err_opt_not_valid_without_opt : Error<
306306
"option '%0' cannot be specified without '%1'">;
307307
def err_opt_not_valid_on_target : Error<
308308
"option '%0' cannot be specified on this target">;
309+
def err_invalid_feature_combination : Error<
310+
"invalid feature combination: %0">;
309311

310312
// Source manager
311313
def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;

clang/include/clang/Basic/JsonSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ inline std::string JsonFormat(StringRef RawSR, bool AddQuotes) {
7070
}
7171

7272
// Remove new-lines.
73-
Str.erase(std::remove(Str.begin(), Str.end(), '\n'), Str.end());
73+
llvm::erase_value(Str, '\n');
7474

7575
if (!AddQuotes)
7676
return Str;

clang/include/clang/Sema/ScopeInfo.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,10 +1001,7 @@ class LambdaScopeInfo final :
10011001
return NonODRUsedCapturingExprs.count(CapturingVarExpr);
10021002
}
10031003
void removePotentialCapture(Expr *E) {
1004-
PotentiallyCapturingExprs.erase(
1005-
std::remove(PotentiallyCapturingExprs.begin(),
1006-
PotentiallyCapturingExprs.end(), E),
1007-
PotentiallyCapturingExprs.end());
1004+
llvm::erase_value(PotentiallyCapturingExprs, E);
10081005
}
10091006
void clearPotentialCaptures() {
10101007
PotentiallyCapturingExprs.clear();

clang/lib/AST/ASTContext.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ void ASTContext::deduplicateMergedDefinitonsFor(NamedDecl *ND) {
11251125
for (Module *&M : Merged)
11261126
if (!Found.insert(M).second)
11271127
M = nullptr;
1128-
Merged.erase(std::remove(Merged.begin(), Merged.end(), nullptr), Merged.end());
1128+
llvm::erase_value(Merged, nullptr);
11291129
}
11301130

11311131
ArrayRef<Module *>
@@ -9222,13 +9222,9 @@ void getIntersectionOfProtocols(ASTContext &Context,
92229222

92239223
// Remove any implied protocols from the list of inherited protocols.
92249224
if (!ImpliedProtocols.empty()) {
9225-
IntersectionSet.erase(
9226-
std::remove_if(IntersectionSet.begin(),
9227-
IntersectionSet.end(),
9228-
[&](ObjCProtocolDecl *proto) -> bool {
9229-
return ImpliedProtocols.count(proto) > 0;
9230-
}),
9231-
IntersectionSet.end());
9225+
llvm::erase_if(IntersectionSet, [&](ObjCProtocolDecl *proto) -> bool {
9226+
return ImpliedProtocols.count(proto) > 0;
9227+
});
92329228
}
92339229

92349230
// Sort the remaining protocols by name.
@@ -11760,13 +11756,9 @@ ASTContext::filterFunctionTargetAttrs(const TargetAttr *TD) const {
1176011756
assert(TD != nullptr);
1176111757
ParsedTargetAttr ParsedAttr = TD->parse();
1176211758

11763-
ParsedAttr.Features.erase(
11764-
llvm::remove_if(ParsedAttr.Features,
11765-
[&](const std::string &Feat) {
11766-
return !Target->isValidFeatureName(
11767-
StringRef{Feat}.substr(1));
11768-
}),
11769-
ParsedAttr.Features.end());
11759+
llvm::erase_if(ParsedAttr.Features, [&](const std::string &Feat) {
11760+
return !Target->isValidFeatureName(StringRef{Feat}.substr(1));
11761+
});
1177011762
return ParsedAttr;
1177111763
}
1177211764

0 commit comments

Comments
 (0)