Skip to content

Commit a9ab5fd

Browse files
authored
merge main into amd-staging (llvm#1205)
2 parents ecadccf + 247f995 commit a9ab5fd

File tree

88 files changed

+2118
-1888
lines changed

Some content is hidden

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

88 files changed

+2118
-1888
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
fetch-depth: 1
6666
- name: Get subprojects that have doc changes
6767
id: docs-changed-subprojects
68-
uses: tj-actions/changed-files@dcc7a0cba800f454d79fff4b993e8c3555bcc0a8 # v45.0.7
68+
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
6969
with:
7070
files_yaml: |
7171
llvm:

.github/workflows/pr-code-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
- name: Get changed files
3434
id: changed-files
35-
uses: tj-actions/changed-files@fea790cb660e33aef4bdf07304e28fedd77dfa13 # v39.2.4
35+
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
3636
with:
3737
separator: ","
3838
skip_initial_fetch: true

clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ static bool sameValue(const Expr *E1, const Expr *E2) {
176176
cast<StringLiteral>(E2)->getString();
177177
case Stmt::DeclRefExprClass:
178178
return cast<DeclRefExpr>(E1)->getDecl() == cast<DeclRefExpr>(E2)->getDecl();
179+
case Stmt::CStyleCastExprClass:
180+
case Stmt::CXXStaticCastExprClass:
181+
case Stmt::CXXFunctionalCastExprClass:
182+
return sameValue(cast<ExplicitCastExpr>(E1)->getSubExpr(),
183+
cast<ExplicitCastExpr>(E2)->getSubExpr());
179184
default:
180185
return false;
181186
}
@@ -206,10 +211,13 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
206211
cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
207212
declRefExpr(to(anyOf(enumConstantDecl(), ConstExpRef))));
208213

214+
auto ExplicitCastExpr = castExpr(hasSourceExpression(InitBase));
215+
auto InitMatcher = anyOf(InitBase, ExplicitCastExpr);
216+
209217
auto Init =
210-
anyOf(initListExpr(anyOf(allOf(initCountIs(1), hasInit(0, InitBase)),
218+
anyOf(initListExpr(anyOf(allOf(initCountIs(1), hasInit(0, InitMatcher)),
211219
initCountIs(0), hasType(arrayType()))),
212-
InitBase);
220+
InitBase, ExplicitCastExpr);
213221

214222
Finder->addMatcher(
215223
cxxConstructorDecl(forEachConstructorInitializer(

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ Changes in existing checks
159159

160160
- Improved :doc:`modernize-use-default-member-init
161161
<clang-tidy/checks/modernize/use-default-member-init>` check by matching
162-
``constexpr`` and ``static`` values on member initialization.
162+
``constexpr`` and ``static``` values on member initialization and by detecting
163+
explicit casting of built-in types within member list initialization.
163164

164165
- Improved :doc:`modernize-use-ranges
165166
<clang-tidy/checks/modernize/use-ranges>` check by updating suppress

clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,4 +536,40 @@ namespace PR122480 {
536536
// CHECK-FIXES: int b{STATIC_VAL};
537537
};
538538

539+
class CStyleCastInit {
540+
CStyleCastInit() : a{(int)1.23}, b{(float)42}, c{(double)'C'} {}
541+
// CHECK-MESSAGES: :[[@LINE-1]]:50: warning: member initializer for 'c' is redundant [modernize-use-default-member-init]
542+
// CHECK-FIXES: CStyleCastInit() {}
543+
544+
int a;
545+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'a' [modernize-use-default-member-init]
546+
// CHECK-FIXES: int a{(int)1.23};
547+
float b;
548+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'b' [modernize-use-default-member-init]
549+
// CHECK-FIXES: float b{(float)42};
550+
double c{(double)'C'};
551+
};
552+
553+
class StaticCastInit {
554+
StaticCastInit() : m(static_cast<int>(9.99)), n(static_cast<char>(65)) {}
555+
// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: member initializer for 'n' is redundant [modernize-use-default-member-init]
556+
// CHECK-FIXES: StaticCastInit() {}
557+
int m;
558+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'm' [modernize-use-default-member-init]
559+
// CHECK-FIXES: int m{static_cast<int>(9.99)};
560+
char n{static_cast<char>(65)};
561+
};
562+
563+
class FunctionalCastInit {
564+
FunctionalCastInit() : a(int(5.67)), b(float(2)), c(double('C')) {}
565+
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: member initializer for 'b' is redundant [modernize-use-default-member-init]
566+
int a;
567+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'a' [modernize-use-default-member-init]
568+
// CHECK-FIXES: int a{int(5.67)};
569+
float b{float(2)};
570+
double c;
571+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'c' [modernize-use-default-member-init]
572+
// CHECK-FIXES: double c{double('C')};
573+
};
574+
539575
} //namespace PR122480

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10755,11 +10755,6 @@ class Sema final : public SemaBase {
1075510755
SourceLocation EndLoc);
1075610756
void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
1075710757

10758-
/// DiagnoseDiscardedExprMarkedNodiscard - Given an expression that is
10759-
/// semantically a discarded-value expression, diagnose if any [[nodiscard]]
10760-
/// value has been discarded.
10761-
void DiagnoseDiscardedExprMarkedNodiscard(const Expr *E);
10762-
1076310758
/// DiagnoseUnusedExprResult - If the statement passed in is an expression
1076410759
/// whose result is unused, warn.
1076510760
void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID);

clang/lib/Sema/SemaExprMember.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,6 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
11361136
if (Converted.isInvalid())
11371137
return true;
11381138
BaseExpr = Converted.get();
1139-
DiagnoseDiscardedExprMarkedNodiscard(BaseExpr);
11401139
return false;
11411140
};
11421141
auto ConvertBaseExprToGLValue = [&] {

clang/lib/Sema/SemaStmt.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,6 @@ void DiagnoseUnused(Sema &S, const Expr *E, std::optional<unsigned> DiagID) {
399399
}
400400
} // namespace
401401

402-
void Sema::DiagnoseDiscardedExprMarkedNodiscard(const Expr *E) {
403-
DiagnoseUnused(*this, E, std::nullopt);
404-
}
405-
406402
void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
407403
if (const LabelStmt *Label = dyn_cast_if_present<LabelStmt>(S))
408404
S = Label->getSubStmt();

clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,21 @@ struct X {
164164

165165
[[nodiscard]] X get_X();
166166
// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
167+
[[nodiscard]] X* get_Ptr();
168+
// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
167169
void f() {
170+
get_X(); // expected-warning{{ignoring return value of function declared with 'nodiscard' attribute}}
171+
(void) get_X();
168172
(void) get_X().variant_member;
169173
(void) get_X().anonymous_struct_member;
170174
(void) get_X().data_member;
171175
(void) get_X().static_data_member;
172-
// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}}
173176
(void) get_X().unscoped_enum;
174-
// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}}
175177
(void) get_X().scoped_enum;
176-
// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}}
177178
(void) get_X().implicit_object_member_function();
178179
(void) get_X().static_member_function();
179-
// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}}
180+
(void) get_Ptr()->implicit_object_member_function();
181+
(void) get_Ptr()->static_member_function();
180182
#if __cplusplus >= 202302L
181183
(void) get_X().explicit_object_member_function();
182184
#endif

clang/test/SemaCXX/ms-property.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -emit-pch -o %t -verify %s
33
// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -include-pch %t %s -ast-print -o - | FileCheck %s
44
// RUN: %clang_cc1 -fdeclspec -fsyntax-only -verify %s -std=c++23
5+
// expected-no-diagnostics
56

67
#ifndef HEADER
78
#define HEADER
@@ -103,7 +104,6 @@ struct X {
103104
void f() {
104105
(void) get_x().imp;
105106
(void) get_x().st;
106-
// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}}
107107
#if __cplusplus >= 202302L
108108
(void) get_x().exp;
109109
#endif

0 commit comments

Comments
 (0)