-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-target-specsArea: Compile-target specificationsArea: Compile-target specificationsA-targetsArea: Concerning the implications of different compiler targetsArea: Concerning the implications of different compiler targetsC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
If you have a custom target JSON with an incorrect type, for example "target-c-int-width": "16"
, the value will just be silently ignored instead of erroring.
this is because of the way the JSON parsing works:
rust/compiler/rustc_target/src/spec/json.rs
Lines 83 to 136 in 6caa224
($key_name:ident = $json_name:expr, u64 as $int_ty:ty) => ( { | |
let name = $json_name; | |
if let Some(s) = obj.remove(name).and_then(|b| b.as_u64()) { | |
base.$key_name = s as $int_ty; | |
} | |
} ); | |
($key_name:ident, bool) => ( { | |
let name = (stringify!($key_name)).replace("_", "-"); | |
if let Some(s) = obj.remove(&name).and_then(|b| b.as_bool()) { | |
base.$key_name = s; | |
} | |
} ); | |
($key_name:ident = $json_name:expr, bool) => ( { | |
let name = $json_name; | |
if let Some(s) = obj.remove(name).and_then(|b| b.as_bool()) { | |
base.$key_name = s; | |
} | |
} ); | |
($key_name:ident, u32) => ( { | |
let name = (stringify!($key_name)).replace("_", "-"); | |
if let Some(s) = obj.remove(&name).and_then(|b| b.as_u64()) { | |
if s < 1 || s > 5 { | |
return Err("Not a valid DWARF version number".into()); | |
} | |
base.$key_name = s as u32; | |
} | |
} ); | |
($key_name:ident, Option<bool>) => ( { | |
let name = (stringify!($key_name)).replace("_", "-"); | |
if let Some(s) = obj.remove(&name).and_then(|b| b.as_bool()) { | |
base.$key_name = Some(s); | |
} | |
} ); | |
($key_name:ident, Option<u64>) => ( { | |
let name = (stringify!($key_name)).replace("_", "-"); | |
if let Some(s) = obj.remove(&name).and_then(|b| b.as_u64()) { | |
base.$key_name = Some(s); | |
} | |
} ); | |
($key_name:ident, Option<StaticCow<str>>) => ( { | |
let name = (stringify!($key_name)).replace("_", "-"); | |
if let Some(s) = obj.remove(&name).and_then(|b| Some(b.as_str()?.to_string())) { | |
base.$key_name = Some(s.into()); | |
} | |
} ); | |
($key_name:ident, Option<Align>) => ( { | |
let name = (stringify!($key_name)).replace("_", "-"); | |
if let Some(b) = obj.remove(&name).and_then(|b| b.as_u64()) { | |
match Align::from_bits(b) { | |
Ok(align) => base.$key_name = Some(align), | |
Err(e) => return Err(alignment_error(&name, e)), | |
} | |
} | |
} ); |
It should be changed so that it emits an error.
Metadata
Metadata
Assignees
Labels
A-target-specsArea: Compile-target specificationsArea: Compile-target specificationsA-targetsArea: Concerning the implications of different compiler targetsArea: Concerning the implications of different compiler targetsC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.