Page MenuHomePhabricator

[OpenCL] Prevent mangling kernel functions
ClosedPublic

Authored by Anastasia on Apr 9 2019, 4:47 AM.

Details

Summary

Kernel function names have to be preserved as in the original source to be able to access them from the host API side.

This patch adds restriction to kernels that prevents them to be used in overloading, templates, etc. This is implemented by enclosing the kernels implicitly into C linkage clause. Therefore all C linkage restrictions will apply to the kernels.

Diff Detail

Repository
rC Clang

Event Timeline

Anastasia created this revision.Apr 9 2019, 4:47 AM

I think it would be more reasonable to just change getDeclLanguageLinkage to check for a kernel function.

Anastasia updated this revision to Diff 197791.May 2 2019, 8:15 AM

Extended FunctionDecl exten C logic to take kernel function into account.

I think it would be more reasonable to just change getDeclLanguageLinkage to check for a kernel function.

lib/AST/Decl.cpp
2961

Both of these changes should be unnecessary because they ultimately defer to isInExternCContext.

I assume that OpenCL bans making a class member function a kernel?

Anastasia updated this revision to Diff 197934.May 3 2019, 2:31 AM
Anastasia marked an inline comment as done.

Removed redundant C linkage checks!

I think it would be more reasonable to just change getDeclLanguageLinkage to check for a kernel function.

I tried to change getDeclLanguageLinkage only but Sema calls isInExternCContext separately while giving diagnostics. getDeclLanguageLinkage also calls it through isFirstInExternCContext. So it seems we just need to check in isInExternCContext and that is a common part for all various program paths. Do you agree?

lib/AST/Decl.cpp
2961

I assume that OpenCL bans making a class member function a kernel?

Yep, that's right! I am adding a diagnostic in this patch.

rjmccall accepted this revision.May 3 2019, 9:20 AM

LGTM.

This revision is now accepted and ready to land.May 3 2019, 9:20 AM
Closed by commit rC360152: [OpenCL] Prevent mangling kernel functions. (authored by stulova, committed by ). · Explain WhyMay 7 2019, 7:20 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2019, 7:21 AM