Skip to content

custom target JSON fields do not error if they have an incorrect type #144153

@Noratrieb

Description

@Noratrieb

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:

($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 specificationsA-targetsArea: Concerning the implications of different compiler targetsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions