{"id":"19a39fa61b69bcfd","repo":"rust-lang/rust","slug":"cg-clif-jit-args-not-unicode","errorCode":null,"errorMessage":"CG_CLIF_JIT_ARGS not unicode: {:?}","messagePattern":"CG_CLIF_JIT_ARGS not unicode: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_cranelift/src/config.rs","lineNumber":24,"sourceCode":"    /// Defaults to AOT compilation. Can be set using `-Cllvm-args=jit-mode`.\n    pub jit_mode: bool,\n\n    /// When JIT mode is enable pass these arguments to the program.\n    ///\n    /// Defaults to the value of `CG_CLIF_JIT_ARGS`.\n    pub jit_args: Vec<String>,\n}\n\nimpl BackendConfig {\n    /// Parse the configuration passed in using `-Cllvm-args`.\n    pub fn from_opts(opts: &[String]) -> Result<Self, String> {\n        let mut config = BackendConfig {\n            jit_mode: false,\n            jit_args: match std::env::var(\"CG_CLIF_JIT_ARGS\") {\n                Ok(args) => args.split(' ').map(|arg| arg.to_string()).collect(),\n                Err(std::env::VarError::NotPresent) => vec![],\n                Err(std::env::VarError::NotUnicode(s)) => {\n                    panic!(\"CG_CLIF_JIT_ARGS not unicode: {:?}\", s);\n                }\n            },\n        };\n\n        for opt in opts {\n            if opt.starts_with(\"-import-instr-limit\") {\n                // Silently ignore -import-instr-limit. It is set by rust's build system even when\n                // testing cg_clif.\n                continue;\n            }\n            match &**opt {\n                \"jit-mode\" => config.jit_mode = true,\n                _ => return Err(format!(\"Unknown option `{}`\", opt)),\n            }\n        }\n\n        Ok(config)\n    }","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_cranelift/src/config.rs#L6-L42","documentation":"Panics inside BackendConfig::from_opts while reading the CG_CLIF_JIT_ARGS environment variable when its bytes are not valid UTF-8. The variable carries CLI arguments passed to the program under JIT mode; non-UTF-8 cannot be split into String args, so the backend aborts before codegen.","triggerScenarios":"Reached when std::env::var returns VarError::NotUnicode during JIT configuration parsing (config.rs:23-25). Any byte sequence that fails UTF-8 validation trips it, regardless of jit-mode actually being requested.","commonSituations":"A shell or wrapper script exports CG_CLIF_JIT_ARGS from a binary/locales-aware source (e.g. xargs over a file with CRLF or Latin-1 bytes); the variable was set by a tool that injected a BOM or NUL; CI sets it via a YAML that mangled quotes into smart-quotes; copied from a Windows cmd session with a non-UTF-8 codepage.","solutions":["Inspect the raw bytes: `printf '%s' \"$CG_CLIF_JIT_ARGS\" | hexdump -C` and look for non-UTF-8 (e.g. 0x96, 0xa0, BOM EF BB BF).","Re-export the variable as plain ASCII: `export CG_CLIF_JIT_ARGS=\"--arg1 --arg2\"` from a UTF-8 shell.","Unset it if JIT args are not needed: `unset CG_CLIF_JIT_ARGS`.","Fix the upstream script that produces the value (strip BOM, normalize encoding to UTF-8)."],"exampleFix":"// before\nErr(std::env::VarError::NotUnicode(s)) => {\n    panic!(\"CG_CLIF_JIT_ARGS not unicode: {:?}\", s);\n}\n// after\nErr(std::env::VarError::NotUnicode(s)) => {\n    let lossy = s.to_string_lossy().into_owned();\n    panic!(\"CG_CLIF_JIT_ARGS not unicode (raw={:?}, lossy={:?}). Set it to UTF-8 ASCII args.\", s, lossy);\n}","handlingStrategy":"validation","validationCode":"fn check_jit_args() -> Result<(), String> {\n    match std::env::var_os(\"CG_CLIF_JIT_ARGS\") {\n        None => Ok(()),\n        Some(v) => match v.to_str() {\n            Some(_) => Ok(()),\n            None => Err(\"CG_CLIF_JIT_ARGS contains non-UTF8 bytes; remove or re-export as UTF-8\".to_string()),\n        },\n    }\n}\n// call before running the cranelift JIT entrypoint","typeGuard":"fn jit_args_is_unicode() -> bool {\n    std::env::var_os(\"CG_CLIF_JIT_ARGS\")\n        .map(|v| v.to_str().is_some())\n        .unwrap_or(true)\n}","tryCatchPattern":null,"preventionTips":["Always set CG_CLIF_JIT_ARGS from a Rust String/&str (UTF-8) rather than OsString built from raw bytes.","In CI, export the env var from a UTF-8 source; avoid piping non-UTF8 shell variables into it.","Do not point CG_CLIF_JIT_ARGS at paths with non-UTF8 components; use UTF-8 path aliases instead.","If unsure, unset the variable rather than guess; the JIT defaults to no extra args."],"tags":["cg-clif","config","environment","unicode","jit"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}