Skip to content

[SYCL] Error out instead of crash when templated global var used #5195

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 3 commits into from
Dec 23, 2021

Conversation

Fznamznon
Copy link
Contributor

SYCL deferred diagnostics couldn't catch the case like:

template <typename T>
class randomType {
 public:
  randomType() {}
  T val;
};

template <typename T>
const randomType<T> Var;

SYCL_EXTERNAL void foo() {
  (void)Var<int>;
}

And CodeGen was crashing due to attempt to emit invalid cast.
That happened because use of Var should be diagnosed. The diagnostic
wasn't emitted because at the places where deferred diagnostic is issued
for this case, templated variable doesn't yet has initializer, or it has
it but current lexical context is out of device code (in this particular
case it will be a translation unit). This patch follows the logic
invented by finalizeOpenMPDelayedAnalysis and finalizeSYCLDelayedAnalysis
routines, i.e. emit immediate diagnostic when post-parsing of AST for
deferred diagnostics happens.

SYCL deferred diagnostics couldn't catch the case like:
```
template <typename T>
class randomType {
 public:
  randomType() {}
  T val;
};

template <typename T>
const randomType<T> Var;

SYCL_EXTERNAL void foo() {
  (void)Var<int>;
}
```
And CodeGen was crashing due to attempt to emit invalid cast.
That happened because use of `Var` should be diagnosed. The diagnostic
wasn't emitted because at the places where deferred diagnostic is issued
for this case, templated variable doesn't yet has initializer, or it has
it but current lexical context is out of device code (in this particular
case it will be a translation unit). This patch follows the logic
invented by `finalizeOpenMPDelayedAnalysis` and `finalizeSYCLDelayedAnalysis`
routines, i.e. emit immediate diagnostic when post-parsing of AST for
deferred diagnostics happens.
Copy link
Contributor

@smanna12 smanna12 left a comment

Choose a reason for hiding this comment

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

LGTM

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