Skip to content

[master-next] Fix up the driver's use of PROGRAM_START after PR #16362 #17494

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
Jun 26, 2018

Conversation

bob-wilson
Copy link
Contributor

On the master-next branch, the InitLLVM class used by the PROGRAM_START
macro can modify the argc/argv values (currently only on Windows).
Expanding response files before initializing the stack trace also modifies
the arguments so use a separate SmallVector for each copy of the argument
vector.

…lang#16362

On the master-next branch, the InitLLVM class used by the PROGRAM_START
macro can modify the argc/argv values (currently only on Windows).
Expanding response files before initializing the stack trace also modifies
the arguments so use a separate SmallVector for each copy of the argument
vector.
@bob-wilson bob-wilson requested a review from jrose-apple June 26, 2018 00:02
@bob-wilson
Copy link
Contributor Author

I'm going to go ahead and merge this to un-break the master-next build, but Jordan, please let me know if you have any comments or suggestions on this.

@bob-wilson bob-wilson merged commit c10a17b into swiftlang:master-next Jun 26, 2018
@bob-wilson bob-wilson deleted the pr16362-fix branch June 26, 2018 00:03
@@ -180,7 +180,7 @@ static int run_driver(StringRef ExecName,
}

int main(int argc_, const char **argv_) {
SmallVector<const char *, 256> argv(&argv_[0], &argv_[argc_]);
SmallVector<const char *, 256> args(&argv_[0], &argv_[argc_]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you give this a more descriptive name, then? It's not good to have args and argv both floating around in this function.

bob-wilson added a commit that referenced this pull request Jun 27, 2018
Jordan reviewed my change and suggested using a better variable name
to avoid potential confusion between "args" and "argv".
bob-wilson added a commit that referenced this pull request Jun 27, 2018
[master-next] NFC: Rename variable from PR #17494
@dabelknap
Copy link
Contributor

@jrose-apple I am confused by the changes made here. In #16362 we refactored main specifically to avoid having to create a copy of the argument vector based on review comments.

@jrose-apple
Copy link
Contributor

The master-next branch mostly just needs to stay working to make sure upstream LLVM doesn't break us in some way. I guess I should have filed a bug to come back and clean this up.

@bob-wilson
Copy link
Contributor Author

FWIW, I compared against other LLVM tools to see how they handle this. At least for the tools that I looked at (e.g., llvm-ar), the pretty stack trace info is initialized before expanding the response files. Austin's change in 3fe62b9 specifically moved the PROGRAM_START macro so that the stack trace info would be initialized after expanding the response files. Since that was clearly an intentional decision, I figured it was better to copy the arguments to preserve that behavior. Maybe there's a clever way to do it without a copy, but that seemed like the most straightforward solution.

@jrose-apple
Copy link
Contributor

I think the point is that we need to copy them once to expand response files, but we shouldn't need to copy a second time for this.

@bob-wilson
Copy link
Contributor Author

I understand that, but with recent versions of LLVM (i.e., master-next), the llvm::InitLLVM constructor used by the PROGRAM_START macro can rewrite the arguments on some platforms, so there's a separate copy for that.

const char **ExpandedArgv = args.data();
PROGRAM_START(ExpandedArgc, ExpandedArgv);
SmallVector<const char *, 256> argv(&ExpandedArgv[0],
&ExpandedArgv[ExpandedArgc]);
Copy link
Contributor

Choose a reason for hiding this comment

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

There is specifically no need for this SmallVector. An ArrayRef would be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. Yeah, of course. #17728

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.

3 participants