{"id":"dca36e8ab670160b","repo":"rust-lang/rust","slug":"use-of-unknown-address-space-c","errorCode":null,"errorMessage":"Use of unknown address space {c:?}","messagePattern":"Use of unknown address space (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_abi/src/lib.rs","lineNumber":740,"sourceCode":"    }\n\n    /// Get the pointer size in the default data address space.\n    #[inline]\n    pub fn pointer_size(&self) -> Size {\n        self.default_address_space_pointer_spec.pointer_size\n    }\n\n    /// Get the pointer size in a specific address space.\n    #[inline]\n    pub fn pointer_size_in(&self, c: AddressSpace) -> Size {\n        if c == self.default_address_space {\n            return self.default_address_space_pointer_spec.pointer_size;\n        }\n\n        if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {\n            e.1.pointer_size\n        } else {\n            panic!(\"Use of unknown address space {c:?}\");\n        }\n    }\n\n    /// Get the pointer index in the default data address space.\n    #[inline]\n    pub fn pointer_offset(&self) -> Size {\n        self.default_address_space_pointer_spec.pointer_offset\n    }\n\n    /// Get the pointer index in a specific address space.\n    #[inline]\n    pub fn pointer_offset_in(&self, c: AddressSpace) -> Size {\n        if c == self.default_address_space {\n            return self.default_address_space_pointer_spec.pointer_offset;\n        }\n\n        if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {\n            e.1.pointer_offset","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_abi/src/lib.rs#L722-L758","documentation":"pointer_size_in(c) resolves the pointer size for address space c. It short-circuits the default space, then scans address_space_info; if c is neither default nor registered it panics. Address spaces are registered during TargetDataLayout::parse from 'p<addr>:size:align' tokens in the data-layout string, so an unregistered space means the target spec never declared it.","triggerScenarios":"Calling pointer_size_in (or any query that delegates to it: size bound, alignment, offset) with an AddressSpace value that has no 'p<addr>:size:align' entry in the target's data-layout string and is not the default space.","commonSituations":"Custom target spec missing address-space declarations; GPU/CHERI code referencing an address space the target did not declare; mismatch between the target that produced the MIR (e.g. rustc) and the one consuming it (e.g. miri, cg_clif); constructing AddressSpace literals ad hoc instead of using the target's declared spaces.","solutions":["Inspect the target's data layout (rustc --print target-spec-json, the 'data-layout' field) and confirm whether the address space is declared.","Add the missing 'p<N>:size:align' entry to the target spec's data-layout so the address space is registered.","Ensure the AddressSpace value you pass matches a declared space (e.g. AddressSpace::ZERO or GPU_WORKGROUP), not an ad-hoc constant."],"exampleFix":"// before: target data-layout missing address space 3\n//   data-layout = \"e-m:e-p:64:64-i64:64\"\n// calling pointer_size_in(AddressSpace(3)) panics\n\n// after: declare address space 3 in the spec\n//   data-layout = \"e-m:e-p:64:64-p3:32:32-i64:64\"","handlingStrategy":"validation","validationCode":"// pointer_size_in(c) panics when c is neither the default address space nor\n// present in address_space_info. Because address_space_info is private, the\n// caller must track declared address spaces from the data-layout string.\nuse rustc_abi::{AddressSpace, TargetDataLayout};\n\n/// Collect every address space mentioned in a data-layout string ('p', 'p<as>',\n/// 'G', 'A' tokens) so callers can validate before invoking *_in(c).\nfn known_address_spaces(\n    data_layout: &str,\n    default_address_space: AddressSpace,\n) -> std::collections::HashSet<AddressSpace> {\n    let mut set = std::collections::HashSet::new();\n    set.insert(default_address_space);\n    for token in data_layout.split('-') {\n        if let Some(rest) = token.strip_prefix('p') {\n            // 'p' alone => AddressSpace::ZERO; 'pN' => address space N\n            let addr = if rest.is_empty() { 0 }\n                else if let Some(digits) = rest.strip_prefix('f') { digits.parse().unwrap_or(0) }\n                else { rest.parse().unwrap_or(0) };\n            set.insert(AddressSpace::from(addr));\n        }\n    }\n    set\n}\n\nlet known = known_address_spaces(&data_layout_str, dl.default_address_space);\nif c != dl.default_address_space && !known.contains(&c) {\n    return Err(format!(\"pointer_size_in: unknown address space {c:?}\"));\n}\nlet sz = dl.pointer_size_in(c);","typeGuard":"fn is_known_address_space(\n    dl: &rustc_abi::TargetDataLayout,\n    known: &std::collections::HashSet<rustc_abi::AddressSpace>,\n    c: rustc_abi::AddressSpace,\n) -> bool {\n    c == dl.default_address_space || known.contains(&c)\n}","tryCatchPattern":null,"preventionTips":["address_space_info is a private field, so you cannot introspect it — maintain your own set of declared address spaces by parsing the same data-layout string used to build the TargetDataLayout.","Never call pointer_size_in / pointer_offset_in / pointer_align_in with an AddressSpace you did not declare in the layout; the default address space is always safe.","If you accept caller-supplied AddressSpace values (e.g. from pointer types), validate them against the known set at the trust boundary before touching the layout.","Centralize the known-set lookup in one helper and reuse it for all three *_in methods to cover errorIndex 17, 18, and 19 uniformly."],"tags":["rustc","abi","target-spec","address-space","compiler-ice"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}