Skip to content

Commit 50ab64d

Browse files
author
iclsrc
committed
Merge from 'main' to 'sycl-web' (59 commits)
2 parents 952caca + 427b644 commit 50ab64d

File tree

230 files changed

+8517
-3794
lines changed

Some content is hidden

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

230 files changed

+8517
-3794
lines changed

clang-tools-extra/clangd/XRefs.cpp

+18-5
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

+17-6
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

+9
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
(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1, 2, 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1, 2, 3
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

+53-1
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

+1
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ Python Binding Changes
747747
allows visiting the methods of a class.
748748
- Added ``Type.get_fully_qualified_name``, which provides fully qualified type names as
749749
instructed by a PrintingPolicy.
750+
- Add equality comparison operators for ``File`` type
750751

751752
OpenMP Support
752753
--------------

clang/include/clang/Basic/BuiltinsAArch64.def

+1-1
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/DiagnosticDriverKinds.td

+7-1
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,14 @@ def err_drv_print_header_env_var : Error<
465465
"environment variable CC_PRINT_HEADERS_%select{FORMAT|FILTERING}0 has invalid value %1">;
466466
def err_drv_print_header_env_var_combination : Error<
467467
"unsupported combination: CC_PRINT_HEADERS_FORMAT=%0 and CC_PRINT_HEADERS_FILTERING=%1">;
468-
def err_drv_print_header_env_var_combination_cc1 : Error<
468+
def err_drv_print_header_env_var_invalid_format : Error<
469+
"environment variable CC_PRINT_HEADERS_FORMAT=%0 requires a compatible value for CC_PRINT_HEADERS_FILTERING">;
470+
def err_drv_print_header_cc1_invalid_combination : Error<
469471
"unsupported combination: -header-include-format=%0 and -header-include-filtering=%1">;
472+
def err_drv_print_header_cc1_invalid_filtering : Error<
473+
"-header-include-filtering=%0 requires a compatible value for -header-include-format">;
474+
def err_drv_print_header_cc1_invalid_format : Error<
475+
"-header-include-format=%0 requires a compatible value for -header-include-filtering">;
470476

471477
def warn_O4_is_O3 : Warning<"-O4 is equivalent to -O3">, InGroup<Deprecated>;
472478
def warn_unsupported_fsycl_fp64_conv_emu_use : Warning<"'-fsycl-fp64-conv-emu' option is supported only for AOT compilation of Intel GPUs. It will be ignored for other targets">,

clang/lib/AST/ByteCode/Interp.h

+16-10
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/AST/ExprConstant.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -2232,10 +2232,15 @@ static bool ArePotentiallyOverlappingStringLiterals(const EvalInfo &Info,
22322232
// within RHS. We don't need to look at the characters of one string that
22332233
// would appear before the start of the other string if they were merged.
22342234
CharUnits Offset = RHS.Offset - LHS.Offset;
2235-
if (Offset.isNegative())
2235+
if (Offset.isNegative()) {
2236+
if (LHSString.Bytes.size() < (size_t)-Offset.getQuantity())
2237+
return false;
22362238
LHSString.Bytes = LHSString.Bytes.drop_front(-Offset.getQuantity());
2237-
else
2239+
} else {
2240+
if (RHSString.Bytes.size() < (size_t)Offset.getQuantity())
2241+
return false;
22382242
RHSString.Bytes = RHSString.Bytes.drop_front(Offset.getQuantity());
2243+
}
22392244

22402245
bool LHSIsLonger = LHSString.Bytes.size() > RHSString.Bytes.size();
22412246
StringRef Longer = LHSIsLonger ? LHSString.Bytes : RHSString.Bytes;

clang/lib/CodeGen/CGClass.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2901,7 +2901,8 @@ void CodeGenFunction::EmitVTablePtrCheck(const CXXRecordDecl *RD,
29012901
}
29022902

29032903
if (CGM.getCodeGenOpts().SanitizeTrap.has(M)) {
2904-
EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail);
2904+
bool NoMerge = !CGM.getCodeGenOpts().SanitizeMergeHandlers.has(M);
2905+
EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail, NoMerge);
29052906
return;
29062907
}
29072908

clang/lib/CodeGen/CGExpr.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -3932,7 +3932,11 @@ void CodeGenFunction::EmitCfiCheckFail() {
39323932
// Data == nullptr means the calling module has trap behaviour for this check.
39333933
llvm::Value *DataIsNotNullPtr =
39343934
Builder.CreateICmpNE(Data, llvm::ConstantPointerNull::get(Int8PtrTy));
3935-
EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail);
3935+
// TODO: since there is no data, we don't know the CheckKind, and therefore
3936+
// cannot inspect CGM.getCodeGenOpts().SanitizeMergeHandlers. We default to
3937+
// NoMerge = false. Users can disable merging by disabling optimization.
3938+
EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail,
3939+
/*NoMerge=*/false);
39363940

39373941
llvm::StructType *SourceLocationTy =
39383942
llvm::StructType::get(VoidPtrTy, Int32Ty, Int32Ty);
@@ -3971,7 +3975,11 @@ void CodeGenFunction::EmitCfiCheckFail() {
39713975
EmitCheck(std::make_pair(Cond, Ordinal), SanitizerHandler::CFICheckFail,
39723976
{}, {Data, Addr, ValidVtable});
39733977
else
3974-
EmitTrapCheck(Cond, SanitizerHandler::CFICheckFail);
3978+
// TODO: we can't rely on CGM.getCodeGenOpts().SanitizeMergeHandlers.
3979+
// Although the compiler allows SanitizeMergeHandlers to be set
3980+
// independently of CGM.getLangOpts().Sanitize, Driver/SanitizerArgs.cpp
3981+
// requires that SanitizeMergeHandlers is a subset of Sanitize.
3982+
EmitTrapCheck(Cond, SanitizerHandler::CFICheckFail, /*NoMerge=*/false);
39753983
}
39763984

39773985
FinishFunction();

clang/lib/Driver/SanitizerArgs.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
853853
SanitizerMask NonTrappingCfi = Kinds & SanitizerKind::CFI & ~TrappingKinds;
854854
if (NonTrappingCfi && DiagnoseErrors)
855855
D.Diag(clang::diag::err_drv_argument_only_allowed_with)
856-
<< "fsanitize-minimal-runtime"
857-
<< "fsanitize-trap=cfi";
856+
<< "-fsanitize-minimal-runtime"
857+
<< "-fsanitize-trap=cfi";
858858
}
859859

860860
for (const auto *Arg : Args.filtered(

clang/lib/Frontend/CompilerInvocation.cpp

+19-7
Original file line numberDiff line numberDiff line change
@@ -2451,13 +2451,25 @@ static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
24512451

24522452
// Check for invalid combinations of header-include-format
24532453
// and header-include-filtering.
2454-
if ((Opts.HeaderIncludeFormat == HIFMT_Textual &&
2455-
Opts.HeaderIncludeFiltering != HIFIL_None) ||
2456-
(Opts.HeaderIncludeFormat == HIFMT_JSON &&
2457-
Opts.HeaderIncludeFiltering != HIFIL_Only_Direct_System))
2458-
Diags.Report(diag::err_drv_print_header_env_var_combination_cc1)
2459-
<< Args.getLastArg(OPT_header_include_format_EQ)->getValue()
2460-
<< Args.getLastArg(OPT_header_include_filtering_EQ)->getValue();
2454+
if (Opts.HeaderIncludeFormat == HIFMT_Textual &&
2455+
Opts.HeaderIncludeFiltering != HIFIL_None) {
2456+
if (Args.hasArg(OPT_header_include_format_EQ))
2457+
Diags.Report(diag::err_drv_print_header_cc1_invalid_combination)
2458+
<< headerIncludeFormatKindToString(Opts.HeaderIncludeFormat)
2459+
<< headerIncludeFilteringKindToString(Opts.HeaderIncludeFiltering);
2460+
else
2461+
Diags.Report(diag::err_drv_print_header_cc1_invalid_filtering)
2462+
<< headerIncludeFilteringKindToString(Opts.HeaderIncludeFiltering);
2463+
} else if (Opts.HeaderIncludeFormat == HIFMT_JSON &&
2464+
Opts.HeaderIncludeFiltering == HIFIL_None) {
2465+
if (Args.hasArg(OPT_header_include_filtering_EQ))
2466+
Diags.Report(diag::err_drv_print_header_cc1_invalid_combination)
2467+
<< headerIncludeFormatKindToString(Opts.HeaderIncludeFormat)
2468+
<< headerIncludeFilteringKindToString(Opts.HeaderIncludeFiltering);
2469+
else
2470+
Diags.Report(diag::err_drv_print_header_cc1_invalid_format)
2471+
<< headerIncludeFormatKindToString(Opts.HeaderIncludeFormat);
2472+
}
24612473

24622474
return Diags.getNumErrors() == NumErrorsBefore;
24632475
}

clang/lib/Headers/arm_acle.h

+3-2
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/Serialization/ASTReaderDecl.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,8 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
10761076
FD->setFriendConstraintRefersToEnclosingTemplate(
10771077
FunctionDeclBits.getNextBit());
10781078
FD->setUsesSEHTry(FunctionDeclBits.getNextBit());
1079+
FD->setIsDestroyingOperatorDelete(FunctionDeclBits.getNextBit());
1080+
FD->setIsTypeAwareOperatorNewOrDelete(FunctionDeclBits.getNextBit());
10791081

10801082
FD->EndRangeLoc = readSourceLocation();
10811083
if (FD->isExplicitlyDefaulted())

0 commit comments

Comments
 (0)