summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcynecx <me@cynecx.net>2018-05-10 22:39:46 +0200
committercynecx <me@cynecx.net>2018-05-10 22:39:46 +0200
commit35d17c006de5ecce7c39dab960f3db840aceeea6 (patch)
treef1bf39c01bc35b32e72700c8003a94cf0c88a454 /src
parent515ca97b462f348b7b3bb9eaea98b2e0bb1b624b (diff)
Canonicalize a type (pointer type) first before checking for constness
Diffstat (limited to 'src')
-rw-r--r--src/ir/ty.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index b5c78c16..b742dcc1 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -1194,7 +1194,23 @@ impl Type {
};
let name = if name.is_empty() { None } else { Some(name) };
- let is_const = ty.is_const();
+
+ // Just using ty.is_const() is wrong here, because when we declare an
+ // argument like 'int* const arg0', arg0 is considered
+ // const but the pointer itself points to mutable data.
+ //
+ // Without canonicalizing the type to the pointer type, we'll get the
+ // following mapping:
+ //
+ // arg0: *const c_int
+ //
+ // So by canonicalizing the type first, we can check constness by
+ // calling is_const() on the pointer type.
+ let is_const = if let Some(pty) = ty.pointee_type() {
+ pty.is_const()
+ } else {
+ ty.is_const()
+ };
let ty = Type::new(name, layout, kind, is_const);
// TODO: maybe declaration.canonical()?