Skip to content

Commit 247267d

Browse files
committed
merge main into amd-staging
2 parents c96e4d4 + 4994174 commit 247267d

File tree

175 files changed

+1865
-3032
lines changed

Some content is hidden

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

175 files changed

+1865
-3032
lines changed

clang-tools-extra/clangd/index/YAMLSerialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ template <> struct MappingTraits<Ref> {
319319
MappingNormalization<NormalizedRefKind, RefKind> NKind(IO, R.Kind);
320320
IO.mapRequired("Kind", NKind->Kind);
321321
IO.mapRequired("Location", R.Location);
322+
IO.mapOptional("Container", R.Container);
322323
}
323324
};
324325

clang-tools-extra/clangd/index/remote/Index.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ message Symbol {
8181
message Ref {
8282
optional SymbolLocation location = 1;
8383
optional uint32 kind = 2;
84+
optional string container = 3;
8485
}
8586

8687
message SymbolInfo {

clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ llvm::Expected<clangd::Ref> Marshaller::fromProtobuf(const Ref &Message) {
203203
return Location.takeError();
204204
Result.Location = *Location;
205205
Result.Kind = static_cast<RefKind>(Message.kind());
206+
auto ContainerID = SymbolID::fromStr(Message.container());
207+
if (ContainerID)
208+
Result.Container = *ContainerID;
206209
return Result;
207210
}
208211

@@ -340,6 +343,7 @@ llvm::Expected<Ref> Marshaller::toProtobuf(const clangd::Ref &From) {
340343
if (!Location)
341344
return Location.takeError();
342345
*Result.mutable_location() = *Location;
346+
Result.set_container(From.Container.str());
343347
return Result;
344348
}
345349

clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ TEST(RemoteMarshallingTest, RefSerialization) {
223223
Location.FileURI = testPathURI(
224224
"llvm-project/llvm/clang-tools-extra/clangd/Protocol.h", Strings);
225225
Ref.Location = Location;
226+
Ref.Container = llvm::cantFail(SymbolID::fromStr("0000000000000001"));
226227

227228
Marshaller ProtobufMarshaller(testPath("llvm-project/"),
228229
testPath("llvm-project/"));

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ Improvements to clang-doc
8888
Improvements to clang-query
8989
---------------------------
9090

91+
Improvements to include-cleaner
92+
-------------------------------
93+
- Deprecated the ``-insert`` and ``-remove`` command line options, and added
94+
the ``-disable-remove`` and ``-disable-insert`` command line options as
95+
replacements. The previous command line options were confusing because they
96+
did not imply the default state of the option (which is inserts and removes
97+
being enabled). The new options are easier to understand the semantics of.
98+
9199
Improvements to clang-tidy
92100
--------------------------
93101

clang-tools-extra/include-cleaner/test/tool.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ int x = foo();
66
// CHANGE: - "foobar.h"
77
// CHANGE-NEXT: + "foo.h"
88

9-
// RUN: clang-include-cleaner -remove=0 -print=changes %s -- -I%S/Inputs/ | FileCheck --check-prefix=INSERT %s
9+
// RUN: clang-include-cleaner -disable-remove -print=changes %s -- -I%S/Inputs/ | FileCheck --check-prefix=INSERT %s
1010
// INSERT-NOT: - "foobar.h"
1111
// INSERT: + "foo.h"
1212

13-
// RUN: clang-include-cleaner -insert=0 -print=changes %s -- -I%S/Inputs/ | FileCheck --check-prefix=REMOVE %s
13+
// RUN: clang-include-cleaner -disable-insert -print=changes %s -- -I%S/Inputs/ | FileCheck --check-prefix=REMOVE %s
1414
// REMOVE: - "foobar.h"
1515
// REMOVE-NOT: + "foo.h"
1616

@@ -58,3 +58,16 @@ int x = foo();
5858
// RUN: FileCheck --match-full-lines --check-prefix=EDIT3 %s < %t.cpp
5959
// EDIT3: #include "foo.h"
6060
// EDIT3-NOT: {{^}}#include "foobar.h"{{$}}
61+
62+
// RUN: clang-include-cleaner -insert=false -print=changes %s -- -I%S/Inputs/ 2>&1 | \
63+
// RUN: FileCheck --check-prefix=DEPRECATED-INSERT %s
64+
// DEPRECATED-INSERT: warning: '-insert=0' is deprecated in favor of '-disable-insert'. The old flag was confusing since it suggested that inserts were disabled by default, when they were actually enabled.
65+
66+
// RUN: clang-include-cleaner -remove=false -print=changes %s -- -I%S/Inputs/ 2>&1 | \
67+
// RUN: FileCheck --check-prefix=DEPRECATED-REMOVE %s
68+
// DEPRECATED-REMOVE: warning: '-remove=0' is deprecated in favor of '-disable-remove'. The old flag was confusing since it suggested that removes were disabled by default, when they were actually enabled.
69+
70+
// RUN: clang-include-cleaner -insert=false -remove=false -print=changes %s -- -I%S/Inputs/ 2>&1 | \
71+
// RUN: FileCheck --check-prefix=DEPRECATED-BOTH %s
72+
// DEPRECATED-BOTH: warning: '-insert=0' is deprecated in favor of '-disable-insert'. The old flag was confusing since it suggested that inserts were disabled by default, when they were actually enabled.
73+
// DEPRECATED-BOTH: warning: '-remove=0' is deprecated in favor of '-disable-remove'. The old flag was confusing since it suggested that removes were disabled by default, when they were actually enabled.

clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,31 @@ cl::opt<bool> Edit{
9090
cl::desc("Apply edits to analyzed source files"),
9191
cl::cat(IncludeCleaner),
9292
};
93-
9493
cl::opt<bool> Insert{
9594
"insert",
96-
cl::desc("Allow header insertions"),
95+
cl::desc(
96+
"Allow header insertions (deprecated. Use -disable-insert instead)"),
9797
cl::init(true),
9898
cl::cat(IncludeCleaner),
9999
};
100100
cl::opt<bool> Remove{
101101
"remove",
102-
cl::desc("Allow header removals"),
102+
cl::desc("Allow header removals (deprecated. Use -disable-remove instead)"),
103103
cl::init(true),
104104
cl::cat(IncludeCleaner),
105105
};
106+
cl::opt<bool> DisableInsert{
107+
"disable-insert",
108+
cl::desc("Disable header insertions"),
109+
cl::init(false),
110+
cl::cat(IncludeCleaner),
111+
};
112+
cl::opt<bool> DisableRemove{
113+
"disable-remove",
114+
cl::desc("Disable header removals"),
115+
cl::init(false),
116+
cl::cat(IncludeCleaner),
117+
};
106118

107119
std::atomic<unsigned> Errors = ATOMIC_VAR_INIT(0);
108120

@@ -183,9 +195,26 @@ class Action : public clang::ASTFrontendAction {
183195
auto Results =
184196
analyze(AST.Roots, PP.MacroReferences, PP.Includes, &PI,
185197
getCompilerInstance().getPreprocessor(), HeaderFilter);
186-
if (!Insert)
198+
199+
if (!Insert) {
200+
llvm::errs()
201+
<< "warning: '-insert=0' is deprecated in favor of "
202+
"'-disable-insert'. "
203+
"The old flag was confusing since it suggested that inserts "
204+
"were disabled by default, when they were actually enabled.\n";
205+
}
206+
207+
if (!Remove) {
208+
llvm::errs()
209+
<< "warning: '-remove=0' is deprecated in favor of "
210+
"'-disable-remove'. "
211+
"The old flag was confusing since it suggested that removes "
212+
"were disabled by default, when they were actually enabled.\n";
213+
}
214+
215+
if (!Insert || DisableInsert)
187216
Results.Missing.clear();
188-
if (!Remove)
217+
if (!Remove || DisableRemove)
189218
Results.Unused.clear();
190219
std::string Final = fixIncludes(Results, AbsPath, Code, getStyle(AbsPath));
191220

clang/bindings/python/clang/cindex.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@
7171
from typing import (
7272
Any,
7373
Callable,
74+
cast as Tcast,
7475
Generic,
7576
Optional,
77+
Sequence,
7678
Type as TType,
7779
TypeVar,
7880
TYPE_CHECKING,
@@ -314,6 +316,8 @@ def is_in_system_header(self):
314316
return conf.lib.clang_Location_isInSystemHeader(self) # type: ignore [no-any-return]
315317

316318
def __eq__(self, other):
319+
if not isinstance(other, SourceLocation):
320+
return False
317321
return conf.lib.clang_equalLocations(self, other) # type: ignore [no-any-return]
318322

319323
def __ne__(self, other):
@@ -372,6 +376,8 @@ def end(self):
372376
return conf.lib.clang_getRangeEnd(self) # type: ignore [no-any-return]
373377

374378
def __eq__(self, other):
379+
if not isinstance(other, SourceRange):
380+
return False
375381
return conf.lib.clang_equalRanges(self, other) # type: ignore [no-any-return]
376382

377383
def __ne__(self, other):
@@ -1556,6 +1562,8 @@ def from_location(tu, location):
15561562
return cursor
15571563

15581564
def __eq__(self, other):
1565+
if not isinstance(other, Cursor):
1566+
return False
15591567
return conf.lib.clang_equalCursors(self, other) # type: ignore [no-any-return]
15601568

15611569
def __ne__(self, other):
@@ -1746,7 +1754,7 @@ def get_definition(self):
17461754

17471755
def get_usr(self):
17481756
"""Return the Unified Symbol Resolution (USR) for the entity referenced
1749-
by the given cursor (or None).
1757+
by the given cursor.
17501758
17511759
A Unified Symbol Resolution (USR) is a string that identifies a
17521760
particular entity (function, class, variable, etc.) within a
@@ -2776,7 +2784,7 @@ def pretty_printed(self, policy):
27762784
return _CXString.from_result(conf.lib.clang_getTypePrettyPrinted(self, policy))
27772785

27782786
def __eq__(self, other):
2779-
if type(other) != type(self):
2787+
if not isinstance(other, Type):
27802788
return False
27812789

27822790
return conf.lib.clang_equalTypes(self, other) # type: ignore [no-any-return]
@@ -2886,10 +2894,9 @@ def kind(self):
28862894
def string(self):
28872895
res = conf.lib.clang_getCompletionChunkCompletionString(self.cs, self.key)
28882896

2889-
if res:
2890-
return CompletionString(res)
2891-
else:
2892-
None
2897+
if not res:
2898+
return None
2899+
return CompletionString(res)
28932900

28942901
def isKindOptional(self):
28952902
return self.__kindNumber == 0
@@ -2955,6 +2962,13 @@ def __getitem__(self, key):
29552962
raise IndexError
29562963
return CompletionChunk(self.obj, key)
29572964

2965+
if TYPE_CHECKING:
2966+
# Defining __getitem__ and __len__ is enough to make an iterable
2967+
# but the typechecker doesn't understand that.
2968+
def __iter__(self):
2969+
for i in range(len(self)):
2970+
yield self[i]
2971+
29582972
@property
29592973
def priority(self):
29602974
return conf.lib.clang_getCompletionPriority(self.obj) # type: ignore [no-any-return]
@@ -2970,7 +2984,7 @@ def briefComment(self):
29702984
return _CXString.from_result(
29712985
conf.lib.clang_getCompletionBriefComment(self.obj)
29722986
)
2973-
return _CXString()
2987+
return ""
29742988

29752989
def __repr__(self):
29762990
return (
@@ -3155,8 +3169,8 @@ def from_source(
31553169
a list via args. These can be used to specify include paths, warnings,
31563170
etc. e.g. ["-Wall", "-I/path/to/include"].
31573171
3158-
In-memory file content can be provided via unsaved_files. This is an
3159-
iterable of 2-tuples. The first element is the filename (str or
3172+
In-memory file content can be provided via unsaved_files. This is a
3173+
list of 2-tuples. The first element is the filename (str or
31603174
PathLike). The second element defines the content. Content can be
31613175
provided as str source code or as file objects (anything with a read()
31623176
method). If a file object is being used, content will be read until EOF
@@ -3328,13 +3342,15 @@ def get_extent(self, filename, locations):
33283342
start_location, end_location = locations
33293343

33303344
if hasattr(start_location, "__len__"):
3345+
start_location = Tcast(Sequence[int], start_location)
33313346
start_location = SourceLocation.from_position(
33323347
self, f, start_location[0], start_location[1]
33333348
)
33343349
elif isinstance(start_location, int):
33353350
start_location = SourceLocation.from_offset(self, f, start_location)
33363351

33373352
if hasattr(end_location, "__len__"):
3353+
end_location = Tcast(Sequence[int], end_location)
33383354
end_location = SourceLocation.from_position(
33393355
self, f, end_location[0], end_location[1]
33403356
)
@@ -3464,6 +3480,8 @@ def get_tokens(self, locations=None, extent=None):
34643480
2-tuple of SourceLocation or as a SourceRange. If both are defined,
34653481
behavior is undefined.
34663482
"""
3483+
if locations is None and extent is None:
3484+
raise TypeError("get_tokens() requires at least one argument")
34673485
if locations is not None:
34683486
extent = SourceRange(start=locations[0], end=locations[1])
34693487

@@ -3510,11 +3528,11 @@ def __ne__(self, other) -> bool:
35103528
@staticmethod
35113529
def from_result(res, arg):
35123530
assert isinstance(res, c_object_p)
3513-
res = File(res)
3531+
file = File(res)
35143532

35153533
# Copy a reference to the TranslationUnit to prevent premature GC.
3516-
res._tu = arg._tu
3517-
return res
3534+
file._tu = arg._tu
3535+
return file
35183536

35193537

35203538
class FileInclusion:
@@ -3593,7 +3611,7 @@ def filename(self):
35933611
def arguments(self):
35943612
"""
35953613
Get an iterable object providing each argument in the
3596-
command line for the compiler invocation as a _CXString.
3614+
command line for the compiler invocation as a string.
35973615
35983616
Invariant : the first argument is the compiler executable
35993617
"""

clang/docs/ReleaseNotes.rst

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,16 @@ C Language Changes
141141
function type in Microsoft compatibility mode. #GH124869
142142
- Clang now allows ``restrict`` qualifier for array types with pointer elements (#GH92847).
143143
- Clang now diagnoses ``const``-qualified object definitions without an
144-
initializer. If the object is zero-initialized, it will be diagnosed under
145-
the new warning ``-Wdefault-const-init`` (which is grouped under
146-
``-Wc++-compat`` because this construct is not compatible with C++). If the
147-
object is left uninitialized, it will be diagnosed unsed the new warning
148-
``-Wdefault-const-init-unsafe`` (which is grouped under
149-
``-Wdefault-const-init``). #GH19297
144+
initializer. If the object is a variable or field which is zero-initialized,
145+
it will be diagnosed under the new warning ``-Wdefault-const-init-var`` or
146+
``-Wdefault-const-init-field``, respectively. Similarly, if the variable or
147+
field is not zero-initialized, it will be diagnosed under the new diagnostic
148+
``-Wdefault-const-init-var-unsafe`` or ``-Wdefault-const-init-field-unsafe``,
149+
respectively. The unsafe diagnostic variants are grouped under a new
150+
diagnostic ``-Wdefault-const-init-unsafe``, which itself is grouped under the
151+
new diagnostic ``-Wdefault-const-init``. Finally, ``-Wdefault-const-init`` is
152+
grouped under ``-Wc++-compat`` because these constructs are not compatible
153+
with C++. #GH19297
150154
- Added ``-Wimplicit-void-ptr-cast``, grouped under ``-Wc++-compat``, which
151155
diagnoses implicit conversion from ``void *`` to another pointer type as
152156
being incompatible with C++. (#GH17792)
@@ -171,6 +175,15 @@ C Language Changes
171175
``-Wenum-conversion`` and ``-Wimplicit-int-enum-cast``. This conversion is an
172176
int-to-enum conversion because the enumeration on the right-hand side is
173177
promoted to ``int`` before the assignment.
178+
- Added ``-Wtentative-definition-compat``, grouped under ``-Wc++-compat``,
179+
which diagnoses tentative definitions in C with multiple declarations as
180+
being incompatible with C++. e.g.,
181+
182+
.. code-block:: c
183+
184+
// File scope
185+
int i;
186+
int i; // Vaild C, invalid C++, now diagnosed
174187
- Added ``-Wunterminated-string-initialization``, grouped under ``-Wextra``,
175188
which diagnoses an initialization from a string literal where only the null
176189
terminator cannot be stored. e.g.,
@@ -188,6 +201,9 @@ C Language Changes
188201
``-Wunterminated-string-initialization``. However, this diagnostic is not
189202
silenced by the ``nonstring`` attribute as these initializations are always
190203
incompatible with C++.
204+
- Added the existing ``-Wduplicate-decl-specifier`` diagnostic, which is on by
205+
default, to ``-Wc++-compat`` because duplicated declaration specifiers are
206+
not valid in C++.
191207

192208
C2y Feature Support
193209
^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,32 @@ def BuiltinRequiresHeader : DiagGroup<"builtin-requires-header">;
156156
def C99Compat : DiagGroup<"c99-compat">;
157157
def C23Compat : DiagGroup<"c23-compat">;
158158
def : DiagGroup<"c2x-compat", [C23Compat]>;
159+
160+
def DuplicateDeclSpecifier : DiagGroup<"duplicate-decl-specifier">;
159161
def InitStringTooLongMissingNonString :
160162
DiagGroup<"unterminated-string-initialization">;
161163
def InitStringTooLongForCpp :
162164
DiagGroup<"c++-unterminated-string-initialization">;
163165
def HiddenCppDecl : DiagGroup<"c++-hidden-decl">;
164-
def DefaultConstInitUnsafe : DiagGroup<"default-const-init-unsafe">;
165-
def DefaultConstInit : DiagGroup<"default-const-init", [DefaultConstInitUnsafe]>;
166+
def DefaultConstInitFieldUnsafe : DiagGroup<"default-const-init-field-unsafe">;
167+
def DefaultConstInitVarUnsafe : DiagGroup<"default-const-init-var-unsafe">;
168+
def DefaultConstInitUnsafe : DiagGroup<"default-const-init-unsafe",
169+
[DefaultConstInitFieldUnsafe,
170+
DefaultConstInitVarUnsafe]>;
171+
def DefaultConstInitField : DiagGroup<"default-const-init-field">;
172+
def DefaultConstInitVar : DiagGroup<"default-const-init-var">;
173+
def DefaultConstInit : DiagGroup<"default-const-init",
174+
[DefaultConstInitField, DefaultConstInitVar,
175+
DefaultConstInitUnsafe]>;
166176
def ImplicitVoidPtrCast : DiagGroup<"implicit-void-ptr-cast">;
167177
def ImplicitIntToEnumCast : DiagGroup<"implicit-int-enum-cast",
168178
[ImplicitEnumEnumCast]>;
179+
def TentativeDefnCompat : DiagGroup<"tentative-definition-compat">;
169180
def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, DefaultConstInit,
170181
ImplicitIntToEnumCast, HiddenCppDecl,
171-
InitStringTooLongForCpp]>;
182+
InitStringTooLongForCpp,
183+
TentativeDefnCompat,
184+
DuplicateDeclSpecifier]>;
172185

173186
def ExternCCompat : DiagGroup<"extern-c-compat">;
174187
def KeywordCompat : DiagGroup<"keyword-compat">;
@@ -814,7 +827,6 @@ def TautologicalCompare : DiagGroup<"tautological-compare",
814827
TautologicalObjCBoolCompare,
815828
TautologicalNegationCompare]>;
816829
def HeaderHygiene : DiagGroup<"header-hygiene">;
817-
def DuplicateDeclSpecifier : DiagGroup<"duplicate-decl-specifier">;
818830
def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
819831
def GNUUnionCast : DiagGroup<"gnu-union-cast">;
820832
def GNUVariableSizedTypeNotAtEnd : DiagGroup<"gnu-variable-sized-type-not-at-end">;

0 commit comments

Comments
 (0)