Skip to content

Commit c3cb866

Browse files
authored
Merge pull request llvm#529 from AMD-Lightning-Internal/amd/merge/upstream_merge_20250206070443
merge main into amd-staging
2 parents 9529223 + 4035184 commit c3cb866

File tree

116 files changed

+2211
-2471
lines changed

Some content is hidden

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

116 files changed

+2211
-2471
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,17 @@ class BinaryContext {
14351435
bool PrintRelocations = false,
14361436
StringRef Endl = "\n") const;
14371437

1438+
/// Print data when embedded in the instruction stream keeping the format
1439+
/// similar to printInstruction().
1440+
void printData(raw_ostream &OS, ArrayRef<uint8_t> Data,
1441+
uint64_t Offset) const;
1442+
1443+
/// Extract data from the binary corresponding to [Address, Address + Size)
1444+
/// range. Return an empty ArrayRef if the address range does not belong to
1445+
/// any section in the binary, crosses a section boundary, or falls into a
1446+
/// virtual section.
1447+
ArrayRef<uint8_t> extractData(uint64_t Address, uint64_t Size) const;
1448+
14381449
/// Print a range of instructions.
14391450
template <typename Itr>
14401451
uint64_t

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,11 @@ class BinaryFunction {
20602060
return Islands ? Islands->getAlignment() : 1;
20612061
}
20622062

2063+
/// If there is a constant island in the range [StartOffset, EndOffset),
2064+
/// return its address.
2065+
std::optional<uint64_t> getIslandInRange(uint64_t StartOffset,
2066+
uint64_t EndOffset) const;
2067+
20632068
uint64_t
20642069
estimateConstantIslandSize(const BinaryFunction *OnBehalfOf = nullptr) const {
20652070
if (!Islands)

bolt/lib/Core/BinaryContext.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,43 @@ static void printDebugInfo(raw_ostream &OS, const MCInst &Instruction,
19421942
OS << " discriminator:" << Row.Discriminator;
19431943
}
19441944

1945+
ArrayRef<uint8_t> BinaryContext::extractData(uint64_t Address,
1946+
uint64_t Size) const {
1947+
ArrayRef<uint8_t> Res;
1948+
1949+
const ErrorOr<const BinarySection &> Section = getSectionForAddress(Address);
1950+
if (!Section || Section->isVirtual())
1951+
return Res;
1952+
1953+
if (!Section->containsRange(Address, Size))
1954+
return Res;
1955+
1956+
auto *Bytes =
1957+
reinterpret_cast<const uint8_t *>(Section->getContents().data());
1958+
return ArrayRef<uint8_t>(Bytes + Address - Section->getAddress(), Size);
1959+
}
1960+
1961+
void BinaryContext::printData(raw_ostream &OS, ArrayRef<uint8_t> Data,
1962+
uint64_t Offset) const {
1963+
DataExtractor DE(Data, AsmInfo->isLittleEndian(),
1964+
AsmInfo->getCodePointerSize());
1965+
uint64_t DataOffset = 0;
1966+
while (DataOffset + 4 <= Data.size()) {
1967+
OS << format(" %08" PRIx64 ": \t.word\t0x", Offset + DataOffset);
1968+
const auto Word = DE.getUnsigned(&DataOffset, 4);
1969+
OS << Twine::utohexstr(Word) << '\n';
1970+
}
1971+
if (DataOffset + 2 <= Data.size()) {
1972+
OS << format(" %08" PRIx64 ": \t.short\t0x", Offset + DataOffset);
1973+
const auto Short = DE.getUnsigned(&DataOffset, 2);
1974+
OS << Twine::utohexstr(Short) << '\n';
1975+
}
1976+
if (DataOffset + 1 == Data.size()) {
1977+
OS << format(" %08" PRIx64 ": \t.byte\t0x%x\n", Offset + DataOffset,
1978+
Data[DataOffset]);
1979+
}
1980+
}
1981+
19451982
void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
19461983
uint64_t Offset,
19471984
const BinaryFunction *Function,

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,27 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
491491
// Offset of the instruction in function.
492492
uint64_t Offset = 0;
493493

494+
auto printConstantIslandInRange = [&](uint64_t Start, uint64_t End) {
495+
assert(Start <= End && "Invalid range");
496+
std::optional<uint64_t> IslandOffset = getIslandInRange(Start, End);
497+
498+
if (!IslandOffset)
499+
return;
500+
501+
const size_t IslandSize = getSizeOfDataInCodeAt(*IslandOffset);
502+
BC.printData(OS, BC.extractData(getAddress() + *IslandOffset, IslandSize),
503+
*IslandOffset);
504+
};
505+
494506
if (BasicBlocks.empty() && !Instructions.empty()) {
495507
// Print before CFG was built.
508+
uint64_t PrevOffset = 0;
496509
for (const std::pair<const uint32_t, MCInst> &II : Instructions) {
497510
Offset = II.first;
498511

512+
// Print any constant islands inbeetween the instructions.
513+
printConstantIslandInRange(PrevOffset, Offset);
514+
499515
// Print label if exists at this offset.
500516
auto LI = Labels.find(Offset);
501517
if (LI != Labels.end()) {
@@ -506,7 +522,12 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation) {
506522
}
507523

508524
BC.printInstruction(OS, II.second, Offset, this);
525+
526+
PrevOffset = Offset;
509527
}
528+
529+
// Print any data at the end of the function.
530+
printConstantIslandInRange(PrevOffset, getMaxSize());
510531
}
511532

512533
StringRef SplitPointMsg = "";
@@ -1048,6 +1069,19 @@ size_t BinaryFunction::getSizeOfDataInCodeAt(uint64_t Offset) const {
10481069
return getSize() - Offset;
10491070
}
10501071

1072+
std::optional<uint64_t>
1073+
BinaryFunction::getIslandInRange(uint64_t StartOffset,
1074+
uint64_t EndOffset) const {
1075+
if (!Islands)
1076+
return std::nullopt;
1077+
1078+
auto Iter = llvm::lower_bound(Islands->DataOffsets, StartOffset);
1079+
if (Iter != Islands->DataOffsets.end() && *Iter < EndOffset)
1080+
return *Iter;
1081+
1082+
return std::nullopt;
1083+
}
1084+
10511085
bool BinaryFunction::isZeroPaddingAt(uint64_t Offset) const {
10521086
ArrayRef<uint8_t> FunctionData = *getData();
10531087
uint64_t EndOfCode = getSize();

bolt/test/AArch64/data-in-code.s

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Check that llvm-bolt prints data embedded in code.
2+
3+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
4+
# RUN: %clang %cflags -fno-PIC -no-pie %t.o -o %t.exe -nostdlib \
5+
# RUN: -fuse-ld=lld -Wl,-q
6+
7+
## Check disassembly of BOLT input.
8+
# RUN: llvm-objdump %t.exe -d | FileCheck %s
9+
10+
# RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm | FileCheck %s
11+
12+
.text
13+
.balign 4
14+
15+
.global _start
16+
.type _start, %function
17+
_start:
18+
mov x0, #0x0
19+
.word 0x4f82e010
20+
ret
21+
.byte 0x0, 0xff, 0x42
22+
# CHECK-LABEL: _start
23+
# CHECK: mov x0, #0x0
24+
# CHECK-NEXT: .word 0x4f82e010
25+
# CHECK-NEXT: ret
26+
# CHECK-NEXT: .short 0xff00
27+
# CHECK-NEXT: .byte 0x42
28+
.size _start, .-_start
29+
30+
## Force relocation mode.
31+
.reloc 0, R_AARCH64_NONE

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,6 +3421,35 @@ the configuration (without a prefix: ``Auto``).
34213421

34223422

34233423

3424+
.. _BreakBeforeTemplateCloser:
3425+
3426+
**BreakBeforeTemplateCloser** (``Boolean``) :versionbadge:`clang-format 21` :ref:`<BreakBeforeTemplateCloser>`
3427+
If ``true``, break before a template closing bracket (``>``) when there is
3428+
a line break after the matching opening bracket (``<``).
3429+
3430+
.. code-block:: c++
3431+
3432+
true:
3433+
template <typename Foo, typename Bar>
3434+
3435+
template <typename Foo,
3436+
typename Bar>
3437+
3438+
template <
3439+
typename Foo,
3440+
typename Bar
3441+
>
3442+
3443+
false:
3444+
template <typename Foo, typename Bar>
3445+
3446+
template <typename Foo,
3447+
typename Bar>
3448+
3449+
template <
3450+
typename Foo,
3451+
typename Bar>
3452+
34243453
.. _BreakBeforeTernaryOperators:
34253454

34263455
**BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`<BreakBeforeTernaryOperators>`

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ AST Matchers
231231
clang-format
232232
------------
233233

234+
- Adds ``BreakBeforeTemplateCloser`` option.
235+
234236
libclang
235237
--------
236238

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def warn_qual_return_type : Warning<
490490
"'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">,
491491
InGroup<IgnoredQualifiers>, DefaultIgnore;
492492
def warn_qual_base_type : Warning<
493-
"'%0' qualifier%s1 on base class type %2 have no effect">,
493+
"'%0' qualifier%s1 on base class type %2 %plural{1:has|:have}1 no effect">,
494494
InGroup<IgnoredQualifiers>, DefaultIgnore;
495495

496496
def warn_deprecated_redundant_constexpr_static_def : Warning<

clang/include/clang/Format/Format.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,33 @@ struct FormatStyle {
22522252
/// \version 16
22532253
BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
22542254

2255+
/// If ``true``, break before a template closing bracket (``>``) when there is
2256+
/// a line break after the matching opening bracket (``<``).
2257+
/// \code
2258+
/// true:
2259+
/// template <typename Foo, typename Bar>
2260+
///
2261+
/// template <typename Foo,
2262+
/// typename Bar>
2263+
///
2264+
/// template <
2265+
/// typename Foo,
2266+
/// typename Bar
2267+
/// >
2268+
///
2269+
/// false:
2270+
/// template <typename Foo, typename Bar>
2271+
///
2272+
/// template <typename Foo,
2273+
/// typename Bar>
2274+
///
2275+
/// template <
2276+
/// typename Foo,
2277+
/// typename Bar>
2278+
/// \endcode
2279+
/// \version 21
2280+
bool BreakBeforeTemplateCloser;
2281+
22552282
/// If ``true``, ternary operators will be placed after line breaks.
22562283
/// \code
22572284
/// true:
@@ -5251,6 +5278,7 @@ struct FormatStyle {
52515278
BreakBeforeBraces == R.BreakBeforeBraces &&
52525279
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations &&
52535280
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
5281+
BreakBeforeTemplateCloser == R.BreakBeforeTemplateCloser &&
52545282
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
52555283
BreakBinaryOperations == R.BreakBinaryOperations &&
52565284
BreakConstructorInitializers == R.BreakConstructorInitializers &&

clang/lib/Basic/Warnings.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
7373
else
7474
Diags.setExtensionHandlingBehavior(diag::Severity::Ignored);
7575

76-
if (!Opts.DiagnosticSuppressionMappingsFile.empty()) {
77-
if (auto FileContents =
78-
VFS.getBufferForFile(Opts.DiagnosticSuppressionMappingsFile)) {
79-
Diags.setDiagSuppressionMapping(**FileContents);
80-
} else if (ReportDiags) {
81-
Diags.Report(diag::err_drv_no_such_file)
82-
<< Opts.DiagnosticSuppressionMappingsFile;
83-
}
84-
}
85-
8676
SmallVector<diag::kind, 10> _Diags;
8777
const IntrusiveRefCntPtr< DiagnosticIDs > DiagIDs =
8878
Diags.getDiagnosticIDs();
@@ -237,4 +227,17 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
237227
}
238228
}
239229
}
230+
231+
// Process suppression mappings file after processing other warning flags
232+
// (like -Wno-unknown-warning-option) as we can emit extra warnings during
233+
// processing.
234+
if (!Opts.DiagnosticSuppressionMappingsFile.empty()) {
235+
if (auto FileContents =
236+
VFS.getBufferForFile(Opts.DiagnosticSuppressionMappingsFile)) {
237+
Diags.setDiagSuppressionMapping(**FileContents);
238+
} else if (ReportDiags) {
239+
Diags.Report(diag::err_drv_no_such_file)
240+
<< Opts.DiagnosticSuppressionMappingsFile;
241+
}
242+
}
240243
}

0 commit comments

Comments
 (0)