Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ findFieldWithName(const std::vector<swift::reflection::FieldInfo> &fields,
if (name != field.Name) {
// A nonnull TypeRef is required for enum cases, where it represents cases
// that have a payload. In other types it will be true anyway.
if (field.TR)
if (!is_enum || field.TR)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to comment (I assume it's because enums have exactly 1 field?)
Also: should this be !is_enum && field.TR`?
Finally: testcase?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to comment (I assume it's because enums have exactly 1 field?)

I think the comment there still applies. If it's an enum and there's no typeref then we don't increment the index, because that's a case without a payload.

Also: should this be !is_enum && field.TR`?

I don't think so? If it's not not an enum we always want to increment the index (given the previous comment), in case it's an enum we wan't to increment only if there's a typeref.

Finally: testcase?

If we merge swiftlang/swift#61081 TestSwiftFoundation.py will catch this. Otherwise I'll have to figure out a way to trigger this behavior.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right.

++index;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3835,6 +3835,10 @@ bool TypeSystemSwiftTypeRef::ShouldSkipValidation(opaque_compiler_type_t type) {
// so we skip validation in that casse as well.
if (mangled_name == "$s10Foundation12NotificationV4NameaD")
return true;

if (mangled_name == "$s10Foundation12NotificationVD")
return true;

if (mangled_name == "$sSo9NSDecimalaD")
return true;
// Reconstruct($sSo11CFStringRefaD) returns a non-typealias type, breaking
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lang/swift/c_type_external_provider/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SWIFT_SOURCES := main.swift
SWIFT_BRIDGING_HEADER := bridging-header.h
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Tests that LLDB uses the external type info provider for C types.
"""
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import unittest2



class TestSwiftCTypeExternalProvider(TestBase):
def setUp(self):
TestBase.setUp(self)
self.main_source = "main.swift"
self.main_source_spec = lldb.SBFileSpec(self.main_source)

@swiftTest
def test_swift_regex(self):
"""Test that C types with builtin metadata emitted are looked up using
external type info provider."""
self.build()
log = self.getBuildArtifact("types.log")
self.runCmd('log enable lldb types -f "%s"' % log)
lldbutil.run_to_source_breakpoint(
self, 'Set breakpoint here', self.main_source_spec)

# Consult the second field to ensure we call GetIndexOfChildMemberWithName.
self.expect('v dummy.second', substrs=['2'])

# Make sure we look up the type with the external type info provider.
provider_log_found = False
with open(log, "r", encoding='utf-8') as logfile:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point we should write an lldbutil function that calls FileCheck on a text file...

for line in logfile:
if '[LLDBTypeInfoProvider] Looking up debug type info for So5DummyV' in line:
provider_log_found = True
break
self.assertTrue(provider_log_found)

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef bridging_header_h
#define bridging_header_h

struct Dummy {
int first;
int second;
};
#endif /* bridging_header_h */
6 changes: 6 additions & 0 deletions lldb/test/API/lang/swift/c_type_external_provider/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var dummy = Dummy()
dummy.first = 1;
dummy.second = 2;
// Print dummy so we ensure we generate it's metadata.
print(Dummy.self) // Set breakpoint here.