Skip to content

Commit a61e604

Browse files
authored
Merge branch 'main' into develop
2 parents 95ddfa1 + 4286f4d commit a61e604

File tree

181 files changed

+9337
-2577
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

+9337
-2577
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/docs/LanguageExtensions.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,6 +4283,17 @@ the ellipsis. This function initializes the given ``__builtin_va_list`` object.
42834283
It is undefined behavior to call this function on an already initialized
42844284
``__builtin_va_list`` object.
42854285
4286+
* ``void __builtin_c23_va_start(__builtin_va_list list, ...)``
4287+
4288+
A builtin function for the target-specific ``va_start`` function-like macro,
4289+
available only in C23 and later. The builtin accepts zero or one argument for
4290+
the ellipsis (``...``). If such an argument is provided, it should be the name
4291+
of the parameter preceeding the ellipsis, which is used for compatibility with
4292+
C versions before C23. It is an error to provide two or more variadic arguments.
4293+
This function initializes the given ``__builtin_va_list`` object. It is
4294+
undefined behavior to call this function on an already initialized
4295+
``__builtin_va_list`` object.
4296+
42864297
* ``void __builtin_va_end(__builtin_va_list list)``
42874298
42884299
A builtin function for the target-specific ``va_end`` function-like macro. This

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ C2y Feature Support
123123

124124
C23 Feature Support
125125
^^^^^^^^^^^^^^^^^^^
126+
- Added ``__builtin_c23_va_start()`` for compatibility with GCC and to enable
127+
better diagnostic behavior for the ``va_start()`` macro in C23 and later.
128+
This also updates the definition of ``va_start()`` in ``<stdarg.h>`` to use
129+
the new builtin. Fixes #GH124031.
126130

127131
Non-comprehensive list of changes in this release
128132
-------------------------------------------------

clang/include/clang/Basic/Builtins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum LanguageID : uint16_t {
4444
OCL_DSE = 0x400, // builtin requires OpenCL device side enqueue.
4545
ALL_OCL_LANGUAGES = 0x800, // builtin for OCL languages.
4646
HLSL_LANG = 0x1000, // builtin requires HLSL.
47+
C23_LANG = 0x2000, // builtin requires C23 or later.
4748
ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
4849
ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode.
4950
ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,12 @@ def BuiltinVaStart : Builtin {
833833
let Prototype = "void(__builtin_va_list_ref, ...)";
834834
}
835835

836+
def BuiltinC23VaStart : LangBuiltin<"C23_LANG"> {
837+
let Spellings = ["__builtin_c23_va_start"];
838+
let Attributes = [NoThrow, CustomTypeChecking];
839+
let Prototype = "void(__builtin_va_list_ref, ...)";
840+
}
841+
836842
def BuiltinStdargStart : Builtin {
837843
let Spellings = ["__builtin_stdarg_start"];
838844
let Attributes = [NoThrow, CustomTypeChecking];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10619,6 +10619,9 @@ def warn_second_arg_of_va_start_not_last_non_variadic_param : Warning<
1061910619
def warn_c17_compat_ellipsis_only_parameter : Warning<
1062010620
"'...' as the only parameter of a function is incompatible with C standards "
1062110621
"before C23">, DefaultIgnore, InGroup<CPre23Compat>;
10622+
def warn_c17_compat_va_start_one_arg : Warning<
10623+
"passing only one argument to 'va_start' is incompatible with C standards "
10624+
"before C23">, DefaultIgnore, InGroup<CPre23Compat>;
1062210625
def warn_va_start_type_is_undefined : Warning<
1062310626
"passing %select{an object that undergoes default argument promotion|"
1062410627
"an object of reference type|a parameter declared with the 'register' "

0 commit comments

Comments
 (0)