8000 Merge pull request #802 from adrian-prantl/59429786-2 · swiftlang/llvm-project@22258cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 22258cf

Browse files
authored
Merge pull request #802 from adrian-prantl/59429786-2
Correctly identify "self" inside an allocator.
2 parents b556d0b + 9ef0fce commit 22258cf

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
include Makefile.rules
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import os
6+
import unittest2
7+
8+
9+
class TestSwiftExprAllocator(lldbtest.TestBase):
10+
11+
mydir = lldbtest.TestBase.compute_mydir(__file__)
12+
13+
@swiftTest
14+
def test_allocator_self(self):
15+
"""Test expressions involving self in a allocating constructor. In an
16+
allocator, self is just a local variable, not being passed in, but
17+
should still be recognized as self."""
18+
self.build()
19+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
20+
self, 'break here', lldb.SBFileSpec('main.swift'))
21+
22+
self.expect("p x", substrs=['23'])
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct Foo {
2+
let x = 23
3+
init() {
4+
print("break here")
5+
}
6+
}
7+
8+
let f = Foo()
9+
print(f)

lldb/source/Target/SwiftLanguageRuntime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,8 @@ bool SwiftLanguageRuntime::IsSelf(Variable &variable) {
17911791
if (node_ptr->getNumChildren() != 1)
17921792
return false;
17931793
node_ptr = node_ptr->getFirstChild();
1794-
return node_ptr->getKind() == swift::Demangle::Node::Kind::Constructor;
1794+
return node_ptr->getKind() == swift::Demangle::Node::Kind::Constructor ||
1795+
node_ptr->getKind() == swift::Demangle::Node::Kind::Allocator;
17951796
}
17961797

17971798
/// Determine whether the scratch SwiftASTContext has been locked.

0 commit comments

Comments
 (0)
0