Skip to content

Commit 1d22fba

Browse files
author
z1.cciauto
committed
merge main into amd-staging
2 parents e57eb67 + 9e82ee5 commit 1d22fba

File tree

89 files changed

+1632
-606
lines changed

Some content is hidden

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

89 files changed

+1632
-606
lines changed

clang-tools-extra/docs/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ Options
3737
.. option:: UseCXXStaticCastsInCppSources
3838

3939
When suggesting fix-its for C++ code, should C++-style ``static_cast<>()``'s
40-
be suggested, or C-style casts. Defaults to ``true``.
40+
be suggested, or C-style casts. Defaults to `true`.
4141

4242
.. option:: UseCXXHeadersInCppSources
4343

4444
When suggesting to include the appropriate header in C++ code,
4545
should ``<cstddef>`` header be suggested, or ``<stddef.h>``.
46-
Defaults to ``true``.
46+
Defaults to `true`.
4747

4848
.. option:: IgnoreConstantIntExpr
4949

5050
If the multiplication operands are compile-time constants (like literals or
5151
are ``constexpr``) and fit within the source expression type, do not emit a
5252
diagnostic or suggested fix. Only considers expressions where the source
53-
expression is a signed integer type. Defaults to ``false``.
53+
expression is a signed integer type. Defaults to `false`.
5454

5555
Examples:
5656

clang-tools-extra/docs/clang-tidy/checks/cert/err33-c.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ This check is an alias of check :doc:`bugprone-unused-return-value <../bugprone/
190190
with a fixed set of functions.
191191

192192
Suppressing issues by casting to ``void`` is enabled by default and can be
193-
disabled by setting `AllowCastToVoid` option to ``false``.
193+
disabled by setting `AllowCastToVoid` option to `false`.
194194

195195
The check corresponds to a part of CERT C Coding Standard rule `ERR33-C.
196196
Detect and handle standard library errors

clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ lives.
144144

145145
When set to true convert loops when in C++20 or later mode using
146146
``std::ranges::reverse_view``.
147-
Default value is ``true``.
147+
Default value is `true`.
148148

149149
.. option:: MakeReverseRangeFunction
150150

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4786,17 +4786,20 @@ the configuration (without a prefix: ``Auto``).
47864786

47874787
.. note::
47884788

4789-
You can also specify the language (``Cpp`` or ``ObjC``) for ``.h`` files
4790-
by adding a ``// clang-format Language:`` line before the first
4789+
You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h``
4790+
files by adding a ``// clang-format Language:`` line before the first
47914791
non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``.
47924792

47934793
Possible values:
47944794

47954795
* ``LK_None`` (in configuration: ``None``)
47964796
Do not use.
47974797

4798+
* ``LK_C`` (in configuration: ``C``)
4799+
Should be used for C.
4800+
47984801
* ``LK_Cpp`` (in configuration: ``Cpp``)
4799-
Should be used for C, C++.
4802+
Should be used for C++.
48004803

48014804
* ``LK_CSharp`` (in configuration: ``CSharp``)
48024805
Should be used for C#.

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,10 @@ clang-format
271271
- Adds ``BreakBeforeTemplateCloser`` option.
272272
- Adds ``BinPackLongBracedList`` option to override bin packing options in
273273
long (20 item or more) braced list initializer lists.
274-
- Allow specifying the language (C++ or Objective-C) for a ``.h`` file by adding
275-
a special comment (e.g. ``// clang-format Language: ObjC``) near the top of
276-
the file.
274+
- Add the C language instead of treating it like C++.
275+
- Allow specifying the language (C, C++, or Objective-C) for a ``.h`` file by
276+
adding a special comment (e.g. ``// clang-format Language: ObjC``) near the
277+
top of the file.
277278

278279
libclang
279280
--------

clang/include/clang/Format/Format.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,7 +3318,9 @@ struct FormatStyle {
33183318
enum LanguageKind : int8_t {
33193319
/// Do not use.
33203320
LK_None,
3321-
/// Should be used for C, C++.
3321+
/// Should be used for C.
3322+
LK_C,
3323+
/// Should be used for C++.
33223324
LK_Cpp,
33233325
/// Should be used for C#.
33243326
LK_CSharp,
@@ -3343,7 +3345,9 @@ struct FormatStyle {
33433345
/// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
33443346
LK_Verilog
33453347
};
3346-
bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
3348+
bool isCpp() const {
3349+
return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC;
3350+
}
33473351
bool isCSharp() const { return Language == LK_CSharp; }
33483352
bool isJson() const { return Language == LK_Json; }
33493353
bool isJavaScript() const { return Language == LK_JavaScript; }
@@ -3355,8 +3359,8 @@ struct FormatStyle {
33553359

33563360
/// The language that this format style targets.
33573361
/// \note
3358-
/// You can also specify the language (``Cpp`` or ``ObjC``) for ``.h`` files
3359-
/// by adding a ``// clang-format Language:`` line before the first
3362+
/// You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h``
3363+
/// files by adding a ``// clang-format Language:`` line before the first
33603364
/// non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``.
33613365
/// \endnote
33623366
/// \version 3.5
@@ -5715,6 +5719,8 @@ FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
57155719
// Returns a string representation of ``Language``.
57165720
inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
57175721
switch (Language) {
5722+
case FormatStyle::LK_C:
5723+
return "C";
57185724
case FormatStyle::LK_Cpp:
57195725
return "C++";
57205726
case FormatStyle::LK_CSharp:

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,11 +1015,14 @@ static bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
10151015
assert(Desc->isRecord() || Desc->isCompositeArray());
10161016

10171017
if (Desc->isCompositeArray()) {
1018+
unsigned N = Desc->getNumElems();
1019+
if (N == 0)
1020+
return true;
10181021
const Descriptor *ElemDesc = Desc->ElemDesc;
10191022
assert(ElemDesc->isRecord());
10201023

10211024
Pointer RP(const_cast<Block *>(B));
1022-
for (unsigned I = 0; I != Desc->getNumElems(); ++I) {
1025+
for (int I = static_cast<int>(N) - 1; I >= 0; --I) {
10231026
if (!runRecordDestructor(S, OpPC, RP.atIndex(I).narrow(), ElemDesc))
10241027
return false;
10251028
}
@@ -1238,8 +1241,10 @@ static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func,
12381241
const Pointer &ThisPtr) {
12391242
assert(Func->isConstructor());
12401243

1241-
const Descriptor *D = ThisPtr.getFieldDesc();
1244+
if (Func->getParentDecl()->isInvalidDecl())
1245+
return false;
12421246

1247+
const Descriptor *D = ThisPtr.getFieldDesc();
12431248
// FIXME: I think this case is not 100% correct. E.g. a pointer into a
12441249
// subobject of a composite array.
12451250
if (!D->ElemRecord)
@@ -1377,6 +1382,18 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
13771382
size_t ArgSize = Func->getArgSize() + VarArgSize;
13781383
size_t ThisOffset = ArgSize - (Func->hasRVO() ? primSize(PT_Ptr) : 0);
13791384
Pointer &ThisPtr = S.Stk.peek<Pointer>(ThisOffset);
1385+
const FunctionDecl *Callee = Func->getDecl();
1386+
1387+
// C++2a [class.abstract]p6:
1388+
// the effect of making a virtual call to a pure virtual function [...] is
1389+
// undefined
1390+
if (Callee->isPureVirtual()) {
1391+
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_pure_virtual_call,
1392+
1)
1393+
<< Callee;
1394+
S.Note(Callee->getLocation(), diag::note_declared_at);
1395+
return false;
1396+
}
13801397

13811398
const CXXRecordDecl *DynamicDecl = nullptr;
13821399
{
@@ -1393,7 +1410,7 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
13931410
assert(DynamicDecl);
13941411

13951412
const auto *StaticDecl = cast<CXXRecordDecl>(Func->getParentDecl());
1396-
const auto *InitialFunction = cast<CXXMethodDecl>(Func->getDecl());
1413+
const auto *InitialFunction = cast<CXXMethodDecl>(Callee);
13971414
const CXXMethodDecl *Overrider = S.getContext().getOverridingFunction(
13981415
DynamicDecl, StaticDecl, InitialFunction);
13991416

clang/lib/Format/Format.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ template <> struct MappingTraits<FormatStyle::KeepEmptyLinesStyle> {
401401

402402
template <> struct ScalarEnumerationTraits<FormatStyle::LanguageKind> {
403403
static void enumeration(IO &IO, FormatStyle::LanguageKind &Value) {
404+
IO.enumCase(Value, "C", FormatStyle::LK_C);
404405
IO.enumCase(Value, "Cpp", FormatStyle::LK_Cpp);
405406
IO.enumCase(Value, "Java", FormatStyle::LK_Java);
406407
IO.enumCase(Value, "JavaScript", FormatStyle::LK_JavaScript);
@@ -3957,7 +3958,12 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) {
39573958
LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
39583959

39593960
LangOpts.LineComment = 1;
3960-
LangOpts.CXXOperatorNames = Style.isCpp();
3961+
3962+
const auto Language = Style.Language;
3963+
LangOpts.C17 = Language == FormatStyle::LK_C;
3964+
LangOpts.CXXOperatorNames =
3965+
Language == FormatStyle::LK_Cpp || Language == FormatStyle::LK_ObjC;
3966+
39613967
LangOpts.Bool = 1;
39623968
LangOpts.ObjC = 1;
39633969
LangOpts.MicrosoftExt = 1; // To get kw___try, kw___finally.
@@ -3982,6 +3988,8 @@ const char *StyleOptionHelpDescription =
39823988
" --style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
39833989

39843990
static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
3991+
if (FileName.ends_with(".c"))
3992+
return FormatStyle::LK_C;
39853993
if (FileName.ends_with(".java"))
39863994
return FormatStyle::LK_Java;
39873995
if (FileName.ends_with_insensitive(".js") ||
@@ -4039,6 +4047,8 @@ static FormatStyle::LanguageKind getLanguageByComment(const Environment &Env) {
40394047
continue;
40404048

40414049
Text = Text.trim();
4050+
if (Text == "C")
4051+
return FormatStyle::LK_C;
40424052
if (Text == "Cpp")
40434053
return FormatStyle::LK_Cpp;
40444054
if (Text == "ObjC")

clang/lib/Format/FormatToken.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ static SmallVector<StringRef> CppNonKeywordTypes = {
4444
bool FormatToken::isTypeName(const LangOptions &LangOpts) const {
4545
if (is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts))
4646
return true;
47-
const bool IsCpp = LangOpts.CXXOperatorNames;
48-
return IsCpp && is(tok::identifier) &&
47+
return (LangOpts.CXXOperatorNames || LangOpts.C17) && is(tok::identifier) &&
4948
std::binary_search(CppNonKeywordTypes.begin(),
5049
CppNonKeywordTypes.end(), TokenText);
5150
}

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class AnnotatingParser {
129129
: Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
130130
IsCpp(Style.isCpp()), LangOpts(getFormattingLangOpts(Style)),
131131
Keywords(Keywords), Scopes(Scopes), TemplateDeclarationDepth(0) {
132-
assert(IsCpp == LangOpts.CXXOperatorNames);
132+
assert(IsCpp == (LangOpts.CXXOperatorNames || LangOpts.C17));
133133
Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
134134
resetTokenMetadata();
135135
}
@@ -3821,7 +3821,7 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
38213821
};
38223822

38233823
const auto *Next = Current.Next;
3824-
const bool IsCpp = LangOpts.CXXOperatorNames;
3824+
const bool IsCpp = LangOpts.CXXOperatorNames || LangOpts.C17;
38253825

38263826
// Find parentheses of parameter list.
38273827
if (Current.is(tok::kw_operator)) {

0 commit comments

Comments
 (0)