Skip to content

Commit 520f43c

Browse files
authored
Merge branch 'main' into users/kparzysz/spr/m01-applymem
2 parents fa0d221 + adeff9f commit 520f43c

File tree

206 files changed

+6468
-2075
lines changed

Some content is hidden

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

206 files changed

+6468
-2075
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6843,6 +6843,45 @@ the configuration (without a prefix: ``Auto``).
68436843
68446844
For example: BOOST_PP_STRINGIZE
68456845

6846+
.. _WrapNamespaceBodyWithEmptyLines:
6847+
6848+
**WrapNamespaceBodyWithEmptyLines** (``WrapNamespaceBodyWithEmptyLinesStyle``) :versionbadge:`clang-format 20` :ref:`<WrapNamespaceBodyWithEmptyLines>`
6849+
Wrap namespace body with empty lines.
6850+
6851+
Possible values:
6852+
6853+
* ``WNBWELS_Never`` (in configuration: ``Never``)
6854+
Remove all empty lines at the beginning and the end of namespace body.
6855+
6856+
.. code-block:: c++
6857+
6858+
namespace N1 {
6859+
namespace N2
6860+
function();
6861+
}
6862+
}
6863+
6864+
* ``WNBWELS_Always`` (in configuration: ``Always``)
6865+
Always have at least one empty line at the beginning and the end of
6866+
namespace body except that the number of empty lines between consecutive
6867+
nested namespace definitions is not increased.
6868+
6869+
.. code-block:: c++
6870+
6871+
namespace N1 {
6872+
namespace N2 {
6873+
6874+
function();
6875+
6876+
}
6877+
}
6878+
6879+
* ``WNBWELS_Leave`` (in configuration: ``Leave``)
6880+
Keep existing newlines at the beginning and the end of namespace body.
6881+
``MaxEmptyLinesToKeep`` still applies.
6882+
6883+
6884+
68466885
.. END_FORMAT_STYLE_OPTIONS
68476886
68486887
Adding additional style options

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3641,7 +3641,7 @@ program location should be executed. It is expected to be used to implement
36413641
<https://llvm.org/docs/LangRef.html#llvm-allow-runtime-check-intrinsic>`_
36423642
intrinsic.
36433643
3644-
The ``__builtin_allow_runtime_check()`` can be used within constrol structures
3644+
The ``__builtin_allow_runtime_check()`` can be used within control structures
36453645
like ``if`` to guard expensive runtime checks. The return value is determined
36463646
by the following compiler options and may differ per call site:
36473647

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ Bug Fixes to C++ Support
886886
out of a module (which is the case e.g. in MSVC's implementation of ``std`` module). (#GH118218)
887887
- Fixed a pack expansion issue in checking unexpanded parameter sizes. (#GH17042)
888888
- Fixed a bug where captured structured bindings were modifiable inside non-mutable lambda (#GH95081)
889+
- Clang now identifies unexpanded parameter packs within the type constraint on a non-type template parameter. (#GH88866)
889890
- Fixed an issue while resolving type of expression indexing into a pack of values of non-dependent type (#GH121242)
890891

891892
Bug Fixes to AST Handling
@@ -1127,6 +1128,7 @@ clang-format
11271128
- Adds ``AllowShortNamespacesOnASingleLine`` option.
11281129
- Adds ``VariableTemplates`` option.
11291130
- Adds support for bash globstar in ``.clang-format-ignore``.
1131+
- Adds ``WrapNamespaceBodyWithEmptyLines`` option.
11301132

11311133
libclang
11321134
--------

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
186186
std::string ProfileExcludeFiles;
187187

188188
/// The version string to put into coverage files.
189-
char CoverageVersion[4];
189+
char CoverageVersion[4] = {'0', '0', '0', '0'};
190190

191191
/// Enable additional debugging information.
192192
std::string DebugPass;

clang/include/clang/Format/Format.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5143,6 +5143,39 @@ struct FormatStyle {
51435143
/// \version 11
51445144
std::vector<std::string> WhitespaceSensitiveMacros;
51455145

5146+
/// Different styles for wrapping namespace body with empty lines.
5147+
enum WrapNamespaceBodyWithEmptyLinesStyle : int8_t {
5148+
/// Remove all empty lines at the beginning and the end of namespace body.
5149+
/// \code
5150+
/// namespace N1 {
5151+
/// namespace N2
5152+
/// function();
5153+
/// }
5154+
/// }
5155+
/// \endcode
5156+
WNBWELS_Never,
5157+
/// Always have at least one empty line at the beginning and the end of
5158+
/// namespace body except that the number of empty lines between consecutive
5159+
/// nested namespace definitions is not increased.
5160+
/// \code
5161+
/// namespace N1 {
5162+
/// namespace N2 {
5163+
///
5164+
/// function();
5165+
///
5166+
/// }
5167+
/// }
5168+
/// \endcode
5169+
WNBWELS_Always,
5170+
/// Keep existing newlines at the beginning and the end of namespace body.
5171+
/// ``MaxEmptyLinesToKeep`` still applies.
5172+
WNBWELS_Leave
5173+
};
5174+
5175+
/// Wrap namespace body with empty lines.
5176+
/// \version 20
5177+
WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines;
5178+
51465179
bool operator==(const FormatStyle &R) const {
51475180
return AccessModifierOffset == R.AccessModifierOffset &&
51485181
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
@@ -5326,7 +5359,8 @@ struct FormatStyle {
53265359
UseTab == R.UseTab && VariableTemplates == R.VariableTemplates &&
53275360
VerilogBreakBetweenInstancePorts ==
53285361
R.VerilogBreakBetweenInstancePorts &&
5329-
WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros;
5362+
WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
5363+
WrapNamespaceBodyWithEmptyLines == R.WrapNamespaceBodyWithEmptyLines;
53305364
}
53315365

53325366
std::optional<FormatStyle> GetLanguageStyle(LanguageKind Language) const;

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -997,13 +997,15 @@ class CXX20ModulesGenerator : public PCHGenerator {
997997
virtual Module *getEmittingModule(ASTContext &Ctx) override;
998998

999999
CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1000-
StringRef OutputFile, bool GeneratingReducedBMI);
1000+
StringRef OutputFile, bool GeneratingReducedBMI,
1001+
bool AllowASTWithErrors);
10011002

10021003
public:
10031004
CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1004-
StringRef OutputFile)
1005+
StringRef OutputFile, bool AllowASTWithErrors = false)
10051006
: CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
1006-
/*GeneratingReducedBMI=*/false) {}
1007+
/*GeneratingReducedBMI=*/false,
1008+
AllowASTWithErrors) {}
10071009

10081010
void HandleTranslationUnit(ASTContext &Ctx) override;
10091011
};
@@ -1013,9 +1015,10 @@ class ReducedBMIGenerator : public CXX20ModulesGenerator {
10131015

10141016
public:
10151017
ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1016-
StringRef OutputFile)
1018+
StringRef OutputFile, bool AllowASTWithErrors = false)
10171019
: CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
1018-
/*GeneratingReducedBMI=*/true) {}
1020+
/*GeneratingReducedBMI=*/true,
1021+
AllowASTWithErrors) {}
10191022
};
10201023

10211024
/// If we can elide the definition of \param D in reduced BMI.

clang/lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6376,7 +6376,7 @@ ASTContext::getAutoType(QualType DeducedType, AutoTypeKeyword Keyword,
63766376
}
63776377

63786378
QualType ASTContext::getUnconstrainedType(QualType T) const {
6379-
QualType CanonT = T.getCanonicalType();
6379+
QualType CanonT = T.getNonPackExpansionType().getCanonicalType();
63806380

63816381
// Remove a type-constraint from a top-level auto or decltype(auto).
63826382
if (auto *AT = CanonT->getAs<AutoType>()) {

clang/lib/Basic/CodeGenOptions.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ CodeGenOptions::CodeGenOptions() {
1717
#include "clang/Basic/CodeGenOptions.def"
1818

1919
RelocationModel = llvm::Reloc::PIC_;
20-
memcpy(CoverageVersion, "408*", 4);
2120
}
2221

2322
void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
@@ -54,7 +53,6 @@ void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
5453
}
5554

5655
RelocationModel = llvm::Reloc::PIC_;
57-
memcpy(CoverageVersion, "408*", 4);
5856
}
5957

6058
} // end namespace clang

clang/lib/Format/Format.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,18 @@ template <> struct ScalarEnumerationTraits<FormatStyle::UseTabStyle> {
839839
}
840840
};
841841

842+
template <>
843+
struct ScalarEnumerationTraits<
844+
FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle> {
845+
static void
846+
enumeration(IO &IO,
847+
FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &Value) {
848+
IO.enumCase(Value, "Never", FormatStyle::WNBWELS_Never);
849+
IO.enumCase(Value, "Always", FormatStyle::WNBWELS_Always);
850+
IO.enumCase(Value, "Leave", FormatStyle::WNBWELS_Leave);
851+
}
852+
};
853+
842854
template <> struct MappingTraits<FormatStyle> {
843855
static void mapping(IO &IO, FormatStyle &Style) {
844856
// When reading, read the language first, we need it for getPredefinedStyle.
@@ -1171,6 +1183,8 @@ template <> struct MappingTraits<FormatStyle> {
11711183
Style.VerilogBreakBetweenInstancePorts);
11721184
IO.mapOptional("WhitespaceSensitiveMacros",
11731185
Style.WhitespaceSensitiveMacros);
1186+
IO.mapOptional("WrapNamespaceBodyWithEmptyLines",
1187+
Style.WrapNamespaceBodyWithEmptyLines);
11741188

11751189
// If AlwaysBreakAfterDefinitionReturnType was specified but
11761190
// BreakAfterReturnType was not, initialize the latter from the former for
@@ -1639,6 +1653,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
16391653
LLVMStyle.WhitespaceSensitiveMacros.push_back("NS_SWIFT_NAME");
16401654
LLVMStyle.WhitespaceSensitiveMacros.push_back("PP_STRINGIZE");
16411655
LLVMStyle.WhitespaceSensitiveMacros.push_back("STRINGIZE");
1656+
LLVMStyle.WrapNamespaceBodyWithEmptyLines = FormatStyle::WNBWELS_Leave;
16421657

16431658
LLVMStyle.PenaltyBreakAssignment = prec::Assignment;
16441659
LLVMStyle.PenaltyBreakBeforeFirstCallParameter = 19;

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,23 @@ static auto computeNewlines(const AnnotatedLine &Line,
15841584
Newlines = 1;
15851585
}
15861586

1587+
if (Style.WrapNamespaceBodyWithEmptyLines != FormatStyle::WNBWELS_Leave) {
1588+
// Modify empty lines after TT_NamespaceLBrace.
1589+
if (PreviousLine && PreviousLine->endsWith(TT_NamespaceLBrace)) {
1590+
if (Style.WrapNamespaceBodyWithEmptyLines == FormatStyle::WNBWELS_Never)
1591+
Newlines = 1;
1592+
else if (!Line.startsWithNamespace())
1593+
Newlines = std::max(Newlines, 2u);
1594+
}
1595+
// Modify empty lines before TT_NamespaceRBrace.
1596+
if (Line.startsWith(TT_NamespaceRBrace)) {
1597+
if (Style.WrapNamespaceBodyWithEmptyLines == FormatStyle::WNBWELS_Never)
1598+
Newlines = 1;
1599+
else if (!PreviousLine->startsWith(TT_NamespaceRBrace))
1600+
Newlines = std::max(Newlines, 2u);
1601+
}
1602+
}
1603+
15871604
// Insert or remove empty line before access specifiers.
15881605
if (PreviousLine && RootToken.isAccessSpecifier()) {
15891606
switch (Style.EmptyLineBeforeAccessModifier) {

0 commit comments

Comments
 (0)