Skip to content

Commit 36a844b

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: I034f03ed97fb9eecc3db2e9aa1507eab7603c966
2 parents 5fa3ff9 + b68340c commit 36a844b

File tree

146 files changed

+3679
-2113
lines changed

Some content is hidden

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

146 files changed

+3679
-2113
lines changed

clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,28 @@ findMembersUsedInInitExpr(const CXXCtorInitializer *Initializer,
116116
return Results;
117117
}
118118

119+
/// Returns the full source range for the field declaration up to (not
120+
/// including) the trailing semicolumn, including potential macro invocations,
121+
/// e.g. `int a GUARDED_BY(mu);`.
122+
static SourceRange getFullFieldSourceRange(const FieldDecl &Field,
123+
const ASTContext &Context) {
124+
SourceRange Range = Field.getSourceRange();
125+
SourceLocation End = Range.getEnd();
126+
const SourceManager &SM = Context.getSourceManager();
127+
const LangOptions &LangOpts = Context.getLangOpts();
128+
while (true) {
129+
std::optional<Token> CurrentToken = Lexer::findNextToken(End, SM, LangOpts);
130+
131+
if (!CurrentToken || CurrentToken->is(tok::semi))
132+
break;
133+
134+
if (CurrentToken->is(tok::eof))
135+
return Range; // Something is wrong, return the original range.
136+
End = CurrentToken->getLastLoc();
137+
}
138+
return SourceRange(Range.getBegin(), End);
139+
}
140+
119141
/// Reorders fields in the definition of a struct/class.
120142
///
121143
/// At the moment reordering of fields with
@@ -145,9 +167,10 @@ static bool reorderFieldsInDefinition(
145167
const auto FieldIndex = Field->getFieldIndex();
146168
if (FieldIndex == NewFieldsOrder[FieldIndex])
147169
continue;
148-
addReplacement(Field->getSourceRange(),
149-
Fields[NewFieldsOrder[FieldIndex]]->getSourceRange(),
150-
Context, Replacements);
170+
addReplacement(
171+
getFullFieldSourceRange(*Field, Context),
172+
getFullFieldSourceRange(*Fields[NewFieldsOrder[FieldIndex]], Context),
173+
Context, Replacements);
151174
}
152175
return true;
153176
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: clang-reorder-fields -record-name Foo -fields-order y,x %s -- | FileCheck %s
2+
3+
#define GUARDED_BY(x) __attribute__((guarded_by(x)))
4+
5+
class Foo {
6+
int x GUARDED_BY(x); // CHECK: {{^ int y;}}
7+
int y; // CHECK-NEXT: {{^ int x GUARDED_BY\(x\);}}
8+
};
9+

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3759,9 +3759,9 @@ the configuration (without a prefix: ``Auto``).
37593759
lists.
37603760

37613761
Important differences:
3762-
- No spaces inside the braced list.
3763-
- No line break before the closing brace.
3764-
- Indentation with the continuation indent, not with the block indent.
3762+
* No spaces inside the braced list.
3763+
* No line break before the closing brace.
3764+
* Indentation with the continuation indent, not with the block indent.
37653765

37663766
Fundamentally, C++11 braced lists are formatted exactly like function
37673767
calls would be formatted in their place. If the braced list follows a name
@@ -4104,10 +4104,10 @@ the configuration (without a prefix: ``Auto``).
41044104
When guessing whether a #include is the "main" include (to assign
41054105
category 0, see above), use this regex of allowed suffixes to the header
41064106
stem. A partial match is done, so that:
4107-
- "" means "arbitrary suffix"
4108-
- "$" means "no suffix"
4107+
* ``""`` means "arbitrary suffix"
4108+
* ``"$"`` means "no suffix"
41094109

4110-
For example, if configured to "(_test)?$", then a header a.h would be seen
4110+
For example, if configured to ``"(_test)?$"``, then a header a.h would be seen
41114111
as the "main" include in both a.cc and a_test.cc.
41124112

41134113
.. _IncludeIsMainSourceRegex:
@@ -5313,21 +5313,21 @@ the configuration (without a prefix: ``Auto``).
53135313

53145314
**QualifierOrder** (``List of Strings``) :versionbadge:`clang-format 14` :ref:`<QualifierOrder>`
53155315
The order in which the qualifiers appear.
5316-
Order is an array that can contain any of the following:
5316+
The order is an array that can contain any of the following:
53175317

5318-
* const
5319-
* inline
5320-
* static
5321-
* friend
5322-
* constexpr
5323-
* volatile
5324-
* restrict
5325-
* type
5318+
* ``const``
5319+
* ``inline``
5320+
* ``static``
5321+
* ``friend``
5322+
* ``constexpr``
5323+
* ``volatile``
5324+
* ``restrict``
5325+
* ``type``
53265326

53275327

53285328
.. note::
53295329

5330-
It **must** contain ``type``.
5330+
It must contain ``type``.
53315331

53325332
Items to the left of ``type`` will be placed to the left of the type and
53335333
aligned in the order supplied. Items to the right of ``type`` will be
@@ -6645,12 +6645,11 @@ the configuration (without a prefix: ``Auto``).
66456645
.. _StatementMacros:
66466646

66476647
**StatementMacros** (``List of Strings``) :versionbadge:`clang-format 8` :ref:`<StatementMacros>`
6648-
A vector of macros that should be interpreted as complete
6649-
statements.
6648+
A vector of macros that should be interpreted as complete statements.
66506649

6651-
Typical macros are expressions, and require a semi-colon to be
6652-
added; sometimes this is not the case, and this allows to make
6653-
clang-format aware of such cases.
6650+
Typical macros are expressions and require a semicolon to be added.
6651+
Sometimes this is not the case, and this allows to make clang-format aware
6652+
of such cases.
66546653

66556654
For example: Q_UNUSED
66566655

clang/docs/ReleaseNotes.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ Improvements to Clang's diagnostics
657657
- Clang now supports using alias templates in deduction guides, aligning with the C++ standard,
658658
which treats alias templates as synonyms for their underlying types (#GH54909).
659659

660+
- Clang now diagnoses dangling references for C++20's parenthesized aggregate initialization (#101957).
661+
660662
Improvements to Clang's time-trace
661663
----------------------------------
662664

@@ -803,6 +805,7 @@ Bug Fixes to AST Handling
803805
and ``relatedalso`` comment commands.
804806
- Clang now uses the location of the begin of the member expression for ``CallExpr``
805807
involving deduced ``this``. (#GH116928)
808+
- Fixed printout of AST that uses pack indexing expression. (#GH116486)
806809

807810
Miscellaneous Bug Fixes
808811
^^^^^^^^^^^^^^^^^^^^^^^
@@ -1055,6 +1058,16 @@ Moved checkers
10551058
original checkers were implemented only using AST matching and make more
10561059
sense as a single clang-tidy check.
10571060

1061+
- The checker ``alpha.unix.Chroot`` was modernized, improved and moved to
1062+
``unix.Chroot``. Testing was done on open source projects that use chroot(),
1063+
and false issues addressed in the improvements based on real use cases. Open
1064+
source projects used for testing include nsjail, lxroot, dive and ruri.
1065+
This checker conforms to SEI Cert C recommendation `POS05-C. Limit access to
1066+
files by creating a jail
1067+
<https://wiki.sei.cmu.edu/confluence/display/c/POS05-C.+Limit+access+to+files+by+creating+a+jail>`_.
1068+
Fixes (#GH34697).
1069+
(#GH117791) [Documentation](https://clang.llvm.org/docs/analyzer/checkers.html#unix-chroot-c).
1070+
10581071
.. _release-notes-sanitizers:
10591072

10601073
Sanitizers

clang/docs/analyzer/checkers.rst

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,37 @@ Critical section handling functions modeled by this checker:
17501750
}
17511751
}
17521752
1753+
.. _unix-Chroot:
1754+
1755+
unix.Chroot (C)
1756+
"""""""""""""""
1757+
Check improper use of chroot described by SEI Cert C recommendation `POS05-C.
1758+
Limit access to files by creating a jail
1759+
<https://wiki.sei.cmu.edu/confluence/display/c/POS05-C.+Limit+access+to+files+by+creating+a+jail>`_.
1760+
The checker finds usage patterns where ``chdir("/")`` is not called immediately
1761+
after a call to ``chroot(path)``.
1762+
1763+
.. code-block:: c
1764+
1765+
void f();
1766+
1767+
void test_bad() {
1768+
chroot("/usr/local");
1769+
f(); // warn: no call of chdir("/") immediately after chroot
1770+
}
1771+
1772+
void test_bad_path() {
1773+
chroot("/usr/local");
1774+
chdir("/usr"); // warn: no call of chdir("/") immediately after chroot
1775+
f();
1776+
}
1777+
1778+
void test_good() {
1779+
chroot("/usr/local");
1780+
chdir("/"); // no warning
1781+
f();
1782+
}
1783+
17531784
.. _unix-Errno:
17541785
17551786
unix.Errno (C)
@@ -3298,21 +3329,6 @@ SEI CERT checkers which tries to find errors based on their `C coding rules <htt
32983329
alpha.unix
32993330
^^^^^^^^^^
33003331
3301-
.. _alpha-unix-Chroot:
3302-
3303-
alpha.unix.Chroot (C)
3304-
"""""""""""""""""""""
3305-
Check improper use of chroot.
3306-
3307-
.. code-block:: c
3308-
3309-
void f();
3310-
3311-
void test() {
3312-
chroot("/usr/local");
3313-
f(); // warn: no call of chdir("/") immediately after chroot
3314-
}
3315-
33163332
.. _alpha-unix-PthreadLock:
33173333
33183334
alpha.unix.PthreadLock (C)

clang/include/clang/Format/Format.h

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,9 +2506,9 @@ struct FormatStyle {
25062506
/// lists.
25072507
///
25082508
/// Important differences:
2509-
/// - No spaces inside the braced list.
2510-
/// - No line break before the closing brace.
2511-
/// - Indentation with the continuation indent, not with the block indent.
2509+
/// * No spaces inside the braced list.
2510+
/// * No line break before the closing brace.
2511+
/// * Indentation with the continuation indent, not with the block indent.
25122512
///
25132513
/// Fundamentally, C++11 braced lists are formatted exactly like function
25142514
/// calls would be formatted in their place. If the braced list follows a name
@@ -3742,19 +3742,19 @@ struct FormatStyle {
37423742
QualifierAlignmentStyle QualifierAlignment;
37433743

37443744
/// The order in which the qualifiers appear.
3745-
/// Order is an array that can contain any of the following:
3745+
/// The order is an array that can contain any of the following:
37463746
///
3747-
/// * const
3748-
/// * inline
3749-
/// * static
3750-
/// * friend
3751-
/// * constexpr
3752-
/// * volatile
3753-
/// * restrict
3754-
/// * type
3747+
/// * ``const``
3748+
/// * ``inline``
3749+
/// * ``static``
3750+
/// * ``friend``
3751+
/// * ``constexpr``
3752+
/// * ``volatile``
3753+
/// * ``restrict``
3754+
/// * ``type``
37553755
///
37563756
/// \note
3757-
/// It **must** contain ``type``.
3757+
/// It must contain ``type``.
37583758
/// \endnote
37593759
///
37603760
/// Items to the left of ``type`` will be placed to the left of the type and
@@ -5449,10 +5449,10 @@ formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
54495449
/// cleaning up the code after that on success; otherwise, return an llvm::Error
54505450
/// carrying llvm::StringError.
54515451
/// This also supports inserting/deleting C++ #include directives:
5452-
/// - If a replacement has offset UINT_MAX, length 0, and a replacement text
5452+
/// * If a replacement has offset UINT_MAX, length 0, and a replacement text
54535453
/// that is an #include directive, this will insert the #include into the
54545454
/// correct block in the \p Code.
5455-
/// - If a replacement has offset UINT_MAX, length 1, and a replacement text
5455+
/// * If a replacement has offset UINT_MAX, length 1, and a replacement text
54565456
/// that is the name of the header to be removed, the header will be removed
54575457
/// from \p Code if it exists.
54585458
/// The include manipulation is done via ``tooling::HeaderInclude``, see its
@@ -5558,13 +5558,12 @@ extern const char *DefaultFallbackStyle;
55585558
///
55595559
/// ``StyleName`` can take several forms:
55605560
/// * "{<key>: <value>, ...}" - Set specic style parameters.
5561-
/// * "<style name>" - One of the style names supported by
5562-
/// getPredefinedStyle().
5561+
/// * "<style name>" - One of the style names supported by getPredefinedStyle().
55635562
/// * "file" - Load style configuration from a file called ``.clang-format``
5564-
/// located in one of the parent directories of ``FileName`` or the current
5565-
/// directory if ``FileName`` is empty.
5563+
/// located in one of the parent directories of ``FileName`` or the current
5564+
/// directory if ``FileName`` is empty.
55665565
/// * "file:<format_file_path>" to explicitly specify the configuration file to
5567-
/// use.
5566+
/// use.
55685567
///
55695568
/// \param[in] StyleName Style name to interpret according to the description
55705569
/// above.

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,14 @@ def VforkChecker : Checker<"Vfork">,
599599
HelpText<"Check for proper usage of vfork">,
600600
Documentation<HasDocumentation>;
601601

602-
} // end "unix"
603-
604-
let ParentPackage = UnixAlpha in {
605-
606602
def ChrootChecker : Checker<"Chroot">,
607603
HelpText<"Check improper use of chroot">,
608604
Documentation<HasDocumentation>;
609605

606+
} // end "unix"
607+
608+
let ParentPackage = UnixAlpha in {
609+
610610
def PthreadLockChecker : Checker<"PthreadLock">,
611611
HelpText<"Simple lock -> unlock checker">,
612612
Dependencies<[PthreadLockBase]>,

clang/include/clang/Tooling/Inclusions/IncludeStyle.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ struct IncludeStyle {
123123
/// When guessing whether a #include is the "main" include (to assign
124124
/// category 0, see above), use this regex of allowed suffixes to the header
125125
/// stem. A partial match is done, so that:
126-
/// - "" means "arbitrary suffix"
127-
/// - "$" means "no suffix"
126+
/// * ``""`` means "arbitrary suffix"
127+
/// * ``"$"`` means "no suffix"
128128
///
129-
/// For example, if configured to "(_test)?$", then a header a.h would be seen
129+
/// For example, if configured to ``"(_test)?$"``, then a header a.h would be seen
130130
/// as the "main" include in both a.cc and a_test.cc.
131131
/// \version 3.9
132132
std::string IncludeIsMainRegex;

clang/lib/AST/StmtPrinter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,10 @@ void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
25142514
}
25152515

25162516
void StmtPrinter::VisitPackIndexingExpr(PackIndexingExpr *E) {
2517-
OS << E->getPackIdExpression() << "...[" << E->getIndexExpr() << "]";
2517+
PrintExpr(E->getPackIdExpression());
2518+
OS << "...[";
2519+
PrintExpr(E->getIndexExpr());
2520+
OS << "]";
25182521
}
25192522

25202523
void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ void Flang::AddAArch64TargetArgs(const ArgList &Args,
203203
}
204204
}
205205

206+
void Flang::AddLoongArch64TargetArgs(const ArgList &Args,
207+
ArgStringList &CmdArgs) const {
208+
const Driver &D = getToolChain().getDriver();
209+
// Currently, flang only support `-mabi=lp64d` in LoongArch64.
210+
if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
211+
StringRef V = A->getValue();
212+
if (V != "lp64d") {
213+
D.Diag(diag::err_drv_argument_not_allowed_with) << "-mabi" << V;
214+
}
215+
}
216+
}
217+
206218
void Flang::AddPPCTargetArgs(const ArgList &Args,
207219
ArgStringList &CmdArgs) const {
208220
const Driver &D = getToolChain().getDriver();
@@ -416,6 +428,7 @@ void Flang::addTargetOptions(const ArgList &Args,
416428
break;
417429
case llvm::Triple::loongarch64:
418430
getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
431+
AddLoongArch64TargetArgs(Args, CmdArgs);
419432
break;
420433
}
421434

clang/lib/Driver/ToolChains/Flang.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
7070
void AddAMDGPUTargetArgs(const llvm::opt::ArgList &Args,
7171
llvm::opt::ArgStringList &CmdArgs) const;
7272

73+
/// Add specific options for LoongArch64 target.
74+
///
75+
/// \param [in] Args The list of input driver arguments
76+
/// \param [out] CmdArgs The list of output command arguments
77+
void AddLoongArch64TargetArgs(const llvm::opt::ArgList &Args,
78+
llvm::opt::ArgStringList &CmdArgs) const;
79+
7380
/// Add specific options for RISC-V target.
7481
///
7582
/// \param [in] Args The list of input driver arguments

clang/lib/Interpreter/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(LLVM_LINK_COMPONENTS
1616
if (EMSCRIPTEN AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
1717
set(WASM_SRC Wasm.cpp)
1818
set(WASM_LINK lldWasm)
19+
set(COMMON_LINK lldCommon)
1920
endif()
2021

2122
add_clang_library(clangInterpreter
@@ -47,6 +48,7 @@ add_clang_library(clangInterpreter
4748
clangSema
4849
clangSerialization
4950
${WASM_LINK}
51+
${COMMON_LINK}
5052
)
5153

5254
if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS)

0 commit comments

Comments
 (0)