This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] new altera kernel name restriction check
ClosedPublic

Authored by ffrankies on Jan 4 2020, 8:10 PM.

Details

Summary

This lint check is part of the FLOCL (FPGA Linters for OpenCL) project out of the Synergy Lab at Virginia Tech.

FLOCL is a set of lint checks aimed at FPGA developers who code in OpenCL.

The altera kernel name restriction check finds kernel files and include directives whose filename is "kernel.cl", "Verilog.cl", or "VHDL.cl". Such kernel file names cause the Altera Offline Compiler to generate intermediate design files that have the same names as certain internal files, which leads to a compilation error.

As per the "Guidelines for Naming the Kernel" section in the "Intel FPGA SDK for OpenCL Pro Edition: Programming Guide."

Depends on D66564 due to the altera module being introduced there.

Diff Detail

Event Timeline

ffrankies created this revision.Jan 4 2020, 8:10 PM
Eugene.Zelenko added inline comments.
clang-tidy/altera/KernelNameRestrictionCheck.cpp
22

Please separate with empty line.

47

Please separate with empty line.

docs/ReleaseNotes.rst
79

Please fix indentation and use single back-ticks to highlight file names. Same in documentation.

docs/clang-tidy/checks/altera-kernel-name-restriction.rst
14

May be link is better?

Eugene.Zelenko added inline comments.Jan 4 2020, 10:03 PM
clang-tidy/altera/KernelNameRestrictionCheck.cpp
14

Please include string, vector

70

Please don't use auto unless type is not spelled in same statement or iterator.

71

Please don't use auto unless type is not spelled in same statement or iterator.

83

Please don't use auto unless type is not spelled in same statement or iterator.

85

Please don't use auto unless type is not spelled in same statement or iterator.

ffrankies marked 9 inline comments as done.
ffrankies edited the summary of this revision. (Show Details)

Implemented changes requested by @Eugene.Zelenko:

  • Added empty lines around namespace block
  • Fixed use of auto keyword
  • Fixed formatting in documentation
  • Added dependency on previous revision (D66564) to the Summary.
ffrankies updated this revision to Diff 254301.Apr 1 2020, 1:43 PM
Eugene.Zelenko set the repository for this revision to rG LLVM Github Monorepo.
Eugene.Zelenko removed a project: Restricted Project.
ffrankies updated this revision to Diff 294215.Sep 24 2020, 7:10 PM
ffrankies edited the summary of this revision. (Show Details)
  • Rebased code and fixed merge conflicts with D66564
  • Added KernelNameRestrictionCheck.cpp to BUILD.gn
Herald added a project: Restricted Project. · View Herald TranscriptSep 24 2020, 7:10 PM
ffrankies removed projects: Restricted Project, Restricted Project.Sep 24 2020, 7:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 24 2020, 7:11 PM
Eugene.Zelenko added inline comments.Sep 24 2020, 7:26 PM
clang-tools-extra/docs/clang-tidy/checks/altera-kernel-name-restriction.rst
4 ↗(On Diff #294215)

Please make same length as text above.

aaron.ballman added inline comments.Sep 25 2020, 6:25 AM
clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
53 ↗(On Diff #294215)

You can elide the identifier ModuleExpanderPP since it's not used in the call.

74–76 ↗(On Diff #294215)

Rather than do path manipulations manually, I'd rather use llvm::sys::path::filename()

78 ↗(On Diff #294215)

clang-tidy diagnostics are not meant to be grammatically correct, so I think this should be something more like: including '%0' may cause additional compilation errors due to the name of the file; consider renaming the included file and pass in the name of the file being included.

86–88 ↗(On Diff #294215)

Similar here about using filesystem utilities.

90 ↗(On Diff #294215)

Similar here, I would word it something like: compiling a source file named '%0' may result in additional compilation errors due to the name of the file; consider renaming the source file

clang-tools-extra/test/clang-tidy/checkers/altera-kernel-name-restriction.cpp
40 ↗(On Diff #294215)

I assume it's also fine if the user does something really weird like: #include "kernel.cl/foo.h" ?

ffrankies updated this revision to Diff 295697.Oct 1 2020, 5:08 PM
ffrankies removed a project: Restricted Project.

Addressed changes requested by @Eugene.Zelenko and @aaron.ballman

Herald added a project: Restricted Project. · View Herald TranscriptOct 1 2020, 5:08 PM
aaron.ballman added inline comments.Oct 2 2020, 8:12 AM
clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
90 ↗(On Diff #294215)

The diagnostic here doesn't look quite right. This is the case where the source compiland is named poorly, but the diagnostic is talking about including files. It looks like there's test coverage missing for this.

mgehre removed a subscriber: mgehre.Oct 2 2020, 3:17 PM
ffrankies updated this revision to Diff 298601.Oct 16 2020, 7:02 AM
ffrankies marked 7 inline comments as done.

Addressed comments by @aaron.ballman regarding the diagnostic warning.

I tried to add a test case for when the filename is kernel.cl, verilog.cl, or vhdl.cl, but that did not work because the test suite appends .tmp.cpp to the end of the test files, and kernel.cl.tmp.cpp is not a restricted filename. If you know of a way to include this test case in the test suite, please let me know. In the meantime, I tested this functionality manually, and found a minor bug that has since been fixed.

The bug was: if kernel.cl does not have any include directives, then the warning would not show up. Fixed this by rearranging the code to check the main file name before checking the include directives.

aaron.ballman accepted this revision.Oct 19 2020, 8:08 AM

Addressed comments by @aaron.ballman regarding the diagnostic warning.

I tried to add a test case for when the filename is kernel.cl, verilog.cl, or vhdl.cl, but that did not work because the test suite appends .tmp.cpp to the end of the test files, and kernel.cl.tmp.cpp is not a restricted filename. If you know of a way to include this test case in the test suite, please let me know.

Oh, that's an interesting fact I hadn't considered before. I don't know of a better way to do that.

In the meantime, I tested this functionality manually, and found a minor bug that has since been fixed.

Great!

The bug was: if kernel.cl does not have any include directives, then the warning would not show up. Fixed this by rearranging the code to check the main file name before checking the include directives.

That makes sense to me.

The check LGTM aside from some minor nits. If you need me to commit on your behalf once you've made the changes, just let me know. Thanks!

clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
60–63 ↗(On Diff #298601)

It looks like you can leave a bunch of identifiers off the parameters to shorten the declaration and avoid unused parameter diagnostics in some compilers.

73–74 ↗(On Diff #298601)

Rather than duplicate the checking logic here and below, I'd like a small helper function to check whether the name is problematic that gets called from both places.

clang-tools-extra/docs/clang-tidy/checks/altera-kernel-name-restriction.rst
7 ↗(On Diff #298601)

We should explicitly document that the check is case insensitive.

This revision is now accepted and ready to land.Oct 19 2020, 8:08 AM
ffrankies updated this revision to Diff 301865.Oct 30 2020, 5:29 AM
ffrankies marked an inline comment as done.

Implemented changes requested by @aaron.ballman

  • Added a helper function that implements the string comparison logic
  • Clarified that check is case insensitive
  • Removed unused identifiers from KernelNameRestrictionPPCallbacks::InclusionDirective function
ffrankies marked 3 inline comments as done.Oct 30 2020, 5:35 AM

@aaron.ballman Can you please commit this on my behalf? My github username is ffrankies.

And could you take a look at D72241 altera single work item barrier check? It's also been updated and awaiting review.

clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
90 ↗(On Diff #294215)

My bad, I copied this line over the from other diagnostic and didn't change "including" to "compiling". Will update shortly

clang-tools-extra/test/clang-tidy/checkers/altera-kernel-name-restriction.cpp
40 ↗(On Diff #294215)

Yes, this is fine. The guide only specifies potential errors when the kernel source file is named kernel.cl, verilog.cl, or vhdl.cl.

I've added additional test cases that use these names as directory names below.

aaron.ballman closed this revision.Nov 2 2020, 7:13 AM

@aaron.ballman Can you please commit this on my behalf? My github username is ffrankies.

I've commit on your behalf in 43a38a65233039b5e71797a644d41a890f8d7f2b, thank you!

And could you take a look at D72241 altera single work item barrier check? It's also been updated and awaiting review.

I'll take a look, thank you for pinging it.

ffrankies updated this revision to Diff 303680.EditedNov 7 2020, 4:26 PM

Moved test files KERNEL.cl, VHDL.cl and vERILOG.cl to the uppercase subdirectory to prevent filename clashes in some environments.

This is in response to the buildbot failure where Verilog.cl, KERNEL.cl, and VHDL.cl were not present in the buildbot output despite showing up as present in Differential.

@aaron.ballman Can you please try committing this again?

Moved test files KERNEL.cl, VHDL.cl and vERILOG.cl to the uppercase subdirectory to prevent filename clashes in some environments.

This is in response to the buildbot failure where Verilog.cl, KERNEL.cl, and VHDL.cl were not present in the buildbot output despite showing up as present in Differential.

@aaron.ballman Can you please try committing this again?

I've recommit in 9ca6fc4e095f9aacd70e406e640472ad2d370553, thanks!