Skip to content

Commit 30833f0

Browse files
author
git apple-llvm automerger
committed
Merge commit '7bd273765933' from swift/release/5.3 into swift/master
2 parents 188ea37 + 7bd2737 commit 30833f0

File tree

22 files changed

+218
-65
lines changed

22 files changed

+218
-65
lines changed

clang-tools-extra/test/clang-tidy/checkers/darwin-avoid-spinlock.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
typedef int OSSpinLock;
44

5+
void OSSpinlockLock(OSSpinLock *l);
6+
void OSSpinlockTry(OSSpinLock *l);
7+
void OSSpinlockUnlock(OSSpinLock *l);
8+
59
@implementation Foo
610
- (void)f {
711
int i = 1;

compiler-rt/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern void __gcov_flush();
2+
extern int remove(const char *);
13
int main(void) {
24
__gcov_flush();
35

compiler-rt/test/profile/Inputs/instrprof-gcov-__gcov_flush-multiple.c.gcov

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
// CHECK-NEXT: -: 0:Data:instrprof-gcov-__gcov_flush-multiple.gcda
44
// CHECK-NEXT: -: 0:Runs:1
55
// CHECK-NEXT: -: 0:Programs:1
6-
// CHECK-NEXT: #####: 1:int main(void) {
7-
// CHECK-NEXT: #####: 2: __gcov_flush();
8-
// CHECK-NEXT: -: 3:
9-
// CHECK-NEXT: #####: 4: if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) {
10-
// CHECK-NEXT: #####: 5: return 1;
11-
// CHECK-NEXT: -: 6: }
12-
// CHECK-NEXT: -: 7:
13-
// CHECK-NEXT: #####: 8: __gcov_flush();
14-
// CHECK-NEXT: #####: 9: __gcov_flush();
15-
// CHECK-NEXT: -: 10:
16-
// CHECK-NEXT: #####: 11: if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) {
17-
// CHECK-NEXT: #####: 12: return 1;
18-
// CHECK-NEXT: -: 13: }
19-
// CHECK-NEXT: -: 14:
20-
// CHECK-NEXT: 1: 15: return 0;
21-
// CHECK-NEXT: 1: 16:}
6+
// CHECK-NEXT: -: 1:extern void __gcov_flush();
7+
// CHECK-NEXT: -: 2:extern int remove(const char *);
8+
// CHECK-NEXT: #####: 3:int main(void) {
9+
// CHECK-NEXT: #####: 4: __gcov_flush();
10+
// CHECK-NEXT: -: 5:
11+
// CHECK-NEXT: #####: 6: if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) {
12+
// CHECK-NEXT: #####: 7: return 1;
13+
// CHECK-NEXT: -: 8: }
14+
// CHECK-NEXT: -: 9:
15+
// CHECK-NEXT: #####: 10: __gcov_flush();
16+
// CHECK-NEXT: #####: 11: __gcov_flush();
17+
// CHECK-NEXT: -: 12:
18+
// CHECK-NEXT: #####: 13: if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) {
19+
// CHECK-NEXT: #####: 14: return 1;
20+
// CHECK-NEXT: -: 15: }
21+
// CHECK-NEXT: -: 16:
22+
// CHECK-NEXT: 1: 17: return 0;
23+
// CHECK-NEXT: 1: 18:}

compiler-rt/test/profile/instrprof-value-prof.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <stdint.h>
2828
#include <stdio.h>
2929
#include <stdlib.h>
30+
#include <string.h>
3031
typedef struct __llvm_profile_data __llvm_profile_data;
3132
const __llvm_profile_data *__llvm_profile_begin_data(void);
3233
const __llvm_profile_data *__llvm_profile_end_data(void);

lldb/include/lldb/Core/IOHandler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class IOHandler {
9595

9696
virtual void Deactivate() { m_active = false; }
9797

98+
virtual void TerminalSizeChanged() {}
99+
98100
virtual const char *GetPrompt() {
99101
// Prompt support isn't mandatory
100102
return nullptr;
@@ -369,6 +371,8 @@ class IOHandlerEditline : public IOHandler {
369371

370372
void Deactivate() override;
371373

374+
void TerminalSizeChanged() override;
375+
372376
ConstString GetControlSequence(char ch) override {
373377
return m_delegate.IOHandlerGetControlSequence(ch);
374378
}

lldb/include/lldb/Host/Editline.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
// good amount of the text will
2020
// disappear. It's still in the buffer, just invisible.
2121
// b) The prompt printing logic for dealing with ANSI formatting characters is
22-
// broken, which is why we're
23-
// working around it here.
24-
// c) When resizing the terminal window, if the cursor moves between rows
25-
// libedit will get confused. d) The incremental search uses escape to cancel
26-
// input, so it's confused by
22+
// broken, which is why we're working around it here.
23+
// c) The incremental search uses escape to cancel input, so it's confused by
2724
// ANSI sequences starting with escape.
28-
// e) Emoji support is fairly terrible, presumably it doesn't understand
25+
// d) Emoji support is fairly terrible, presumably it doesn't understand
2926
// composed characters?
3027

3128
#ifndef liblldb_Editline_h_
@@ -50,6 +47,7 @@
5047
#include <histedit.h>
5148
#endif
5249

50+
#include <csignal>
5351
#include <mutex>
5452
#include <string>
5553
#include <vector>
@@ -171,9 +169,7 @@ class Editline {
171169
/// editing scenarios.
172170
void SetContinuationPrompt(const char *continuation_prompt);
173171

174-
/// Required to update the width of the terminal registered for I/O. It is
175-
/// critical that this
176-
/// be correct at all times.
172+
/// Call when the terminal size changes
177173
void TerminalSizeChanged();
178174

179175
/// Returns the prompt established by SetPrompt()
@@ -328,6 +324,8 @@ class Editline {
328324

329325
bool CompleteCharacter(char ch, EditLineGetCharType &out);
330326

327+
void ApplyTerminalSizeChange();
328+
331329
private:
332330
#if LLDB_EDITLINE_USE_WCHAR
333331
std::wstring_convert<std::codecvt_utf8<wchar_t>> m_utf8conv;
@@ -350,6 +348,7 @@ class Editline {
350348
std::string m_set_continuation_prompt;
351349
std::string m_current_prompt;
352350
bool m_needs_prompt_repaint = false;
351+
volatile std::sig_atomic_t m_terminal_size_has_changed = 0;
353352
std::string m_editor_name;
354353
FILE *m_input_file;
355354
FILE *m_output_file;

lldb/include/lldb/Symbol/SwiftASTContext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,11 @@ class SwiftASTContext : public TypeSystemSwift {
817817
Status GetFatalErrors();
818818
void DiagnoseWarnings(Process &process, Module &module) const override;
819819

820+
/// Return a list of warnings collected from ClangImporter.
821+
const std::vector<std::string> &GetModuleImportWarnings() const {
822+
return m_module_import_warnings;
823+
}
824+
820825
const swift::irgen::TypeInfo *
821826
GetSwiftTypeInfo(lldb::opaque_compiler_type_t type);
822827

lldb/source/Core/Debugger.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ uint32_t Debugger::GetTerminalWidth() const {
389389
}
390390

391391
bool Debugger::SetTerminalWidth(uint32_t term_width) {
392+
if (auto handler_sp = m_input_reader_stack.Top())
393+
handler_sp->TerminalSizeChanged();
394+
392395
const uint32_t idx = ePropertyTerminalWidth;
393396
return m_collection_sp->SetPropertyAtIndexAsSInt64(nullptr, idx, term_width);
394397
}

lldb/source/Core/IOHandler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ void IOHandlerEditline::Deactivate() {
287287
m_delegate.IOHandlerDeactivated(*this);
288288
}
289289

290+
void IOHandlerEditline::TerminalSizeChanged() {
291+
#if LLDB_ENABLE_LIBEDIT
292+
m_editline_up->TerminalSizeChanged();
293+
#endif
294+
}
295+
290296
// Split out a line from the buffer, if there is a full one to get.
291297
static Optional<std::string> SplitLine(std::string &line_buffer) {
292298
size_t pos = line_buffer.find('\n');

lldb/source/Host/common/Editline.cpp

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ int Editline::GetCharacter(EditLineGetCharType *c) {
563563
lldb::ConnectionStatus status = lldb::eConnectionStatusSuccess;
564564
char ch = 0;
565565

566+
if (m_terminal_size_has_changed)
567+
ApplyTerminalSizeChange();
568+
566569
// This mutex is locked by our caller (GetLine). Unlock it while we read a
567570
// character (blocking operation), so we do not hold the mutex
568571
// indefinitely. This gives a chance for someone to interrupt us. After
@@ -1055,7 +1058,7 @@ void Editline::ConfigureEditor(bool multiline) {
10551058

10561059
m_editline =
10571060
el_init(m_editor_name.c_str(), m_input_file, m_output_file, m_error_file);
1058-
TerminalSizeChanged();
1061+
ApplyTerminalSizeChange();
10591062

10601063
if (m_history_sp && m_history_sp->IsValid()) {
10611064
if (!m_history_sp->Load()) {
@@ -1308,28 +1311,32 @@ void Editline::SetContinuationPrompt(const char *continuation_prompt) {
13081311
continuation_prompt == nullptr ? "" : continuation_prompt;
13091312
}
13101313

1311-
void Editline::TerminalSizeChanged() {
1312-
if (m_editline != nullptr) {
1313-
el_resize(m_editline);
1314-
int columns;
1315-
// This function is documenting as taking (const char *, void *) for the
1316-
// vararg part, but in reality in was consuming arguments until the first
1317-
// null pointer. This was fixed in libedit in April 2019
1318-
// <http://mail-index.netbsd.org/source-changes/2019/04/26/msg105454.html>,
1319-
// but we're keeping the workaround until a version with that fix is more
1320-
// widely available.
1321-
if (el_get(m_editline, EL_GETTC, "co", &columns, nullptr) == 0) {
1322-
m_terminal_width = columns;
1323-
if (m_current_line_rows != -1) {
1324-
const LineInfoW *info = el_wline(m_editline);
1325-
int lineLength =
1326-
(int)((info->lastchar - info->buffer) + GetPromptWidth());
1327-
m_current_line_rows = (lineLength / columns) + 1;
1328-
}
1329-
} else {
1330-
m_terminal_width = INT_MAX;
1331-
m_current_line_rows = 1;
1314+
void Editline::TerminalSizeChanged() { m_terminal_size_has_changed = 1; }
1315+
1316+
void Editline::ApplyTerminalSizeChange() {
1317+
if (!m_editline)
1318+
return;
1319+
1320+
m_terminal_size_has_changed = 0;
1321+
el_resize(m_editline);
1322+
int columns;
1323+
// This function is documenting as taking (const char *, void *) for the
1324+
// vararg part, but in reality in was consuming arguments until the first
1325+
// null pointer. This was fixed in libedit in April 2019
1326+
// <http://mail-index.netbsd.org/source-changes/2019/04/26/msg105454.html>,
1327+
// but we're keeping the workaround until a version with that fix is more
1328+
// widely available.
1329+
if (el_get(m_editline, EL_GETTC, "co", &columns, nullptr) == 0) {
1330+
m_terminal_width = columns;
1331+
if (m_current_line_rows != -1) {
1332+
const LineInfoW *info = el_wline(m_editline);
1333+
int lineLength =
1334+
(int)((info->lastchar - info->buffer) + GetPromptWidth());
1335+
m_current_line_rows = (lineLength / columns) + 1;
13321336
}
1337+
} else {
1338+
m_terminal_width = INT_MAX;
1339+
m_current_line_rows = 1;
13331340
}
13341341
}
13351342

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,9 +1684,24 @@ unsigned SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
16841684
}
16851685

16861686
if (!m_module) {
1687-
diagnostic_manager.PutString(
1688-
eDiagnosticSeverityError,
1689-
"Couldn't IRGen expression, no additional error");
1687+
auto &warnings = swift_ast_ctx->GetModuleImportWarnings();
1688+
for (StringRef message : warnings) {
1689+
// FIXME: Don't store diagnostics as strings.
1690+
auto severity = eDiagnosticSeverityWarning;
1691+
if (message.consume_front("warning: "))
1692+
severity = eDiagnosticSeverityWarning;
1693+
if (message.consume_front("error: "))
1694+
severity = eDiagnosticSeverityError;
1695+
diagnostic_manager.PutString(severity, message);
1696+
}
1697+
std::string error = "couldn't IRGen expression";
1698+
diagnostic_manager.Printf(
1699+
eDiagnosticSeverityError, "couldn't IRGen expression. %s",
1700+
warnings.empty()
1701+
? "Please enable the expression log by running \"log enable lldb "
1702+
"expr\", then run the failing expression again, and file a "
1703+
"bugreport with the log output."
1704+
: "Please check the above error messages for possible root causes.");
16901705
return 1;
16911706
}
16921707

lldb/source/Symbol/SwiftASTContext.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
22062206
logError("couldn't load the Swift stdlib");
22072207
return {};
22082208
}
2209-
2209+
22102210
return swift_ast_sp;
22112211
}
22122212

@@ -3198,15 +3198,17 @@ swift::ASTContext *SwiftASTContext::GetASTContext() {
31983198
// Handle any errors.
31993199
if (!clang_importer_ap || HasErrors()) {
32003200
std::string message;
3201-
if (!HasErrors())
3201+
if (!HasErrors()) {
32023202
message = "failed to create ClangImporter.";
3203-
else {
3203+
m_module_import_warnings.push_back(message);
3204+
} else {
32043205
DiagnosticManager diagnostic_manager;
32053206
PrintDiagnostics(diagnostic_manager);
3207+
std::string underlying_error = diagnostic_manager.GetString();
32063208
message = "failed to initialize ClangImporter: ";
3207-
message += diagnostic_manager.GetString();
3209+
message += underlying_error;
3210+
m_module_import_warnings.push_back(underlying_error);
32083211
}
3209-
m_module_import_warnings.push_back(message);
32103212
LOG_PRINTF(LIBLLDB_LOG_TYPES, "%s", message.c_str());
32113213
}
32123214
if (clang_importer_ap)

lldb/test/API/functionalities/thread/step_out/TestThreadStepOut.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ def setUp(self):
7070
self.bkpt_string = '// Set breakpoint here'
7171
self.breakpoint = line_number('main.cpp', self.bkpt_string)
7272

73-
if "gcc" in self.getCompiler() or self.isIntelCompiler() or self.getArchitecture() in ['arm64', 'arm64e']:
73+
if "gcc" in self.getCompiler() or self.isIntelCompiler():
7474
self.step_out_destination = line_number(
75-
'main.cpp', '// Expect to stop here after step-out (icc and gcc; arm64)')
75+
'main.cpp', '// Expect to stop here after step-out (icc and gcc)')
7676
else:
7777
self.step_out_destination = line_number(
7878
'main.cpp', '// Expect to stop here after step-out (clang)')

lldb/test/API/functionalities/thread/step_out/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ thread_func ()
3030
step_out_of_here(); // Expect to stop here after step-out (clang)
3131

3232
// Return
33-
return NULL; // Expect to stop here after step-out (icc and gcc; arm64)
33+
return NULL; // Expect to stop here after step-out (icc and gcc)
3434
}
3535

3636
int main ()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Test resizing in our IOHandlers.
3+
"""
4+
5+
import os
6+
7+
import lldb
8+
from lldbsuite.test.decorators import *
9+
from lldbsuite.test.lldbtest import *
10+
from lldbsuite.test.lldbpexpect import PExpectTest
11+
12+
class IOHandlerCompletionTest(PExpectTest):
13+
14+
mydir = TestBase.compute_mydir(__file__)
15+
16+
# PExpect uses many timeouts internally and doesn't play well
17+
# under ASAN on a loaded machine..
18+
@skipIfAsan
19+
@skipIfEditlineSupportMissing
20+
def test_resize(self):
21+
22+
# Start with a small window
23+
self.launch(dimensions=(10,10))
24+
25+
self.child.send("his is a long sentence missing its first letter.")
26+
27+
# Now resize to something bigger
28+
self.child.setwinsize(100,500)
29+
30+
# Hit "left" 60 times (to go to the beginning of the line) and insert
31+
# a character.
32+
self.child.send(60 * "\033[D")
33+
self.child.send("T")
34+
35+
self.child.expect_exact("(lldb) This is a long sentence missing its first letter.")
36+
self.quit()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public func foo(_ x : Int) -> Int {
2+
return x + x
3+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFT_OBJC_INTEROP := 1
3+
SWIFTFLAGS_EXTRAS = -I$(BUILDDIR)
4+
LD_EXTRAS = -L$(BUILDDIR) -lFoo
5+
6+
all: libFoo.dylib $(EXE)
7+
8+
include Makefile.rules
9+
10+
OVERLAY := $(BUILDDIR)/overlay.yaml
11+
lib%.dylib: %.swift
12+
rm -f $(OVERLAY)
13+
echo "{ 'version': 0, 'roots': [] }" >$(OVERLAY)
14+
$(MAKE) MAKE_DSYM=$(MAKE_DSYM) CC=$(CC) SWIFTC=$(SWIFTC) \
15+
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
16+
BASENAME=$(shell basename $< .swift) \
17+
SWIFTFLAGS_EXTRAS="-Xcc -ivfsoverlay -Xcc $(OVERLAY)" \
18+
VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk all
19+
rm -f $(OVERLAY)
20+
21+
clean::
22+
$(MAKE) MAKE_DSYM=$(MAKE_DSYM) CC=$(CC) SWIFTC=$(SWIFTC) \
23+
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
24+
BASENAME=$(shell basename $< .swift) \
25+
VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/dylib.mk clean

0 commit comments

Comments
 (0)