diff --git a/gen/toir.cpp b/gen/toir.cpp
index c5439443..b131c7f0 100644
--- a/gen/toir.cpp
+++ b/gen/toir.cpp
@@ -266,8 +266,16 @@ LLConstant* VarExp::toConstElem(IRState* p)
VarDeclaration* vd = var->isVarDeclaration();
if (vd && vd->isConst() && vd->init)
{
+ if (vd->inuse)
+ {
+ error("recursive reference %s", toChars());
+ return llvm::UndefValue::get(DtoType(type));
+ }
+ vd->inuse++;
+ LLConstant* ret = DtoConstInitializer(loc, type, vd->init);
+ vd->inuse--;
// return the initializer
- return DtoConstInitializer(loc, type, vd->init);
+ return ret;
}
// fail
diff --git a/tests/runtest b/tests/runtest
index 7094e490..49ca5174 100755
--- a/tests/runtest
+++ b/tests/runtest
@@ -7,6 +7,14 @@ if [ -z "$1" ] ; then
fi
TARGETFILE=$1
+# check for libtangobos-partial
+if ! [ -f testincludes/libtangobos-partial.a ] ; then
+ echo "Could not find libtangobos-partial.a, attempting to build."
+ cd testincludes
+ make
+ cd ..
+fi
+
# check for dstress
if ! [ -d dstress ] ; then
echo "Testing requires DStress to be checked out into dstress/"
diff --git a/tests/testincludes/Makefile b/tests/testincludes/Makefile
index b0f3d0f8..612c4c8f 100644
--- a/tests/testincludes/Makefile
+++ b/tests/testincludes/Makefile
@@ -58,9 +58,9 @@ lib : tangobos.lib
OBJ_CORE= \
std/gc.bc \
std/outofmemory.bc \
+ std/IEEE.bc \
+ std/stdarg.bc \
# std/asserterror.bc \
-# std/math.bc \
-# std/stdarg.bc
# std/format.bc \
ALL_OBJS= \
diff --git a/tests/testincludes/std/IEEE.d b/tests/testincludes/std/IEEE.d
new file mode 100644
index 00000000..96fb0c62
--- /dev/null
+++ b/tests/testincludes/std/IEEE.d
@@ -0,0 +1,136 @@
+// Written in the D programming language
+/*
+ * Authors:
+ * Walter Bright, Don Clugston
+ * Copyright:
+ * Copyright (c) 2001-2005 by Digital Mars,
+ * All Rights Reserved,
+ * www.digitalmars.com
+ * License:
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ *
+ * - The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ *
+ * - Altered source versions must be plainly marked as such, and must not
+ * be misrepresented as being the original software.
+ *
+ * - This notice may not be removed or altered from any source
+ * distribution.
+ *
+ *
+ */
+/* Cut down version for libtangobos-partial/dstress */
+
+module tango.math.IEEE;
+
+
+private:
+/*
+ * The following IEEE 'real' formats are currently supported:
+ * 64 bit Big-endian 'double' (eg PowerPC)
+ * 128 bit Big-endian 'quadruple' (eg SPARC)
+ * 64 bit Little-endian 'double' (eg x86-SSE2)
+ * 80 bit Little-endian, with implied bit 'real80' (eg x87, Itanium).
+ * 128 bit Little-endian 'quadruple' (not implemented on any known processor!)
+ *
+ * Non-IEEE 128 bit Big-endian 'doubledouble' (eg PowerPC) has partial support
+ */
+version(LittleEndian) {
+ static assert(real.mant_dig == 53 || real.mant_dig==64
+ || real.mant_dig == 113,
+ "Only 64-bit, 80-bit, and 128-bit reals"
+ " are supported for LittleEndian CPUs");
+} else {
+ static assert(real.mant_dig == 53 || real.mant_dig==106
+ || real.mant_dig == 113,
+ "Only 64-bit and 128-bit reals are supported for BigEndian CPUs."
+ " double-double reals have partial support");
+}
+
+// Constants used for extracting the components of the representation.
+// They supplement the built-in floating point properties.
+template floatTraits(T) {
+ // EXPMASK is a ushort mask to select the exponent portion (without sign)
+ // POW2MANTDIG = pow(2, real.mant_dig) is the value such that
+ // (smallest_denormal)*POW2MANTDIG == real.min
+ // EXPPOS_SHORT is the index of the exponent when represented as a ushort array.
+ // SIGNPOS_BYTE is the index of the sign when represented as a ubyte array.
+ static if (T.mant_dig == 24) { // float
+ const ushort EXPMASK = 0x7F80;
+ const ushort EXPBIAS = 0x3F00;
+ const uint EXPMASK_INT = 0x7F80_0000;
+ const uint MANTISSAMASK_INT = 0x007F_FFFF;
+ const real POW2MANTDIG = 0x1p+24;
+ version(LittleEndian) {
+ const EXPPOS_SHORT = 1;
+ } else {
+ const EXPPOS_SHORT = 0;
+ }
+ } else static if (T.mant_dig == 53) { // double, or real==double
+ const ushort EXPMASK = 0x7FF0;
+ const ushort EXPBIAS = 0x3FE0;
+ const uint EXPMASK_INT = 0x7FF0_0000;
+ const uint MANTISSAMASK_INT = 0x000F_FFFF; // for the MSB only
+ const real POW2MANTDIG = 0x1p+53;
+ version(LittleEndian) {
+ const EXPPOS_SHORT = 3;
+ const SIGNPOS_BYTE = 7;
+ } else {
+ const EXPPOS_SHORT = 0;
+ const SIGNPOS_BYTE = 0;
+ }
+ } else static if (T.mant_dig == 64) { // real80
+ const ushort EXPMASK = 0x7FFF;
+ const ushort EXPBIAS = 0x3FFE;
+ const real POW2MANTDIG = 0x1p+63;
+ version(LittleEndian) {
+ const EXPPOS_SHORT = 4;
+ const SIGNPOS_BYTE = 9;
+ } else {
+ const EXPPOS_SHORT = 0;
+ const SIGNPOS_BYTE = 0;
+ }
+ } else static if (real.mant_dig == 113){ // quadruple
+ const ushort EXPMASK = 0x7FFF;
+ const real POW2MANTDIG = 0x1p+113;
+ version(LittleEndian) {
+ const EXPPOS_SHORT = 7;
+ const SIGNPOS_BYTE = 15;
+ } else {
+ const EXPPOS_SHORT = 0;
+ const SIGNPOS_BYTE = 0;
+ }
+ } else static if (real.mant_dig == 106) { // doubledouble
+ const ushort EXPMASK = 0x7FF0;
+ const real POW2MANTDIG = 0x1p+53; // doubledouble denormals are strange
+ // and the exponent byte is not unique
+ version(LittleEndian) {
+ const EXPPOS_SHORT = 7; // [3] is also an exp short
+ const SIGNPOS_BYTE = 15;
+ } else {
+ const EXPPOS_SHORT = 0; // [4] is also an exp short
+ const SIGNPOS_BYTE = 0;
+ }
+ }
+}
+
+
+public:
+/*********************************
+ * Return 1 if sign bit of e is set, 0 if not.
+ */
+
+int signbit(real x)
+{
+ return ((cast(ubyte *)&x)[floatTraits!(real).SIGNPOS_BYTE] & 0x80) != 0;
+}
diff --git a/tests/testincludes/std/stdarg.d b/tests/testincludes/std/stdarg.d
new file mode 100644
index 00000000..9e69f6f4
--- /dev/null
+++ b/tests/testincludes/std/stdarg.d
@@ -0,0 +1,22 @@
+
+/*
+ * Placed in public domain.
+ * Written by Hauke Duden and Walter Bright
+ */
+
+/* This is for use with variable argument lists with extern(D) linkage. */
+
+module std.stdarg;
+
+alias void* va_list;
+
+template va_arg(T)
+{
+ T va_arg(inout va_list _argptr)
+ {
+ T arg = *cast(T*)_argptr;
+ _argptr = _argptr + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1));
+ return arg;
+ }
+}
+