{"id":"cf69685f3b6e483e","repo":"rust-lang/rust","slug":"can-t-get-the-layout-of-i128","errorCode":null,"errorMessage":"Can't get the layout of `i128`","messagePattern":"Can't get the layout of `i128`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_gcc/src/context.rs","lineNumber":239,"sourceCode":"        let longlong_type = context.new_c_type(CType::LongLong);\n        let ulonglong_type = context.new_c_type(CType::ULongLong);\n        let sizet_type = context.new_c_type(CType::SizeT);\n\n        let usize_type = sizet_type;\n        let isize_type = usize_type;\n        let bool_type = context.new_type::<bool>();\n\n        let mut functions = FxHashMap::default();\n        let builtins = [\"abort\"];\n\n        for builtin in builtins.iter() {\n            functions.insert(builtin.to_string(), context.get_builtin_function(builtin));\n        }\n\n        let mut cx = Self {\n            int128_align: tcx\n                .layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.i128))\n                .expect(\"Can't get the layout of `i128`\")\n                .align\n                .abi,\n            const_cache: Default::default(),\n            codegen_unit,\n            context,\n            current_func: RefCell::new(None),\n            normal_function_addresses: Default::default(),\n            function_address_names: Default::default(),\n            functions: RefCell::new(functions),\n            intrinsics: RefCell::new(FxHashMap::default()),\n\n            tls_model,\n\n            bool_type,\n            i8_type,\n            i16_type,\n            i32_type,\n            i64_type,","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_gcc/src/context.rs#L221-L257","documentation":"During `CodegenCx` construction (context.rs:236-241) the backend computes `int128_align` by calling `tcx.layout_of(...i128...).expect(\"Can't get the layout of \\`i128\\`\")`. If the target's layout for `i128` cannot be computed, the `expect` panics and the entire codegen context fails to initialize. This typically means the target's data layout / target specification does not admit a 128-bit integer type or is malformed, so rustc's layout query returns `Err`.","triggerScenarios":"Constructing a `CodegenCx` for a target triple whose data layout lacks an i128 representation (or has a malformed spec) — `tcx.layout_of(TypingEnv::fully_monomorphized().as_query_input(tcx.types.i128))` returns `Err` and the `expect` at context.rs:239 panics. Also reachable if the target spec is a hand-written custom target missing i128 support.","commonSituations":"Custom/exotic target specs (e.g. embedded, unusual architectures, MSP430-class targets without 128-bit integers); a corrupted or in-progress target-spec file; pointing rustc_codegen_gcc at a target it was not built to support. The i128 alignment is needed unconditionally at cx init, so any unsupported target aborts immediately.","solutions":["Verify the target triple is one this backend supports; switch to a mainstream triple (x86_64, aarch64) to confirm the issue is target-specific.","Inspect/fix the custom target spec's `data-layout` field to ensure it defines a valid 128-bit integer alignment.","If the target genuinely has no i128, patch context.rs:239 to fall back to a default alignment (e.g. 8 or 16 bytes) instead of `expect`, mirroring how the LLVM backend tolerates such targets.","Confirm you are not accidentally compiling for the host while a `--target` override points at an unsupported spec."],"exampleFix":"// before (context.rs:237-241)\nint128_align: tcx\n    .layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.i128))\n    .expect(\"Can't get the layout of `i128`\")\n    .align\n    .abi,\n\n// after (tolerate targets without i128 layout)\nint128_align: tcx\n    .layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.i128))\n    .map(|l| l.align.abi)\n    .unwrap_or_else(|_| tcx.data_layout().aggregate_align.abi),","handlingStrategy":"validation","validationCode":"// context.rs:239 -> layout_of(i128).expect(\"Can't get the layout of `i128`\")\n// at CodegenCx construction. Fires for targets whose spec lacks a valid\n// 128-bit integer layout. Probe before constructing the context:\nuse rustc_middle::ty;\nlet layout = tcx.layout_of(\n    ty::TypingEnv::fully_monomorphized().as_query_input(tcx.types.i128),\n);\nif layout.is_err() {\n    return Err(\"target has no valid i128 layout; cannot use gcc backend\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["This fires at CodegenCx construction, not on user input - it means the target spec lacks a valid 128-bit integer layout.","Use a target spec whose data layout includes i128 (most native targets do); avoid exotic or bare-metal targets missing it.","If you must target such a platform, fall back to the LLVM backend or patch the spec's data layout."],"tags":["rustc-codegen-gcc","target-spec","data-layout","i128","panic","option-expect"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}