{"record":{"id":"51d591e089fd8ca2","repo":"golang/go","slug":"asan-c-compiler-is-not-gcc-or-clang","errorCode":null,"errorMessage":"-asan: C compiler is not gcc or clang","messagePattern":"-asan: C compiler is not gcc or clang","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/init.go","lineNumber":455,"sourceCode":"\tcompiler, err := compilerVersion()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"-asan: the version of $(go env CC) could not be parsed\")\n\t}\n\n\tswitch compiler.name {\n\tcase \"gcc\":\n\t\tif runtime.GOARCH == \"ppc64le\" && compiler.major < 9 {\n\t\t\treturn fmt.Errorf(\"-asan is not supported with %s compiler %d.%d\\n\", compiler.name, compiler.major, compiler.minor)\n\t\t}\n\t\tif compiler.major < 7 {\n\t\t\treturn fmt.Errorf(\"-asan is not supported with %s compiler %d.%d\\n\", compiler.name, compiler.major, compiler.minor)\n\t\t}\n\tcase \"clang\":\n\t\tif compiler.major < 9 {\n\t\t\treturn fmt.Errorf(\"-asan is not supported with %s compiler %d.%d\\n\", compiler.name, compiler.major, compiler.minor)\n\t\t}\n\tdefault:\n\t\treturn fmt.Errorf(\"-asan: C compiler is not gcc or clang\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":437,"sourceCodeEnd":459,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/init.go#L437-L459","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Set CC to a supported compiler: `CC=gcc go build -asan` or `CC=clang go build -asan`.","Drop -asan if Asan is not required for this target.","If you wrote a CC wrapper, make `-dumpversion`/`--version` output a recognizable gcc or clang signature.","Verify detection: `$(go env CC) -dumpversion`."],"exampleFix":"// before\n// CC=tcc go build -asan  (not gcc/clang)\n\n// after\n// CC=clang go build -asan","handlingStrategy":"validation","validationCode":"// Confirm CC is gcc or clang before -asan\ncc := strings.TrimSpace(string(execMust(\"go\", \"env\", \"CC\")))\nfor _, args := range [][]string{{cc, \"--version\"}, {cc, \"-v\"}} {\n    out, _ := exec.Command(args[0], args[1:]...).CombinedOutput()\n    s := string(out)\n    if strings.Contains(s, \"gcc\") || strings.Contains(s, \"clang\") || strings.Contains(s, \"LLVM\") {\n        return // ok\n    }\n}\nlog.Fatalf(\"-asan requires gcc or clang; %s is neither\", cc)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not point CC at tcc/msvc/icx-classified wrappers for -asan.","Document supported compilers for Asan builds.","Run the detection snippet in CI before -asan tests."],"tags":["go-toolchain","asan","cgo","compiler-detection"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}