Ineffectual Compiler Directive
ID |
go.ineffectual_compiler_directive |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Go |
Tags |
CWE:1164, build, reliability |
Description
Reports a line comment that looks like a Go compiler directive but is silently ignored because of
misplaced whitespace between the // and go:. The directive has no effect, so whatever it was
meant to enable (inlining control, symbol linking, embedding, …) does not happen.
Rationale
A Go compiler directive must be written as //go:name with no space between the // and the
go:. The moment a space or tab appears there — // go:noinline or //<tab>go:linkname — the
toolchain treats the line as an ordinary comment and the directive is dropped without a warning.
Because the build still succeeds, the mistake is easy to miss and the program behaves as if the
directive were never written. The check fires only when the comment clearly intends a directive (a
go: prefix immediately followed by a name); leading whitespace before the // is fine, and
// go: just prose is treated as prose.
// go:noinline // FLAW — space after // ; the directive is ignored
func hot() {}
//go:noinline // OK — well-formed directive
func hot2() {}