Giter Site home page Giter Site logo

ldc-developers / ldc Goto Github PK

View Code? Open in Web Editor NEW
1.2K 77.0 250.0 162.86 MB

The LLVM-based D Compiler.

Home Page: http://wiki.dlang.org/LDC

License: Other

CMake 0.52% C 2.31% C++ 17.35% Makefile 0.24% D 74.25% Python 0.01% Shell 0.21% Objective-C 0.01% Inno Setup 0.02% Assembly 0.11% HTML 4.89% SWIG 0.07% DTrace 0.01%
ldc llvm d compiler dlang

ldc's People

Contributors

9rnsr avatar alexeyprokhin avatar andralex avatar andrejmitrovic avatar braddr avatar ckamm avatar complexmath avatar cybershadow avatar dkorpel avatar dlang-bot avatar dnadlinger avatar don-clugston-sociomantic avatar geod24 avatar hardcode84 avatar ibuclaw avatar jacob-carlborg avatar jinshil avatar johanengelen avatar kinke avatar lindquist avatar martinnowak avatar moonlightsentinel avatar ntrel avatar rainers avatar razvann7 avatar redstar avatar thewilsonator avatar walterbright avatar wilzbach avatar yebblies avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ldc's Issues

Build fail

when i try to build ldc from latest revision this error appear

Linking CXX executable bin/ldc2
/usr/bin/cmake -E cmake_link_script CMakeFiles/ldc2.dir/link.txt --verbose=2
/usr/bin/c++   -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4  -m64 -mtune=generic     CMakeFiles/ldc2.dir/dmd2/id.c.o CMakeFiles/ldc2.dir/dmd2/impcnvtab.c.o CMakeFiles/ldc2.dir/dmd2/init.c.o CMakeFiles/ldc2.dir/dmd2/intrange.c.o CMakeFiles/ldc2.dir/dmd2/inline.c.o CMakeFiles/ldc2.dir/dmd2/optimize.c.o CMakeFiles/ldc2.dir/dmd2/html.c.o CMakeFiles/ldc2.dir/dmd2/staticassert.c.o CMakeFiles/ldc2.dir/dmd2/dump.c.o CMakeFiles/ldc2.dir/dmd2/root/array.c.o CMakeFiles/ldc2.dir/dmd2/root/stringtable.c.o CMakeFiles/ldc2.dir/dmd2/root/lstring.c.o CMakeFiles/ldc2.dir/dmd2/root/gnuc.c.o CMakeFiles/ldc2.dir/dmd2/root/dchar.c.o CMakeFiles/ldc2.dir/dmd2/root/root.c.o CMakeFiles/ldc2.dir/dmd2/root/port.c.o CMakeFiles/ldc2.dir/dmd2/root/speller.c.o CMakeFiles/ldc2.dir/dmd2/root/aav.c.o CMakeFiles/ldc2.dir/dmd2/root/man.c.o CMakeFiles/ldc2.dir/dmd2/root/response.c.o CMakeFiles/ldc2.dir/dmd2/root/async.c.o CMakeFiles/ldc2.dir/dmd2/cppmangle.c.o CMakeFiles/ldc2.dir/dmd2/inifile.c.o CMakeFiles/ldc2.dir/dmd2/mtype.c.o CMakeFiles/ldc2.dir/dmd2/scope.c.o CMakeFiles/ldc2.dir/dmd2/argtypes.c.o CMakeFiles/ldc2.dir/dmd2/clone.c.o CMakeFiles/ldc2.dir/dmd2/irstate.c.o CMakeFiles/ldc2.dir/dmd2/unittests.c.o CMakeFiles/ldc2.dir/dmd2/access.c.o CMakeFiles/ldc2.dir/dmd2/expression.c.o CMakeFiles/ldc2.dir/dmd2/aliasthis.c.o CMakeFiles/ldc2.dir/dmd2/version.c.o CMakeFiles/ldc2.dir/dmd2/struct.c.o CMakeFiles/ldc2.dir/dmd2/arrayop.c.o CMakeFiles/ldc2.dir/dmd2/declaration.c.o CMakeFiles/ldc2.dir/dmd2/unialpha.c.o CMakeFiles/ldc2.dir/dmd2/dsymbol.c.o CMakeFiles/ldc2.dir/dmd2/cond.c.o CMakeFiles/ldc2.dir/dmd2/imphint.c.o CMakeFiles/ldc2.dir/dmd2/opover.c.o CMakeFiles/ldc2.dir/dmd2/lexer.c.o CMakeFiles/ldc2.dir/dmd2/doc.c.o CMakeFiles/ldc2.dir/dmd2/attrib.c.o CMakeFiles/ldc2.dir/dmd2/identifier.c.o CMakeFiles/ldc2.dir/dmd2/entity.c.o CMakeFiles/ldc2.dir/dmd2/cast.c.o CMakeFiles/ldc2.dir/dmd2/macro.c.o CMakeFiles/ldc2.dir/dmd2/mem.c.o CMakeFiles/ldc2.dir/dmd2/template.c.o CMakeFiles/ldc2.dir/dmd2/mars.c.o CMakeFiles/ldc2.dir/dmd2/import.c.o CMakeFiles/ldc2.dir/dmd2/func.c.o CMakeFiles/ldc2.dir/dmd2/json.c.o CMakeFiles/ldc2.dir/dmd2/mangle.c.o CMakeFiles/ldc2.dir/dmd2/class.c.o CMakeFiles/ldc2.dir/dmd2/interpret.c.o CMakeFiles/ldc2.dir/dmd2/delegatize.c.o CMakeFiles/ldc2.dir/dmd2/statement.c.o CMakeFiles/ldc2.dir/dmd2/constfold.c.o CMakeFiles/ldc2.dir/dmd2/builtin.c.o CMakeFiles/ldc2.dir/dmd2/traits.c.o CMakeFiles/ldc2.dir/dmd2/parse.c.o CMakeFiles/ldc2.dir/dmd2/enum.c.o CMakeFiles/ldc2.dir/dmd2/hdrgen.c.o CMakeFiles/ldc2.dir/dmd2/module.c.o CMakeFiles/ldc2.dir/dmd2/utf.c.o CMakeFiles/ldc2.dir/gen/statements.cpp.o CMakeFiles/ldc2.dir/gen/toir.cpp.o CMakeFiles/ldc2.dir/gen/warnings.cpp.o CMakeFiles/ldc2.dir/gen/tocall.cpp.o CMakeFiles/ldc2.dir/gen/linkage.cpp.o CMakeFiles/ldc2.dir/gen/main.cpp.o CMakeFiles/ldc2.dir/gen/logger.cpp.o CMakeFiles/ldc2.dir/gen/abi-x86-64.cpp.o CMakeFiles/ldc2.dir/gen/nested.cpp.o CMakeFiles/ldc2.dir/gen/abi.cpp.o CMakeFiles/ldc2.dir/gen/declarations.cpp.o CMakeFiles/ldc2.dir/gen/rttibuilder.cpp.o CMakeFiles/ldc2.dir/gen/programs.cpp.o CMakeFiles/ldc2.dir/gen/cl_helpers.cpp.o CMakeFiles/ldc2.dir/gen/todebug.cpp.o CMakeFiles/ldc2.dir/gen/configfile.cpp.o CMakeFiles/ldc2.dir/gen/structs.cpp.o CMakeFiles/ldc2.dir/gen/dvalue.cpp.o CMakeFiles/ldc2.dir/gen/toobj.cpp.o CMakeFiles/ldc2.dir/gen/typinf.cpp.o CMakeFiles/ldc2.dir/gen/asmstmt.cpp.o CMakeFiles/ldc2.dir/gen/llvmhelpers.cpp.o CMakeFiles/ldc2.dir/gen/irstate.cpp.o CMakeFiles/ldc2.dir/gen/aa.cpp.o CMakeFiles/ldc2.dir/gen/linker.cpp.o CMakeFiles/ldc2.dir/gen/binops.cpp.o CMakeFiles/ldc2.dir/gen/optimizer.cpp.o CMakeFiles/ldc2.dir/gen/classes.cpp.o CMakeFiles/ldc2.dir/gen/passes/GarbageCollect2Stack.cpp.o CMakeFiles/ldc2.dir/gen/passes/StripExternals.cpp.o CMakeFiles/ldc2.dir/gen/passes/SimplifyDRuntimeCalls.cpp.o CMakeFiles/ldc2.dir/gen/complex.cpp.o CMakeFiles/ldc2.dir/gen/tollvm.cpp.o CMakeFiles/ldc2.dir/gen/arrays.cpp.o CMakeFiles/ldc2.dir/gen/runtime.cpp.o CMakeFiles/ldc2.dir/gen/cl_options.cpp.o CMakeFiles/ldc2.dir/gen/functions.cpp.o CMakeFiles/ldc2.dir/gen/naked.cpp.o CMakeFiles/ldc2.dir/ir/irclass.cpp.o CMakeFiles/ldc2.dir/ir/irtype.cpp.o CMakeFiles/ldc2.dir/ir/irtypefunction.cpp.o CMakeFiles/ldc2.dir/ir/irmodule.cpp.o CMakeFiles/ldc2.dir/ir/irfunction.cpp.o CMakeFiles/ldc2.dir/ir/irstruct.cpp.o CMakeFiles/ldc2.dir/ir/irtypeclass.cpp.o CMakeFiles/ldc2.dir/ir/ir.cpp.o CMakeFiles/ldc2.dir/ir/irvar.cpp.o CMakeFiles/ldc2.dir/ir/irtypestruct.cpp.o CMakeFiles/ldc2.dir/ir/irsymbol.cpp.o CMakeFiles/ldc2.dir/ir/irdsymbol.cpp.o CMakeFiles/ldc2.dir/ir/irlandingpad.cpp.o  -o bin/ldc2 -rdynamic -L/usr/lib64/llvm  -lpthread -lffi -ldl -lm /usr/lib64/llvm/libLLVMX86Disassembler.a /usr/lib64/llvm/libLLVMX86AsmParser.a /usr/lib64/llvm/libLLVMX86CodeGen.a /usr/lib64/llvm/libLLVMSelectionDAG.a /usr/lib64/llvm/libLLVMAsmPrinter.a /usr/lib64/llvm/libLLVMMCParser.a /usr/lib64/llvm/libLLVMCodeGen.a /usr/lib64/llvm/libLLVMX86AsmPrinter.a /usr/lib64/llvm/libLLVMX86Utils.a /usr/lib64/llvm/libLLVMX86Info.a /usr/lib64/llvm/libLLVMInstrumentation.a /usr/lib64/llvm/libLLVMipo.a /usr/lib64/llvm/libLLVMScalarOpts.a /usr/lib64/llvm/libLLVMInstCombine.a /usr/lib64/llvm/libLLVMLinker.a /usr/lib64/llvm/libLLVMTransformUtils.a /usr/lib64/llvm/libLLVMipa.a /usr/lib64/llvm/libLLVMAnalysis.a /usr/lib64/llvm/libLLVMTarget.a /usr/lib64/llvm/libLLVMMC.a /usr/lib64/llvm/libLLVMArchive.a /usr/lib64/llvm/libLLVMBitReader.a /usr/lib64/llvm/libLLVMBitWriter.a /usr/lib64/llvm/libLLVMCore.a /usr/lib64/llvm/libLLVMSupport.a -lconfig++ -lconfig++ 
`.text._ZN4llvm13RGPassManagerD2Ev' referenced in section `.text._ZN4llvm13RGPassManagerD1Ev[non-virtual thunk to llvm::RGPassManager::~RGPassManager()]' of /usr/lib64/llvm/libLLVMAnalysis.a(RegionPass.o): defined in discarded section `.text._ZN4llvm13RGPassManagerD2Ev[_ZN4llvm13RGPassManagerD5Ev]' of /usr/lib64/llvm/libLLVMAnalysis.a(RegionPass.o)
collect2: ld returned 1 exit status
make[3]: *** [bin/ldc2] Error 1

[Patch] Build system

I have do a patch for fix some build problem:

  • multiple definition of bitop
  • choose rigth llvm config header
  • perform installation process
  • generate di file for files in druntime/ldc (to druntime/import/core) like: bitop, eh, memory, arrayinit

On fedora you could have llvm in 32 and 64 bits so llvm config header could be:

  • config-32.h
  • config-64.h
  • default config.h
    i.e run cmake with -DLLVM_CONFIG_HEADER=config-64.h

current system build with O2, if you try O3 == segfault
me i override like this:
-DD_FLAGS:STRING="-O2;-g;-w;-d;-release"

I do not know if it is better to use gc instead g for code debugging

Now install process install devel file for phobos usefull for programmer.

PATCH:

diff -up ldc/CMakeLists.txt.fix ldc/CMakeLists.txt
--- ldc/CMakeLists.txt.fix  2011-10-03 12:02:34.145947341 +0200
+++ ldc/CMakeLists.txt  2011-10-03 17:11:33.071106536 +0200
@@ -15,8 +15,8 @@ if(NOT PKG_CONFIG_FOUND)
 else(NOT PKG_CONFIG_FOUND)
     pkg_search_module(LIBCONFIGPP libconfig++)
     if(NOT LIBCONFIGPP_FOUND)
-        set(LIBCONFIG_CXXFLAGS "" CACHE STRING "libconfig++ compiler flags")
-        set(LIBCONFIG_LDFLAGS "" CACHE STRING "libconfig++ linker flags")
+        set(LIBCONFIG_CXXFLAGS  "" CACHE STRING "libconfig++ compiler flags")
+        set(LIBCONFIG_LDFLAGS   "" CACHE STRING "libconfig++ linker flags")
     else(NOT LIBCONFIGPP_FOUND)
         set(LIBCONFIG_CXXFLAGS ${LIBCONFIGPP_CFLAGS} CACHE STRING "libconfig++ compiler flags")
         set(LIBCONFIG_LDFLAGS ${LIBCONFIGPP_LDFLAGS} CACHE STRING "libconfig++ linker flags")
@@ -31,6 +31,7 @@ set(LLVM_INSTDIR ${LLVM_DIR} CACHE PATH
 if(NOT LLVM_INSTDIR)
    message(FATAL_ERROR "llvm not found")
 endif(NOT LLVM_INSTDIR)
+set(LLVM_CONFIG_HEADER "config.h" CACHE STRING "llvm config header file name")

 execute_process(
    COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --host-target
@@ -53,23 +54,27 @@ execute_process(
    OUTPUT_STRIP_TRAILING_WHITESPACE
 )

-set(D_VERSION 1 CACHE STRING "D language version")
-set(CONF_INST_DIR "${CMAKE_INSTALL_PREFIX}/etc" CACHE STRING "set ldc.conf directory for installation")
-set(PROGRAM_PREFIX CACHE STRING "prepended to ldc binary name")
-set(PROGRAM_SUFFIX CACHE STRING "appended to ldc binary name")
-option(USE_BOEHM_GC "use the Boehm garbage collector internally")
-option(GENERATE_OFFTI "generate complete ClassInfo.offTi arrays")
-option(USE_METADATA "use metadata and related custom optimization passes")
+set(D_VERSION               1                                       CACHE STRING "D language version")
+set(CONF_INST_DIR           "${CMAKE_INSTALL_PREFIX}/etc"           CACHE STRING "set ldc.conf directory for installation")
+set(CMAKE_INSTALL_LIBDIR    "lib"                                   CACHE STRING "directory where lib will be installed")
+set(LIB_SUFFIX              ""                                      CACHE STRING "take empty string or 64. Directory where lib will be installed: lib or lib64")
+set(LIBRARY_OUTPUT_PATH     ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX}  CACHE PATH "output dir for built libraries")
+set(INCLUDE_INSTALL_DIR     /usr/include/d                          CACHE PATH "Directory wher will be put header file")
+set(PROGRAM_PREFIX                                                  CACHE STRING "prepended to ldc binary name")
+set(PROGRAM_SUFFIX                                                  CACHE STRING "appended to ldc binary name")
+option(USE_BOEHM_GC     "use the Boehm garbage collector internally")
+option(GENERATE_OFFTI   "generate complete ClassInfo.offTi arrays")
+option(USE_METADATA     "use metadata and related custom optimization passes")

 if(D_VERSION EQUAL 1)
-   set(DMDFE_PATH dmd)
-   set(LDC_EXE ldc)
-   set(LDMD_EXE ldmd)
+   set(DMDFE_PATH  dmd)
+   set(LDC_EXE     ldc)
+   set(LDMD_EXE    ldmd)
    add_definitions(-DDMDV1)
 elseif(D_VERSION EQUAL 2)
-   set(DMDFE_PATH dmd2)
-   set(LDC_EXE ldc2)
-   set(LDMD_EXE ldmd2)
+   set(DMDFE_PATH  dmd2)
+   set(LDC_EXE     ldc2)
+   set(LDMD_EXE    ldmd2)
    add_definitions(-DDMDV2)
 else(D_VERSION EQUAL 1)
    message(FATAL_ERROR "unsupported D version")
@@ -136,24 +141,24 @@ execute_process(

 # build a define that contains all LLVM targets required and is usable for
 # preprocessor code generation. start with the native target.
-find_path(LLVM_CONFIG_FILE_PATH config.h PATHS ${LLVM_INCLUDEDIR}/llvm/Config ${LLVM_INCLUDEDIR}/Config NO_DEFAULT_PATH)
+find_path(LLVM_CONFIG_FILE_PATH ${LLVM_CONFIG_HEADER} PATHS ${LLVM_INCLUDEDIR}/llvm/Config ${LLVM_INCLUDEDIR}/Config NO_DEFAULT_PATH)
 if(LLVM_CONFIG_FILE_PATH STREQUAL "LLVM_CONFIG_FILE_PATH-NOTFOUND")
-        message("Couldn't find your llvm Config.h file in ${LLVM_INCLUDEDIR}, no native target will be initialized.")
+        message("Couldn't find your llvm ${LLVM_CONFIG_HEADER} file in ${LLVM_INCLUDEDIR}, no native target will be initialized.")
 else(LLVM_CONFIG_FILE_PATH STREQUAL "LLVM_CONFIG_FILE_PATH-NOTFOUND")
         if(NOT HOST_TARGET AND NOT DEFAULT_TARGET)
-            file(STRINGS ${LLVM_CONFIG_FILE_PATH}/config.h LLVM_HOSTTRIPLE REGEX "^#define LLVM_HOSTTRIPLE")
+            file(STRINGS ${LLVM_CONFIG_FILE_PATH}/${LLVM_CONFIG_HEADER} LLVM_HOSTTRIPLE REGEX "^#define LLVM_HOSTTRIPLE")
             if(LLVM_HOSTTRIPLE)
                 string(REGEX REPLACE "^#define LLVM_HOSTTRIPLE \"(.*)\"$" "\\1" HOST_TARGET ${LLVM_HOSTTRIPLE})
             endif(LLVM_HOSTTRIPLE)
         endif(NOT HOST_TARGET AND NOT DEFAULT_TARGET)

-        file(STRINGS ${LLVM_CONFIG_FILE_PATH}/config.h LLVM_NATIVE_ARCH REGEX "^#define LLVM_NATIVE_ARCH")
+        file(STRINGS ${LLVM_CONFIG_FILE_PATH}/${LLVM_CONFIG_HEADER} LLVM_NATIVE_ARCH REGEX "^#define LLVM_NATIVE_ARCH")
         if(LLVM_NATIVE_ARCH)
                 string(REGEX REPLACE "^#define LLVM_NATIVE_ARCH (.*)(Target|)$" "\\1" LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH})
                 message(STATUS "Found native target ${LLVM_NATIVE_ARCH}")
                 set(LLVM_MODULES_DEFINE "LLVM_TARGET(${LLVM_NATIVE_ARCH})")
         else(LLVM_NATIVE_ARCH)
-                message("Couldn't find the LLVM_NATIVE_ARCH define in ${LLVM_CONFIG_FILE_PATH}/config.h. Probably you have an older LLVM and can ignore this warning.")
+                message("Couldn't find the LLVM_NATIVE_ARCH define in ${LLVM_CONFIG_FILE_PATH}/${LLVM_CONFIG_HEADER}. Probably you have an older LLVM and can ignore this warning.")
         endif(LLVM_NATIVE_ARCH)
 endif(LLVM_CONFIG_FILE_PATH STREQUAL "LLVM_CONFIG_FILE_PATH-NOTFOUND")
 # chain the extra target list to the define
@@ -176,9 +181,9 @@ set(DEFAULT_ALT_TARGET ${HOST_ALT_TARGET

 # Also add the header files to the build so that they are available in IDE
 # project files generated via CMake.
-file(GLOB_RECURSE FE_SRC ${DMDFE_PATH}/*.c ${DMDFE_PATH}/*.h)
-file(GLOB_RECURSE GEN_SRC gen/*.cpp gen/*.h)
-file(GLOB IR_SRC ir/*.cpp ir/*.h)
+file(GLOB_RECURSE   FE_SRC  ${DMDFE_PATH}/*.c   ${DMDFE_PATH}/*.h)
+file(GLOB_RECURSE   GEN_SRC gen/*.cpp           gen/*.h)
+file(GLOB           IR_SRC  ir/*.cpp            ir/*.h)
 # exclude idgen and impcnvgen and generated sources, just in case
 list(REMOVE_ITEM FE_SRC
    ${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/idgen.c
@@ -222,7 +227,6 @@ endif(USE_METADATA)

 if(CMAKE_MINOR_VERSION LESS 6)
     set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "output dir for built executables")
-    set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib CACHE PATH "output dir for built libraries")
     add_definitions(-DDEFAULT_TARGET_TRIPLE=\\"${DEFAULT_TARGET}\\")
     add_definitions(-DDEFAULT_ALT_TARGET_TRIPLE=\\"${DEFAULT_ALT_TARGET}\\")
     add_definitions(-DLDC_INSTALL_PREFIX=\\"${CMAKE_INSTALL_PREFIX}\\")
@@ -237,10 +241,10 @@ add_executable(${LDC_EXE} ${LDC_SOURCE_F
 set(LDC_EXE_NAME ${PROGRAM_PREFIX}${LDC_EXE}${PROGRAM_SUFFIX})

 set_target_properties(
-   ${LDC_EXE} PROPERTIES
-   OUTPUT_NAME ${LDC_EXE_NAME}
-   RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
-   COMPILE_FLAGS "${LLVM_CXXFLAGS} ${LIBCONFIG_CXXFLAGS} -Wno-deprecated -Wno-write-strings -fexceptions"
+   ${LDC_EXE}                  PROPERTIES
+   OUTPUT_NAME                 ${LDC_EXE_NAME}
+   RUNTIME_OUTPUT_DIRECTORY    ${PROJECT_BINARY_DIR}/bin
+   COMPILE_FLAGS               "${LLVM_CXXFLAGS} ${LIBCONFIG_CXXFLAGS} -Wno-deprecated -Wno-write-strings -fexceptions"
 )

 # LDFLAGS should actually be in target property LINK_FLAGS, but this works, and gets around linking problems
@@ -257,10 +261,14 @@ get_target_property(LDC_LOC ${LDC_EXE} L

 # TODO: testrun

-install(TARGETS ${LDC_EXE} DESTINATION bin)
-install(PROGRAMS ${PROJECT_SOURCE_DIR}/bin/${LDMD_EXE} DESTINATION bin)
-install(FILES ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}.conf DESTINATION ${CONF_INST_DIR})
-install(FILES ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}.rebuild.conf DESTINATION ${CONF_INST_DIR})
-install(DIRECTORY ${PROJECT_BINARY_DIR}/lib DESTINATION . USE_SOURCE_PERMISSIONS)
+install(TARGETS     ${LDC_EXE}                                          DESTINATION bin)
+install(PROGRAMS    ${PROJECT_SOURCE_DIR}/bin/${LDMD_EXE}               DESTINATION bin)
+install(FILES       ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}.conf           DESTINATION ${CONF_INST_DIR})
+install(FILES       ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}.rebuild.conf   DESTINATION ${CONF_INST_DIR})
+install(DIRECTORY   ${LIBRARY_OUTPUT_PATH}                              DESTINATION .               USE_SOURCE_PERMISSIONS)
+install(DIRECTORY   ${PROJECT_BINARY_DIR}/import/core                   DESTINATION ${INCLUDE_INSTALL_DIR}/)
+install(DIRECTORY   ${PROJECT_BINARY_DIR}/phobos                        DESTINATION ${INCLUDE_INSTALL_DIR}/)
+install(DIRECTORY   ${PROJECT_BINARY_DIR}/druntime/import/ldc           DESTINATION ${INCLUDE_INSTALL_DIR}/)
+install(FILES       ${PROJECT_BINARY_DIR}/druntime/import/object.di     DESTINATION ${INCLUDE_INSTALL_DIR}/ldc)

 add_subdirectory(runtime EXCLUDE_FROM_ALL)
diff -up ldc/runtime/CMakeLists.txt.fix ldc/runtime/CMakeLists.txt
--- ldc/runtime/CMakeLists.txt.fix  2011-10-03 12:50:23.364721772 +0200
+++ ldc/runtime/CMakeLists.txt  2011-10-04 01:19:19.555360961 +0200
@@ -2,10 +2,10 @@ project(runtime)

 cmake_minimum_required(VERSION 2.6)

-option(BUILD_SHARED_LIBS "build the runtime as shared libraries (linux only)")
-option(BUILD_BC_LIBS "build the runtime as bytecode libraries")
-option(BUILD_SINGLE_LIB "build single runtime library" ON)
-set(D_FLAGS -g -w -d CACHE STRING "runtime build flags, separated by ;")
+option(BUILD_SHARED_LIBS                    "build the runtime as shared libraries (linux only)")
+option(BUILD_BC_LIBS                        "build the runtime as bytecode libraries")
+option(BUILD_SINGLE_LIB                     "build single runtime library" ON)
+set(D_FLAGS -g -w -d        CACHE STRING    "runtime build flags, separated by ;")

 if(BUILD_SHARED_LIBS)
    list(APPEND D_FLAGS -relocation-model=pic)
@@ -62,20 +62,23 @@ if(D_VERSION EQUAL 1)
    file(GLOB DCRT_C ${RUNTIME_DC_DIR}/*.c)
    set(CONFIG_NAME ${LDC_EXE})
 elseif(D_VERSION EQUAL 2)
-   set(PHOBOS2_DIR ${PROJECT_PARENT_DIR}/phobos CACHE PATH "phobos2 source dir")
-   set(RUNTIME_CC druntime-core)
-   set(RUNTIME_GC druntime-gc-basic)
-   set(RUNTIME_DC druntime-rt-ldc)
-   set(RUNTIME_AIO druntime-ldc)
-   set(RUNTIME_DC_DIR ${RUNTIME_DIR}/src/rt)
-   set(RUNTIME_GC_DIR ${RUNTIME_DIR}/src/gc)
+   set(PHOBOS2_DIR     ${PROJECT_PARENT_DIR}/phobos CACHE PATH "phobos2 source dir")
+   set(RUNTIME_CC      druntime-core)
+   set(RUNTIME_GC      druntime-gc-basic)
+   set(RUNTIME_DC      druntime-rt-ldc)
+   set(RUNTIME_AIO     druntime-ldc)
+   set(RUNTIME_DC_DIR  ${RUNTIME_DIR}/src/rt)
+   set(RUNTIME_GC_DIR  ${RUNTIME_DIR}/src/gc)
    set(RUNTIME_INCLUDE ${RUNTIME_DIR}/src)
-   file(GLOB CORE_D ${RUNTIME_DIR}/src/core/*.d )
-   file(GLOB CORE_D_SYNC ${RUNTIME_DIR}/src/core/sync/*.d )
-   file(GLOB CORE_D_STDC ${RUNTIME_DIR}/src/core/stdc/*.d )
-   file(GLOB_RECURSE GC_D ${RUNTIME_GC_DIR}/*.d)
-   file(GLOB_RECURSE DCRT_D ${RUNTIME_DC_DIR}/*.d)
-   file(GLOB_RECURSE LDC_D ${RUNTIME_DIR}/src/ldc/*.d)
+   file(GLOB CORE_D            ${RUNTIME_DIR}/src/core/*.d )
+   file(GLOB CORE_D_SYNC       ${RUNTIME_DIR}/src/core/sync/*.d )
+   file(GLOB CORE_D_STDC       ${RUNTIME_DIR}/src/core/stdc/*.d )
+   file(GLOB_RECURSE GC_D      ${RUNTIME_GC_DIR}/*.d)
+   file(GLOB_RECURSE DCRT_D    ${RUNTIME_DC_DIR}/*.d)
+   file(GLOB_RECURSE LDC_D     ${RUNTIME_DIR}/src/ldc/*.d)
+    list(REMOVE_ITEM CORE_D
+       ${RUNTIME_DIR}/src/core/bitop.d
+   )
    list(REMOVE_ITEM DCRT_D
        ${RUNTIME_DC_DIR}/alloca.d
        ${RUNTIME_DC_DIR}/arraybyte.d
@@ -102,7 +105,7 @@ elseif(D_VERSION EQUAL 2)
        file(GLOB_RECURSE CORE_D_SYS ${RUNTIME_DIR}/src/core/sys/osx/*.d)
    endif(UNIX)
    list(APPEND CORE_D ${CORE_D_SYNC} ${CORE_D_SYS} ${CORE_D_STDC} )
-   set(GENERATE_DI ${CORE_D})
+   list(APPEND GENERATE_DI ${CORE_D} ${LDC_D})
    list(APPEND CORE_D ${LDC_D} ${RUNTIME_DIR}/src/object_.d)
    file(GLOB CORE_C ${RUNTIME_DIR}/src/core/stdc/*.c)

@@ -198,13 +201,14 @@ macro(dc INPUT_D OUTLIST_O OUTLIST_BC IN
    endif ("${path}" STREQUAL "")
    set(OUTPUT_O ${PROJECT_BINARY_DIR}/${output}.o)
    set(OUTPUT_BC ${PROJECT_BINARY_DIR}/${output}.bc)
-   list(APPEND ${OUTLIST_O} ${OUTPUT_O})
-   list(APPEND ${OUTLIST_BC} ${OUTPUT_BC})
+   list(APPEND ${OUTLIST_O}    ${OUTPUT_O})
+   list(APPEND ${OUTLIST_BC}   ${OUTPUT_BC})

    list(FIND GENERATE_DI "${INPUT_D}" INDEX)
    if (INDEX EQUAL -1)
        set(DI_CMD "")
    else (INDEX EQUAL -1)
+        string(REGEX REPLACE "src/ldc" "src/core" output ${output})
        string(REGEX REPLACE "^src/" "" di_output ${output})
        set(DI_CMD -Hf=${CMAKE_BINARY_DIR}/import/${di_output}.di)
        list(REMOVE_AT GENERATE_DI ${INDEX})
@@ -271,7 +275,7 @@ if(BUILD_BC_LIBS)
        COMMAND ${LLVM_AR_EXE} rs lib${RUNTIME_GC}-bc.a ${GC_BC}
        # cannot parse genobj.bc if built with -g
        # COMMAND ${LLVM_AR_EXE} rs lib${RUNTIME_DC}-bc.a ${DCRT_BC}
-       WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/../lib
+       WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH}
        DEPENDS
            ${CORE_BC}
            ${GC_BC}
@@ -282,10 +286,10 @@ if(BUILD_BC_LIBS)
 endif(BUILD_BC_LIBS)

 set_target_properties(
-    ${LIBS} PROPERTIES
-    LINKER_LANGUAGE C
-    ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib
-    LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib
+    ${LIBS}                     PROPERTIES
+    LINKER_LANGUAGE             C
+    ARCHIVE_OUTPUT_DIRECTORY    ${LIBRARY_OUTPUT_PATH}
+    LIBRARY_OUTPUT_DIRECTORY    ${LIBRARY_OUTPUT_PATH}
 )

 # BCLIBS is empty if BUILD_BC_LIBS is not selected
@@ -307,10 +311,10 @@ if(PHOBOS2_DIR)
    )
     add_dependencies(lphobos2 runtime)
     set_target_properties(
-        lphobos2 PROPERTIES
-        LINKER_LANGUAGE C
-        ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib
-        LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib
+        lphobos2                    PROPERTIES
+        LINKER_LANGUAGE             C
+        ARCHIVE_OUTPUT_DIRECTORY    ${LIBRARY_OUTPUT_PATH}
+        LIBRARY_OUTPUT_DIRECTORY    ${LIBRARY_OUTPUT_PATH}
     )
     add_custom_target(phobos2 DEPENDS lphobos2)
 endif(PHOBOS2_DIR)

ldmd doesn't work with response file

ldmd2 @/tmp/.rdmd-1000/rdmd.rsp just passes @... to ldc which of course doesn't understand the dmd parameters inside the .rsp file.
Thus ldmd isn't usable with rdmd in this case.

core/bitop.d not copied

On two different boxes (a Ubuntu 10.4 box and a Debian Testing box), I've successfully built and installed LDC. However, when I try to compile hello, world, I get:

$ ldmd2 test.d
/usr/local/include/d/phobos/std/array.d(15): Error: module bitop is in file 'core/bitop.d' which cannot be read

This is because bitop.d/bitop.di is never copied to the include directory by the install system. When I copy it there manually, the problem is solved.

StructType::setBody assert isOpaque() failed

//matrix.d:
import vector;
struct Matrix
{
    vec4 v;
}

//vector.d:
template Tuple(T...)
{
    alias T Tuple;
}

template Repeat(T, int count)
{
    static if (!count)
        alias Tuple!() Repeat;
    else
        alias Tuple!(T, Repeat!(T, count-1)) Repeat;
}

struct Vector(T, int dim)
{
    Repeat!(T, dim) tuple;
    const static Vector zero = Vector();
}

alias Vector!(float, 4) vec4;
$ ldc2 -c *.d
ldc2: llvm-3.0/lib/VMCore/Type.cpp:401: void llvm::StructType::setBody(llvm::ArrayRef<llvm::Type*>, bool): Assertion `isOpaque() && "Struct body already set!"' failed.

Pulling the vector code into the matrix module makes it compile.

ICE: llvm::GlobalVariable::setInitializer assert failed

weird one:

import std.datetime;
class Cgi
{
    this()
    {
        string[][string] _post;
        postArray = cast(immutable)(_post);
        string[string] pa;
        foreach(k, v; postArray)
            pa[k] = v[$-1];
    }

    void flushHeaders() {
            auto expires = SysTime();
            cast(DateTime) expires;
    }

    immutable(string[][string]) postArray;
}
$ ldc2 -c cgi.d 
ldc2: llvm-3.0/lib/VMCore/Globals.cpp:168: void llvm::GlobalVariable::setInitializer(llvm::Constant*): Assertion `InitVal->getType() == getType()->getElementType() && "Initializer type must match GlobalVariable type"' failed.

Multilib: --no-warn-search-mismatch

I appreciate the effort on the new multilib feature. It works great except for one small detail:

$ ldc2 -m32 hello.d -L--no-warn-search-mismatch
/usr/bin/ld: skipping incompatible /cis/home/dsimcha/apps/lib/libphobos2-ldc.a when searching for -lphobos2-ldc

Apparently the --no-warn-search-mismatch never gets forwarded to the linker, leading to some really annoying warnings.

ICE: DValue::getLVal(): Assertion `0' failed

extern (C)
{
    struct Color
    {
    }

    Color C_GetColor(float r, float g, float b, float a)
    {
        return Color();
    }

}

void main()
{

    Color color = C_GetColor(1, 2, 3, 4);
}
$ ldc2 test.d 
ldc2: ldc/./gen/dvalue.h:42: virtual llvm::Value* DValue::getLVal(): Assertion `0' failed.

how create a shared library?

1/ build project with pic

$ ldc2 -g -O3 -op -release -c -relocation-model=pic localization.d -of localization.o
localization.s-iWqEVS: Assembler messages:
localization.s-iWqEVS:105: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:107: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:108: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:129: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:131: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:132: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:147: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:149: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:150: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:168: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:170: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:171: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:452: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:454: Warning: stand-alone `data16' prefix
localization.s-iWqEVS:455: Warning: stand-alone `data16' prefix

They are some warning but no error (i do not know whet is the problem with)

2/ create a shared library

$ ld -o localization.so -L/lib64/ -llphobos2 -lm -lpthread -ldl -lrt -ldruntime-ldc localization.o  -soname=localization.s
ld: warning: cannot find entry symbol _start; defaulting to 0000000000403140
/usr/lib64/liblphobos2.so: undefined reference to `__data_start'
/usr/lib64/liblphobos2.so: undefined reference to `_Dmain'

In which lib are define these thing?

2/ create a static lib is easy

$ ar rcs localization.o localization.a

thanks

Hello world doesn't compile on -O3 or higher

Hello world program:

import std.stdio;

void main() {
    writeln("Hello, world.");
}

Everything works if I only use -O2 optimization, but:

$ ldc2 -O3 test.d
/usr/local/include/d/phobos/std/math.d(327): Error: pure function 'cos' cannot call impure function 'llvm_cos'
/usr/local/include/d/phobos/std/math.d(327): Error: safe function 'cos' cannot call system function 'llvm_cos'
/usr/local/include/d/phobos/std/math.d(327): Error: llvm_cos is not nothrow
/usr/local/include/d/phobos/std/math.d(325): Error: function std.math.cos 'cos' is nothrow yet may throw

ldc .di file under POSIX OS

hi, ldc use \r\n instead \n for generate .di file when is build under POSIX OS
they are away to use \r\n when ldc is build on windows only ?

-lib Switch for ldmd2

The ldmd2 script, which is supposed to provide DMD-like command line flags to LDC, doesn't support building libraries using -lib. This is easy to work around and fix (just build individual object files and archive them manually), but it should be supported so that LDC can be a drop in replacement for DMD without any changes to build processes.

Renaming shared lib

hi,
we cannot rename the shared lib by using -of , like this fail

$ ldc2 -shared foo1.d foo2.d -of libFoo.so.0
Error: multiple source files, but only one .obj name

Find triple on fedora

I have this error: Unable to find target for this triple
did you know cmake i am a noob with this system
on fedora config.h contains:

#include <bits/wordsize.h>

#if __WORDSIZE == 32
#include "config-32.h"
#elif __WORDSIZE == 64
#include "config-64.h"
#else
#error "Unknown word size"
#endif

So current build system try do a regexp in this file for take triple, and this regexp fail
I would like add to current build system 2 others tests like:

  • if ${LLVM_CONFIG_FILE_PATH}/config-64.h exist
  • if ${LLVM_CONFIG_FILE_PATH}/config-32.h exist
    someone could add this in CmakeList.txt around line 140

Casting Associative Arrays To Immutable

void main() {
    uint[string] foo;
    immutable bar = cast(immutable) foo;
}

test.d(3): Error: invalid cast from 'uint[string]' to 'immutable(uint[string])'

These conversions are supposed to be allowed with an explicit cast. GDC and DMD both allow them.

undefined reference to `dladdr'

Compiling the revision 52c6347 results in these error messages:

Linking CXX executable ../bin/ldc
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Signals.o): In function PrintStackTrace(void*)': (.text+0x6c): undefined reference todladdr'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Signals.o): In function PrintStackTrace(void*)': (.text+0x187): undefined reference todladdr'

Workabout is to do add this define when running cmake:

-DCMAKE_EXE_LINKER_FLAGS=-ldl

Compile-time segfault involving libpthread, _aaGet

This one must be a memory management issue or something because it's deterministic but chaotic. It only happens at -O3 or greater optimization settings (implying that it's codegen related), yet can only be reproduced when templates that are never instantiated and code that's versioned out are included (implying it's in the front end) and only with multiple modules.

Since this bug report involves multiple files and cannot be reproduced if they're all concatenated, I've temporarily added a zip file to the relevant project's Git repo, at https://github.com/dsimcha/dstats/blob/master/summaryLdc.zip . After unzipping, trying to compile bug.d gets the following results:

$ldmd2 -O5 bug.d
0 ldc2 0x0000000001004eaf
1 ldc2 0x0000000001005399
2 libpthread.so.0 0x00007f7ab8a33020
3 ldc2 0x000000000062beea aaGet(AA*, void_) + 26
4 ldc2 0x00000000006127dc BinExp::arrayOp(Scope_) + 364
5 ldc2 0x00000000006199cb ExpStatement::semantic(Scope_) + 27
6 ldc2 0x0000000000624ce4 CompoundStatement::semantic(Scope_) + 196
7 ldc2 0x000000000061c18b ForStatement::semantic(Scope_) + 251
8 ldc2 0x000000000061d1b6 ForeachRangeStatement::semantic(Scope_) + 854
9 ldc2 0x0000000000624ce4 CompoundStatement::semantic(Scope_) + 196
10 ldc2 0x00000000005e9c22 FuncDeclaration::semantic3(Scope_) + 2434
11 ldc2 0x0000000000630632 AttribDeclaration::semantic3(Scope_) + 66
12 ldc2 0x0000000000614c08 Module::semantic3(Scope*) + 88
13 ldc2 0x00000000005ce67c main + 7580
14 libc.so.6 0x00007f7ab7b07ead __libc_start_main + 253
15 ldc2 0x00000000005dda0d
Segmentation fault

ICE: postfix operation on typedef'd value

typedef const(ubyte)* cstring;

void main()
{
    cstring c;
    c++; // toir.cpp:1767: virtual DValue* PostExp::toElem(IRState*): Assertion `e2type->isintegral()' failed
//  --c; // Error: 'c' is not of arithmetic type, it is a cstring
}

Code Update to LLVM 3.0 set for branch tagging 2011/10/04

LLVM 3.0 is slated for branch tagging on 2011/10/04 and breaks the current build of ldc.

Taken from http://llvm.org/docs/ReleaseNotes.html

The way the type system works has been rewritten: PATypeHolder and OpaqueType? are gone, and all APIs deal with Type* instead of const Type*. If you need to create recursive structures, then create a named structure, and use setBody() when all its elements are built. Type merging and refining is gone too: named structures are not merged with other structures, even if their layout is identical. (of course anonymous structures are still uniqued by layout).

Currently Used here:

  • dmd/module.c:156: moduleInfoType = new llvm::PATypeHolder(llvm::OpaqueType::get(llvm::getGlobalContext()));
  • dmd/module.c:294: delete moduleInfoType;
  • dmd/module.h:205: llvm::PATypeHolder* moduleInfoType;
  • dmd2/module.c:217: moduleInfoType = new llvm::PATypeHolder(llvm::OpaqueType::get(llvm::getGlobalContext()));
  • dmd2/module.c:417: delete moduleInfoType;
  • dmd2/module.h:211: llvm::PATypeHolder* moduleInfoType;
  • gen/toobj.cpp:578: moduleInfoVar = new llvm::GlobalVariable(*gIR->module, moduleInfoType->get(), false, llvm::GlobalValue::ExternalLinkage, NULL, MIname);
  • gen/toobj.cpp:791: llvm::castllvm::OpaqueType(moduleInfoType->get())->refineAbstractTypeTo(constMI->getType());
  • gen/arrays.cpp:1455: const LLType *moduleInfoType = DtoType(Module::moduleinfo->type);
  • gen/arrays.cpp:1456: args.push_back(DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)));
  • gen/aa.cpp:112: const LLType *moduleInfoType = DtoType(Module::moduleinfo->type);
  • gen/aa.cpp:113: args.push_back(DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)));
  • gen/statements.cpp:1630: const LLType *moduleInfoType = DtoType(Module::moduleinfo->type);
  • gen/statements.cpp:1631: args.push_back(DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)));

[D1] Floating point exception compiling Tango

This line:
ldc -c -Itango/core -Itango/core/rt/compiler/ldc -I. -Itango/core/vendor -release -ofobjs/tango-util-digestWhirlpool-release.o tango/util/digest/Whirlpool.d

Produces the following error:

Program received signal SIGFPE, Arithmetic exception.
StringTable::search (this=0x1386a70, s=0x1569ae0 "_arraySliceSliceXorSliceAssign_m", len=32)
    at /home/mwarning/otherProjects/ldc/dmd/root/stringtable.c:72
72          u = hash % tabledim;
(gdb) bt
#0  StringTable::search (this=0x1386a70, s=0x1569ae0 "_arraySliceSliceXorSliceAssign_m", len=32)
    at /home/mwarning/otherProjects/ldc/dmd/root/stringtable.c:72
#1  0x0000000000598b0d in StringTable::update (this=<optimized out>, s=0x1569ae0 "_arraySliceSliceXorSliceAssign_m", len=32)
    at /home/mwarning/otherProjects/ldc/dmd/root/stringtable.c:111
#2  0x000000000059cf84 in BinExp::arrayOp (this=0x1569940, sc=0x1562920) at /home/mwarning/otherProjects/ldc/dmd/arrayop.c:132
#3  0x00000000005cb188 in VarDeclaration::semantic (this=0x1390510, sc=0x1562920) at /home/mwarning/otherProjects/ldc/dmd/declaration.c:1159
#4  0x00000000005b68ee in semantic (sc=0x1562840, this=0x13906a0) at /home/mwarning/otherProjects/ldc/dmd/expression.c:4431
#5  DeclarationExp::semantic (this=0x13906a0, sc=0x1562840) at /home/mwarning/otherProjects/ldc/dmd/expression.c:4405
#6  0x00000000005fe19b in ExpStatement::semantic (this=0x1390670, sc=0x1562840) at /home/mwarning/otherProjects/ldc/dmd/statement.c:260

Can't handle intrinsics with more than 1 parameter

Compiling core.bitop with LDC2 from llvm-3.1 branch results in following error message:

src\core\bitop.d: Error: module core.bitop Intrinsic prototype has incorrect number of arguments!
i64 (i64)* @llvm.cttz.i64
is_zero_undef argument of bit counting intrinsics must be a constant int
%tmp1 = call i64 @llvm.cttz.i64(i64 %tmp) nounwind readnone
Broken module found, compilation terminated.
Intrinsic prototype has incorrect number of arguments!
i64 (i64)* @llvm.ctlz.i64
is_zero_undef argument of bit counting intrinsics must be a constant int
%tmp1 = call i64 @llvm.ctlz.i64(i64 %tmp) nounwind readnone
Broken module found, compilation terminated.

Root cause seems to be that the cttz and ctlz intrinsics require 2 parameters but only one is passed. Adding the 2nd parameter results in a different error message. It seems that intrinsics with more than 1 parameter are not supported.

[Druntime] Build fail

build fail when druntime try to linl against ldc. The problem is quite simple, some file are rewritten and put in druntime/src/ldc/ like bitop.d so the build system need to ignore the "same file" in druntime/src/core/bitop.d.

What to do?
Edit cmake for ignore this module is exist in druntime/src/core/

maybe somethink like:

sed -i "78a \   list(REMOVE_ITEM CORE_D\n\
        \${RUNTIME_DIR}/src/core/bitop.d\n\
\   )" runtime/CMakeLists.txt

Multilib: 64 on 32

Apparently the build process for LDC with multilib enabled hard-codes building 32-bit multilibs. This is wrong if you want to cross-compile 64-bit binaries on a 32-bit system. When building multilib, the build process should check whether it's building 32- or 64-bit binaries in the native directory and do the opposite in the multilib directory.

"signal" C function makes ldc crash

The following minimal codesample makes ldc2 (latest master, i.e. b41688a) plain crash (SIGSEGV):

import core.stdc.signal;

extern(C) private void exitSignalHandler(int) { }

void main()
{
    signal(SIGINT, &exitSignalHandler);
}

it compiles well using dmd 2.057 frop d-p-l.org.

64-bit unions are not the same size as C language unions in some situations

Works on 32bit.

** C:

#include <stdio.h>
#include <stdlib.h>

union a {
  long double a1;
  char        ac[20];
};

int
main (int argc, char *argv[]) {
  union a a;
  printf ("C\n");
  printf ("sizeof a: %d\n", sizeof (a));
  printf ("sizeof a.a1: %d\n", sizeof (a.a1));
  printf ("sizeof a.ac: %d\n", sizeof (a.ac));
  printf ("offsetof a.ac: %d\n", (int) ((char *) &a.ac - (char *) &a.a1));
  return 0;
}

bll-desktop:bll$ cc -o x1c x1.c
bll-desktop:bll$ ./x1c
C
sizeof a: 32
sizeof a.a1: 16
sizeof a.ac: 20
offsetof a.ac: 0

** D2:

import std.stdio;

union ua {
  real     a1;
  char     ac[20];
};

int
main (string argv[]) {
  ua a;
  writefln ("D");
  writefln ("sizeof a: %d", a.sizeof);
  writefln ("sizeof a.a1: %d", a.a1.sizeof);
  writefln ("sizeof a.ac: %d", a.ac.sizeof);
  writefln ("offsetof a.ac: %d", a.ac.offsetof);
  return 0;
}

bll-desktop:bll$ ldc2 -d x1.d
bll-desktop:bll$ ./x1
D
sizeof a: 24
sizeof a.a1: 16
sizeof a.ac: 20
offsetof a.ac: 0

bll-desktop:bll$ ldc2 --version
LLVM D Compiler LDC trunk
based on DMD v2.052 and LLVM 2.9

** D1:

alias char[] string;
import io.Stdout;

union ua {
  real     a1;
  char     ac[20];
};

int
main (string argv[]) {
  ua a;
  Stdout ("D1\n");
  Stdout ("sizeof a: ", a.sizeof, "\n");
  Stdout ("sizeof a.a1: ", a.a1.sizeof, "\n");
  Stdout ("sizeof a.ac: ", a.ac.sizeof, "\n");
  Stdout ("offsetof a.ac: ", a.ac.offsetof, "\n");
  return 0;
}

bll-desktop:bll$ ldc x2.d
bll-desktop:bll$ ./x2
D1
sizeof a: , 24,
sizeof a.a1: , 16,
sizeof a.ac: , 20,
offsetof a.ac: , 0,

bll-desktop:bll$ ldc --version
LLVM D Compiler LDC trunk
based on DMD v1.067 and LLVM 2.9

I used (9/18/2011), though this bug is still extant:

hg clone 'https://bitbucket.org/lindquist/ldc'

git clone 'https://github.com/AlexeyProkhin/phobos'

git clone 'https://github.com/AlexeyProkhin/druntime'

svn co 'http://svn.dsource.org/projects/tango/tags/releases/0.99.9' tango

patch -p0 -d tango/ < tango-0.99.9.patch

ICE on local import + -O3

It doesn't seem to matter what module gets imported. All that is necessary to reproduce this bug is an import statement inside main().

void main() {
    import core.stdc.stdlib;
}

ldc2: /home/dsimcha/ldcStuff/ldc/dmd2/module.c:1017: virtual void Module::semantic3(Scope*): Assertion `semanticstarted == 2' failed.
0 ldc2 0x0000000001004ebf
1 ldc2 0x00000000010053a9
2 libpthread.so.0 0x00007f4e55895020
3 libc.so.6 0x00007f4e5497d405 gsignal + 53
4 libc.so.6 0x00007f4e54980680 abort + 384
5 libc.so.6 0x00007f4e549765b1 __assert_fail + 241
6 ldc2 0x0000000000614c57
7 ldc2 0x00000000005ce67c main + 7580
8 libc.so.6 0x00007f4e54969ead __libc_start_main + 253
9 ldc2 0x00000000005dda0d
Aborted

scasw opcode not accepted in inline assembler in 64 bit mode

On X86_64 platform with -m64 command line switch the scasw assembler opcode is not accepted.
The error message is:
Error: unknown opcode 'scasw'

Both DMD and GDC accept the scasw opcode (the code produced by these is 0x66 0xaf).

Version:
LLVM D Compiler LDC trunk
based on DMD v2.057 and LLVM 3.0

Platform is Linux 3.1.5-6.fc16.x86_64
Compiled with gcc version 4.6.2 20111027

backend is not a component name of llvm-config in LLVM 3.1+

With commit r143548 (2011-11-02), support for the pseudo component 'backend' was dropped from llvm-config. Currently, CMakeLists.txt produces an error message. The resulting makefile lacks important LLVM libraries. (This applies to the llvm3.0 branch.)

Quick fix is to replace all component names with all, but this may not be the best solution.

Atomic Increment Broken, Breaks std.parallelism

import core.atomic;

void main() {
    ulong u;
    atomicOp!"+="(u, 1);
}

/home/dsimcha/apps/include/d/core/atomic.di(165): Error: cannot implicitly convert expression (here) of type shared(ulong)* to ulong*
/home/dsimcha/apps/include/d/core/atomic.di(112): Error: template instance core.atomic.cas!(ulong,ulong,ulong) error instantiating
instantiatied in test2.d(5): atomicOp!("+=",ulong,int)
test2.d(5): Error: template instance core.atomic.atomicOp!("+=",ulong,int) error instantiating

This breaks std.parallelism.

Build Errors

Using LLVM 2.9 and GCC 4.4.3, trying to build LDC2 trunk:

{{{
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp: In member function ‘bool ConfigFile::read(const char_, void_, const char*)’:
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:117: error: invalid use of incomplete type ‘struct libconfig::Config’
/home/dsimcha/ldcStuff/ldc/./gen/configfile.h:9: error: forward declaration of ‘struct libconfig::Config’
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:120: error: invalid use of incomplete type ‘struct libconfig::Config’
/home/dsimcha/ldcStuff/ldc/./gen/configfile.h:9: error: forward declaration of ‘struct libconfig::Config’
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:125: error: ‘Setting’ is not a member of ‘libconfig’
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:125: error: ‘root’ was not declared in this scope
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:125: error: invalid use of incomplete type ‘struct libconfig::Config’
/home/dsimcha/ldcStuff/ldc/./gen/configfile.h:9: error: forward declaration of ‘struct libconfig::Config’
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:137: warning: ‘llvm::StringRef llvm::sys::Path::getDirname() const’ is deprecated (declared at /home/dsimcha/apps/include/llvm/Support/PathV1.h:283)
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:139: error: ‘Setting’ is not a member of ‘libconfig’
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:139: error: ‘arr’ was not declared in this scope
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:139: error: invalid use of incomplete type ‘struct libconfig::Config’
/home/dsimcha/ldcStuff/ldc/./gen/configfile.h:9: error: forward declaration of ‘struct libconfig::Config’
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:155: error: expected type-specifier
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:155: error: expected unqualified-id before ‘&’ token
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:155: error: expected ‘)’ before ‘&’ token
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:155: error: expected ‘{’ before ‘&’ token
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:155: error: ‘fioe’ was not declared in this scope
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:155: error: expected ‘;’ before ‘)’ token
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:160: error: expected primary-expression before ‘catch’
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:160: error: expected ‘;’ before ‘catch’
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:166: error: expected primary-expression before ‘catch’
/home/dsimcha/ldcStuff/ldc/gen/configfile.cpp:166: error: expected ‘;’ before ‘catch’
}}}

Both operands to a binary operator are not of the same type!

on fedora 16 x86_64, I compile me some code like so:

ldc2 dis.d ~/mercurial/my-deimos/wrapper/udis86.d -op -oq -of dis ~/mercurial/my-deimos/deimos/udis86.d

and for my labors, I am rewarded with err.. this:

mercurial/my-deimos/deimos/udis86.d: Error: module deimos.udis86 Both operands to a binary operator are not of the same type!
%tmp7 = or i8 %tmp6, i32 1
Instruction does not dominate all uses!
%tmp7 = or i8 %tmp6, i32 1
store i8 %tmp7, i8* %tmp5
Both operands to a binary operator are not of the same type!
%tmp12 = and i8 %tmp11, i32 -2
Instruction does not dominate all uses!
%tmp12 = and i8 %tmp11, i32 -2
store i8 %tmp12, i8* %tmp10
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Both operands to a binary operator are not of the same type!
%tmp7 = or i8 %tmp6, i32 2
Instruction does not dominate all uses!
%tmp7 = or i8 %tmp6, i32 2
store i8 %tmp7, i8* %tmp5
Both operands to a binary operator are not of the same type!
%tmp12 = and i8 %tmp11, i32 -3
Instruction does not dominate all uses!
%tmp12 = and i8 %tmp11, i32 -3
store i8 %tmp12, i8* %tmp10
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Both operands to a binary operator are not of the same type!
%tmp7 = or i8 %tmp6, i32 4
Instruction does not dominate all uses!
%tmp7 = or i8 %tmp6, i32 4
store i8 %tmp7, i8* %tmp5
Both operands to a binary operator are not of the same type!
%tmp12 = and i8 %tmp11, i32 -5
Instruction does not dominate all uses!
%tmp12 = and i8 %tmp11, i32 -5
store i8 %tmp12, i8* %tmp10
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Both operands to a binary operator are not of the same type!
%tmp7 = or i8 %tmp6, i32 8
Instruction does not dominate all uses!
%tmp7 = or i8 %tmp6, i32 8
store i8 %tmp7, i8* %tmp5
Both operands to a binary operator are not of the same type!
%tmp12 = and i8 %tmp11, i32 -9
Instruction does not dominate all uses!
%tmp12 = and i8 %tmp11, i32 -9
store i8 %tmp12, i8* %tmp10
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Both operands to a binary operator are not of the same type!
%tmp7 = or i8 %tmp6, i32 16
Instruction does not dominate all uses!
%tmp7 = or i8 %tmp6, i32 16
store i8 %tmp7, i8* %tmp5
Both operands to a binary operator are not of the same type!
%tmp12 = and i8 %tmp11, i32 -17
Instruction does not dominate all uses!
%tmp12 = and i8 %tmp11, i32 -17
store i8 %tmp12, i8* %tmp10
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.
Broken module found, compilation terminated.

Access violation

they are a problem around private var, below code:

private import std.array    : split;
private import std.stdio    : writeln;
private import std.string   : format, stripLeft, stripRight;

class Container{
    private:
        string[string] dict;
        string name;
    this( string name ){
        this.name = name;
        this.dict = dict;
    }
}
void main( string[] args ){
    string[]words = split(cast(string)"key=value", "=");
    foreach( ref string word; words )
        word.stripRight().stripLeft();

    Container c = new Container("test");
    c.dict[words[0]] = words[1];
    writeln( "strange access to private var!!!" );
    writeln( c.dict );
    writeln( c.dict["key"] );
    writeln( c.dict.keys );
}

poduce this output:

$ ldc2 test.d
$ ./test
strange access to private var!!!
["key":"value"]
value
["key"]

Error: invalid cast from 'typeof(null)' to 'void*'

I receive the following error message in the middle of compiling a large library:

Error: invalid cast from 'typeof(null)' to 'void*'

The line number reported by LDC is probably wrong, because there's nothing on that line that seems relevant. Therefore, I've got DustMite churning away on this one, but I decided to file the bug report before I had fully reduced it because it seems like the kind of thing where the fix might be obvious to someone who knows the implementation details of the compiler even w/o a test case.

invalid memory read in gc

Compiling an empty D2 program (void main() {}) using ldc2 master (ldc b41688a, druntime v2.054-226-g10e4512 and phobos v2.054-844-g1f6264e) and then running it through valgrind gives me an invalid read, conditional jump depending on uninit value and 5 leaks. (for details: http://pastebin.com/sEfnqUdd).

Compiling the same program with the dmd 2.057 from d-p-l.org and running it through valgrind gives no invalid read or conditional jump depending on uninit value and only 4 memory leaks, which are included in the 5 from ldc2. The one which happens only if using ldc2 is #2.

line 2280 in gcx.d (which is the offending line) contains the following code:
auto p = cast(byte _)(_p1);

and the conditional jump depending on uninit value is most probably just a subsequent error which will go away when the invalid read is solved.

pompei2: Looks like one of the GC root ranges our druntime uses is off, thus producing an invalid read. Don't know off-hand if this is a bug, though [...]

Null pointer deref in _d_arrayappendcTp with multithreaded code

GDC has basically the same bug, but DMD appears not to have this issue. It could be that druntime is doing something that's thread unsafe given certain compiler optimizations, but DMD doesn't do those optimizations.

import core.thread;

void main() {
    auto t = new Thread(&doIt);
    t.start();
    doIt();
}

void doIt() {
    while(1) {
        int[] arr1, arr2;
        double[] arr3;

        foreach(i; 0..10_000) {
            arr1 ~= 1;
            arr2 ~= 2;
            arr3 ~= 3;
        }
    }
}

GDB gives the following info:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000429abd in _d_arrayappendcTX (ti=0x444940, n=1) at lifetime.d:1754
1754                    if(*(cast(size_t*)info.base) == size + offset)
(gdb) bt
#0  0x0000000000429abd in _d_arrayappendcTX (ti=0x444940, n=1) at lifetime.d:1754
#1  0x00000000004020e2 in _D4test4doItFZv ()
#2  0x0000000000402043 in _Dmain ()
#3  0x000000000043542f in _D2rt6dmain24mainUiPPaZi7runMainMFZv () at dmain2.d:513
#4  0x00000000004353aa in _D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv () at dmain2.d:488
#5  0x0000000000435487 in _D2rt6dmain24mainUiPPaZi6runAllMFZv () at dmain2.d:526
#6  0x00000000004353aa in _D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv () at dmain2.d:488
#7  0x0000000000435315 in main (argc=1, argv=0x7fffffffe508) at /cis/home/dsimcha/ldcStuff/ldc/.:536
(gdb) info registers
rax            0x0      0
rbx            0x0      0
rcx            0xffffffcf       4294967247
rdx            0xe054   57428
rsi            0x7ffff6726a74   140737328081524
rdi            0x10     16
rbp            0x7fffffffe200   0x7fffffffe200
rsp            0x7fffffffe010   0x7fffffffe010
r8             0x0      0
r9             0x229c   8860
r10            0x200000002      8589934594
r11            0x200000002      8589934594
r12            0x401ef0 4202224
r13            0x7fffffffe500   140737488348416
r14            0x0      0
r15            0x0      0
rip            0x429abd 0x429abd <_d_arrayappendcTX+541>
eflags         0x10206  [ PF IF RF ]
cs             0x33     51
ss             0x2b     43
ds             0x0      0
es             0x0      0
fs             0x0      0
gs             0x0      0

And the instruction that the segfault occurs on is:

=> 0x0000000000429abd <+541>: cmp %rsi,(%rax)

So, since rax is zero, it's a null pointer deref.

Assertion `!isaStruct(t)`

// gtkwrapper.d
module plot2kill.gtkwrapper;

import std.conv;
import plot2kill.figure;

class FigureBase { }

class MenuItem {
    this(void delegate(MenuItem) dg, string s) {}
}

class DefaultPlotWindow {
    void buildRightClickMenu() {
        new MenuItem(&popupTickDialog!'y', "_Y Ticks...");
    }

    void popupTickDialog(char xy)(MenuItem menuItem) {
        double[] locations;
        try   locations = to!(double[])(["1.0"]);
        catch(Exception) {}
    }
}

 // figure.d:
 module plot2kill.figure;

 public import plot2kill.gtkwrapper;
 class Figure : FigureBase {}

dsimcha@debian:~/dustmitePlot2kill/plot2kill$ ldc2 -c -O3 figure.d -I..
ldc2: /home/dsimcha/ldcStuff/ldc/gen/tollvm.cpp:656: llvm::Value* DtoBitCast(llvm::Value_, llvm::Type_, const char_): Assertion `!isaStruct(t)' failed.
0 ldc2 0x000000000100a78f
1 ldc2 0x000000000100ac79
2 libpthread.so.0 0x00007f805f88e020
3 libc.so.6 0x00007f805e976405 gsignal + 53
4 libc.so.6 0x00007f805e979680 abort + 384
5 libc.so.6 0x00007f805e96f5b1 assert_fail + 241
6 ldc2 0x0000000000722e6d
7 ldc2 0x00000000006ad108
8 ldc2 0x00000000006af32d DtoCallFunction(Loc&, Type
, DValue
, ArrayBase) + 3469
9 ldc2 0x00000000006d736c CallExp::toElem(IRState
) + 412
10 ldc2 0x00000000007020a7 DtoArgument(Parameter_, Expression_) + 71
11 ldc2 0x00000000006af1dd DtoCallFunction(Loc&, Type_, DValue_, ArrayBase) + 3133
12 ldc2 0x00000000006f7c4b DtoNewClass(Loc, TypeClass
, NewExp_) + 491
13 ldc2 0x00000000006da4a8 NewExp::toElem(IRState_) + 1096
14 ldc2 0x00000000006d3504 Expression::toElemDtor(IRState_) + 68
15 ldc2 0x00000000007285c8 ReturnStatement::toIR(IRState_) + 1016
16 ldc2 0x000000000072819e CompoundStatement::toIR(IRState_) + 94
Aborted

-shared do not set a SONAME

hi,
After check with:

$ objdump libGreatLib.so -p | grep SONAME

I have seen that -shared must put a soname! and use a versionned lib should be better
$libname.$libext.$version

I have tried to do

$ ldc2 -shared foo.d -L-Wl-soname,libfoo.so.1

this generate a .so whithout error but without soname too!!

ldc2 SEGFAULT for linux x86_64

In first install on your system derelict:

$ svn export -r 591 http://svn.dsource.org/projects/derelict/branches/Derelict2 derelict-20111031svn591
$ mv inc/ldc_inc.mak inc/ldc2_inc.mak
$ find . -name "Makefile" | xargs sed -i "s/ldc_build/ldc2_build/g"
$ make  -f linux.mak DC=ldc2 DFLAGS="-w -g -O2"   DerelictAL_ALL DerelictAllegro_ALL  DerelictFT_ALL DerelictFT  DerelictGL_ALL DerelictIL_ALL DerelictODE_ALL DerelictOgg_ALL DerelictPA_ALL DerelictSDL_ALL DerelictSFML_ALL DerelictUtil_ALL

copy lib and include file to right dir

now take this project:

$ hg clone https://bitbucket.org/dav1d/gljm

And try to build

$ make DC=ldc2

ldc segfault for this command

$ gdb --args ldc2  -m64 -L-lDerelictGL -L-lDerelictUtil -I"src" -I"gljm" -d -c gljm/parser/ply.d -ofgljm/parser/ply.o

you can see exit status with

$ echo $?
1

D Doc

they are a way to add extra information in generated html ?
cuurrent:

<dt><big>template <u>reduce</u>(fun...) if (fun.length &gt;= 1)</big></dt>

request:

<dt class="template" >template <u>reduce</u>(fun...) if (fun.length &gt;= 1)</dt>

Error: unknown opcode 'movsq'

I get the message "src\rt\alloca.d(194): Error: unknown opcode 'movsq'" while compiling alloca.d on x86_64-pc-win32. The opcode string is there, but not found using binary search.

Solution: move the definition of the opcode in gen\asm-x86-64.c, line 1018, 2 lines down to get the correct sort order.

Forward Reference Issues

// a.d
import b;
// b.d
import hash;

void fun() {
    alias StackSet!(string) SS;
}
// hash.d
struct HashRange(K, S, ) {
    size_t _length;

    this(S* set) {
        this._length = set.length;
    }
}


struct StackSet(K) {
    HashRange!(K, typeof(this)) elems() {
        assert(0);
    }

    @property size_t length() {
        assert(0);
    }
}

Build command/result:

$ ldc2 -O3 -c a.d
hash.d(11): Error: struct hash.StackSet!(string).StackSet no size yet for forward reference
hash.d(5): Error: cannot implicitly convert expression ((*set).length()) of type size_t to ulong
hash.d(13): Error: template instance hash.HashRange!(string,StackSet!(string)) error instantiating
instantiatied in b.d(4): StackSet!(string)
b.d(4): Error: template instance hash.StackSet!(string) error instantiating

Runtime is not automatically built before installation, but make install fails without it being present

If I don't manually build the runtime before installing, this happens:

$ make install
[  0%] Built target idgen
[  0%] Built target impcnvgen
[100%] Built target ldc2
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/bin/ldc2
-- Up-to-date: /usr/local/bin/ldmd2
-- Installing: /usr/local/etc/ldc2.conf
-- Installing: /usr/local/etc/ldc2.rebuild.conf
CMake Error at cmake_install.cmake:63 (FILE):
  file INSTALL cannot find "/Build/Work/ldc2/runtime/import/core".

This is not quite optimal from an usability point of view. As far as I know, installation dependencies for CMake are so easy to specify – is there any reason not to build the runtime as part of the default make target? @bioinfornatics?

Bad/No Dead Code Elimination

LDC and/or the linker options it uses do a terrible job of eliminating dead code. This results in two annoying problems:

  1. Linker undefined reference errors for symbols that are only referred to from dead code.
  2. Huge binaries.

Example:

// lib/file1.d:
int doNothing();

void callDoNothing() {
    doNothing();
}

// lib/file2.d:
module lib.file2;

import std.stdio;

void sayHello() {
    writeln("Hello, world.");
}

// main.d:
import lib.file2;

void main() {
    sayHello();
}

$ ldmd2 -lib -ofliblib.a lib/*.d
$ ldmd2 main.d -Lliblib.a
liblib.a(liblib.o): In function _D5file113callDoNothingFZv': file1:(.text+0x2): undefined reference to_D5file19doNothingFZi'
collect2: ld returned 1 exit status
Error: linking failed:
status: 1

When I do the same thing with GDC or DMD, the linker recognizes that doNothing() is only referred to from dead code, doesn't complain about the fact that the reference isn't defined, and presumably removes the dead code referring to doNothing() from the executable.

Illegal instruction

// test.d:
void fun(const string[] arr) {
    byte[0][string] keep;
    foreach(elem; arr) keep[elem] = (byte[0]).init;
}

void main() {
    fun(["a", "b"]);
}

$ ldc2 -O test.d && ./test
Illegal instruction

This is caused by the illegal ud2 instruction being emitted at the end of fun. Here's the disassembly of this function:

_D4test3funFxAAyaZv PROC
        sub     rsp, 24                                 ; 0000 _ 48: 83. EC, 18
        mov     qword ptr [rsp+10H], 0                  ; 0004 _ 48: C7. 44 24, 10, 00000000
        test    rdi, rdi                                ; 000D _ 48: 85. FF
        jz      ?_001                                   ; 0010 _ 74, 2A
        mov     rax, qword ptr [rsi]                    ; 0012 _ 48: 8B. 06
        mov     rcx, qword ptr [rsi+8H]                 ; 0015 _ 48: 8B. 4E, 08
        mov     qword ptr [rsp+8H], rcx                 ; 0019 _ 48: 89. 4C 24, 08
        mov     qword ptr [rsp], rax                    ; 001E _ 48: 89. 04 24
        lea     rdi, [rsp+10H]                          ; 0022 _ 48: 8D. 7C 24, 10
        lea     rcx, [rsp]                              ; 0027 _ 48: 8D. 0C 24
        mov     esi, offset _D12TypeInfo_Aya6__initZ    ; 002B _ BE, 00000000(d)
        mov     edx, 1                                  ; 0030 _ BA, 00000001
        call    _aaGetX                                 ; 0035 _ E8, 00000000(rel)
        ud2                                             ; 003A _ 0F 0B

?_001:  add     rsp, 24                                 ; 003C _ 48: 83. C4, 18
        ret                                             ; 0040 _ C3
_D4test3funFxAAyaZv ENDP

Multilib

As far as I can tell, there's no multiarch/multilib build option that compiles Phobos and druntime as both 32- and 64-bit and installs them in the proper paths based on this designation. In DMD, the binaries ship with both 32- and 64-bit Phobos/druntime pre-built. When building GDC, both are built automatically if --enable-multilib is used. I want to be able to do something like:

ldc2 hello.d  # Default, 64-bit on 64-bit machine
ldc2 hello.d -m32  # 32-bit, automatically links w/ 32-bit Phobos and druntime

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.