Skip to content

Commit 91883c7

Browse files
committed
Merge branch 'main' into amd-trunk-dev
2 parents 112ba05 + 1c94388 commit 91883c7

File tree

748 files changed

+22924
-28126
lines changed

Some content is hidden

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

748 files changed

+22924
-28126
lines changed

.ci/generate-buildkite-pipeline-premerge

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ function keep-modified-projects() {
191191
}
192192

193193
function check-targets() {
194+
# Do not use "check-all" here because if there is "check-all" plus a
195+
# project specific target like "check-clang", that project's tests
196+
# will be run twice.
194197
projects=${@}
195198
for project in ${projects}; do
196199
case ${project} in
@@ -216,7 +219,7 @@ function check-targets() {
216219
echo "check-lldb"
217220
;;
218221
pstl)
219-
echo "check-all"
222+
# Currently we do not run pstl tests in CI.
220223
;;
221224
libclc)
222225
# Currently there is no testing for libclc.

.github/workflows/release-binaries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ jobs:
328328
run: |
329329
# Build some of the mlir tools that take a long time to link
330330
if [ "${{ needs.prepare.outputs.build-flang }}" = "true" ]; then
331-
ninja -C ${{ steps.setup-stage.outputs.build-prefix }}/build/tools/clang/stage2-bins/ -j2 flang-new bbc
331+
ninja -C ${{ steps.setup-stage.outputs.build-prefix }}/build/tools/clang/stage2-bins/ -j2 flang bbc
332332
fi
333333
ninja -C ${{ steps.setup-stage.outputs.build-prefix }}/build/tools/clang/stage2-bins/ \
334334
mlir-bytecode-parser-fuzzer \

clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,8 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
148148

149149
if (auto Entry = SM.getFileManager().getOptionalFileRef(Path)) {
150150
if (SourceTU) {
151-
auto &Replaces = DiagReplacements[*Entry];
152-
auto It = Replaces.find(R);
153-
if (It == Replaces.end())
154-
Replaces.emplace(R, SourceTU);
155-
else if (It->second != SourceTU)
151+
auto [It, Inserted] = DiagReplacements[*Entry].try_emplace(R, SourceTU);
152+
if (!Inserted && It->second != SourceTU)
156153
// This replacement is a duplicate of one suggested by another TU.
157154
return;
158155
}

clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,8 @@ void ChangeNamespaceTool::run(
606606
Result.Nodes.getNodeAs<DeclRefExpr>("func_ref")) {
607607
// If this reference has been processed as a function call, we do not
608608
// process it again.
609-
if (ProcessedFuncRefs.count(FuncRef))
609+
if (!ProcessedFuncRefs.insert(FuncRef).second)
610610
return;
611-
ProcessedFuncRefs.insert(FuncRef);
612611
const auto *Func = Result.Nodes.getNodeAs<FunctionDecl>("func_decl");
613612
assert(Func);
614613
const auto *Context = Result.Nodes.getNodeAs<Decl>("dc");

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ void ForwardDeclarationNamespaceCheck::onEndOfTranslationUnit() {
146146
}
147147
// Check if a definition in another namespace exists.
148148
const auto DeclName = CurDecl->getName();
149-
if (!DeclNameToDefinitions.contains(DeclName)) {
149+
auto It = DeclNameToDefinitions.find(DeclName);
150+
if (It == DeclNameToDefinitions.end()) {
150151
continue; // No definition in this translation unit, we can skip it.
151152
}
152153
// Make a warning for each definition with the same name (in other
153154
// namespaces).
154-
const auto &Definitions = DeclNameToDefinitions[DeclName];
155+
const auto &Definitions = It->second;
155156
for (const auto *Def : Definitions) {
156157
diag(CurDecl->getLocation(),
157158
"no definition found for %0, but a definition with "

clang-tools-extra/clang-tidy/portability/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_clang_library(clangTidyPortabilityModule STATIC
99
RestrictSystemIncludesCheck.cpp
1010
SIMDIntrinsicsCheck.cpp
1111
StdAllocatorConstCheck.cpp
12+
TemplateVirtualMemberFunctionCheck.cpp
1213

1314
LINK_LIBS
1415
clangTidy

clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "RestrictSystemIncludesCheck.h"
1313
#include "SIMDIntrinsicsCheck.h"
1414
#include "StdAllocatorConstCheck.h"
15+
#include "TemplateVirtualMemberFunctionCheck.h"
1516

1617
namespace clang::tidy {
1718
namespace portability {
@@ -25,6 +26,8 @@ class PortabilityModule : public ClangTidyModule {
2526
"portability-simd-intrinsics");
2627
CheckFactories.registerCheck<StdAllocatorConstCheck>(
2728
"portability-std-allocator-const");
29+
CheckFactories.registerCheck<TemplateVirtualMemberFunctionCheck>(
30+
"portability-template-virtual-member-function");
2831
}
2932
};
3033

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===--- TemplateVirtualMemberFunctionCheck.cpp - clang-tidy --------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "TemplateVirtualMemberFunctionCheck.h"
10+
#include "clang/ASTMatchers/ASTMatchFinder.h"
11+
12+
using namespace clang::ast_matchers;
13+
14+
namespace clang::tidy::portability {
15+
namespace {
16+
AST_MATCHER(CXXMethodDecl, isUsed) { return Node.isUsed(); }
17+
} // namespace
18+
19+
void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) {
20+
Finder->addMatcher(
21+
cxxMethodDecl(ofClass(classTemplateSpecializationDecl(
22+
unless(isExplicitTemplateSpecialization()))
23+
.bind("specialization")),
24+
isVirtual(), unless(isUsed()),
25+
unless(cxxDestructorDecl(isDefaulted())))
26+
.bind("method"),
27+
this);
28+
}
29+
30+
void TemplateVirtualMemberFunctionCheck::check(
31+
const MatchFinder::MatchResult &Result) {
32+
const auto *ImplicitSpecialization =
33+
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("specialization");
34+
const auto *MethodDecl = Result.Nodes.getNodeAs<CXXMethodDecl>("method");
35+
36+
diag(MethodDecl->getLocation(),
37+
"unspecified virtual member function instantiation; the virtual "
38+
"member function is not instantiated but it might be with a "
39+
"different compiler");
40+
diag(ImplicitSpecialization->getPointOfInstantiation(),
41+
"template instantiated here", DiagnosticIDs::Note);
42+
}
43+
44+
} // namespace clang::tidy::portability
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===--- TemplateVirtualMemberFunctionCheck.h - clang-tidy ------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_TEMPLATEVIRTUALMEMBERFUNCTIONCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_TEMPLATEVIRTUALMEMBERFUNCTIONCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::portability {
15+
16+
/// Upon instantiating a template class, non-virtual member functions don't have
17+
/// to be instantiated unless they are used. Virtual member function
18+
/// instantiation on the other hand is unspecified and depends on the
19+
/// implementation of the compiler. This check intends to find cases when a
20+
/// virtual member function is not instantiated but it might be with a different
21+
/// compiler.
22+
///
23+
/// For the user-facing documentation see:
24+
/// http://clang.llvm.org/extra/clang-tidy/checks/portability/template-virtual-member-function.html
25+
class TemplateVirtualMemberFunctionCheck : public ClangTidyCheck {
26+
public:
27+
TemplateVirtualMemberFunctionCheck(StringRef Name, ClangTidyContext *Context)
28+
: ClangTidyCheck(Name, Context) {}
29+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
30+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
31+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
32+
return LangOpts.CPlusPlus;
33+
}
34+
};
35+
36+
} // namespace clang::tidy::portability
37+
38+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_TEMPLATEVIRTUALMEMBERFUNCTIONCHECK_H

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ New checks
121121
Gives warnings for tagged unions, where the number of tags is
122122
different from the number of data members inside the union.
123123

124+
- New :doc:`portability-template-virtual-member-function
125+
<clang-tidy/checks/portability/template-virtual-member-function>` check.
126+
127+
Finds cases when an uninstantiated virtual member function in a template class
128+
causes cross-compiler incompatibility.
129+
124130
New check aliases
125131
^^^^^^^^^^^^^^^^^
126132

clang-tools-extra/docs/clang-tidy/checks/list.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ Clang-Tidy Checks
348348
:doc:`portability-restrict-system-includes <portability/restrict-system-includes>`, "Yes"
349349
:doc:`portability-simd-intrinsics <portability/simd-intrinsics>`,
350350
:doc:`portability-std-allocator-const <portability/std-allocator-const>`,
351+
:doc:`portability-template-virtual-member-function <portability/template-virtual-member-function>`,
351352
:doc:`readability-avoid-const-params-in-decls <readability/avoid-const-params-in-decls>`, "Yes"
352353
:doc:`readability-avoid-nested-conditional-operator <readability/avoid-nested-conditional-operator>`,
353354
:doc:`readability-avoid-return-with-void-value <readability/avoid-return-with-void-value>`, "Yes"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. title:: clang-tidy - portability-template-virtual-member-function
2+
3+
portability-template-virtual-member-function
4+
============================================
5+
6+
Finds cases when an uninstantiated virtual member function in a template class causes
7+
cross-compiler incompatibility.
8+
9+
Upon instantiating a template class, non-virtual member functions don't have to be
10+
instantiated unless they are used. Virtual member function instantiation on the other hand
11+
is unspecified and depends on the implementation of the compiler.
12+
13+
In the following snippets the virtual member function is not instantiated by GCC and Clang,
14+
but it is instantiated by MSVC, so while the snippet is accepted by the former compilers,
15+
it is rejected by the latter.
16+
17+
.. code:: c++
18+
19+
template<typename T>
20+
struct CrossPlatformError {
21+
virtual ~CrossPlatformError() = default;
22+
23+
static void used() {}
24+
25+
virtual void unused() {
26+
T MSVCError = this;
27+
};
28+
};
29+
30+
int main() {
31+
CrossPlatformError<int>::used();
32+
return 0;
33+
}
34+
35+
Cross-platform projects that need to support MSVC on Windows might see compiler errors
36+
because certain virtual member functions are instantiated, which are not instantiated
37+
by other compilers on other platforms. This check highlights such virtual member functions.

0 commit comments

Comments
 (0)