rune
rune copied to clipboard
invalid trunc should throw
errortests/trunc.rn fails with a var (and also a constant)
variable should add a runtime truncation check:
%2 = trunc i64 %1 to i16, !dbg !208
; missing %1 vs %2 check
constant may throw directly at compile-time:
println "%x16" % <u16>0xdeadbeef =>
%1 = trunc i64 3735928559 to i16, !dbg !205
diff --git llvm/genllvm.c llvm/genllvm.c
index a9fff61..245cb0d 100644
--- llvm/genllvm.c
+++ llvm/genllvm.c
@@ -1490,6 +1490,8 @@ static llElement resizeSmallInteger(llElement element, uint32 newWidth, bool isS
char *operation;
if (newWidth < oldWidth) {
operation = "trunc";
+ //TODO if constant throw error if truncation looses info.
+ // else if not constant add code to check at run-time.
} else {
deDatatypeType type = deDatatypeGetType(oldDatatype);
if (type == DE_TYPE_INT) {
See also: https://cwe.mitre.org/data/definitions/197.html