Skip to content

Commit 7687e06

Browse files
committed
Handle pointer constness at the right level.
1 parent 35fb113 commit 7687e06

File tree

2 files changed

+2
-17
lines changed

2 files changed

+2
-17
lines changed

src/codegen/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3054,7 +3054,7 @@ impl TryToRustTy for Type {
30543054
}
30553055
TypeKind::Pointer(inner) |
30563056
TypeKind::Reference(inner) => {
3057-
let is_const = self.is_const() || ctx.resolve_type(inner).is_const();
3057+
let is_const = ctx.resolve_type(inner).is_const();
30583058

30593059
let inner = inner.into_resolver().through_type_refs().resolve(ctx);
30603060
let inner_ty = inner.expect_type();

src/ir/ty.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -1195,22 +1195,7 @@ impl Type {
11951195

11961196
let name = if name.is_empty() { None } else { Some(name) };
11971197

1198-
// Just using ty.is_const() is wrong here, because when we declare an
1199-
// argument like 'int* const arg0', arg0 is considered
1200-
// const but the pointer itself points to mutable data.
1201-
//
1202-
// Without canonicalizing the type to the pointer type, we'll get the
1203-
// following mapping:
1204-
//
1205-
// arg0: *const c_int
1206-
//
1207-
// So by canonicalizing the type first, we can check constness by
1208-
// calling is_const() on the pointer type.
1209-
let is_const = if let Some(pty) = ty.pointee_type() {
1210-
pty.is_const()
1211-
} else {
1212-
ty.is_const()
1213-
};
1198+
let is_const = ty.is_const();
12141199

12151200
let ty = Type::new(name, layout, kind, is_const);
12161201
// TODO: maybe declaration.canonical()?

0 commit comments

Comments
 (0)