Skip to content

Commit 4ab738e

Browse files
Davide ItalianoDavide Italiano
authored andcommitted
[MetadataReader] Initialize fields to prevent UB.
hasVtable is not initialized on all paths, so when we read it, we end up reading a random value. On debug builds, this value almost always happen to be zero, so we do the right thing. This isn't necessarily true when the optimizations kick in. lldb uses metadata reder to resolve types and as result of this undefined behaviour sometimes gets wrong results back, causing a bunch of tests to fail in release builds.
1 parent 37beb71 commit 4ab738e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/swift/Remote/MetadataReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,9 +933,9 @@ class MetadataReader {
933933
sizeof(flags)))
934934
return nullptr;
935935

936-
unsigned baseSize;
936+
unsigned baseSize = 0;
937937
unsigned genericHeaderSize = sizeof(GenericContextDescriptorHeader);
938-
bool hasVTable;
938+
bool hasVTable = false;
939939
switch (auto kind = flags.getKind()) {
940940
case ContextDescriptorKind::Module:
941941
baseSize = sizeof(TargetModuleContextDescriptor<Runtime>);

0 commit comments

Comments
 (0)