Skip to content

Commit c9c6310

Browse files
committed
rebase
Created using spr 1.3.5-bogner
2 parents 41835cb + af4d76d commit c9c6310

File tree

392 files changed

+64294
-58583
lines changed

Some content is hidden

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

392 files changed

+64294
-58583
lines changed

clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -337,33 +337,34 @@ FileOptionsBaseProvider::FileOptionsBaseProvider(
337337
void FileOptionsBaseProvider::addRawFileOptions(
338338
llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
339339
auto CurSize = CurOptions.size();
340-
341340
// Look for a suitable configuration file in all parent directories of the
342341
// file. Start with the immediate parent directory and move up.
343-
StringRef Path = llvm::sys::path::parent_path(AbsolutePath);
344-
for (StringRef CurrentPath = Path; !CurrentPath.empty();
345-
CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
346-
std::optional<OptionsSource> Result;
347-
348-
auto Iter = CachedOptions.find(CurrentPath);
349-
if (Iter != CachedOptions.end())
350-
Result = Iter->second;
351-
352-
if (!Result)
353-
Result = tryReadConfigFile(CurrentPath);
354-
355-
if (Result) {
356-
// Store cached value for all intermediate directories.
357-
while (Path != CurrentPath) {
342+
StringRef RootPath = llvm::sys::path::parent_path(AbsolutePath);
343+
auto MemorizedConfigFile =
344+
[this, &RootPath](StringRef CurrentPath) -> std::optional<OptionsSource> {
345+
const auto Iter = CachedOptions.Memorized.find(CurrentPath);
346+
if (Iter != CachedOptions.Memorized.end())
347+
return CachedOptions.Storage[Iter->second];
348+
std::optional<OptionsSource> OptionsSource = tryReadConfigFile(CurrentPath);
349+
if (OptionsSource) {
350+
const size_t Index = CachedOptions.Storage.size();
351+
CachedOptions.Storage.emplace_back(OptionsSource.value());
352+
while (RootPath != CurrentPath) {
358353
LLVM_DEBUG(llvm::dbgs()
359-
<< "Caching configuration for path " << Path << ".\n");
360-
if (!CachedOptions.count(Path))
361-
CachedOptions[Path] = *Result;
362-
Path = llvm::sys::path::parent_path(Path);
354+
<< "Caching configuration for path " << RootPath << ".\n");
355+
CachedOptions.Memorized[RootPath] = Index;
356+
RootPath = llvm::sys::path::parent_path(RootPath);
363357
}
364-
CachedOptions[Path] = *Result;
365-
366-
CurOptions.push_back(*Result);
358+
CachedOptions.Memorized[CurrentPath] = Index;
359+
RootPath = llvm::sys::path::parent_path(CurrentPath);
360+
}
361+
return OptionsSource;
362+
};
363+
for (StringRef CurrentPath = RootPath; !CurrentPath.empty();
364+
CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
365+
if (std::optional<OptionsSource> Result =
366+
MemorizedConfigFile(CurrentPath)) {
367+
CurOptions.emplace_back(Result.value());
367368
if (!Result->first.InheritParentConfig.value_or(false))
368369
break;
369370
}

clang-tools-extra/clang-tidy/ClangTidyOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
241241
/// \c ConfigHandlers.
242242
std::optional<OptionsSource> tryReadConfigFile(llvm::StringRef Directory);
243243

244-
llvm::StringMap<OptionsSource> CachedOptions;
244+
struct OptionsCache {
245+
llvm::StringMap<size_t> Memorized;
246+
llvm::SmallVector<OptionsSource, 4U> Storage;
247+
} CachedOptions;
245248
ClangTidyOptions OverrideOptions;
246249
ConfigFileHandlers ConfigHandlers;
247250
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;

clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void UseInternalLinkageCheck::registerMatchers(MatchFinder *Finder) {
125125
exportDecl()))))));
126126
Finder->addMatcher(
127127
functionDecl(Common, hasBody(),
128-
unless(anyOf(cxxMethodDecl(),
128+
unless(anyOf(cxxMethodDecl(), isConsteval(),
129129
isAllocationOrDeallocationOverloadedFunction(),
130130
isMain())))
131131
.bind("fn"),

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ Improvements to clang-tidy
112112
the configuration options of the `Clang Static Analyzer Checks
113113
<https://clang.llvm.org/docs/analyzer/checkers.html>`_.
114114

115+
- Improved :program:`clang-tidy` by accepting parameters file in command line.
116+
115117
- Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise
116118
happening on certain platforms when interrupting the script.
117119

118-
- Improved :program:`clang-tidy` by accepting parameters file in command line.
119-
120120
- Removed :program:`clang-tidy`'s global options for most of checks. All options
121121
are changed to local options except `IncludeStyle`, `StrictMode` and
122122
`IgnoreMacros`. Global scoped `StrictMode` and `IgnoreMacros` are deprecated
@@ -286,13 +286,13 @@ Changes in existing checks
286286

287287
- Improved :doc:`misc-use-internal-linkage
288288
<clang-tidy/checks/misc/use-internal-linkage>` check to insert ``static``
289-
keyword before type qualifiers such as ``const`` and ``volatile`` and fix
290-
false positives for function declaration without body and fix false positives
291-
for C++20 export declarations and fix false positives for global scoped
289+
keyword before type qualifiers such as ``const`` and ``volatile``. Also, fix
290+
false positives for function declaration without body, C++20 consteval
291+
functions, C++20 export declarations, and global scoped
292292
overloaded ``operator new`` and ``operator delete``.
293293

294294
- Improved :doc:`modernize-avoid-c-arrays
295-
<clang-tidy/checks/modernize/avoid-c-arrays>` check to suggest using
295+
<clang-tidy/checks/modernize/avoid-c-arrays>` check to suggest using
296296
``std::span`` as a replacement for parameters of incomplete C array type in
297297
C++20 and ``std::array`` or ``std::vector`` before C++20.
298298

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %check_clang_tidy -std=c++20 %s misc-use-internal-linkage %t -- -- -I%S/Inputs/use-internal-linkage
2+
3+
consteval void gh122096() {}
4+
5+
constexpr void cxf() {}
6+
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: function 'cxf'
7+
// CHECK-FIXES: static constexpr void cxf() {}

clang/bindings/python/clang/cindex.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,10 @@ def spelling(self):
27012701
"""Retrieve the spelling of this Type."""
27022702
return _CXString.from_result(conf.lib.clang_getTypeSpelling(self))
27032703

2704+
def pretty_printed(self, policy):
2705+
"""Pretty-prints this Type with the given PrintingPolicy"""
2706+
return _CXString.from_result(conf.lib.clang_getTypePrettyPrinted(self, policy))
2707+
27042708
def __eq__(self, other):
27052709
if type(other) != type(self):
27062710
return False
@@ -3955,6 +3959,7 @@ def set_property(self, property, value):
39553959
("clang_getTypedefDeclUnderlyingType", [Cursor], Type),
39563960
("clang_getTypedefName", [Type], _CXString),
39573961
("clang_getTypeKindSpelling", [c_uint], _CXString),
3962+
("clang_getTypePrettyPrinted", [Type, PrintingPolicy], _CXString),
39583963
("clang_getTypeSpelling", [Type], _CXString),
39593964
("clang_hashCursor", [Cursor], c_uint),
39603965
("clang_isAttribute", [CursorKind], bool),

clang/bindings/python/tests/cindex/test_type.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import os
22

3-
from clang.cindex import Config, CursorKind, RefQualifierKind, TranslationUnit, TypeKind
3+
from clang.cindex import (
4+
Config,
5+
CursorKind,
6+
PrintingPolicy,
7+
PrintingPolicyProperty,
8+
RefQualifierKind,
9+
TranslationUnit,
10+
TypeKind,
11+
)
412

513
if "CLANG_LIBRARY_PATH" in os.environ:
614
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
@@ -517,3 +525,12 @@ class Template {
517525
# Variable without a template argument.
518526
cursor = get_cursor(tu, "bar")
519527
self.assertEqual(cursor.get_num_template_arguments(), -1)
528+
529+
def test_pretty(self):
530+
tu = get_tu("struct X {}; X x;", lang="cpp")
531+
f = get_cursor(tu, "x")
532+
533+
pp = PrintingPolicy.create(f)
534+
self.assertEqual(f.type.get_canonical().pretty_printed(pp), "X")
535+
pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False)
536+
self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X")

clang/docs/ReleaseNotes.rst

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ C++ Specific Potentially Breaking Changes
147147
// Fixed version:
148148
unsigned operator""_udl_name(unsigned long long);
149149

150-
- Clang will now produce an error diagnostic when [[clang::lifetimebound]] is
150+
- Clang will now produce an error diagnostic when ``[[clang::lifetimebound]]`` is
151151
applied on a parameter or an implicit object parameter of a function that
152152
returns void. This was previously ignored and had no effect. (#GH107556)
153153

@@ -156,6 +156,21 @@ C++ Specific Potentially Breaking Changes
156156
// Now diagnoses with an error.
157157
void f(int& i [[clang::lifetimebound]]);
158158

159+
- Clang will now produce an error diagnostic when ``[[clang::lifetimebound]]``
160+
is applied on a type (instead of a function parameter or an implicit object
161+
parameter); this includes the case when the attribute is specified for an
162+
unnamed function parameter. These were previously ignored and had no effect.
163+
(#GH118281)
164+
165+
.. code-block:: c++
166+
167+
// Now diagnoses with an error.
168+
int* [[clang::lifetimebound]] x;
169+
// Now diagnoses with an error.
170+
void f(int* [[clang::lifetimebound]] i);
171+
// Now diagnoses with an error.
172+
void g(int* [[clang::lifetimebound]]);
173+
159174
- Clang now rejects all field accesses on null pointers in constant expressions. The following code
160175
used to work but will now be rejected:
161176

@@ -947,6 +962,9 @@ Miscellaneous Clang Crashes Fixed
947962
- Fixed internal assertion firing when a declaration in the implicit global
948963
module is found through ADL. (GH#109879)
949964

965+
- Fixed a crash when an unscoped enumeration declared by an opaque-enum-declaration within a class template
966+
with a dependent underlying type is subject to integral promotion. (#GH117960)
967+
950968
OpenACC Specific Changes
951969
------------------------
952970

@@ -1069,6 +1087,12 @@ CUDA Support
10691087
- Clang now supports CUDA SDK up to 12.6
10701088
- Added support for sm_100
10711089
- Added support for `__grid_constant__` attribute.
1090+
- CUDA now uses the new offloading driver by default. The new driver supports
1091+
device-side LTO, interoperability with OpenMP and other languages, and native ``-fgpu-rdc``
1092+
support with static libraries. The old behavior can be returned using the
1093+
``--no-offload-new-driver`` flag. The binary format is no longer compatible
1094+
with the NVIDIA compiler's RDC-mode support. More information can be found at:
1095+
https://clang.llvm.org/docs/OffloadingDesign.html
10721096

10731097
AIX Support
10741098
^^^^^^^^^^^
@@ -1162,6 +1186,8 @@ libclang
11621186
--------
11631187
- Add ``clang_isBeforeInTranslationUnit``. Given two source locations, it determines
11641188
whether the first one comes strictly before the second in the source code.
1189+
- Add ``clang_getTypePrettyPrinted``. It allows controlling the PrintingPolicy used
1190+
to pretty-print a type.
11651191

11661192
Static Analyzer
11671193
---------------
@@ -1302,10 +1328,13 @@ Sanitizers
13021328
Python Binding Changes
13031329
----------------------
13041330
- Fixed an issue that led to crashes when calling ``Type.get_exception_specification_kind``.
1305-
- Added bindings for ``clang_getCursorPrettyPrinted`` and related functions,
1306-
which allow changing the formatting of pretty-printed code.
1307-
- Added binding for ``clang_Cursor_isAnonymousRecordDecl``, which allows checking if
1308-
a declaration is an anonymous union or anonymous struct.
1331+
- Added ``Cursor.pretty_printed``, a binding for ``clang_getCursorPrettyPrinted``,
1332+
and related functions, which allow changing the formatting of pretty-printed code.
1333+
- Added ``Cursor.is_anonymous_record_decl``, a binding for
1334+
``clang_Cursor_isAnonymousRecordDecl``, which allows checking if a
1335+
declaration is an anonymous union or anonymous struct.
1336+
- Added ``Type.pretty_printed`, a binding for ``clang_getTypePrettyPrinted``,
1337+
which allows changing the formatting of pretty-printed types.
13091338

13101339
OpenMP Support
13111340
--------------

clang/docs/UsersManual.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,38 @@ indexed format, regardeless whether it is produced by frontend or the IR pass.
30353035
overhead. ``prefer-atomic`` will be transformed to ``atomic`` when supported
30363036
by the target, or ``single`` otherwise.
30373037

3038+
.. option:: -ftemporal-profile
3039+
3040+
Enables the temporal profiling extension for IRPGO to improve startup time by
3041+
reducing ``.text`` section page faults. To do this, we instrument function
3042+
timestamps to measure when each function is called for the first time and use
3043+
this data to generate a function order to improve startup.
3044+
3045+
The profile is generated as normal.
3046+
3047+
.. code-block:: console
3048+
3049+
$ clang++ -O2 -fprofile-generate -ftemporal-profile code.cc -o code
3050+
$ ./code
3051+
$ llvm-profdata merge -o code.profdata yyy/zzz
3052+
3053+
Using the resulting profile, we can generate a function order to pass to the
3054+
linker via ``--symbol-ordering-file`` for ELF or ``-order_file`` for Mach-O.
3055+
3056+
.. code-block:: console
3057+
3058+
$ llvm-profdata order code.profdata -o code.orderfile
3059+
$ clang++ -O2 -Wl,--symbol-ordering-file=code.orderfile code.cc -o code
3060+
3061+
Or the profile can be passed to LLD directly.
3062+
3063+
.. code-block:: console
3064+
3065+
$ clang++ -O2 -fuse-ld=lld -Wl,--irpgo-profile=code.profdata,--bp-startup-sort=function code.cc -o code
3066+
3067+
For more information, please read the RFC:
3068+
https://discourse.llvm.org/t/rfc-temporal-profiling-extension-for-irpgo/68068
3069+
30383070
Fine Tuning Profile Collection
30393071
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30403072

clang/include/clang-c/Index.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4182,6 +4182,14 @@ CINDEX_LINKAGE void clang_PrintingPolicy_dispose(CXPrintingPolicy Policy);
41824182
CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor,
41834183
CXPrintingPolicy Policy);
41844184

4185+
/**
4186+
* Pretty-print the underlying type using a custom printing policy.
4187+
*
4188+
* If the type is invalid, an empty string is returned.
4189+
*/
4190+
CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT,
4191+
CXPrintingPolicy cxPolicy);
4192+
41854193
/**
41864194
* Retrieve the display name for the entity referenced by this cursor.
41874195
*

0 commit comments

Comments
 (0)