Skip to content

Commit 285c25f

Browse files
committed
rustc: put range asserts on char loads.
A `char` is a Unicode codepoint, and so ranges from 0--0x10FFFF (with the surrogate gaps): we may as well inform LLVM of this.
1 parent 1dd1880 commit 285c25f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/librustc/middle/trans/datum.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ fn load<'a>(bcx: &'a Block<'a>, llptr: ValueRef, ty: ty::t) -> ValueRef {
546546
C_undef(type_of::type_of(bcx.ccx(), ty))
547547
} else if ty::type_is_bool(ty) {
548548
LoadRangeAssert(bcx, llptr, 0, 2, lib::llvm::True)
549+
} else if ty::type_is_char(ty) {
550+
// a char is a unicode codepoint, and so takes values from 0
551+
// to 0x10FFFF inclusive only.
552+
LoadRangeAssert(bcx, llptr, 0, 0x10FFFF + 1, lib::llvm::False)
549553
} else {
550554
Load(bcx, llptr)
551555
}

0 commit comments

Comments
 (0)