{"record":{"id":"6d14b4caeadccc36","repo":"gfx-rs/wgpu","slug":"unexpected-abs","errorCode":null,"errorMessage":"Unexpected abs({:?})","messagePattern":"Unexpected abs\\((.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"naga/src/back/spv/block.rs","lineNumber":1399,"sourceCode":"\n                let id = self.gen_id();\n                let math_op = match fun {\n                    // comparison\n                    Mf::Abs => {\n                        match arg_scalar_kind {\n                            Some(crate::ScalarKind::Float) => {\n                                MathOp::Ext(spirv::GlslStd450Op::FAbs)\n                            }\n                            Some(crate::ScalarKind::Sint) => MathOp::Ext(spirv::GlslStd450Op::SAbs),\n                            Some(crate::ScalarKind::Uint) => {\n                                MathOp::Custom(Instruction::unary(\n                                    spirv::Op::CopyObject, // do nothing\n                                    result_type_id,\n                                    id,\n                                    arg0_id,\n                                ))\n                            }\n                            other => unimplemented!(\"Unexpected abs({:?})\", other),\n                        }\n                    }\n                    Mf::Min => MathOp::Ext(match arg_scalar_kind {\n                        Some(crate::ScalarKind::Float) => spirv::GlslStd450Op::FMin,\n                        Some(crate::ScalarKind::Sint) => spirv::GlslStd450Op::SMin,\n                        Some(crate::ScalarKind::Uint) => spirv::GlslStd450Op::UMin,\n                        other => unimplemented!(\"Unexpected min({:?})\", other),\n                    }),\n                    Mf::Max => MathOp::Ext(match arg_scalar_kind {\n                        Some(crate::ScalarKind::Float) => spirv::GlslStd450Op::FMax,\n                        Some(crate::ScalarKind::Sint) => spirv::GlslStd450Op::SMax,\n                        Some(crate::ScalarKind::Uint) => spirv::GlslStd450Op::UMax,\n                        other => unimplemented!(\"Unexpected max({:?})\", other),\n                    }),\n                    Mf::Clamp => match arg_scalar_kind {\n                        // Clamp is undefined if min > max. In practice this means it can use a median-of-three\n                        // instruction to determine the value. This is fine according to the WGSL spec for float\n                        // clamp, but integer clamp _must_ use min-max. As such we write out min/max.","sourceCodeStart":1381,"sourceCodeEnd":1417,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/naga/src/back/spv/block.rs#L1381-L1417","documentation":"The SPIR-V backend's math-instruction lowering for MathFunction::Abs only supports float and signed/unsigned integer scalar kinds (via SPV arithmetic or GlslStd450 SAbs); any other argument scalar kind (None/kindless, e.g. bool or composite) hits the explicit `unimplemented!(\"Unexpected abs({:?})\", other)` panic. Raised in cache_expression_value from write_block.","triggerScenarios":"Translating an `abs(...)` built-in call whose argument type has no recognized scalar kind (bool, struct, pointer, or unexpected kind) during SPIR-V emission.","commonSituations":"Fuzzed IR applying abs to a bool/vector-of-bool; validation bypass by calling the backend directly; a naga upgrade changing how argument scalar kinds are derived (arg_scalar_kind).","solutions":["Call abs only on numeric (i32/u32/f32 or vectors thereof) values in the shader","Validate the module before SPIR-V emission so bad IR is diagnosed","Dump the IR to find the malformed abs call","File a naga bug with the reproducer if the shader is valid WGSL"],"exampleFix":"// before\nlet x = abs(true); // invalid\n// after\nlet x = abs(-3i); // i32","handlingStrategy":"validation","validationCode":"assert!(matches!(arg_scalar_kind, Some(crate::ScalarKind::Float | crate::ScalarKind::Sint | crate::ScalarKind::Uint)), \"abs() requires numeric argument\");","typeGuard":"fn abs_supported(kind: Option<crate::ScalarKind>) -> bool {\n    matches!(kind, Some(crate::ScalarKind::Float | crate::ScalarKind::Sint | crate::ScalarKind::Uint))\n}","tryCatchPattern":null,"preventionTips":["Call abs only on f32/i32/u32 or vectors of them","Validate shader modules before backend emission","Cover math built-ins per scalar kind in tests"],"tags":["spv","naga","unimplemented","math-function","codegen-panic"],"backgroundTag":"spv-backend-unimplemented-opcode","analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}