Skip to content

Commit a0426f8

Browse files
authored
merge main into amd-staging (llvm#1823)
2 parents 1c8a52e + fe445a7 commit a0426f8

File tree

150 files changed

+4715
-1642
lines changed

Some content is hidden

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

150 files changed

+4715
-1642
lines changed

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,7 +2380,7 @@ outgoingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index) {
23802380
// Initially store the ranges in a map keyed by SymbolID of the callee.
23812381
// This allows us to group different calls to the same function
23822382
// into the same CallHierarchyOutgoingCall.
2383-
llvm::DenseMap<SymbolID, std::vector<Range>> CallsOut;
2383+
llvm::DenseMap<SymbolID, std::vector<Location>> CallsOut;
23842384
// We can populate the ranges based on a refs request only. As we do so, we
23852385
// also accumulate the callee IDs into a lookup request.
23862386
LookupRequest CallsOutLookup;
@@ -2390,8 +2390,8 @@ outgoingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index) {
23902390
elog("outgoingCalls failed to convert location: {0}", Loc.takeError());
23912391
return;
23922392
}
2393-
auto It = CallsOut.try_emplace(R.Symbol, std::vector<Range>{}).first;
2394-
It->second.push_back(Loc->range);
2393+
auto It = CallsOut.try_emplace(R.Symbol, std::vector<Location>{}).first;
2394+
It->second.push_back(*Loc);
23952395

23962396
CallsOutLookup.IDs.insert(R.Symbol);
23972397
});
@@ -2411,9 +2411,22 @@ outgoingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index) {
24112411

24122412
auto It = CallsOut.find(Callee.ID);
24132413
assert(It != CallsOut.end());
2414-
if (auto CHI = symbolToCallHierarchyItem(Callee, Item.uri.file()))
2414+
if (auto CHI = symbolToCallHierarchyItem(Callee, Item.uri.file())) {
2415+
std::vector<Range> FromRanges;
2416+
for (const Location &L : It->second) {
2417+
if (L.uri != Item.uri) {
2418+
// Call location not in same file as the item that outgoingCalls was
2419+
// requested for. This can happen when Item is a declaration separate
2420+
// from the implementation. There's not much we can do, since the
2421+
// protocol only allows returning ranges interpreted as being in
2422+
// Item's file.
2423+
continue;
2424+
}
2425+
FromRanges.push_back(L.range);
2426+
}
24152427
Results.push_back(
2416-
CallHierarchyOutgoingCall{std::move(*CHI), std::move(It->second)});
2428+
CallHierarchyOutgoingCall{std::move(*CHI), std::move(FromRanges)});
2429+
}
24172430
});
24182431
// Sort results by name of the callee.
24192432
llvm::sort(Results, [](const CallHierarchyOutgoingCall &A,

clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ using ::testing::UnorderedElementsAre;
4545
// Helpers for matching call hierarchy data structures.
4646
MATCHER_P(withName, N, "") { return arg.name == N; }
4747
MATCHER_P(withDetail, N, "") { return arg.detail == N; }
48+
MATCHER_P(withFile, N, "") { return arg.uri.file() == N; }
4849
MATCHER_P(withSelectionRange, R, "") { return arg.selectionRange == R; }
4950

5051
template <class ItemMatcher>
@@ -383,18 +384,28 @@ TEST(CallHierarchy, MultiFileCpp) {
383384
EXPECT_THAT(IncomingLevel4, IsEmpty());
384385
};
385386

386-
auto CheckOutgoingCalls = [&](ParsedAST &AST, Position Pos, PathRef TUPath) {
387+
auto CheckOutgoingCalls = [&](ParsedAST &AST, Position Pos, PathRef TUPath,
388+
bool IsDeclaration) {
387389
std::vector<CallHierarchyItem> Items =
388390
prepareCallHierarchy(AST, Pos, TUPath);
389-
ASSERT_THAT(Items, ElementsAre(withName("caller3")));
391+
ASSERT_THAT(
392+
Items,
393+
ElementsAre(AllOf(
394+
withName("caller3"),
395+
withFile(testPath(IsDeclaration ? "caller3.hh" : "caller3.cc")))));
390396
auto OutgoingLevel1 = outgoingCalls(Items[0], Index.get());
391397
ASSERT_THAT(
392398
OutgoingLevel1,
399+
// fromRanges are interpreted in the context of Items[0]'s file.
400+
// If that's the header, we can't get ranges from the implementation
401+
// file!
393402
ElementsAre(
394403
AllOf(to(AllOf(withName("caller1"), withDetail("nsa::caller1"))),
395-
oFromRanges(Caller3C.range("Caller1"))),
404+
IsDeclaration ? oFromRanges()
405+
: oFromRanges(Caller3C.range("Caller1"))),
396406
AllOf(to(AllOf(withName("caller2"), withDetail("nsb::caller2"))),
397-
oFromRanges(Caller3C.range("Caller2")))));
407+
IsDeclaration ? oFromRanges()
408+
: oFromRanges(Caller3C.range("Caller2")))));
398409

399410
auto OutgoingLevel2 = outgoingCalls(OutgoingLevel1[1].to, Index.get());
400411
ASSERT_THAT(OutgoingLevel2,
@@ -423,15 +434,15 @@ TEST(CallHierarchy, MultiFileCpp) {
423434
CheckIncomingCalls(*AST, CalleeH.point(), testPath("callee.hh"));
424435
AST = Workspace.openFile("caller3.hh");
425436
ASSERT_TRUE(bool(AST));
426-
CheckOutgoingCalls(*AST, Caller3H.point(), testPath("caller3.hh"));
437+
CheckOutgoingCalls(*AST, Caller3H.point(), testPath("caller3.hh"), true);
427438

428439
// Check that invoking from the definition site works.
429440
AST = Workspace.openFile("callee.cc");
430441
ASSERT_TRUE(bool(AST));
431442
CheckIncomingCalls(*AST, CalleeC.point(), testPath("callee.cc"));
432443
AST = Workspace.openFile("caller3.cc");
433444
ASSERT_TRUE(bool(AST));
434-
CheckOutgoingCalls(*AST, Caller3C.point(), testPath("caller3.cc"));
445+
CheckOutgoingCalls(*AST, Caller3C.point(), testPath("caller3.cc"), false);
435446
}
436447

437448
TEST(CallHierarchy, IncomingMultiFileObjC) {

clang/bindings/python/clang/cindex.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,6 +3499,14 @@ def __str__(self):
34993499
def __repr__(self):
35003500
return "<File: %s>" % (self.name)
35013501

3502+
def __eq__(self, other) -> bool:
3503+
return isinstance(other, File) and bool(
3504+
conf.lib.clang_File_isEqual(self, other)
3505+
)
3506+
3507+
def __ne__(self, other) -> bool:
3508+
return not self.__eq__(other)
3509+
35023510
@staticmethod
35033511
def from_result(res, arg):
35043512
assert isinstance(res, c_object_p)
@@ -3986,6 +3994,7 @@ def set_property(self, property, value):
39863994
("clang_getFile", [TranslationUnit, c_interop_string], c_object_p),
39873995
("clang_getFileName", [File], _CXString),
39883996
("clang_getFileTime", [File], c_uint),
3997+
("clang_File_isEqual", [File, File], bool),
39893998
("clang_getIBOutletCollectionType", [Cursor], Type),
39903999
("clang_getIncludedFile", [Cursor], c_object_p),
39914000
(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1, 2, 3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1, 2, 3
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int a[] = {
2+
#include "a.inc"
3+
};
4+
int b[] = {
5+
#include "b.inc"
6+
};

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
22

3-
from clang.cindex import Config, File, Index
3+
from clang.cindex import Config, File, Index, TranslationUnit
44

55
if "CLANG_LIBRARY_PATH" in os.environ:
66
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
77

88
import unittest
99

10+
inputs_dir = os.path.join(os.path.dirname(__file__), "INPUTS")
1011

1112
class TestFile(unittest.TestCase):
1213
def test_file(self):
@@ -16,3 +17,54 @@ def test_file(self):
1617
self.assertEqual(str(file), "t.c")
1718
self.assertEqual(file.name, "t.c")
1819
self.assertEqual(repr(file), "<File: t.c>")
20+
21+
def test_file_eq(self):
22+
path = os.path.join(inputs_dir, "testfile.c")
23+
path_a = os.path.join(inputs_dir, "a.inc")
24+
path_b = os.path.join(inputs_dir, "b.inc")
25+
tu = TranslationUnit.from_source(path)
26+
main_file = File.from_name(tu, path)
27+
a_file = File.from_name(tu, path_a)
28+
a_file2 = File.from_name(tu, path_a)
29+
b_file = File.from_name(tu, path_b)
30+
31+
self.assertEqual(a_file, a_file2)
32+
self.assertNotEqual(a_file, b_file)
33+
self.assertNotEqual(main_file, a_file)
34+
self.assertNotEqual(main_file, b_file)
35+
self.assertNotEqual(main_file, "t.c")
36+
37+
def test_file_eq_in_memory(self):
38+
tu = TranslationUnit.from_source(
39+
"testfile.c",
40+
unsaved_files=[
41+
(
42+
"testfile.c",
43+
"""
44+
int a[] = {
45+
#include "a.inc"
46+
};
47+
int b[] = {
48+
#include "b.inc"
49+
};
50+
""",
51+
),
52+
("a.inc", "1,2,3"),
53+
("b.inc", "1,2,3"),
54+
],
55+
)
56+
57+
path = os.path.join(inputs_dir, "testfile.c")
58+
path_a = os.path.join(inputs_dir, "a.inc")
59+
path_b = os.path.join(inputs_dir, "b.inc")
60+
tu = TranslationUnit.from_source(path)
61+
main_file = File.from_name(tu, path)
62+
a_file = File.from_name(tu, path_a)
63+
a_file2 = File.from_name(tu, path_a)
64+
b_file = File.from_name(tu, path_b)
65+
66+
self.assertEqual(a_file, a_file2)
67+
self.assertNotEqual(a_file, b_file)
68+
self.assertNotEqual(main_file, a_file)
69+
self.assertNotEqual(main_file, b_file)
70+
self.assertNotEqual(main_file, "a.inc")

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ C Language Changes
140140
- Clang now allows an ``inline`` specifier on a typedef declaration of a
141141
function type in Microsoft compatibility mode. #GH124869
142142
- Clang now allows ``restrict`` qualifier for array types with pointer elements (#GH92847).
143+
- Added ``-Wimplicit-void-ptr-cast``, grouped under ``-Wc++-compat``, which
144+
diagnoses implicit conversion from ``void *`` to another pointer type as
145+
being incompatible with C++. (#GH17792)
143146

144147
C2y Feature Support
145148
^^^^^^^^^^^^^^^^^^^
@@ -767,6 +770,7 @@ Python Binding Changes
767770
allows visiting the methods of a class.
768771
- Added ``Type.get_fully_qualified_name``, which provides fully qualified type names as
769772
instructed by a PrintingPolicy.
773+
- Add equality comparison operators for ``File`` type
770774

771775
OpenMP Support
772776
--------------

clang/include/clang/Basic/BuiltinsAArch64.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ TARGET_BUILTIN(__builtin_arm_st64bv0, "WUiv*WUiC*", "n", "ls64")
137137

138138
// Armv9.3-A Guarded Control Stack
139139
TARGET_BUILTIN(__builtin_arm_gcspopm, "WUiWUi", "n", "gcs")
140-
TARGET_BUILTIN(__builtin_arm_gcsss, "vC*vC*", "n", "gcs")
140+
TARGET_BUILTIN(__builtin_arm_gcsss, "v*v*", "n", "gcs")
141141

142142
TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
143143
TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def C99Compat : DiagGroup<"c99-compat">;
155155
def C23Compat : DiagGroup<"c23-compat">;
156156
def : DiagGroup<"c2x-compat", [C23Compat]>;
157157

158-
def CXXCompat: DiagGroup<"c++-compat">;
158+
def ImplicitVoidPtrCast : DiagGroup<"implicit-void-ptr-cast">;
159+
def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast]>;
159160
def ExternCCompat : DiagGroup<"extern-c-compat">;
160161
def KeywordCompat : DiagGroup<"keyword-compat">;
161162
def GNUCaseRange : DiagGroup<"gnu-case-range">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8687,7 +8687,17 @@ def err_typecheck_missing_return_type_incompatible : Error<
86878687
"%diff{return type $ must match previous return type $|"
86888688
"return type must match previous return type}0,1 when %select{block "
86898689
"literal|lambda expression}2 has unspecified explicit return type">;
8690-
8690+
def warn_compatible_implicit_pointer_conv : Warning<
8691+
"implicit conversion when %select{"
8692+
"%diff{assigning to $ from type $|assigning to type from type}0,1|"
8693+
"%diff{passing $ to parameter of type $|passing type to parameter of type}0,1|"
8694+
"%diff{returning $ from a function with result type $|returning type from a function with result type}0,1|"
8695+
"<CLANG BUG IF YOU SEE THIS>|" // converting
8696+
"%diff{initializing $ with an expression of type $|initializing type with an expression of type}0,1|"
8697+
"%diff{sending $ to parameter of type $|sending type to parameter of type}0,1|"
8698+
"<CLANG BUG IF YOU SEE THIS>" // casting
8699+
"}2 is not permitted in C++">,
8700+
InGroup<ImplicitVoidPtrCast>, DefaultIgnore;
86918701
def note_incomplete_class_and_qualified_id : Note<
86928702
"conformance of forward class %0 to protocol %1 cannot be confirmed">;
86938703
def warn_incompatible_qualified_id : Warning<

clang/include/clang/Sema/Sema.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7786,6 +7786,11 @@ class Sema final : public SemaBase {
77867786
/// Compatible - the types are compatible according to the standard.
77877787
Compatible,
77887788

7789+
/// CompatibleVoidPtrToNonVoidPtr - The types are compatible in C because
7790+
/// a void * can implicitly convert to another pointer type, which we
7791+
/// differentiate for better diagnostic behavior.
7792+
CompatibleVoidPtrToNonVoidPtr,
7793+
77897794
/// PointerToInt - The assignment converts a pointer to an int, which we
77907795
/// accept as an extension.
77917796
PointerToInt,
@@ -7866,6 +7871,18 @@ class Sema final : public SemaBase {
78667871
Incompatible
78677872
};
78687873

7874+
bool IsAssignConvertCompatible(AssignConvertType ConvTy) {
7875+
switch (ConvTy) {
7876+
default:
7877+
return false;
7878+
case Compatible:
7879+
case CompatiblePointerDiscardsQualifiers:
7880+
case CompatibleVoidPtrToNonVoidPtr:
7881+
return true;
7882+
}
7883+
llvm_unreachable("impossible");
7884+
}
7885+
78697886
/// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
78707887
/// assignment conversion type specified by ConvTy. This returns true if the
78717888
/// conversion was invalid or false if the conversion was accepted.

clang/lib/AST/ByteCode/Interp.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,16 +2161,22 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
21612161
}
21622162
}
21632163

2164-
T A = LHS.isBlockPointer()
2165-
? (LHS.isElementPastEnd() ? T::from(LHS.getNumElems())
2166-
: T::from(LHS.getIndex()))
2167-
: T::from(LHS.getIntegerRepresentation());
2168-
T B = RHS.isBlockPointer()
2169-
? (RHS.isElementPastEnd() ? T::from(RHS.getNumElems())
2170-
: T::from(RHS.getIndex()))
2171-
: T::from(RHS.getIntegerRepresentation());
2172-
2173-
return AddSubMulHelper<T, T::sub, std::minus>(S, OpPC, A.bitWidth(), A, B);
2164+
int64_t A64 =
2165+
LHS.isBlockPointer()
2166+
? (LHS.isElementPastEnd() ? LHS.getNumElems() : LHS.getIndex())
2167+
: LHS.getIntegerRepresentation();
2168+
2169+
int64_t B64 =
2170+
RHS.isBlockPointer()
2171+
? (RHS.isElementPastEnd() ? RHS.getNumElems() : RHS.getIndex())
2172+
: RHS.getIntegerRepresentation();
2173+
2174+
int64_t R64 = A64 - B64;
2175+
if (static_cast<int64_t>(T::from(R64)) != R64)
2176+
return handleOverflow(S, OpPC, R64);
2177+
2178+
S.Stk.push<T>(T::from(R64));
2179+
return true;
21742180
}
21752181

21762182
//===----------------------------------------------------------------------===//

clang/lib/Headers/arm_acle.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,9 @@ __gcspopm() {
841841
return __builtin_arm_gcspopm(0);
842842
}
843843

844-
static __inline__ const void * __attribute__((__always_inline__, __nodebug__, target("gcs")))
845-
__gcsss(const void *__stack) {
844+
static __inline__ void *__attribute__((__always_inline__, __nodebug__,
845+
target("gcs")))
846+
__gcsss(void *__stack) {
846847
return __builtin_arm_gcsss(__stack);
847848
}
848849
#endif

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3589,8 +3589,8 @@ static void handleCleanupAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
35893589
// If this ever proves to be a problem it should be easy to fix.
35903590
QualType Ty = S.Context.getPointerType(cast<VarDecl>(D)->getType());
35913591
QualType ParamTy = FD->getParamDecl(0)->getType();
3592-
if (S.CheckAssignmentConstraints(FD->getParamDecl(0)->getLocation(),
3593-
ParamTy, Ty) != Sema::Compatible) {
3592+
if (!S.IsAssignConvertCompatible(S.CheckAssignmentConstraints(
3593+
FD->getParamDecl(0)->getLocation(), ParamTy, Ty))) {
35943594
S.Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
35953595
<< NI.getName() << ParamTy << Ty;
35963596
return;

clang/lib/Sema/SemaExpr.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9078,8 +9078,12 @@ checkPointerTypesForAssignment(Sema &S, QualType LHSType, QualType RHSType,
90789078
}
90799079

90809080
if (rhptee->isVoidType()) {
9081+
// In C, void * to another pointer type is compatible, but we want to note
9082+
// that there will be an implicit conversion happening here.
90819083
if (lhptee->isIncompleteOrObjectType())
9082-
return ConvTy;
9084+
return ConvTy == Sema::Compatible && !S.getLangOpts().CPlusPlus
9085+
? Sema::CompatibleVoidPtrToNonVoidPtr
9086+
: ConvTy;
90839087

90849088
// As an extension, we allow cast to/from void* to function pointer.
90859089
assert(lhptee->isFunctionType());
@@ -9114,7 +9118,7 @@ checkPointerTypesForAssignment(Sema &S, QualType LHSType, QualType RHSType,
91149118
// Types are compatible ignoring the sign. Qualifier incompatibility
91159119
// takes priority over sign incompatibility because the sign
91169120
// warning can be disabled.
9117-
if (ConvTy != Sema::Compatible)
9121+
if (!S.IsAssignConvertCompatible(ConvTy))
91189122
return ConvTy;
91199123

91209124
return Sema::IncompatiblePointerSign;
@@ -17047,7 +17051,11 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
1704717051
case Compatible:
1704817052
DiagnoseAssignmentEnum(DstType, SrcType, SrcExpr);
1704917053
return false;
17050-
17054+
case CompatibleVoidPtrToNonVoidPtr:
17055+
// Still a valid conversion, but we may want to diagnose for C++
17056+
// compatibility reasons.
17057+
DiagKind = diag::warn_compatible_implicit_pointer_conv;
17058+
break;
1705117059
case PointerToInt:
1705217060
if (getLangOpts().CPlusPlus) {
1705317061
DiagKind = diag::err_typecheck_convert_pointer_int;

0 commit comments

Comments
 (0)