Skip to content

Commit b29f0a5

Browse files
authored
merge main into amd-staging (llvm#1927)
2 parents e245f7c + a9fed22 commit b29f0a5

Some content is hidden

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

43 files changed

+668
-143
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5195,6 +5195,29 @@ the configuration (without a prefix: ``Auto``).
51955195
Add a space in front of an Objective-C protocol list, i.e. use
51965196
``Foo <Protocol>`` instead of ``Foo<Protocol>``.
51975197

5198+
.. _OneLineFormatOffRegex:
5199+
5200+
**OneLineFormatOffRegex** (``String``) :versionbadge:`clang-format 21` :ref:`<OneLineFormatOffRegex>`
5201+
A regular expression that describes markers for turning formatting off for
5202+
one line. If it matches a comment that is the only token of a line,
5203+
clang-format skips the comment and the next line. Otherwise, clang-format
5204+
skips lines containing a matched token.
5205+
5206+
.. code-block:: c++
5207+
5208+
// OneLineFormatOffRegex: ^(// NOLINT|logger$)
5209+
// results in the output below:
5210+
int a;
5211+
int b ; // NOLINT
5212+
int c;
5213+
// NOLINTNEXTLINE
5214+
int d ;
5215+
int e;
5216+
s = "// NOLINT";
5217+
logger() ;
5218+
logger2();
5219+
my_logger();
5220+
51985221
.. _PPIndentWidth:
51995222

52005223
**PPIndentWidth** (``Integer``) :versionbadge:`clang-format 13` :ref:`<PPIndentWidth>`

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ Non-comprehensive list of changes in this release
251251
- Added `__builtin_elementwise_minnum` and `__builtin_elementwise_maxnum`.
252252
- No longer crashing on invalid Objective-C categories and extensions when
253253
dumping the AST as JSON. (#GH137320)
254+
- Clang itself now uses split stacks instead of threads for allocating more
255+
stack space when running on Apple AArch64 based platforms. This means that
256+
stack traces of Clang from debuggers, crashes, and profilers may look
257+
different than before.
254258

255259
New Compiler Flags
256260
------------------
@@ -762,6 +766,7 @@ clang-format
762766
top of the file.
763767
- Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
764768
``enum`` enumerator lists.
769+
- Add ``OneLineFormatOffRegex`` option for turning formatting off for one line.
765770

766771
libclang
767772
--------

clang/include/clang/Basic/Stack.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ namespace clang {
2727

2828
/// Call this once on each thread, as soon after starting the thread as
2929
/// feasible, to note the approximate address of the bottom of the stack.
30-
void noteBottomOfStack();
30+
///
31+
/// \param ForceSet set to true if you know the call is near the bottom of a
32+
/// new stack. Used for split stacks.
33+
void noteBottomOfStack(bool ForceSet = false);
3134

3235
/// Determine whether the stack is nearly exhausted.
3336
bool isStackNearlyExhausted();

clang/include/clang/Format/Format.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,6 +3654,27 @@ struct FormatStyle {
36543654
/// \version 3.7
36553655
bool ObjCSpaceBeforeProtocolList;
36563656

3657+
/// A regular expression that describes markers for turning formatting off for
3658+
/// one line. If it matches a comment that is the only token of a line,
3659+
/// clang-format skips the comment and the next line. Otherwise, clang-format
3660+
/// skips lines containing a matched token.
3661+
/// \code
3662+
/// // OneLineFormatOffRegex: ^(// NOLINT|logger$)
3663+
/// // results in the output below:
3664+
/// int a;
3665+
/// int b ; // NOLINT
3666+
/// int c;
3667+
/// // NOLINTNEXTLINE
3668+
/// int d ;
3669+
/// int e;
3670+
/// s = "// NOLINT";
3671+
/// logger() ;
3672+
/// logger2();
3673+
/// my_logger();
3674+
/// \endcode
3675+
/// \version 21
3676+
std::string OneLineFormatOffRegex;
3677+
36573678
/// Different ways to try to fit all constructor initializers on a line.
36583679
enum PackConstructorInitializersStyle : int8_t {
36593680
/// Always put each constructor initializer on its own line.
@@ -5399,6 +5420,7 @@ struct FormatStyle {
53995420
ObjCPropertyAttributeOrder == R.ObjCPropertyAttributeOrder &&
54005421
ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
54015422
ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
5423+
OneLineFormatOffRegex == R.OneLineFormatOffRegex &&
54025424
PackConstructorInitializers == R.PackConstructorInitializers &&
54035425
PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
54045426
PenaltyBreakBeforeFirstCallParameter ==

clang/include/clang/Sema/Sema.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,15 @@ enum class FormatStringType {
510510
Unknown
511511
};
512512

513+
// Used for emitting the right warning by DefaultVariadicArgumentPromotion
514+
enum class VariadicCallType {
515+
Function,
516+
Block,
517+
Method,
518+
Constructor,
519+
DoesNotApply
520+
};
521+
513522
/// Sema - This implements semantic analysis and AST building for C.
514523
/// \nosubgrouping
515524
class Sema final : public SemaBase {
@@ -2381,15 +2390,6 @@ class Sema final : public SemaBase {
23812390
void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr,
23822391
SourceLocation OpLoc);
23832392

2384-
// Used for emitting the right warning by DefaultVariadicArgumentPromotion
2385-
enum VariadicCallType {
2386-
VariadicFunction,
2387-
VariadicBlock,
2388-
VariadicMethod,
2389-
VariadicConstructor,
2390-
VariadicDoesNotApply
2391-
};
2392-
23932393
bool IsLayoutCompatible(QualType T1, QualType T2) const;
23942394
bool IsPointerInterconvertibleBaseOf(const TypeSourceInfo *Base,
23952395
const TypeSourceInfo *Derived);
@@ -7739,13 +7739,12 @@ class Sema final : public SemaBase {
77397739

77407740
/// GatherArgumentsForCall - Collector argument expressions for various
77417741
/// form of call prototypes.
7742-
bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl,
7743-
const FunctionProtoType *Proto,
7744-
unsigned FirstParam, ArrayRef<Expr *> Args,
7745-
SmallVectorImpl<Expr *> &AllArgs,
7746-
VariadicCallType CallType = VariadicDoesNotApply,
7747-
bool AllowExplicit = false,
7748-
bool IsListInitialization = false);
7742+
bool GatherArgumentsForCall(
7743+
SourceLocation CallLoc, FunctionDecl *FDecl,
7744+
const FunctionProtoType *Proto, unsigned FirstParam,
7745+
ArrayRef<Expr *> Args, SmallVectorImpl<Expr *> &AllArgs,
7746+
VariadicCallType CallType = VariadicCallType::DoesNotApply,
7747+
bool AllowExplicit = false, bool IsListInitialization = false);
77497748

77507749
// DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
77517750
// will create a runtime trap if the resulting type is not a POD type.

clang/lib/AST/ByteCode/InterpFrame.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,18 @@ void InterpFrame::destroy(unsigned Idx) {
107107
template <typename T>
108108
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx,
109109
QualType Ty) {
110-
V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty);
110+
if constexpr (std::is_same_v<Pointer, T>) {
111+
if (Ty->isPointerOrReferenceType())
112+
V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty);
113+
else {
114+
if (std::optional<APValue> RValue = V.toRValue(ASTCtx, Ty))
115+
RValue->printPretty(OS, ASTCtx, Ty);
116+
else
117+
OS << "...";
118+
}
119+
} else {
120+
V.toAPValue(ASTCtx).printPretty(OS, ASTCtx, Ty);
121+
}
111122
}
112123

113124
static bool shouldSkipInBacktrace(const Function *F) {

clang/lib/Basic/Stack.cpp

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,13 @@
1313

1414
#include "clang/Basic/Stack.h"
1515
#include "llvm/Support/CrashRecoveryContext.h"
16+
#include "llvm/Support/ProgramStack.h"
1617

17-
#ifdef _MSC_VER
18-
#include <intrin.h> // for _AddressOfReturnAddress
19-
#endif
18+
static LLVM_THREAD_LOCAL uintptr_t BottomOfStack = 0;
2019

21-
static LLVM_THREAD_LOCAL void *BottomOfStack = nullptr;
22-
23-
static void *getStackPointer() {
24-
#if __GNUC__ || __has_builtin(__builtin_frame_address)
25-
return __builtin_frame_address(0);
26-
#elif defined(_MSC_VER)
27-
return _AddressOfReturnAddress();
28-
#else
29-
char CharOnStack = 0;
30-
// The volatile store here is intended to escape the local variable, to
31-
// prevent the compiler from optimizing CharOnStack into anything other
32-
// than a char on the stack.
33-
//
34-
// Tested on: MSVC 2015 - 2019, GCC 4.9 - 9, Clang 3.2 - 9, ICC 13 - 19.
35-
char *volatile Ptr = &CharOnStack;
36-
return Ptr;
37-
#endif
38-
}
39-
40-
void clang::noteBottomOfStack() {
41-
if (!BottomOfStack)
42-
BottomOfStack = getStackPointer();
20+
void clang::noteBottomOfStack(bool ForceSet) {
21+
if (!BottomOfStack || ForceSet)
22+
BottomOfStack = llvm::getStackPointer();
4323
}
4424

4525
bool clang::isStackNearlyExhausted() {
@@ -51,7 +31,8 @@ bool clang::isStackNearlyExhausted() {
5131
if (!BottomOfStack)
5232
return false;
5333

54-
intptr_t StackDiff = (intptr_t)getStackPointer() - (intptr_t)BottomOfStack;
34+
intptr_t StackDiff =
35+
(intptr_t)llvm::getStackPointer() - (intptr_t)BottomOfStack;
5536
size_t StackUsage = (size_t)std::abs(StackDiff);
5637

5738
// If the stack pointer has a surprising value, we do not understand this
@@ -66,9 +47,12 @@ bool clang::isStackNearlyExhausted() {
6647
void clang::runWithSufficientStackSpaceSlow(llvm::function_ref<void()> Diag,
6748
llvm::function_ref<void()> Fn) {
6849
llvm::CrashRecoveryContext CRC;
69-
CRC.RunSafelyOnThread([&] {
70-
noteBottomOfStack();
50+
// Preserve the BottomOfStack in case RunSafelyOnNewStack uses split stacks.
51+
uintptr_t PrevBottom = BottomOfStack;
52+
CRC.RunSafelyOnNewStack([&] {
53+
noteBottomOfStack(true);
7154
Diag();
7255
Fn();
7356
}, DesiredStackSize);
57+
BottomOfStack = PrevBottom;
7458
}

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,7 @@ template <> struct MappingTraits<FormatStyle> {
11001100
IO.mapOptional("ObjCSpaceAfterProperty", Style.ObjCSpaceAfterProperty);
11011101
IO.mapOptional("ObjCSpaceBeforeProtocolList",
11021102
Style.ObjCSpaceBeforeProtocolList);
1103+
IO.mapOptional("OneLineFormatOffRegex", Style.OneLineFormatOffRegex);
11031104
IO.mapOptional("PackConstructorInitializers",
11041105
Style.PackConstructorInitializers);
11051106
IO.mapOptional("PenaltyBreakAssignment", Style.PenaltyBreakAssignment);

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ FormatTokenLexer::FormatTokenLexer(
3232
LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
3333
Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
3434
Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
35-
FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
35+
FormattingDisabled(false), FormatOffRegex(Style.OneLineFormatOffRegex),
36+
MacroBlockBeginRegex(Style.MacroBlockBegin),
3637
MacroBlockEndRegex(Style.MacroBlockEnd) {
3738
Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
3839
Lex->SetKeepWhitespaceMode(true);
@@ -83,8 +84,42 @@ FormatTokenLexer::FormatTokenLexer(
8384
ArrayRef<FormatToken *> FormatTokenLexer::lex() {
8485
assert(Tokens.empty());
8586
assert(FirstInLineIndex == 0);
87+
enum { FO_None, FO_CurrentLine, FO_NextLine } FormatOff = FO_None;
8688
do {
8789
Tokens.push_back(getNextToken());
90+
auto &Tok = *Tokens.back();
91+
const auto NewlinesBefore = Tok.NewlinesBefore;
92+
switch (FormatOff) {
93+
case FO_CurrentLine:
94+
if (NewlinesBefore == 0)
95+
Tok.Finalized = true;
96+
else
97+
FormatOff = FO_None;
98+
break;
99+
case FO_NextLine:
100+
if (NewlinesBefore > 1) {
101+
FormatOff = FO_None;
102+
} else {
103+
Tok.Finalized = true;
104+
FormatOff = FO_CurrentLine;
105+
}
106+
break;
107+
default:
108+
if (!FormattingDisabled && FormatOffRegex.match(Tok.TokenText)) {
109+
if (Tok.is(tok::comment) &&
110+
(NewlinesBefore > 0 || Tokens.size() == 1)) {
111+
Tok.Finalized = true;
112+
FormatOff = FO_NextLine;
113+
} else {
114+
for (auto *Token : reverse(Tokens)) {
115+
Token->Finalized = true;
116+
if (Token->NewlinesBefore > 0)
117+
break;
118+
}
119+
FormatOff = FO_CurrentLine;
120+
}
121+
}
122+
}
88123
if (Style.isJavaScript()) {
89124
tryParseJSRegexLiteral();
90125
handleTemplateStrings();

clang/lib/Format/FormatTokenLexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class FormatTokenLexer {
134134
VariableTemplates;
135135

136136
bool FormattingDisabled;
137+
llvm::Regex FormatOffRegex; // For one line.
137138

138139
llvm::Regex MacroBlockBeginRegex;
139140
llvm::Regex MacroBlockEndRegex;

0 commit comments

Comments
 (0)