Skip to content

Commit 62f684c

Browse files
committed
Simplify optional handling
Created using spr 1.3.4
2 parents 66f78b7 + d73ef97 commit 62f684c

File tree

18 files changed

+1889
-184
lines changed

18 files changed

+1889
-184
lines changed

bolt/tools/merge-fdata/merge-fdata.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -278,22 +278,18 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
278278

279279
std::ifstream FdataFile(Filename, std::ios::in);
280280
std::string FdataLine;
281+
std::getline(FdataFile, FdataLine);
281282

282283
auto checkMode = [&](const std::string &Key, std::optional<bool> &Flag) {
283-
std::string ErrorMsg = "cannot mix profile with and without " + Key;
284-
auto Pos = FdataFile.tellg();
285-
std::getline(FdataFile, FdataLine);
286-
if (FdataLine.rfind(Key, 0) == 0) {
287-
if (!Flag.value_or(true))
288-
report_error(Filename, ErrorMsg);
289-
Flag = true;
290-
} else {
291-
if (Flag.value_or(false))
292-
report_error(Filename, ErrorMsg);
293-
Flag = false;
294-
// Rewind line
295-
FdataFile.seekg(Pos);
296-
}
284+
const bool KeyIsSet = FdataLine.rfind(Key, 0) == 0;
285+
286+
if (!Flag.has_value())
287+
Flag = KeyIsSet;
288+
else if (*Flag != KeyIsSet)
289+
report_error(Filename, "cannot mix profile with and without " + Key);
290+
if (KeyIsSet)
291+
// Advance line
292+
std::getline(FdataFile, FdataLine);
297293
};
298294

299295
ProfileTy *Profile;
@@ -307,7 +303,7 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
307303
Profile = &Profiles[tid];
308304
}
309305

310-
while (std::getline(FdataFile, FdataLine)) {
306+
do {
311307
StringRef Line(FdataLine);
312308
size_t Pos = Line.rfind(" ");
313309
if (Pos == StringRef::npos)
@@ -318,7 +314,7 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
318314
report_error(Filename, "Malformed / corrupted profile counter");
319315
Count += Profile->lookup(Signature);
320316
Profile->insert_or_assign(Signature, Count);
321-
}
317+
} while (std::getline(FdataFile, FdataLine));
322318
};
323319

324320
// The final reduction has non-trivial cost, make sure each thread has at

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static void format_msg(const char *kind, uintptr_t caller, char *buf,
4848
*buf = '\0';
4949
}
5050

51-
static void report_error(const char *kind, uintptr_t caller) {
51+
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
52+
uintptr_t caller) {
5253
if (caller == 0)
5354
return;
5455
while (true) {
@@ -114,13 +115,13 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
114115

115116
#define HANDLER_RECOVER(name, kind) \
116117
INTERFACE void __ubsan_handle_##name##_minimal() { \
117-
report_error(kind, GET_CALLER_PC()); \
118+
__ubsan_report_error(kind, GET_CALLER_PC()); \
118119
}
119120

120121
#define HANDLER_NORECOVER(name, kind) \
121122
INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
122123
uintptr_t caller = GET_CALLER_PC(); \
123-
report_error(kind, caller); \
124+
__ubsan_report_error(kind, caller); \
124125
abort_with_message(kind, caller); \
125126
}
126127

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang -fsanitize=implicit-integer-sign-change %s -o %t && %run %t 0 2>&1 | FileCheck %s
2+
#include <stdint.h>
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
6+
static int Result;
7+
8+
void __ubsan_report_error(const char *kind, uintptr_t caller) {
9+
fprintf(stderr, "CUSTOM_CALLBACK: %s\n", kind);
10+
}
11+
12+
int main(int argc, const char **argv) {
13+
int32_t t0 = (~((uint32_t)0));
14+
// CHECK: CUSTOM_CALLBACK: implicit-conversion
15+
}

lld/COFF/Chunks.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,14 @@ static void maybeReportRelocationToDiscarded(const SectionChunk *fromChunk,
369369
// Get the name of the symbol. If it's null, it was discarded early, so we
370370
// have to go back to the object file.
371371
ObjFile *file = fromChunk->file;
372-
StringRef name;
372+
std::string name;
373373
if (sym) {
374-
name = sym->getName();
374+
name = toString(file->ctx, *sym);
375375
} else {
376376
COFFSymbolRef coffSym =
377377
check(file->getCOFFObj()->getSymbol(rel.SymbolTableIndex));
378-
name = check(file->getCOFFObj()->getSymbolName(coffSym));
378+
name = maybeDemangleSymbol(
379+
file->ctx, check(file->getCOFFObj()->getSymbolName(coffSym)));
379380
}
380381

381382
std::vector<std::string> symbolLocations =

lld/COFF/Symbols.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ static_assert(sizeof(SymbolUnion) <= 48,
2828
"symbols should be optimized for memory usage");
2929

3030
// Returns a symbol name for an error message.
31-
static std::string maybeDemangleSymbol(const COFFLinkerContext &ctx,
32-
StringRef symName) {
31+
std::string maybeDemangleSymbol(const COFFLinkerContext &ctx,
32+
StringRef symName) {
3333
if (ctx.config.demangle) {
3434
std::string prefix;
3535
StringRef prefixless = symName;

lld/COFF/Symbols.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ std::string toString(const coff::COFFLinkerContext &ctx, coff::Symbol &b);
533533
std::string toCOFFString(const coff::COFFLinkerContext &ctx,
534534
const llvm::object::Archive::Symbol &b);
535535

536+
// Returns a symbol name for an error message.
537+
std::string maybeDemangleSymbol(const coff::COFFLinkerContext &ctx,
538+
StringRef symName);
539+
536540
} // namespace lld
537541

538542
#endif

lld/test/COFF/reloc-discarded.s

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88

99
# RUN: not lld-link -entry:main -nodefaultlib %t1.obj %t2.obj -out:%t.exe -opt:ref 2>&1 | FileCheck %s
1010
# RUN: not lld-link -entry:main -nodefaultlib %t1.obj %t2.obj -out:%t.exe -opt:noref 2>&1 | FileCheck %s
11+
# RUN: not lld-link -entry:main -nodefaultlib %t1.obj %t2.obj -out:%t.exe -demangle:no 2>&1 \
12+
# RUN: | FileCheck --check-prefix=NODEMANGLE %s
1113

12-
# CHECK: error: relocation against symbol in discarded section: assoc_global
14+
# CHECK: error: relocation against symbol in discarded section: int __cdecl assoc_global(void)
1315
# CHECK: >>> referenced by {{.*}}reloc-discarded{{.*}}.obj:(main)
1416

17+
# NODEMANGLE: error: relocation against symbol in discarded section: ?assoc_global@@YAHXZ
18+
# NODEMANGLE: >>> referenced by {{.*}}reloc-discarded{{.*}}.obj:(main)
19+
1520
.section .bss,"bw",discard,main_global
1621
.globl main_global
1722
.p2align 2
@@ -20,12 +25,12 @@ main_global:
2025

2126
.section .CRT$XCU,"dr",associative,main_global
2227
.p2align 3
23-
assoc_global:
28+
"?assoc_global@@YAHXZ":
2429
.quad main_global
2530

2631
.text
2732
.globl main
2833
main:
29-
movq assoc_global(%rip), %rax
34+
movq "?assoc_global@@YAHXZ"(%rip), %rax
3035
movl (%rax), %eax
3136
retq

lldb/source/DataFormatters/FormatterSection.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ static void ForEachFormatterInModule(
5050
uint8_t addr_size = section.getAddressSize();
5151
llvm::DataExtractor::Cursor cursor(0);
5252
while (cursor && cursor.tell() < section_size) {
53+
while (cursor && cursor.tell() < section_size) {
54+
// Skip over 0 padding.
55+
if (section.getU8(cursor) == 0)
56+
continue;
57+
cursor.seek(cursor.tell() - 1);
58+
break;
59+
}
5360
uint64_t version = section.getULEB128(cursor);
5461
uint64_t record_size = section.getULEB128(cursor);
5562
if (version == 1) {

lldb/test/API/functionalities/data-formatter/embedded-summary/TestEmbeddedTypeSummary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ def test(self):
1010
self.build()
1111
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
1212
self.expect("v player", substrs=['"Dirk" (41)'])
13+
self.expect("v layer", substrs=['"crust" (3)'])
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
1-
#include <stdio.h>
1+
void puts(const char *);
2+
3+
#define LLDBSUMMARY __attribute__((section("__TEXT,__lldbsummaries"), used))
24

35
struct Player {
46
char *name;
57
int number;
68
};
79

8-
__attribute__((used, section("__DATA_CONST,__lldbsummaries"))) unsigned char
9-
_Player_type_summary[] = "\x01" // version
10-
"\x25" // record size
11-
"\x07" // type name size
12-
"Player\0" // type name
13-
"\x1c" // summary string size
14-
"${var.name} (${var.number})"; // summary string
10+
LLDBSUMMARY unsigned char _Player_type_summary[] =
11+
"\x01" // version
12+
"\x25" // record size
13+
"\x07" // type name size
14+
"Player\0" // type name
15+
"\x1c" // summary string size
16+
"${var.name} (${var.number})"; // summary string
17+
18+
struct Layer {
19+
char *name;
20+
int number;
21+
};
22+
23+
LLDBSUMMARY unsigned char _padding[] = "\x00\x00";
24+
25+
// Near copy of the record for `Player`, using a regex type name (`^Layer`).
26+
LLDBSUMMARY unsigned char _Layer_type_summary[] =
27+
"\x01" // version
28+
"\x25" // record size
29+
"\x07" // type name size
30+
"^Layer\0" // type name
31+
"\x1c" // summary string size
32+
"${var.name} (${var.number})"; // summary string
1533

1634
int main() {
1735
struct Player player;
1836
player.name = "Dirk";
1937
player.number = 41;
38+
struct Layer layer;
39+
layer.name = "crust";
40+
layer.number = 3;
2041
puts("break here");
2142
return 0;
2243
}

0 commit comments

Comments
 (0)