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

[SYCL] Null VarDecl dereference when a binding declaration is captured #6924

Merged
merged 7 commits into from
Oct 7, 2022

Conversation

premanandrao
Copy link
Contributor

After the support for capturing structured bindings in lambdas, variables captured in BuildCaptureField
need not be VarDecls. A previous patch needs to now account for a possible null pointer before
dereferencing the pointer to get its name string.

After the support for capturing structured bindings in lambdas,
variables captured in BuildCaptureField need not be VarDecls.
A previous patch added needs to now account for a possible null
pointer before dereferencing the pointer to get its name string.
@premanandrao premanandrao requested a review from a team as a code owner September 30, 2022 17:22

// CHECK: expected-no-diagnostics

template <typename T>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the test be simpler? Something like the following should be enough to test this right?

int main() {
  int a[2] = {1, 2};
  auto [x, y] = a;
  auto L = [=]() {x = 10;};
  L();
  return 0;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Also can these kind of captures happen inside SYCL kernel and if so should we add a test to see what metadata is generated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can the test be simpler? Something like the following should be enough to test this right?

int main() {
  int a[2] = {1, 2};
  auto [x, y] = a;
  auto L = [=]() {x = 10;};
  L();
  return 0;
}

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also can these kind of captures happen inside SYCL kernel and if so should we add a test to see what metadata is generated?

I have added a CodeGen test.

@@ -1723,7 +1723,7 @@ FieldDecl *Sema::BuildCaptureField(RecordDecl *RD,
// For SYCL compilations, save user specified names for
// lambda capture.
if (getLangOpts().SYCLIsDevice || getLangOpts().SYCLIsHost) {
StringRef CaptureName = Var->getName();
StringRef CaptureName = Var ? Var->getName() : "";
Copy link
Contributor

Choose a reason for hiding this comment

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

So binding declarations are just null VarDecls?

Copy link
Contributor

Choose a reason for hiding this comment

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

So binding declarations are just null VarDecls?

Yeah, that feels weird to me too.
Also, they seem to have a name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So binding declarations are just null VarDecls?

No. Originally this routine had a VarDecl return type. This was changed to return a ValueDecl as part of the support for lambdas capturing BindingDecls. So now, in this routine, when we dynamic cast to VarDecl, there is a possibility that Var could be NULL. That is the bad null-dereference that this PR is fixing.

Copy link
Contributor

Choose a reason for hiding this comment

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

A ValueDecl is a NamedDecl. Is there a reason why we can't retain the name for this as well? The reason we retained names for captures is so that the metadata generated for openCL kernel arguments retained use specified names - which we are now not doing for this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added the name of the BindingDecl.

Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

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

Just a couple of NITs to tests style, otherwise LGTM.

clang/test/CodeGenSYCL/kernel_binding_decls.cpp Outdated Show resolved Hide resolved
clang/test/CodeGenSYCL/kernel_binding_decls.cpp Outdated Show resolved Hide resolved
@premanandrao
Copy link
Contributor Author

The failure of lsc/lsc_surf_load_u32.cpp is unrelated to this change.
@intel/llvm-gatekeepers, this is ready for your review and merge.

@steffenlarsen steffenlarsen merged commit 0e455c9 into intel:sycl Oct 7, 2022
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.

5 participants