golang/go · error

-asan: C compiler is not gcc or clang

Error message

-asan: C compiler is not gcc or clang

What it means

Thrown by compilerRequiredAsanVersion when -asan is requested but the detected C compiler is neither gcc nor clang (compiler.name falls through to the default case). The Go -asan integration only supports libasan from gcc or clang; other compilers are rejected outright.

Source

Thrown at src/cmd/go/internal/work/init.go:455

	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 nil
}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Set CC to a supported compiler: `CC=gcc go build -asan` or `CC=clang go build -asan`.
  2. Drop -asan if Asan is not required for this target.
  3. If you wrote a CC wrapper, make `-dumpversion`/`--version` output a recognizable gcc or clang signature.
  4. Verify detection: `$(go env CC) -dumpversion`.

Example fix

// before
// CC=tcc go build -asan  (not gcc/clang)

// after
// CC=clang go build -asan
Defensive patterns

Strategy: validation

Validate before calling

// Confirm CC is gcc or clang before -asan
cc := strings.TrimSpace(string(execMust("go", "env", "CC")))
for _, args := range [][]string{{cc, "--version"}, {cc, "-v"}} {
    out, _ := exec.Command(args[0], args[1:]...).CombinedOutput()
    s := string(out)
    if strings.Contains(s, "gcc") || strings.Contains(s, "clang") || strings.Contains(s, "LLVM") {
        return // ok
    }
}
log.Fatalf("-asan requires gcc or clang; %s is neither", cc)

Prevention

When it happens

Trigger: Run `go build -asan` with CGO_ENABLED=1 where `$(go env CC) -dumpversion` returns a vendor string compilerVersion() recognizes but does not classify as gcc/clang (e.g. MSVC via a wrapper, TinyCC (tcc), Intel icc/icx older classification, or a custom wrapper).

Common situations: CC overridden to a non-gcc/clang toolchain; Windows builds with a non-gcc/clang compiler; embedded vendor compilers; a CC wrapper script that does not echo a recognizable gcc/clang dumpversion.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/51d591e089fd8ca2. Report an issue: GitHub.