{"id":"2cef4f0cbd0d91d5","repo":"rust-lang/rust","slug":"last-arg","errorCode":null,"errorMessage":"last arg","messagePattern":"last arg","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs","lineNumber":402,"sourceCode":"                    new_args.push(last_arg);\n                }\n\n                args = new_args.into();\n            }\n            \"__builtin_ia32_addps512_mask\"\n            | \"__builtin_ia32_addpd512_mask\"\n            | \"__builtin_ia32_subps512_mask\"\n            | \"__builtin_ia32_subpd512_mask\"\n            | \"__builtin_ia32_mulps512_mask\"\n            | \"__builtin_ia32_mulpd512_mask\"\n            | \"__builtin_ia32_divps512_mask\"\n            | \"__builtin_ia32_divpd512_mask\"\n            | \"__builtin_ia32_maxps512_mask\"\n            | \"__builtin_ia32_maxpd512_mask\"\n            | \"__builtin_ia32_minps512_mask\"\n            | \"__builtin_ia32_minpd512_mask\" => {\n                let mut new_args = args.to_vec();\n                let last_arg = new_args.pop().expect(\"last arg\");\n                let arg3_type = gcc_func.get_param_type(2);\n                let undefined = builder\n                    .current_func()\n                    .new_local(None, arg3_type, \"undefined_for_intrinsic\")\n                    .to_rvalue();\n                new_args.push(undefined);\n                let arg4_type = gcc_func.get_param_type(3);\n                let minus_one = builder.context.new_rvalue_from_int(arg4_type, -1);\n                new_args.push(minus_one);\n                new_args.push(last_arg);\n                args = new_args.into();\n            }\n            \"__builtin_ia32_vfmaddsubps512_mask\"\n            | \"__builtin_ia32_vfmaddsubpd512_mask\"\n            | \"__builtin_ia32_cmpsh_mask_round\"\n            | \"__builtin_ia32_vfmaddph512_mask\"\n            | \"__builtin_ia32_vfmaddsubph512_mask\" => {\n                let mut new_args = args.to_vec();","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs#L384-L420","documentation":"`new_args.pop().expect(\"last arg\")` in the `__builtin_ia32_{add,sub,mul,div,max,min}{ps,pd}512_mask` arm. The adapter relocates the caller's trailing rounding/sae argument to the end (after inserting an undefined src and an all-ones mask) to match GCC's parameter order. It panics if the incoming `args` slice is empty, which only happens when an LLVM intrinsic routed here was called with no arguments — i.e. the intrinsic definition in rustc drifted from the GCC adapter's expected arity.","triggerScenarios":"Code lowering `llvm.x86.avx512.add.ps.512` / `pd.512` (and sub/mul/div/max/min) through rustc_codegen_gcc when rustc passes an argument list shorter than the adapter assumes, or when a non-masked form is incorrectly routed into the masked arm.","commonSituations":"Mismatched rustc/rustc_codegen_gcc checkout, a half-applied refactor of an LLVM intrinsic arity, or calling a raw `llvm.x86.avx512.*` intrinsic with a malformed argument list. End users hit it mainly after a rustup that bumped rustc past the rustc_codegen_gcc backend's supported version.","solutions":["Ensure rustc_codegen_gcc backend revision matches the rustc toolchain it was built for.","Pin the toolchain with `rustup default <matching-version>` or rust-toolchain.toml.","Rebuild the backend from a commit that supports the current rustc intrinsic definitions.","Avoid hand-written `llvm.x86.avx512.*.512` intrinsics; prefer `core::arch::x86_64::_mm512_*` which carry the correct arity."],"exampleFix":"// before (intrinsic/llvm.rs:402)\nlet last_arg = new_args.pop().expect(\"last arg\");\n\n// after\nlet Some(last_arg) = new_args.pop() else {\n    sess.dcx().fatal(format!(\n        \"`{}` reached masked arm with no rounding argument; \\\n         rustc/GCC intrinsic arity mismatch\",\n        gcc_func.get_name()\n    ));\n};","handlingStrategy":"validation","validationCode":"// Validate argument count before invoking AVX-512 arithmetic intrinsics\n// The GCC backend pops the last arg; if args is empty, it panics.\nfn validate_intrinsic_argc(name: &str, args_provided: usize) -> Result<(), String> {\n    let required = match name {\n        \"llvm.x86.avx512.add.ps.512\"\n        | \"llvm.x86.avx512.add.pd.512\"\n        | \"llvm.x86.avx512.sub.ps.512\"\n        | \"llvm.x86.avx512.mul.ps.512\"\n        | \"llvm.x86.avx512.div.ps.512\"\n        | \"llvm.x86.avx512.max.ps.512\"\n        | \"llvm.x86.avx512.min.ps.512\" => 3, // src1, src2, rounding_control\n        _ => return Ok(()),\n    };\n    if args_provided < required {\n        return Err(format!(\n            \"{} requires at least {} args but got {}\",\n            name, required, args_provided\n        ));\n    }\n    Ok(())\n}\n\n// In build.rs: probe whether the GCC backend handles your intrinsics\nfn gcc_backend_probe() -> Result<(), String> {\n    let out = std::process::Command::new(\"rustc\")\n        .args([\"-Z\", \"codegen-backend=gcc\", \"--crate-type=lib\", \"-\", \"-o\", \"/dev/null\"])\n        .stdin(std::process::Stdio::piped())\n        .stderr(std::process::Stdio::piped())\n        .spawn()\n        .map_err(|e| format!(\"Cannot spawn rustc: {}\", e))?;\n    // Feed a minimal AVX-512 test crate and check for panic\n    // If it panics, fall back to LLVM backend\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid raw core::arch::x86_64 AVX-512 arithmetic intrinsics (_mm512_add_ps etc.) with the GCC backend — use core::simd operators instead which have separate code paths","If you must use AVX-512 intrinsics, prefer the LLVM backend (-Ccodegen-backend=llvm) for those crates","Run a probe compilation with the GCC backend in CI to detect unsupported intrinsic patterns before they reach production builds"],"tags":["rustc-codegen-gcc","avx512","simd","gcc","intrinsic","panic"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}