Skip to content
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

Fix CC1Main setting trigger undefined behavior #4714

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

bricknerb
Copy link
Contributor

@bricknerb bricknerb commented Dec 19, 2024

This is caused by setting a temporary lambda to a llvm::function_ref.
The fix is to assign the lambda into std::function that outlives the llvm::function_ref.

This is caused by setting a temporary lambda to a llvm::function_ref.
The fix is to avoid using a lambda and define a function instead.
This is caused by setting a temporary lambda to a `llvm::function_ref`.
 The fix is to assign the lambda into `std::function` that outlives the `llvm::function_ref`.
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

Nice catch!

@@ -146,13 +146,15 @@ auto ClangRunner::Run(llvm::ArrayRef<llvm::StringRef> args) -> bool {
// Note the subprocessing will effectively call `clang -cc1`, which turns into
// `carbon-busybox clang -cc1`, which results in an equivalent `clang_main`
// call.
driver.CC1Main = [](llvm::SmallVectorImpl<const char*>& cc1_args) -> int {
std::function<int(llvm::SmallVectorImpl<const char*> & cc1_args)> cc1_main =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
std::function<int(llvm::SmallVectorImpl<const char*> & cc1_args)> cc1_main =
auto cc1_main =

Does this need to explicitly be a std::function, or is it enough to store the lambda directly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants