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

User defined/declared functions are wrongly identified as OpenCL builtins #2513

Open
asudarsa opened this issue Apr 18, 2024 · 1 comment
Open

Comments

@asudarsa
Copy link
Contributor

Existing checks in OCLIsBuiltin(...) function are not sufficient to identify OpenCL builtins correctly. There is a possibility that user can define/declare functions with names that could cause them to be identified as OpenCL builtins.

An LLVM IR test that showcases this issue has been added as part of an ongoing PR:
https://github.com/KhronosGroup/SPIRV-LLVM-Translator/pull/2512/files#diff-7bb994ec5258f2246431ab51bfff2ff1643b801fefdd7a498c666ba5c1480ac4

Without the fix in this PR (#2512), this test will fail.

The above PR addresses user-defined functions. However, we do not currently have a resolution for user-declared functions.

Thanks

@asudarsa
Copy link
Contributor Author

A well-rounded solution is available in #2525

The root cause in this issue is that the OCLIsBuiltin identifies any function name that ‘might’ be a OCL builtin name. In his case, the demangled name was ‘atomic_fetch_and_add_uint32_explicit’ and this name was not found in the OCLSPIRVBuiltinMap.
If we directly call OCLSPIRVBuiltinMap::map, it does the following:

  1. Call OCLSPIRVBuiltinMap::find(name, &B)
  2. Assert if the call fails
  3. Return B
    Though, OCLIsBuiltin is named as such, all it does is return an unmangled name if one exists, irrespective of whether it is OCL builtin or not.
    So, we need an extra check instead of directly calling OCLSPIRVBuiltinMap::map
  4. Call OCLSPIRVBuiltinMap::find(name, &B)
  5. Return early if the call fails
  6. Proceed processing with B

Thanks

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

No branches or pull requests

1 participant