golang/go · error
-asan: the version of $(go env CC) could not be parsed
Error message
-asan: the version of $(go env CC) could not be parsed
What it means
When -asan is requested, the go command calls compilerVersion() which runs `$(go env CC) --version`, then (for gcc) `CC -v`, parsing `gcc version N.M` or `clang version N.M`. If running the compiler fails, or the matched version digits cannot be parsed as integers, compilerVersion returns an error and this wraps it. The build aborts because the Asan support requirement cannot be verified without a known compiler version.
Source
Thrown at src/cmd/go/internal/work/init.go:439
return err
}
if compiler.minor, err = strconv.Atoi(string(match[2])); err != nil {
return err
}
return nil
}()
})
return compiler.version, compiler.err
}
// compilerRequiredAsanVersion is a copy of the function defined in
// cmd/cgo/internal/testsanitizers/cc_test.go
// compilerRequiredAsanVersion reports whether the compiler is the version
// required by Asan.
func compilerRequiredAsanVersion() error {
compiler, err := compilerVersion()
if err != nil {
return fmt.Errorf("-asan: the version of $(go env CC) could not be parsed")
}
switch compiler.name {
case "gcc":
if runtime.GOARCH == "ppc64le" && compiler.major < 9 {
return fmt.Errorf("-asan is not supported with %s compiler %d.%d\n", compiler.name, compiler.major, compiler.minor)
}
if compiler.major < 7 {
return fmt.Errorf("-asan is not supported with %s compiler %d.%d\n", compiler.name, compiler.major, compiler.minor)
}
case "clang":
if compiler.major < 9 {
return fmt.Errorf("-asan is not supported with %s compiler %d.%d\n", compiler.name, compiler.major, compiler.minor)
}
default:
return fmt.Errorf("-asan: C compiler is not gcc or clang")
}
return nilView on GitHub (pinned to b6b368adc5)
Solutions
- Ensure `go env CC` points to real gcc or clang: run `$(go env CC) --version` and check the output
- Upgrade the C compiler to an Asan-capable version (gcc >= 7, clang >= 9)
- Drop -asan if AddressSanitizer is not required
Example fix
// before (unparseable / missing compiler) CC=my-wrapper go build -asan ./... // after CC=gcc go build -asan ./...
Defensive patterns
Strategy: validation
Validate before calling
// Verify CC is real gcc/clang with parseable version before -asan
cc := os.Getenv("CC")
if cc == "" { cc = "cc" }
out, err := exec.Command(cc, "--version").Output()
if err != nil || (!bytes.HasPrefix(out, []byte("gcc")) && !bytes.Contains(out, []byte("clang version"))) {
return fmt.Errorf("CC must be gcc or clang with parseable --version for -asan")
} Prevention
- Set CC to a real gcc (>= 7) or clang (>= 9) for -asan builds
- Run `$(go env CC) --version` and confirm parseable gcc/clang output
- Avoid wrapper scripts or non-standard compilers when using -asan
When it happens
Trigger: Fires in compilerRequiredAsanVersion when compilerVersion() returns a non-nil error - i.e. CC --version or CC -v failed to execute, or strconv.Atoi on the matched major/minor failed.
Common situations: $CC unset or pointing to a non-existent/wrapper compiler whose --version output is non-standard or fails, a compiler that exits non-zero on --version, or a version string whose digits are not pure integers.
Related errors
- -asan is not supported with %s compiler %d.%d\n
- -asan: C compiler is not gcc or clang
- parsing $CGO_%s_ALLOW: %v
- parsing $CGO_%s_DISALLOW: %v
- unclosed quote
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/c37f055f6ae0a154.
Report an issue: GitHub.