Skip to content

Commit 5178e46

Browse files
authored
merge main into amd-staging (llvm#3077)
2 parents 77e3b07 + e331331 commit 5178e46

File tree

76 files changed

+715
-264
lines changed

Some content is hidden

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

76 files changed

+715
-264
lines changed

clang-tools-extra/clang-tidy/llvm/PreferStaticOverAnonymousNamespaceCheck.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ AST_MATCHER(NamedDecl, isInMacro) {
2121

2222
AST_MATCHER(VarDecl, isLocalVariable) { return Node.isLocalVarDecl(); }
2323

24+
AST_MATCHER(Decl, isLexicallyInAnonymousNamespace) {
25+
for (const DeclContext *DC = Node.getLexicalDeclContext(); DC != nullptr;
26+
DC = DC->getLexicalParent()) {
27+
if (const auto *ND = dyn_cast<NamespaceDecl>(DC))
28+
if (ND->isAnonymousNamespace())
29+
return true;
30+
}
31+
32+
return false;
33+
}
34+
2435
} // namespace
2536

2637
PreferStaticOverAnonymousNamespaceCheck::
@@ -40,9 +51,9 @@ void PreferStaticOverAnonymousNamespaceCheck::storeOptions(
4051

4152
void PreferStaticOverAnonymousNamespaceCheck::registerMatchers(
4253
MatchFinder *Finder) {
43-
const auto IsDefinitionInAnonymousNamespace =
44-
allOf(unless(isExpansionInSystemHeader()), isInAnonymousNamespace(),
45-
unless(isInMacro()), isDefinition());
54+
const auto IsDefinitionInAnonymousNamespace = allOf(
55+
unless(isExpansionInSystemHeader()), isLexicallyInAnonymousNamespace(),
56+
unless(isInMacro()), isDefinition());
4657

4758
if (AllowMemberFunctionsInClass) {
4859
Finder->addMatcher(

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ bool contextAllowsIndex(enum CodeCompletionContext::Kind K) {
870870
}
871871

872872
static bool isInjectedClass(const NamedDecl &D) {
873-
if (auto *R = dyn_cast_or_null<RecordDecl>(&D))
873+
if (auto *R = dyn_cast_or_null<CXXRecordDecl>(&D))
874874
if (R->isInjectedClassName())
875875
return true;
876876
return false;

clang-tools-extra/clangd/Quality.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static SymbolRelevanceSignals::AccessibleScope
258258
computeScope(const NamedDecl *D) {
259259
// Injected "Foo" within the class "Foo" has file scope, not class scope.
260260
const DeclContext *DC = D->getDeclContext();
261-
if (auto *R = dyn_cast_or_null<RecordDecl>(D))
261+
if (auto *R = dyn_cast_or_null<CXXRecordDecl>(D))
262262
if (R->isInjectedClassName())
263263
DC = DC->getParent();
264264
// Class constructor should have the same scope as the class.

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ class HighlightingsBuilder {
597597
std::optional<HighlightingModifier> scopeModifier(const NamedDecl *D) {
598598
const DeclContext *DC = D->getDeclContext();
599599
// Injected "Foo" within the class "Foo" has file scope, not class scope.
600-
if (auto *R = dyn_cast_or_null<RecordDecl>(D))
600+
if (auto *R = dyn_cast_or_null<CXXRecordDecl>(D))
601601
if (R->isInjectedClassName())
602602
DC = DC->getParent();
603603
// Lambda captures are considered function scope, not class scope.

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ Changes in existing checks
185185
<clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
186186
conversion in argument of ``std::make_optional``.
187187

188-
- Improved :doc: `bugprone-sizeof-expression
189-
<clang-tidy/checks/bugprone/bugprone-sizeof-expression>` check by adding
188+
- Improved :doc:`bugprone-sizeof-expression
189+
<clang-tidy/checks/bugprone/sizeof-expression>` check by adding
190190
`WarnOnSizeOfInLoopTermination` option to detect misuses of ``sizeof``
191191
expression in loop conditions.
192192

clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-static-over-anonymous-namespace.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,95 @@ void OuterClass::NestedClass::nestedMemberFunc() {}
178178

179179
} // namespace
180180

181+
namespace {
182+
183+
class MyClassOutOfAnon {
184+
public:
185+
MyClassOutOfAnon();
186+
MyClassOutOfAnon(const MyClassOutOfAnon&) {}
187+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:3: warning: place definition of method 'MyClassOutOfAnon' outside of an anonymous namespace
188+
MyClassOutOfAnon(MyClassOutOfAnon&&) = default;
189+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:3: warning: place definition of method 'MyClassOutOfAnon' outside of an anonymous namespace
190+
MyClassOutOfAnon& operator=(const MyClassOutOfAnon&);
191+
MyClassOutOfAnon& operator=(MyClassOutOfAnon&&);
192+
bool operator<(const MyClassOutOfAnon&) const;
193+
void memberFunction();
194+
static void staticMemberFunction();
195+
void memberDefinedInClass() {}
196+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:8: warning: place definition of method 'memberDefinedInClass' outside of an anonymous namespace
197+
static void staticMemberDefinedInClass() {}
198+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:15: warning: place definition of method 'staticMemberDefinedInClass' outside of an anonymous namespace
199+
template <typename T>
200+
void templateFunction();
201+
template <typename T>
202+
void templateFunctionInClass() {}
203+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:8: warning: place definition of method 'templateFunctionInClass' outside of an anonymous namespace
204+
};
205+
206+
} // namespace
207+
208+
MyClassOutOfAnon::MyClassOutOfAnon() {}
209+
210+
MyClassOutOfAnon& MyClassOutOfAnon::operator=(const MyClassOutOfAnon&) { return *this; }
211+
212+
MyClassOutOfAnon& MyClassOutOfAnon::operator=(MyClassOutOfAnon&&) = default;
213+
214+
bool MyClassOutOfAnon::operator<(const MyClassOutOfAnon&) const { return true; }
215+
216+
void MyClassOutOfAnon::memberFunction() {}
217+
218+
void MyClassOutOfAnon::staticMemberFunction() {}
219+
220+
template <typename T>
221+
void MyClassOutOfAnon::templateFunction() {}
222+
223+
namespace {
224+
225+
template<typename T>
226+
class TemplateClassOutOfAnon {
227+
public:
228+
TemplateClassOutOfAnon();
229+
TemplateClassOutOfAnon(const TemplateClassOutOfAnon&) {}
230+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:3: warning: place definition of method 'TemplateClassOutOfAnon<T>' outside of an anonymous namespace
231+
TemplateClassOutOfAnon(TemplateClassOutOfAnon&&) = default;
232+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:3: warning: place definition of method 'TemplateClassOutOfAnon<T>' outside of an anonymous namespace
233+
TemplateClassOutOfAnon& operator=(const TemplateClassOutOfAnon&);
234+
TemplateClassOutOfAnon& operator=(TemplateClassOutOfAnon&&);
235+
bool operator<(const TemplateClassOutOfAnon&) const;
236+
void memberFunc();
237+
T getValue() const;
238+
void memberDefinedInClass() {}
239+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:8: warning: place definition of method 'memberDefinedInClass' outside of an anonymous namespace
240+
static void staticMemberDefinedInClass() {}
241+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:15: warning: place definition of method 'staticMemberDefinedInClass' outside of an anonymous namespace
242+
template <typename U>
243+
void templateMethodInTemplateClass() {}
244+
// CHECK-MESSAGES-MEM: :[[@LINE-1]]:8: warning: place definition of method 'templateMethodInTemplateClass' outside of an anonymous namespace
245+
private:
246+
T Value;
247+
};
248+
249+
} // namespace
250+
251+
template<typename T>
252+
TemplateClassOutOfAnon<T>::TemplateClassOutOfAnon() {}
253+
254+
template<typename T>
255+
TemplateClassOutOfAnon<T>& TemplateClassOutOfAnon<T>::operator=(const TemplateClassOutOfAnon&) { return *this; }
256+
257+
template<typename T>
258+
TemplateClassOutOfAnon<T>& TemplateClassOutOfAnon<T>::operator=(TemplateClassOutOfAnon&&) = default;
259+
260+
template<typename T>
261+
bool TemplateClassOutOfAnon<T>::operator<(const TemplateClassOutOfAnon&) const { return true; }
262+
263+
template<typename T>
264+
void TemplateClassOutOfAnon<T>::memberFunc() {}
265+
266+
template<typename T>
267+
T TemplateClassOutOfAnon<T>::getValue() const { return Value; }
268+
269+
181270
#define DEFINE_FUNCTION(name) \
182271
namespace { \
183272
void name() {} \

clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header\.h' %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER %s
1313
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header\.h' -quiet %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER %s
1414

15-
// `-header-filter` operates on the actual file path that the user provided in
16-
// the #include directive; however, Clang's path name simplification causes the
17-
// path to be printed in canonicalised form here.
15+
// Check that `-header-filter` operates on the same file paths as paths in
16+
// diagnostics printed by ClangTidy.
1817
#include "dir1/dir2/../header_alias.h"
19-
// CHECK_HEADER_ALIAS: dir1/header.h:1:11: warning: single-argument constructors
18+
// CHECK_HEADER_ALIAS: dir1/dir2/../header_alias.h:1:11: warning: single-argument constructors
2019
// CHECK_HEADER-NOT: warning:

clang/include/clang/AST/Decl.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4420,21 +4420,6 @@ class RecordDecl : public TagDecl {
44204420

44214421
void reorderDecls(const SmallVectorImpl<Decl *> &Decls);
44224422

4423-
/// Determines whether this declaration represents the
4424-
/// injected class name.
4425-
///
4426-
/// The injected class name in C++ is the name of the class that
4427-
/// appears inside the class itself. For example:
4428-
///
4429-
/// \code
4430-
/// struct C {
4431-
/// // C is implicitly declared here as a synonym for the class name.
4432-
/// };
4433-
///
4434-
/// C::C c; // same as "C c;"
4435-
/// \endcode
4436-
bool isInjectedClassName() const;
4437-
44384423
/// Determine whether this record is a class describing a lambda
44394424
/// function object.
44404425
bool isLambda() const;

clang/include/clang/AST/DeclCXX.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,7 @@ class CXXRecordDecl : public RecordDecl {
546546
}
547547

548548
CXXRecordDecl *getMostRecentNonInjectedDecl() {
549-
CXXRecordDecl *Recent =
550-
static_cast<CXXRecordDecl *>(this)->getMostRecentDecl();
549+
CXXRecordDecl *Recent = getMostRecentDecl();
551550
while (Recent->isInjectedClassName()) {
552551
// FIXME: Does injected class name need to be in the redeclarations chain?
553552
assert(Recent->getPreviousDecl());
@@ -1889,6 +1888,21 @@ class CXXRecordDecl : public RecordDecl {
18891888
DL.IsGenericLambda = IsGeneric;
18901889
}
18911890

1891+
/// Determines whether this declaration represents the
1892+
/// injected class name.
1893+
///
1894+
/// The injected class name in C++ is the name of the class that
1895+
/// appears inside the class itself. For example:
1896+
///
1897+
/// \code
1898+
/// struct C {
1899+
/// // C is implicitly declared here as a synonym for the class name.
1900+
/// };
1901+
///
1902+
/// C::C c; // same as "C c;"
1903+
/// \endcode
1904+
bool isInjectedClassName() const;
1905+
18921906
// Determine whether this type is an Interface Like type for
18931907
// __interface inheritance purposes.
18941908
bool isInterfaceLike() const;

clang/include/clang/Basic/SourceManager.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -824,12 +824,6 @@ class SourceManager : public RefCountedBase<SourceManager> {
824824

825825
mutable std::unique_ptr<SrcMgr::SLocEntry> FakeSLocEntryForRecovery;
826826

827-
/// Cache for filenames used in diagnostics. See 'getNameForDiagnostic()'.
828-
mutable llvm::StringMap<StringRef> DiagNames;
829-
830-
/// Allocator for absolute/short names.
831-
mutable llvm::BumpPtrAllocator DiagNameAlloc;
832-
833827
/// Lazily computed map of macro argument chunks to their expanded
834828
/// source location.
835829
using MacroArgsMap = std::map<unsigned, SourceLocation>;
@@ -1854,16 +1848,6 @@ class SourceManager : public RefCountedBase<SourceManager> {
18541848
/// \return Location of the top-level macro caller.
18551849
SourceLocation getTopMacroCallerLoc(SourceLocation Loc) const;
18561850

1857-
/// Retrieve the name of a file suitable for diagnostics.
1858-
// FIXME: Passing in the DiagnosticOptions here is a workaround for the
1859-
// fact that installapi does some weird things with DiagnosticsEngines,
1860-
// which causes the 'Diag' member of SourceManager (or at least the
1861-
// DiagnosticsOptions member thereof) to be a dangling reference
1862-
// sometimes. We should probably fix that or decouple the two classes
1863-
// to avoid this issue entirely.
1864-
StringRef getNameForDiagnostic(StringRef Filename,
1865-
const DiagnosticOptions &Opts) const;
1866-
18671851
private:
18681852
friend class ASTReader;
18691853
friend class ASTWriter;

0 commit comments

Comments
 (0)