Skip to content

Commit f25a4d5

Browse files
authored
merge main into amd-staging (llvm#933)
2 parents 310a99e + 737e11b commit f25a4d5

Some content is hidden

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

48 files changed

+908
-454
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,6 @@ class MCPlusBuilder {
637637
return false;
638638
}
639639

640-
virtual void getADRReg(const MCInst &Inst, MCPhysReg &RegName) const {
641-
llvm_unreachable("not implemented");
642-
}
643-
644640
virtual bool isMoveMem2Reg(const MCInst &Inst) const { return false; }
645641

646642
virtual bool mayLoad(const MCInst &Inst) const {
@@ -1538,6 +1534,13 @@ class MCPlusBuilder {
15381534
llvm_unreachable("not implemented");
15391535
}
15401536

1537+
/// Undo the linker's ADRP+ADD to ADR relaxation. Take \p ADRInst and return
1538+
/// ADRP+ADD instruction sequence.
1539+
virtual InstructionListType undoAdrpAddRelaxation(const MCInst &ADRInst,
1540+
MCContext *Ctx) const {
1541+
llvm_unreachable("not implemented");
1542+
}
1543+
15411544
/// Return not 0 if the instruction CurInst, in combination with the recent
15421545
/// history of disassembled instructions supplied by [Begin, End), is a linker
15431546
/// generated veneer/stub that needs patching. This happens in AArch64 when

bolt/lib/Passes/ADRRelaxationPass.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,10 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
7171
continue;
7272
}
7373

74-
MCPhysReg Reg;
75-
BC.MIB->getADRReg(Inst, Reg);
76-
int64_t Addend = BC.MIB->getTargetAddend(Inst);
77-
InstructionListType Addr;
78-
74+
InstructionListType AdrpAdd;
7975
{
8076
auto L = BC.scopeLock();
81-
Addr = BC.MIB->materializeAddress(Symbol, BC.Ctx.get(), Reg, Addend);
77+
AdrpAdd = BC.MIB->undoAdrpAddRelaxation(Inst, BC.Ctx.get());
8278
}
8379

8480
if (It != BB.begin() && BC.MIB->isNoop(*std::prev(It))) {
@@ -99,7 +95,7 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
9995
PassFailed = true;
10096
return;
10197
}
102-
It = BB.replaceInstruction(It, Addr);
98+
It = BB.replaceInstruction(It, AdrpAdd);
10399
}
104100
}
105101
}

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,23 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
278278
return Inst.getOpcode() == AArch64::ADDXri;
279279
}
280280

281-
void getADRReg(const MCInst &Inst, MCPhysReg &RegName) const override {
281+
MCPhysReg getADRReg(const MCInst &Inst) const {
282282
assert((isADR(Inst) || isADRP(Inst)) && "Not an ADR instruction");
283283
assert(MCPlus::getNumPrimeOperands(Inst) != 0 &&
284284
"No operands for ADR instruction");
285285
assert(Inst.getOperand(0).isReg() &&
286286
"Unexpected operand in ADR instruction");
287-
RegName = Inst.getOperand(0).getReg();
287+
return Inst.getOperand(0).getReg();
288+
}
289+
290+
InstructionListType undoAdrpAddRelaxation(const MCInst &ADRInst,
291+
MCContext *Ctx) const override {
292+
assert(isADR(ADRInst) && "ADR instruction expected");
293+
294+
const MCPhysReg Reg = getADRReg(ADRInst);
295+
const MCSymbol *Target = getTargetSymbol(ADRInst);
296+
const uint64_t Addend = getTargetAddend(ADRInst);
297+
return materializeAddress(Target, Ctx, Reg, Addend);
288298
}
289299

290300
bool isTB(const MCInst &Inst) const {

clang/bindings/python/clang/cindex.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,6 +2713,21 @@ def visitor(base, children):
27132713
conf.lib.clang_visitCXXBaseClasses(self, fields_visit_callback(visitor), bases)
27142714
return iter(bases)
27152715

2716+
def get_methods(self):
2717+
"""Return an iterator for accessing the methods of this type."""
2718+
2719+
def visitor(method, children):
2720+
assert method != conf.lib.clang_getNullCursor()
2721+
2722+
# Create reference to TU so it isn't GC'd before Cursor.
2723+
method._tu = self._tu
2724+
methods.append(method)
2725+
return 1 # continue
2726+
2727+
methods: list[Cursor] = []
2728+
conf.lib.clang_visitCXXMethods(self, fields_visit_callback(visitor), methods)
2729+
return iter(methods)
2730+
27162731
def get_exception_specification_kind(self):
27172732
"""
27182733
Return the kind of the exception specification; a value from
@@ -4020,6 +4035,7 @@ def set_property(self, property, value):
40204035
),
40214036
("clang_visitChildren", [Cursor, cursor_visit_callback, py_object], c_uint),
40224037
("clang_visitCXXBaseClasses", [Type, fields_visit_callback, py_object], c_uint),
4038+
("clang_visitCXXMethods", [Type, fields_visit_callback, py_object], c_uint),
40234039
("clang_Cursor_getNumArguments", [Cursor], c_int),
40244040
("clang_Cursor_getArgument", [Cursor, c_uint], Cursor),
40254041
("clang_Cursor_getNumTemplateArguments", [Cursor], c_int),

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,21 @@ class Template : public A, public B, virtual C {
559559
self.assertEqual(bases[1].get_base_offsetof(cursor_type_decl), 96)
560560
self.assertTrue(bases[2].is_virtual_base())
561561
self.assertEqual(bases[2].get_base_offsetof(cursor_type_decl), 128)
562+
563+
def test_class_methods(self):
564+
source = """
565+
template <typename T>
566+
class Template { void Foo(); };
567+
typedef Template<int> instance;
568+
instance bar;
569+
"""
570+
tu = get_tu(source, lang="cpp", flags=["--target=x86_64-linux-gnu"])
571+
cursor = get_cursor(tu, "instance")
572+
cursor_type = cursor.underlying_typedef_type
573+
self.assertEqual(cursor.kind, CursorKind.TYPEDEF_DECL)
574+
methods = list(cursor_type.get_methods())
575+
self.assertEqual(len(methods), 4)
576+
self.assertEqual(methods[0].kind, CursorKind.CXX_METHOD)
577+
self.assertEqual(methods[1].kind, CursorKind.CONSTRUCTOR)
578+
self.assertEqual(methods[2].kind, CursorKind.CONSTRUCTOR)
579+
self.assertEqual(methods[3].kind, CursorKind.CONSTRUCTOR)

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ clang-format
349349

350350
libclang
351351
--------
352+
- Added ``clang_visitCXXMethods``, which allows visiting the methods
353+
of a class.
352354

353355
- Fixed a buffer overflow in ``CXString`` implementation. The fix may result in
354356
increased memory allocation.
@@ -386,8 +388,12 @@ Moved checkers
386388
Sanitizers
387389
----------
388390

391+
- ``-fsanitize=vptr`` is no longer a part of ``-fsanitize=undefined``.
392+
389393
Python Binding Changes
390394
----------------------
395+
- Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which
396+
allows visiting the methods of a class.
391397

392398
OpenMP Support
393399
--------------

clang/docs/UndefinedBehaviorSanitizer.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,14 @@ Available checks are:
214214
the wrong dynamic type, or that its lifetime has not begun or has ended.
215215
Incompatible with ``-fno-rtti``. Link must be performed by ``clang++``, not
216216
``clang``, to make sure C++-specific parts of the runtime library and C++
217-
standard libraries are present.
217+
standard libraries are present. The check is not a part of the ``undefined``
218+
group. Also it does not support ``-fsanitize-trap=vptr``.
218219

219220
You can also use the following check groups:
220221
- ``-fsanitize=undefined``: All of the checks listed above other than
221222
``float-divide-by-zero``, ``unsigned-integer-overflow``,
222-
``implicit-conversion``, ``local-bounds`` and the ``nullability-*`` group
223-
of checks.
223+
``implicit-conversion``, ``local-bounds``, ``vptr`` and the
224+
``nullability-*`` group of checks.
224225
- ``-fsanitize=undefined-trap``: Deprecated alias of
225226
``-fsanitize=undefined``.
226227
- ``-fsanitize=implicit-integer-truncation``: Catches lossy integral

clang/include/clang-c/Index.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6628,6 +6628,28 @@ CINDEX_LINKAGE unsigned clang_visitCXXBaseClasses(CXType T,
66286628
CXFieldVisitor visitor,
66296629
CXClientData client_data);
66306630

6631+
/**
6632+
* Visit the class methods of a type.
6633+
*
6634+
* This function visits all the methods of the given cursor,
6635+
* invoking the given \p visitor function with the cursors of each
6636+
* visited method. The traversal may be ended prematurely, if
6637+
* the visitor returns \c CXFieldVisit_Break.
6638+
*
6639+
* \param T The record type whose field may be visited.
6640+
*
6641+
* \param visitor The visitor function that will be invoked for each
6642+
* field of \p T.
6643+
*
6644+
* \param client_data Pointer data supplied by the client, which will
6645+
* be passed to the visitor each time it is invoked.
6646+
*
6647+
* \returns A non-zero value if the traversal was terminated
6648+
* prematurely by the visitor returning \c CXFieldVisit_Break.
6649+
*/
6650+
CINDEX_LINKAGE unsigned clang_visitCXXMethods(CXType T, CXFieldVisitor visitor,
6651+
CXClientData client_data);
6652+
66316653
/**
66326654
* Describes the kind of binary operators.
66336655
*/

clang/include/clang/Basic/Sanitizers.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ SANITIZER_GROUP("undefined", Undefined,
152152
FloatCastOverflow |
153153
IntegerDivideByZero | NonnullAttribute | Null | ObjectSize |
154154
PointerOverflow | Return | ReturnsNonnullAttribute | Shift |
155-
SignedIntegerOverflow | Unreachable | VLABound | Function |
156-
Vptr)
155+
SignedIntegerOverflow | Unreachable | VLABound | Function)
157156

158157
// -fsanitize=undefined-trap is an alias for -fsanitize=undefined.
159158
SANITIZER_GROUP("undefined-trap", UndefinedTrap, Undefined)

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ static const SanitizerMask NeedsUbsanRt =
3030
SanitizerKind::Undefined | SanitizerKind::Integer |
3131
SanitizerKind::LocalBounds | SanitizerKind::ImplicitConversion |
3232
SanitizerKind::Nullability | SanitizerKind::CFI |
33-
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast;
33+
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast |
34+
SanitizerKind::Vptr;
3435
static const SanitizerMask NeedsUbsanCxxRt =
3536
SanitizerKind::Vptr | SanitizerKind::CFI;
3637
static const SanitizerMask NotAllowedWithTrap = SanitizerKind::Vptr;
@@ -53,23 +54,25 @@ static const SanitizerMask SupportsCoverage =
5354
SanitizerKind::FuzzerNoLink | SanitizerKind::FloatDivideByZero |
5455
SanitizerKind::SafeStack | SanitizerKind::ShadowCallStack |
5556
SanitizerKind::Thread | SanitizerKind::ObjCCast | SanitizerKind::KCFI |
56-
SanitizerKind::NumericalStability;
57+
SanitizerKind::NumericalStability | SanitizerKind::Vptr;
5758
static const SanitizerMask RecoverableByDefault =
5859
SanitizerKind::Undefined | SanitizerKind::Integer |
5960
SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
60-
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast;
61+
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast |
62+
SanitizerKind::Vptr;
6163
static const SanitizerMask Unrecoverable =
6264
SanitizerKind::Unreachable | SanitizerKind::Return;
6365
static const SanitizerMask AlwaysRecoverable = SanitizerKind::KernelAddress |
6466
SanitizerKind::KernelHWAddress |
6567
SanitizerKind::KCFI;
6668
static const SanitizerMask NeedsLTO = SanitizerKind::CFI;
6769
static const SanitizerMask TrappingSupported =
68-
(SanitizerKind::Undefined & ~SanitizerKind::Vptr) | SanitizerKind::Integer |
70+
SanitizerKind::Undefined | SanitizerKind::Integer |
6971
SanitizerKind::ImplicitConversion | SanitizerKind::Nullability |
7072
SanitizerKind::LocalBounds | SanitizerKind::CFI |
7173
SanitizerKind::FloatDivideByZero | SanitizerKind::ObjCCast;
72-
static const SanitizerMask MergeDefault = SanitizerKind::Undefined;
74+
static const SanitizerMask MergeDefault =
75+
SanitizerKind::Undefined | SanitizerKind::Vptr;
7376
static const SanitizerMask TrappingDefault =
7477
SanitizerKind::CFI | SanitizerKind::LocalBounds;
7578
static const SanitizerMask CFIClasses =
@@ -195,8 +198,8 @@ static void addDefaultIgnorelists(const Driver &D, SanitizerMask Kinds,
195198
{"dfsan_abilist.txt", SanitizerKind::DataFlow},
196199
{"cfi_ignorelist.txt", SanitizerKind::CFI},
197200
{"ubsan_ignorelist.txt",
198-
SanitizerKind::Undefined | SanitizerKind::Integer |
199-
SanitizerKind::Nullability |
201+
SanitizerKind::Undefined | SanitizerKind::Vptr |
202+
SanitizerKind::Integer | SanitizerKind::Nullability |
200203
SanitizerKind::FloatDivideByZero}};
201204

202205
for (auto BL : Ignorelists) {

0 commit comments

Comments
 (0)