diff --git a/dmd/mtype.d b/dmd/mtype.d index 9b210528f7d..cf1e58fde29 100644 --- a/dmd/mtype.d +++ b/dmd/mtype.d @@ -892,10 +892,38 @@ version (IN_LLVM) twstring = twchar.immutableOf().arrayOf(); tdstring = tdchar.immutableOf().arrayOf(); +version (IN_LLVM) +{ + switch (target.ptrsize) + { + case 1: + tsize_t = basic[Tuns8]; + tptrdiff_t = basic[Tint8]; + break; + case 2: + tsize_t = basic[Tuns16]; + tptrdiff_t = basic[Tint16]; + break; + case 4: + tsize_t = basic[Tuns32]; + tptrdiff_t = basic[Tint32]; + break; + case 8: + tsize_t = basic[Tuns64]; + tptrdiff_t = basic[Tint64]; + break; + default: + assert(0, "Unsupported target pointer size"); + } +} +else +{ const isLP64 = target.isLP64; tsize_t = basic[isLP64 ? Tuns64 : Tuns32]; tptrdiff_t = basic[isLP64 ? Tint64 : Tint32]; +} + thash_t = tsize_t; } diff --git a/runtime/druntime/src/object.d b/runtime/druntime/src/object.d index 28c6db1b009..a737ba0ca37 100644 --- a/runtime/druntime/src/object.d +++ b/runtime/druntime/src/object.d @@ -2765,12 +2765,12 @@ class Exception : Throwable * This constructor does not automatically throw the newly-created * Exception; the $(D throw) expression should be used for that purpose. */ - @nogc @safe pure nothrow this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null) + @nogc @safe pure nothrow this(string msg, string file = __FILE__, size_t line = cast(size_t) __LINE__, Throwable nextInChain = null) { super(msg, file, line, nextInChain); } - @nogc @safe pure nothrow this(string msg, Throwable nextInChain, string file = __FILE__, size_t line = __LINE__) + @nogc @safe pure nothrow this(string msg, Throwable nextInChain, string file = __FILE__, size_t line = cast(size_t) __LINE__) { super(msg, file, line, nextInChain); } @@ -2797,7 +2797,7 @@ class Exception : Throwable { auto e = new Exception("msg"); assert(e.file == __FILE__); - assert(e.line == __LINE__ - 2); + assert(e.line == cast(size_t) (__LINE__ - 2)); assert(e.nextInChain is null); assert(e.msg == "msg"); } diff --git a/tests/compilable/size_t_16bit.d b/tests/compilable/size_t_16bit.d new file mode 100644 index 00000000000..53e8681e63f --- /dev/null +++ b/tests/compilable/size_t_16bit.d @@ -0,0 +1,13 @@ +// A minimal test wrt. size_t on a 16-bit architecture. + +// REQUIRES: target_AVR +// RUN: %ldc -mtriple=avr -betterC -c %s + +static assert(size_t.sizeof == 2); +static assert(ptrdiff_t.sizeof == 2); + +// test bounds checks +int foo(int[] arr) +{ + return arr[1]; +}