Skip to content

[IRGen] Zero-init stack shadow copies of values at -Onone. #16486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2018

Conversation

dcci
Copy link
Member

@dcci dcci commented May 10, 2018

We already zero init AllocStack, and here's the same.
The debugger's variable view shows up variables on the line
where they're declared (before they've been initialized).
In some cases, we just print garbage. In some others, it's
dangerous (imagine an array which we believe has 2^32 elements
because we ended up reusing a stack slot). This way it's always
consistent, as lldb uses the first word to understand whether
an object is initialized or not here.

Fixes rdar://problem/39883298

@dcci dcci requested a review from adrian-prantl May 10, 2018 00:44
@dcci
Copy link
Member Author

dcci commented May 10, 2018

@swift-ci please test

Copy link
Contributor

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good!

@@ -719,6 +719,28 @@ class IRGenSILFunction :
}
}

// To make it unambiguous whether a `var` binding has been initialized,
Copy link
Contributor

Choose a reason for hiding this comment

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

///
Doesn't show up in Doxygen, but some editors format the comments nicer then.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

// zero-initialize the first pointer-sized field. LLDB uses this to
// recognize to detect uninitizialized variables. This can be removed once
// swiftc switches to @llvm.dbg.addr() intrinsics.
void zeroInit(llvm::AllocaInst *AI) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like we could just make this an llvm::AllocaInst & ?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the other user doesn't seem to always pass an alloca, so we can't just blatantly make the dyn_cast<> a cast<> [I tried]. If you think it's a bug, the assertion fires while building the swift standard library.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to know: what is it when it isn't an AllocaInst? Just wondering if there is another case we should handle.

@slavapestov
Copy link
Contributor

The commit message is inaccurate, this is IRGen not SILGen.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 8350b4fae9bd770447b3f93e688c1e1a6057a89b

@dcci
Copy link
Member Author

dcci commented May 10, 2018

The commit message is inaccurate, this is IRGen not SILGen.

Thanks! I'll fix this.

@dcci
Copy link
Member Author

dcci commented May 10, 2018

Looks like this change broke a bunch of lldb tests. I'm going to investigate :)

@dcci
Copy link
Member Author

dcci commented May 10, 2018

We looked at this with Adrian and this patch is wrong. I'm going to submit an update.

@dcci dcci force-pushed the garbageshadow branch from 8350b4f to b85cd0d Compare May 10, 2018 21:49
We already zero init AllocStack, and here's the same.
The debugger's variable view shows up variables on the line
where they're declared (before they've been initialized).
In some cases, we just print garbage. In some others, it's
dangerous (imagine an array which we believe has 2^32 elements
because we ended up reusing a stack slot). This way it's always
consistent, as lldb uses the first word to understand whether
an object is initialized or not here.

Fixes <rdar://problem/39883298>
@dcci dcci force-pushed the garbageshadow branch from b85cd0d to ddf5130 Compare May 10, 2018 21:50
@dcci dcci changed the title [SILGen] Zero-init stack shadow copies of values at -Onone. [IRGen] Zero-init stack shadow copies of values at -Onone. May 10, 2018
@dcci
Copy link
Member Author

dcci commented May 10, 2018

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 8350b4fae9bd770447b3f93e688c1e1a6057a89b

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 8350b4fae9bd770447b3f93e688c1e1a6057a89b

if (DL.getTypeSizeInBits(AI->getAllocatedType()) <
DL.getPointerSizeInBits())
return;

Copy link
Contributor

Choose a reason for hiding this comment

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

// No debug location is how LLVM marks prologue instructions.

@dcci dcci merged commit 119e2b6 into swiftlang:master May 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants