Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/release-binaries-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ on:
required: true
default: false
type: boolean
secrets:
RELEASE_TASKS_USER_TOKEN:
description: "Secret used to check user permissions."
required: false

pull_request:
types:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
# add extra CMake args to disable them.
# See https://github.com/llvm/llvm-project/issues/99767
if [ "$RUNNER_OS" = "macOS" ]; then
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF"
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_COMPILER_RT_ENABLE_IOS=OFF"
if [ "$RUNNER_ARCH" = "ARM64" ]; then
arches=arm64
else
Expand All @@ -144,7 +144,7 @@ jobs:
# so we need to disable flang there.
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;polly;mlir'"
fi
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches"
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches"
fi

build_flang="true"
Expand Down
53 changes: 50 additions & 3 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Improvements to clangd
Inlay hints
^^^^^^^^^^^

- Added `DefaultArguments` Inlay Hints option.
- Added support for inlay hints for default arguments, enabled using the
`DefaultArguments` config option (#GH95712)

Diagnostics
^^^^^^^^^^^
Expand All @@ -67,35 +68,81 @@ Semantic Highlighting
Compile flags
^^^^^^^^^^^^^

- Fixed a bug where clangd would unnecessarily reparse open files whose
compile command did not change when receiving a new compile command
via an LSP `workspace/configuration` request (#GH115438)

Hover
^^^^^

- Hovering over a function name now shows the function's documentation
comment even if the comment is written above the function's out-of-line
definition in a different source file (#GH67802)

Code completion
^^^^^^^^^^^^^^^

- Added an `ArgumentLists` config option under `Completion`. This is a more
flexible version of the `--function-arg-placeholders` command line flag,
allowing users more detailed control of what is inserted in argument list
position when clangd completes the name of a function in a function call
context. (#GH111322)
- Clangd now supports configuring which headers should be inserted using
`<>` vs. `""` syntax using the `QuotedHeaders` and `AngledHeaders` config
options under `Style` (#GH67749)
- Added completion for C++20 keywords.
- Improved code completion behaviour in dependent/templated code
- Completion items now include documentation comments in more cases (#GH120099)

Code actions
^^^^^^^^^^^^

- Added `Swap operands` tweak for certain binary operators.

- Improved the extract-to-function code action to allow extracting statements
with overloaded operators like ``<<`` of ``std::ostream``.
- `Define outline` now handles member functions of class templates, and
member function templates.
- `Extract variable` can now operate on the top-level expression in an
expression statement (#GH112525)

Signature help
^^^^^^^^^^^^^^

Cross-references
^^^^^^^^^^^^^^^^

- Clangd now supports the "outgoing calls" direction of call hierarchy
(#GH77556)
- Call hierarchy can now be invoked on fields and namespace-scope
variables (#GH113900)
- Improved heuristics for filtering out generated Protobuf symbol names
during indexing (#GH110091)
- Compiler intrinsics defined in `*intrin.h` system headers are now
indexed even if they have reserved names (#GH119735)
- Various improvements to go-to-definition in templated code

Objective-C
^^^^^^^^^^^

Clang-tidy integration
^^^^^^^^^^^^^^^^^^^^^^

- Improved robustness in handling clang-tidy check names (#GH109421)

C++20 Modules Support
^^^^^^^^^^^^^^^^^^^^^

- Support code completion for symbols defined in modules (#GH110083)
- Improve performance when opening files that import modules (#GH106683)
- Compile commands for modules now respect modifications specified in `.clangd`
files (#GH122606)

Miscellaneous
^^^^^^^^^^^^^

- The DefineOutline tweak now handles member functions of class templates.
- Fixed an OOM affecting some versions of libcxx headers compiled in C++20
mode (#GH108866)
- Various other stability improvements, e.g. crash fixes

Improvements to clang-doc
-------------------------
Expand Down
13 changes: 11 additions & 2 deletions clang/docs/ClangFormatStyleOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4735,15 +4735,24 @@ the configuration (without a prefix: ``Auto``).
.. _Language:

**Language** (``LanguageKind``) :versionbadge:`clang-format 3.5` :ref:`¶ <Language>`
Language, this format style is targeted at.
The language that this format style targets.

.. note::

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

Possible values:

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

* ``LK_C`` (in configuration: ``C``)
Should be used for C.

* ``LK_Cpp`` (in configuration: ``Cpp``)
Should be used for C, C++.
Should be used for C++.

* ``LK_CSharp`` (in configuration: ``CSharp``)
Should be used for C#.
Expand Down
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,10 @@ clang-format
- Adds ``WrapNamespaceBodyWithEmptyLines`` option.
- Adds the ``IndentExportBlock`` option.
- Adds ``PenaltyBreakBeforeMemberAccess`` option.
- Add the C language instead of treating it like C++.
- Allow specifying the language (C, C++, or Objective-C) for a ``.h`` file by
adding a special comment (e.g. ``// clang-format Language: ObjC``) near the
top of the file.

libclang
--------
Expand Down
17 changes: 14 additions & 3 deletions clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3275,7 +3275,9 @@ struct FormatStyle {
enum LanguageKind : int8_t {
/// Do not use.
LK_None,
/// Should be used for C, C++.
/// Should be used for C.
LK_C,
/// Should be used for C++.
LK_Cpp,
/// Should be used for C#.
LK_CSharp,
Expand All @@ -3300,7 +3302,9 @@ struct FormatStyle {
/// https://sci-hub.st/10.1109/IEEESTD.2018.8299595
LK_Verilog
};
bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
bool isCpp() const {
return Language == LK_Cpp || Language == LK_C || Language == LK_ObjC;
}
bool isCSharp() const { return Language == LK_CSharp; }
bool isJson() const { return Language == LK_Json; }
bool isJavaScript() const { return Language == LK_JavaScript; }
Expand All @@ -3310,7 +3314,12 @@ struct FormatStyle {
}
bool isTableGen() const { return Language == LK_TableGen; }

/// Language, this format style is targeted at.
/// The language that this format style targets.
/// \note
/// You can specify the language (``C``, ``Cpp``, or ``ObjC``) for ``.h``
/// files by adding a ``// clang-format Language:`` line before the first
/// non-comment (and non-empty) line, e.g. ``// clang-format Language: Cpp``.
/// \endnote
/// \version 3.5
LanguageKind Language;

Expand Down Expand Up @@ -5665,6 +5674,8 @@ FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
// Returns a string representation of ``Language``.
inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
switch (Language) {
case FormatStyle::LK_C:
return "C";
case FormatStyle::LK_Cpp:
return "C++";
case FormatStyle::LK_CSharp:
Expand Down
43 changes: 42 additions & 1 deletion clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ template <> struct MappingTraits<FormatStyle::KeepEmptyLinesStyle> {

template <> struct ScalarEnumerationTraits<FormatStyle::LanguageKind> {
static void enumeration(IO &IO, FormatStyle::LanguageKind &Value) {
IO.enumCase(Value, "C", FormatStyle::LK_C);
IO.enumCase(Value, "Cpp", FormatStyle::LK_Cpp);
IO.enumCase(Value, "Java", FormatStyle::LK_Java);
IO.enumCase(Value, "JavaScript", FormatStyle::LK_JavaScript);
Expand Down Expand Up @@ -3952,7 +3953,12 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) {
LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;

LangOpts.LineComment = 1;
LangOpts.CXXOperatorNames = Style.isCpp();

const auto Language = Style.Language;
LangOpts.C17 = Language == FormatStyle::LK_C;
LangOpts.CXXOperatorNames =
Language == FormatStyle::LK_Cpp || Language == FormatStyle::LK_ObjC;

LangOpts.Bool = 1;
LangOpts.ObjC = 1;
LangOpts.MicrosoftExt = 1; // To get kw___try, kw___finally.
Expand All @@ -3977,6 +3983,8 @@ const char *StyleOptionHelpDescription =
" --style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";

static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
if (FileName.ends_with(".c"))
return FormatStyle::LK_C;
if (FileName.ends_with(".java"))
return FormatStyle::LK_Java;
if (FileName.ends_with_insensitive(".js") ||
Expand Down Expand Up @@ -4016,6 +4024,35 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
return FormatStyle::LK_Cpp;
}

static FormatStyle::LanguageKind getLanguageByComment(const Environment &Env) {
const auto ID = Env.getFileID();
const auto &SourceMgr = Env.getSourceManager();

LangOptions LangOpts;
LangOpts.CPlusPlus = 1;
LangOpts.LineComment = 1;

Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
Lex.SetCommentRetentionState(true);

for (Token Tok; !Lex.LexFromRawLexer(Tok) && Tok.is(tok::comment);) {
auto Text = StringRef(SourceMgr.getCharacterData(Tok.getLocation()),
Tok.getLength());
if (!Text.consume_front("// clang-format Language:"))
continue;

Text = Text.trim();
if (Text == "C")
return FormatStyle::LK_C;
if (Text == "Cpp")
return FormatStyle::LK_Cpp;
if (Text == "ObjC")
return FormatStyle::LK_ObjC;
}

return FormatStyle::LK_None;
}

FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code) {
const auto GuessedLanguage = getLanguageByFileName(FileName);
if (GuessedLanguage == FormatStyle::LK_Cpp) {
Expand All @@ -4025,6 +4062,10 @@ FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code) {
if (!Code.empty() && (Extension.empty() || Extension == ".h")) {
auto NonEmptyFileName = FileName.empty() ? "guess.h" : FileName;
Environment Env(Code, NonEmptyFileName, /*Ranges=*/{});
if (const auto Language = getLanguageByComment(Env);
Language != FormatStyle::LK_None) {
return Language;
}
ObjCHeaderStyleGuesser Guesser(Env, getLLVMStyle());
Guesser.process();
if (Guesser.isObjC())
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/Format/FormatToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ static SmallVector<StringRef> CppNonKeywordTypes = {
};

bool FormatToken::isTypeName(const LangOptions &LangOpts) const {
const bool IsCpp = LangOpts.CXXOperatorNames;
return is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts) ||
(IsCpp && is(tok::identifier) &&
std::binary_search(CppNonKeywordTypes.begin(),
CppNonKeywordTypes.end(), TokenText));
if (is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts))
return true;
return (LangOpts.CXXOperatorNames || LangOpts.C17) && is(tok::identifier) &&
std::binary_search(CppNonKeywordTypes.begin(),
CppNonKeywordTypes.end(), TokenText);
}

bool FormatToken::isTypeOrIdentifier(const LangOptions &LangOpts) const {
Expand Down
23 changes: 0 additions & 23 deletions clang/lib/Format/FormatToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,29 +743,6 @@ struct FormatToken {
return isOneOf(tok::star, tok::amp, tok::ampamp);
}

bool isCppAlternativeOperatorKeyword() const {
assert(!TokenText.empty());
if (!isalpha(TokenText[0]))
return false;

switch (Tok.getKind()) {
case tok::ampamp:
case tok::ampequal:
case tok::amp:
case tok::pipe:
case tok::tilde:
case tok::exclaim:
case tok::exclaimequal:
case tok::pipepipe:
case tok::pipeequal:
case tok::caret:
case tok::caretequal:
return true;
default:
return false;
}
}

bool isUnaryOperator() const {
switch (Tok.getKind()) {
case tok::plus:
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class AnnotatingParser {
: Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
IsCpp(Style.isCpp()), LangOpts(getFormattingLangOpts(Style)),
Keywords(Keywords), Scopes(Scopes), TemplateDeclarationDepth(0) {
assert(IsCpp == LangOpts.CXXOperatorNames);
assert(IsCpp == (LangOpts.CXXOperatorNames || LangOpts.C17));
Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
resetTokenMetadata();
}
Expand Down Expand Up @@ -3820,7 +3820,7 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
};

const auto *Next = Current.Next;
const bool IsCpp = LangOpts.CXXOperatorNames;
const bool IsCpp = LangOpts.CXXOperatorNames || LangOpts.C17;

// Find parentheses of parameter list.
if (Current.is(tok::kw_operator)) {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/TokenAnnotator.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class TokenAnnotator {
TokenAnnotator(const FormatStyle &Style, const AdditionalKeywords &Keywords)
: Style(Style), IsCpp(Style.isCpp()),
LangOpts(getFormattingLangOpts(Style)), Keywords(Keywords) {
assert(IsCpp == LangOpts.CXXOperatorNames);
assert(IsCpp == (LangOpts.CXXOperatorNames || LangOpts.C17));
}

/// Adapts the indent levels of comment lines to the indent of the
Expand Down
8 changes: 1 addition & 7 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ UnwrappedLineParser::UnwrappedLineParser(
: IG_Inited),
IncludeGuardToken(nullptr), FirstStartColumn(FirstStartColumn),
Macros(Style.Macros, SourceMgr, Style, Allocator, IdentTable) {
assert(IsCpp == LangOpts.CXXOperatorNames);
assert(IsCpp == (LangOpts.CXXOperatorNames || LangOpts.C17));
}

void UnwrappedLineParser::reset() {
Expand Down Expand Up @@ -1712,12 +1712,6 @@ void UnwrappedLineParser::parseStructuralElement(
OpeningBrace && OpeningBrace->isOneOf(TT_RequiresExpressionLBrace,
TT_CompoundRequirementLBrace);
!eof();) {
if (IsCpp && FormatTok->isCppAlternativeOperatorKeyword()) {
if (auto *Next = Tokens->peekNextToken(/*SkipComment=*/true);
Next && Next->isBinaryOperator()) {
FormatTok->Tok.setKind(tok::identifier);
}
}
const FormatToken *Previous = FormatTok->Previous;
switch (FormatTok->Tok.getKind()) {
case tok::at:
Expand Down
Loading