Skip to content

Commit 89361f0

Browse files
committed
merge main into amd-staging
Revert: breaks MIOpen https://ontrack-internal.amd.com/browse/SWDEV-436625 [clang][Sema] Add -Wswitch-default warning option (llvm#73077) Change-Id: I182ea84b40257240ed42db5cd28213ab192ac3f7
2 parents 4321b97 + 04c4566 commit 89361f0

File tree

241 files changed

+8914
-2603
lines changed

Some content is hidden

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

241 files changed

+8914
-2603
lines changed

.github/workflows/llvm-project-tests.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ on:
1010
required: false
1111
projects:
1212
required: false
13+
extra_cmake_args:
14+
required: false
15+
os_list:
16+
required: false
17+
default: '["ubuntu-latest", "windows-2019", "macOS-11"]'
1318
workflow_call:
1419
inputs:
1520
build_target:
@@ -20,6 +25,19 @@ on:
2025
required: true
2126
type: string
2227

28+
extra_cmake_args:
29+
required: false
30+
type: string
31+
32+
os_list:
33+
required: false
34+
type: string
35+
# Use windows-2019 due to:
36+
# https://developercommunity.visualstudio.com/t/Prev-Issue---with-__assume-isnan-/1597317
37+
# We're using a specific version of macOS due to:
38+
# https://github.com/actions/virtual-environments/issues/5900
39+
default: '["ubuntu-latest", "windows-2019", "macOS-11"]'
40+
2341
concurrency:
2442
# Skip intermediate builds: always.
2543
# Cancel intermediate builds: only if it is a pull request build.
@@ -35,14 +53,7 @@ jobs:
3553
strategy:
3654
fail-fast: false
3755
matrix:
38-
os:
39-
- ubuntu-latest
40-
# Use windows-2019 due to:
41-
# https://developercommunity.visualstudio.com/t/Prev-Issue---with-__assume-isnan-/1597317
42-
- windows-2019
43-
# We're using a specific version of macOS due to:
44-
# https://github.com/actions/virtual-environments/issues/5900
45-
- macOS-11
56+
os: ${{ fromJSON(inputs.os_list) }}
4657
steps:
4758
- name: Setup Windows
4859
if: startsWith(matrix.os, 'windows')
@@ -85,7 +96,7 @@ jobs:
8596
# This should be a no-op for non-mac OSes
8697
PKG_CONFIG_PATH: /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig//12
8798
with:
88-
cmake_args: '-GNinja -DLLVM_ENABLE_PROJECTS="${{ inputs.projects }}" -DCMAKE_BUILD_TYPE=Release -DLLDB_INCLUDE_TESTS=OFF -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache'
99+
cmake_args: '-GNinja -DLLVM_ENABLE_PROJECTS="${{ inputs.projects }}" -DCMAKE_BUILD_TYPE=Release -DLLDB_INCLUDE_TESTS=OFF -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache ${{ inputs.extra_cmake_args }}'
89100
build_target: '${{ inputs.build_target }}'
90101

91102
- name: Build and Test libclc

.github/workflows/spirv-tests.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: SPIR-V Tests
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
paths:
10+
- 'llvm/lib/Target/SPIRV/**'
11+
- 'llvm/test/CodeGen/SPIRV/**'
12+
- '.github/workflows/spirv-tests.yml'
13+
14+
concurrency:
15+
# Skip intermediate builds: always.
16+
# Cancel intermediate builds: only if it is a pull request build.
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
19+
20+
jobs:
21+
check_spirv:
22+
if: github.repository_owner == 'llvm'
23+
name: Test SPIR-V
24+
uses: ./.github/workflows/llvm-project-tests.yml
25+
with:
26+
build_target: check-llvm-codegen-spirv
27+
projects:
28+
extra_cmake_args: '-DLLVM_TARGETS_TO_BUILD="" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="SPIRV"'
29+
os_list: '["ubuntu-latest"]'

.mailmap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
3434
3535
36+
Jianjian GUAN <[email protected]>
37+
3638
3739
3840

clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "clang/AST/Decl.h"
1616
#include "clang/Basic/Diagnostic.h"
1717
#include <optional>
18+
#include <utility>
1819

1920
namespace clang::tidy::performance {
2021
namespace {
@@ -263,19 +264,25 @@ void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
263264

264265
void UnnecessaryCopyInitialization::check(
265266
const MatchFinder::MatchResult &Result) {
266-
const auto *NewVar = Result.Nodes.getNodeAs<VarDecl>("newVarDecl");
267+
const auto &NewVar = *Result.Nodes.getNodeAs<VarDecl>("newVarDecl");
268+
const auto &BlockStmt = *Result.Nodes.getNodeAs<Stmt>("blockStmt");
269+
const auto &VarDeclStmt = *Result.Nodes.getNodeAs<DeclStmt>("declStmt");
270+
// Do not propose fixes if the DeclStmt has multiple VarDecls or in
271+
// macros since we cannot place them correctly.
272+
const bool IssueFix =
273+
VarDeclStmt.isSingleDecl() && !NewVar.getLocation().isMacroID();
274+
const bool IsVarUnused = isVariableUnused(NewVar, BlockStmt, *Result.Context);
275+
const bool IsVarOnlyUsedAsConst =
276+
isOnlyUsedAsConst(NewVar, BlockStmt, *Result.Context);
277+
const CheckContext Context{
278+
NewVar, BlockStmt, VarDeclStmt, *Result.Context,
279+
IssueFix, IsVarUnused, IsVarOnlyUsedAsConst};
267280
const auto *OldVar = Result.Nodes.getNodeAs<VarDecl>(OldVarDeclId);
268281
const auto *ObjectArg = Result.Nodes.getNodeAs<VarDecl>(ObjectArgId);
269-
const auto *BlockStmt = Result.Nodes.getNodeAs<Stmt>("blockStmt");
270282
const auto *CtorCall = Result.Nodes.getNodeAs<CXXConstructExpr>("ctorCall");
271-
const auto *Stmt = Result.Nodes.getNodeAs<DeclStmt>("declStmt");
272283

273284
TraversalKindScope RAII(*Result.Context, TK_AsIs);
274285

275-
// Do not propose fixes if the DeclStmt has multiple VarDecls or in macros
276-
// since we cannot place them correctly.
277-
bool IssueFix = Stmt->isSingleDecl() && !NewVar->getLocation().isMacroID();
278-
279286
// A constructor that looks like T(const T& t, bool arg = false) counts as a
280287
// copy only when it is called with default arguments for the arguments after
281288
// the first.
@@ -289,74 +296,71 @@ void UnnecessaryCopyInitialization::check(
289296
// instantiations where the types differ and rely on implicit conversion would
290297
// no longer compile if we switched to a reference.
291298
if (differentReplacedTemplateParams(
292-
NewVar->getType(), constructorArgumentType(OldVar, Result.Nodes),
299+
Context.Var.getType(), constructorArgumentType(OldVar, Result.Nodes),
293300
*Result.Context))
294301
return;
295302

296303
if (OldVar == nullptr) {
297-
handleCopyFromMethodReturn(*NewVar, *BlockStmt, *Stmt, IssueFix, ObjectArg,
298-
*Result.Context);
304+
// `auto NewVar = functionCall();`
305+
handleCopyFromMethodReturn(Context, ObjectArg);
299306
} else {
300-
handleCopyFromLocalVar(*NewVar, *OldVar, *BlockStmt, *Stmt, IssueFix,
301-
*Result.Context);
307+
// `auto NewVar = OldVar;`
308+
handleCopyFromLocalVar(Context, *OldVar);
302309
}
303310
}
304311

305312
void UnnecessaryCopyInitialization::handleCopyFromMethodReturn(
306-
const VarDecl &Var, const Stmt &BlockStmt, const DeclStmt &Stmt,
307-
bool IssueFix, const VarDecl *ObjectArg, ASTContext &Context) {
308-
bool IsConstQualified = Var.getType().isConstQualified();
309-
if (!IsConstQualified && !isOnlyUsedAsConst(Var, BlockStmt, Context))
313+
const CheckContext &Ctx, const VarDecl *ObjectArg) {
314+
bool IsConstQualified = Ctx.Var.getType().isConstQualified();
315+
if (!IsConstQualified && !Ctx.IsVarOnlyUsedAsConst)
310316
return;
311317
if (ObjectArg != nullptr &&
312-
!isInitializingVariableImmutable(*ObjectArg, BlockStmt, Context,
318+
!isInitializingVariableImmutable(*ObjectArg, Ctx.BlockStmt, Ctx.ASTCtx,
313319
ExcludedContainerTypes))
314320
return;
315-
if (isVariableUnused(Var, BlockStmt, Context)) {
316-
auto Diagnostic =
317-
diag(Var.getLocation(),
318-
"the %select{|const qualified }0variable %1 is copy-constructed "
319-
"from a const reference but is never used; consider "
320-
"removing the statement")
321-
<< IsConstQualified << &Var;
322-
if (IssueFix)
323-
recordRemoval(Stmt, Context, Diagnostic);
324-
} else {
325-
auto Diagnostic =
326-
diag(Var.getLocation(),
327-
"the %select{|const qualified }0variable %1 is copy-constructed "
328-
"from a const reference%select{ but is only used as const "
329-
"reference|}0; consider making it a const reference")
330-
<< IsConstQualified << &Var;
331-
if (IssueFix)
332-
recordFixes(Var, Context, Diagnostic);
333-
}
321+
diagnoseCopyFromMethodReturn(Ctx);
334322
}
335323

336324
void UnnecessaryCopyInitialization::handleCopyFromLocalVar(
337-
const VarDecl &NewVar, const VarDecl &OldVar, const Stmt &BlockStmt,
338-
const DeclStmt &Stmt, bool IssueFix, ASTContext &Context) {
339-
if (!isOnlyUsedAsConst(NewVar, BlockStmt, Context) ||
340-
!isInitializingVariableImmutable(OldVar, BlockStmt, Context,
325+
const CheckContext &Ctx, const VarDecl &OldVar) {
326+
if (!Ctx.IsVarOnlyUsedAsConst ||
327+
!isInitializingVariableImmutable(OldVar, Ctx.BlockStmt, Ctx.ASTCtx,
341328
ExcludedContainerTypes))
342329
return;
330+
diagnoseCopyFromLocalVar(Ctx, OldVar);
331+
}
343332

344-
if (isVariableUnused(NewVar, BlockStmt, Context)) {
345-
auto Diagnostic = diag(NewVar.getLocation(),
346-
"local copy %0 of the variable %1 is never modified "
347-
"and never used; "
348-
"consider removing the statement")
349-
<< &NewVar << &OldVar;
350-
if (IssueFix)
351-
recordRemoval(Stmt, Context, Diagnostic);
352-
} else {
353-
auto Diagnostic =
354-
diag(NewVar.getLocation(),
355-
"local copy %0 of the variable %1 is never modified; "
356-
"consider avoiding the copy")
357-
<< &NewVar << &OldVar;
358-
if (IssueFix)
359-
recordFixes(NewVar, Context, Diagnostic);
333+
void UnnecessaryCopyInitialization::diagnoseCopyFromMethodReturn(
334+
const CheckContext &Ctx) {
335+
auto Diagnostic =
336+
diag(Ctx.Var.getLocation(),
337+
"the %select{|const qualified }0variable %1 is "
338+
"copy-constructed "
339+
"from a const reference%select{%select{ but is only used as const "
340+
"reference|}0| but is never used}2; consider "
341+
"%select{making it a const reference|removing the statement}2")
342+
<< Ctx.Var.getType().isConstQualified() << &Ctx.Var << Ctx.IsVarUnused;
343+
maybeIssueFixes(Ctx, Diagnostic);
344+
}
345+
346+
void UnnecessaryCopyInitialization::diagnoseCopyFromLocalVar(
347+
const CheckContext &Ctx, const VarDecl &OldVar) {
348+
auto Diagnostic =
349+
diag(Ctx.Var.getLocation(),
350+
"local copy %1 of the variable %0 is never modified%select{"
351+
"| and never used}2; consider %select{avoiding the copy|removing "
352+
"the statement}2")
353+
<< &OldVar << &Ctx.Var << Ctx.IsVarUnused;
354+
maybeIssueFixes(Ctx, Diagnostic);
355+
}
356+
357+
void UnnecessaryCopyInitialization::maybeIssueFixes(
358+
const CheckContext &Ctx, DiagnosticBuilder &Diagnostic) {
359+
if (Ctx.IssueFix) {
360+
if (Ctx.IsVarUnused)
361+
recordRemoval(Ctx.VarDeclStmt, Ctx.ASTCtx, Diagnostic);
362+
else
363+
recordFixes(Ctx.Var, Ctx.ASTCtx, Diagnostic);
360364
}
361365
}
362366

clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.h

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,32 @@ class UnnecessaryCopyInitialization : public ClangTidyCheck {
3232
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3333
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
3434

35+
protected:
36+
// A helper to manipulate the state common to
37+
// `CopyFromMethodReturn` and `CopyFromLocalVar`.
38+
struct CheckContext {
39+
const VarDecl &Var;
40+
const Stmt &BlockStmt;
41+
const DeclStmt &VarDeclStmt;
42+
clang::ASTContext &ASTCtx;
43+
const bool IssueFix;
44+
const bool IsVarUnused;
45+
const bool IsVarOnlyUsedAsConst;
46+
};
47+
48+
// Create diagnostics. These are virtual so that derived classes can change
49+
// behaviour.
50+
virtual void diagnoseCopyFromMethodReturn(const CheckContext &Ctx);
51+
virtual void diagnoseCopyFromLocalVar(const CheckContext &Ctx,
52+
const VarDecl &OldVar);
53+
3554
private:
36-
void handleCopyFromMethodReturn(const VarDecl &Var, const Stmt &BlockStmt,
37-
const DeclStmt &Stmt, bool IssueFix,
38-
const VarDecl *ObjectArg,
39-
ASTContext &Context);
40-
void handleCopyFromLocalVar(const VarDecl &NewVar, const VarDecl &OldVar,
41-
const Stmt &BlockStmt, const DeclStmt &Stmt,
42-
bool IssueFix, ASTContext &Context);
55+
void handleCopyFromMethodReturn(const CheckContext &Ctx,
56+
const VarDecl *ObjectArg);
57+
void handleCopyFromLocalVar(const CheckContext &Ctx, const VarDecl &OldVar);
58+
59+
void maybeIssueFixes(const CheckContext &Ctx, DiagnosticBuilder &Diagnostic);
60+
4361
const std::vector<StringRef> AllowedTypes;
4462
const std::vector<StringRef> ExcludedContainerTypes;
4563
};

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,7 @@ Conditional ``explicit`` __cpp_conditional_explicit C++20
14831483
``using enum`` __cpp_using_enum C++20 C++03
14841484
``if consteval`` __cpp_if_consteval C++23 C++20
14851485
``static operator()`` __cpp_static_call_operator C++23 C++03
1486+
Attributes on Lambda-Expressions C++23 C++11
14861487
-------------------------------------- -------------------------------- ------------- -------------
14871488
Designated initializers (N494) C99 C89
14881489
Array & element qualification (N2607) C23 C89

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ C++23 Feature Support
156156
support for this feature is still experimental, the feature test macro ``__cpp_explicit_this_parameter``
157157
was not set in this version.
158158

159+
- Added a separate warning to warn the use of attributes on lambdas as a C++23 extension
160+
in previous language versions: ``-Wc++23-lambda-attributes``.
161+
159162
C++2c Feature Support
160163
^^^^^^^^^^^^^^^^^^^^^
161164
- Compiler flags ``-std=c++2c`` and ``-std=gnu++2c`` have been added for experimental C++2c implementation work.
@@ -709,6 +712,9 @@ Bug Fixes in This Version
709712
- Fixed false positive error emitted by clang when performing qualified name
710713
lookup and the current class instantiation has dependent bases.
711714
Fixes (`#13826 <https://github.com/llvm/llvm-project/issues/13826>`_)
715+
- Fix a ``clang-17`` regression where a templated friend with constraints is not
716+
properly applied when its parameters reference an enclosing non-template class.
717+
Fixes (`#71595 <https://github.com/llvm/llvm-project/issues/71595>`_)
712718
- Fix the name of the ifunc symbol emitted for multiversion functions declared with the
713719
``target_clones`` attribute. This addresses a linker error that would otherwise occur
714720
when these functions are referenced from other TUs.

clang/include/clang/Basic/AttrDocs.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,8 +2659,9 @@ An error will be given if:
26592659
- Specified values violate subtarget specifications;
26602660
- Specified values are not compatible with values provided through other
26612661
attributes;
2662-
- The AMDGPU target backend is unable to create machine code that can meet the
2663-
request.
2662+
2663+
The AMDGPU target backend will emit a warning whenever it is unable to
2664+
create machine code that meets the request.
26642665
}];
26652666
}
26662667

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,8 @@ def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
11261126
CXX17Attrs,
11271127
CXX20Attrs]>;
11281128

1129+
def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
1130+
11291131
// A warning group for warnings about using C++11 features as extensions in
11301132
// earlier C++ versions.
11311133
def CXX11 : DiagGroup<"c++11-extensions", [CXX11ExtraSemi, CXX11InlineNamespace,
@@ -1145,7 +1147,7 @@ def CXX20 : DiagGroup<"c++20-extensions", [CXX20Designator, CXX20Attrs]>;
11451147

11461148
// A warning group for warnings about using C++23 features as extensions in
11471149
// earlier C++ versions.
1148-
def CXX23 : DiagGroup<"c++23-extensions">;
1150+
def CXX23 : DiagGroup<"c++23-extensions", [CXX23AttrsOnLambda]>;
11491151

11501152
// A warning group for warnings about using C++26 features as extensions in
11511153
// earlier C++ versions.

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ def err_capture_default_first : Error<
10351035
"capture default must be first">;
10361036
def ext_decl_attrs_on_lambda : ExtWarn<
10371037
"%select{an attribute specifier sequence|%0}1 in this position "
1038-
"is a C++23 extension">, InGroup<CXX23>;
1038+
"is a C++23 extension">, InGroup<CXX23AttrsOnLambda>;
10391039
def ext_lambda_missing_parens : ExtWarn<
10401040
"lambda without a parameter clause is a C++23 extension">,
10411041
InGroup<CXX23>;

0 commit comments

Comments
 (0)