{"id":"51558cdb78cf6dc1","repo":"rust-lang/rust","slug":"obj-size-bound-unknown-pointer-bit-size-bits","errorCode":null,"errorMessage":"obj_size_bound: unknown pointer bit size {bits}","messagePattern":"obj_size_bound: unknown pointer bit size (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_abi/src/lib.rs","lineNumber":655,"sourceCode":"    }\n\n    /// Returns **exclusive** upper bound on object size in bytes, in the default data address\n    /// space.\n    ///\n    /// The theoretical maximum object size is defined as the maximum positive `isize` value.\n    /// This ensures that the `offset` semantics remain well-defined by allowing it to correctly\n    /// index every address within an object along with one byte past the end, along with allowing\n    /// `isize` to store the difference between any two pointers into an object.\n    ///\n    /// LLVM uses a 64-bit integer to represent object size in *bits*, but we care only for bytes,\n    /// so we adopt such a more-constrained size bound due to its technical limitations.\n    #[inline]\n    pub fn obj_size_bound(&self) -> u64 {\n        match self.pointer_size().bits() {\n            16 => 1 << 15,\n            32 => 1 << 31,\n            64 => 1 << 61,\n            bits => panic!(\"obj_size_bound: unknown pointer bit size {bits}\"),\n        }\n    }\n\n    /// Returns **exclusive** upper bound on object size in bytes.\n    ///\n    /// The theoretical maximum object size is defined as the maximum positive `isize` value.\n    /// This ensures that the `offset` semantics remain well-defined by allowing it to correctly\n    /// index every address within an object along with one byte past the end, along with allowing\n    /// `isize` to store the difference between any two pointers into an object.\n    ///\n    /// LLVM uses a 64-bit integer to represent object size in *bits*, but we care only for bytes,\n    /// so we adopt such a more-constrained size bound due to its technical limitations.\n    #[inline]\n    pub fn obj_size_bound_in(&self, address_space: AddressSpace) -> u64 {\n        match self.pointer_size_in(address_space).bits() {\n            16 => 1 << 15,\n            32 => 1 << 31,\n            64 => 1 << 61,","sourceCodeStart":637,"sourceCodeEnd":673,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_abi/src/lib.rs#L637-L673","documentation":"TargetDataLayout::obj_size_bound returns the exclusive upper bound on object size for the default address space (1<<15, 1<<31, 1<<61 bytes for 16/32/64-bit pointers). The match covers only those three widths; any other pointer_size.bits() panics. The bound keeps isize offset arithmetic and LLVM's 64-bit bit-size representation well-defined.","triggerScenarios":"Calling obj_size_bound() on a TargetDataLayout whose default pointer_size is not 16/32/64 bits — for example a custom target spec with pointer_width = \"128\" (CHERI / experimental ISAs) or a hand-built layout parsed from a malformed data-layout string.","commonSituations":"Adding or using an experimental target whose pointer width differs from the supported set without extending the match arms; constructing a TargetDataLayout in a codegen tool (cranelift/miri) from a hand-written spec; a typo in the target's data-layout 'p:size:align' token.","solutions":["Inspect the target's pointer width: rustc --print target-spec-json (or -C target-spec) and check the 'p:size:align' token in data-layout.","If a non-16/32/64 width is legitimate for your target, extend the match arms in obj_size_bound and obj_size_bound_in.","Otherwise fix the malformed target spec / data-layout string that produced the wrong pointer size."],"exampleFix":"// before\nmatch self.pointer_size().bits() {\n    16 => 1 << 15,\n    32 => 1 << 31,\n    64 => 1 << 61,\n    bits => panic!(\"obj_size_bound: unknown pointer bit size {bits}\"),\n}\n\n// after: add support for the new width\nmatch self.pointer_size().bits() {\n    16 => 1 << 15,\n    32 => 1 << 31,\n    64 => 1 << 61,\n    128 => 1 << 121,\n    bits => panic!(\"obj_size_bound: unknown pointer bit size {bits}\"),\n}","handlingStrategy":"validation","validationCode":"// Validate BEFORE calling obj_size_bound():\nuse rustc_abi::TargetDataLayout;\n\n#[inline]\nfn check_pointer_bits_for_obj_size_bound(dl: &TargetDataLayout) -> Result<(), String> {\n    match dl.pointer_size().bits() {\n        16 | 32 | 64 => Ok(()),\n        bits => Err(format!(\"obj_size_bound: unsupported pointer bit size {bits}\")),\n    }\n}\n\ncheck_pointer_bits_for_obj_size_bound(&dl)?;\nlet bound = dl.obj_size_bound(); // safe now","typeGuard":"// Predicate narrowing TargetDataLayout to one obj_size_bound supports.\nfn supports_obj_size_bound(dl: &rustc_abi::TargetDataLayout) -> bool {\n    matches!(dl.pointer_size().bits(), 16 | 32 | 64)\n}\n\n// Usage:\n// if supports_obj_size_bound(&dl) { Some(dl.obj_size_bound()) } else { None }","tryCatchPattern":null,"preventionTips":["obj_size_bound only recognizes 16/32/64-bit pointers; do not construct a TargetDataLayout whose default PointerSpec.pointer_size is anything else (e.g. 128-bit CHERI fat pointers).","Build TargetDataLayout via TargetDataLayout::parse_from_data_layout / a target spec rather than hand-filling PointerSpec — the parser enforces sane sizes.","If you parse a custom data-layout string, validate the 'p' token's size field is 16, 32, or 64 before adopting the layout.","Centralize the 16/32/64 check in one helper and call it at every site that reads pointer-derived bounds."],"tags":["rustc","abi","target-spec","pointer","compiler-ice"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}