From cc17c56855fe90193635d16577e1be475b5c555f Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 20 Oct 2017 10:57:14 -0500 Subject: [PATCH 001/141] MAINT: include win32 headers --- lib/scutil/lockfile.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/scutil/lockfile.c b/lib/scutil/lockfile.c index 27681137a79..fea20f16a6f 100644 --- a/lib/scutil/lockfile.c +++ b/lib/scutil/lockfile.c @@ -43,7 +43,11 @@ * Clean up by deleting the uniquely named file we had created earlier. */ -#include +#ifdef _WIN32 + #include +#else + #include +#endif #include #include #include From 4fba3416628799c28d1d28f052e4a5bd5e1a867d Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 20 Oct 2017 11:21:11 -0500 Subject: [PATCH 002/141] ENH: allow getcpu to work on windows --- lib/scutil/cpu-stopwatch.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/scutil/cpu-stopwatch.c b/lib/scutil/cpu-stopwatch.c index a2ea16a5182..b738ee6d7b9 100644 --- a/lib/scutil/cpu-stopwatch.c +++ b/lib/scutil/cpu-stopwatch.c @@ -21,6 +21,8 @@ * since the most recent call. Very much not thread-safe. */ +#ifndef _WIN32 + #include #include #include "scutil.h" @@ -51,3 +53,33 @@ getcpu(void) last = now; return elapsed; } + +#else + +#include +#include "scutil.h" + +unsigned long +getcpu(void) +{ + LARGE_INTEGER ticks_per_second = -1; + LARGE_INTEGER ticks; + + unsigned long last = 0; + unsigned long now, elapsed; + + /* Initialize ticks_per_second. */ + if (ticks_per_second.QuadPart <= 0) + QueryPerformanceFrequency(&ticks_per_second.QuadPart); + + QueryPerformanceCounter(&ticks); + now = ticks.QuadPart; + now *= 1000; /* milliseconds */ + now /= ticks_per_second.QuadPart; + + elapsed = now - last; + last = now; + return elapsed; +} + +#endif From c60f68087b4143b682eeb423d02ffd3c85240259 Mon Sep 17 00:00:00 2001 From: Fernando Date: Sat, 21 Oct 2017 06:26:17 -0700 Subject: [PATCH 003/141] Windows Fixes --- CMakeLists.txt | 32 ++++++++++------ include/legacy-util-api.h | 2 + lib/scutil/cpu-stopwatch.c | 4 +- lib/scutil/host-fp-folding.c | 2 +- lib/scutil/lockfile.c | 6 ++- lib/scutil/path-utils.c | 2 + lib/scutil/pgnewfil.c | 11 ++++-- runtime/flang/CMakeLists.txt | 15 ++++++-- runtime/flangrti/CMakeLists.txt | 17 +++++--- runtime/flangrti/cacos.c | 4 ++ runtime/flangrti/casin.c | 4 ++ runtime/flangrti/catan.c | 4 ++ runtime/flangrti/ccosh.c | 4 ++ runtime/flangrti/cdacos.c | 4 ++ runtime/flangrti/cdasin.c | 4 ++ runtime/flangrti/cdatan.c | 4 ++ runtime/flangrti/cdcosh.c | 4 ++ runtime/flangrti/cdsinh.c | 4 ++ runtime/flangrti/cdtan.c | 4 ++ runtime/flangrti/cdtanh.c | 4 ++ runtime/flangrti/csinh.c | 4 ++ runtime/flangrti/ctan.c | 4 ++ runtime/flangrti/ctanh.c | 4 ++ runtime/flangrti/iostdinit.c | 16 +++++--- runtime/flangrti/trace_lin.c | 9 ++++- runtime/flangrti/x86_64-Linux/dumpregs.c | 4 +- runtime/include/mthdecls.h | 49 +++++++----------------- runtime/include/stdioInterf.h | 2 + runtime/ompstub/CMakeLists.txt | 4 ++ tools/flang1/flang1exe/CMakeLists.txt | 6 ++- tools/flang2/flang2exe/CMakeLists.txt | 8 +++- 31 files changed, 168 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d22b2ef62d..0e298e403e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,16 +21,17 @@ cmake_minimum_required(VERSION 2.8) # In order to bootstrap the runtime library we need to skip # CMake's Fortran tests SET(CMAKE_Fortran_COMPILER_WORKS 1) +set(CMAKE_Fortran_PREPROCESS_SOURCE + " -Mpreprocess -E -o ") -if( NOT DEFINED TARGET_ARCHITECTURE ) - execute_process(COMMAND uname -m OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE TARGET_ARCHITECTURE) +# If we are not building as a part of LLVM, build Flang as an +# standalone project, using LLVM as an external library: +if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Flang) endif() -if( NOT DEFINED TARGET_OS ) - execute_process(COMMAND uname -s OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE TARGET_OS) -endif() +set(TARGET_OS ${CMAKE_HOST_SYSTEM_NAME}) +set(TARGET_ARCHITECTURE ${CMAKE_HOST_SYSTEM_PROCESSOR}) if( ${TARGET_OS} STREQUAL "Linux" ) set(OS "LINUX") @@ -51,16 +52,23 @@ if( ${TARGET_OS} STREQUAL "Linux" ) message("Unsupported architecture: ${TARGET_ARCHITECTURE}" ) return() endif() +elseif(${TARGET_OS} STREQUAL "Windows" ) + set(OS "WINDOWS") + set(OSNAME "Windows") + if( ${TARGET_ARCHITECTURE} STREQUAL "AMD64" ) + set(TARGET_ARCHITECTURE "x86_64") + set(ARCHNAME x86-64) + set(ARCH X86) + set(WRDSZ 64) + else() + message("Unsupported architecture: ${TARGET_ARCHITECTURE}" ) + return() + endif() else() message("Unsupported OS: ${TARGET_OS}" ) return() endif() -# The cmake documentation states that these are set. They are not so we -# set them here -set(CMAKE_HOST_SYSTEM_NAME ${TARGET_OS}) -set(CMAKE_HOST_SYSTEM_PROCESSOR ${TARGET_ARCHITECTURE}) - # If we are not building as a part of LLVM, build Flang as an # standalone project, using LLVM as an external library: if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) diff --git a/include/legacy-util-api.h b/include/legacy-util-api.h index f4fa9a261a2..e30530c5739 100644 --- a/include/legacy-util-api.h +++ b/include/legacy-util-api.h @@ -41,7 +41,9 @@ extern "C" { #include #include #include /* time() */ +#ifndef _WIN32 #include /* getcwd() */ +#endif /* See tmpfile(3). */ FILE *tmpf(char *ignored); diff --git a/lib/scutil/cpu-stopwatch.c b/lib/scutil/cpu-stopwatch.c index b738ee6d7b9..95b6755e605 100644 --- a/lib/scutil/cpu-stopwatch.c +++ b/lib/scutil/cpu-stopwatch.c @@ -57,12 +57,12 @@ getcpu(void) #else #include -#include "scutil.h" +//#include "scutil.h" unsigned long getcpu(void) { - LARGE_INTEGER ticks_per_second = -1; + LARGE_INTEGER ticks_per_second = {-1}; LARGE_INTEGER ticks; unsigned long last = 0; diff --git a/lib/scutil/host-fp-folding.c b/lib/scutil/host-fp-folding.c index 50e48047bdf..cd03bb7b57a 100644 --- a/lib/scutil/host-fp-folding.c +++ b/lib/scutil/host-fp-folding.c @@ -81,7 +81,7 @@ configure_denormals(bool denorms_are_zeros, bool flush_to_zero) fenv_t fenv; if (fegetenv(&fenv) != 0) fprintf(stderr, "fegetenv() failed: %s\n", strerror(errno)); -#ifdef __x86_64__ +#if defined(__x86_64__) && !defined(_WIN32) fenv.__mxcsr &= ~0x0040; if (denorms_are_zeros) fenv.__mxcsr |= 0x0040; diff --git a/lib/scutil/lockfile.c b/lib/scutil/lockfile.c index fea20f16a6f..70dc41d52b4 100644 --- a/lib/scutil/lockfile.c +++ b/lib/scutil/lockfile.c @@ -43,10 +43,11 @@ * Clean up by deleting the uniquely named file we had created earlier. */ -#ifdef _WIN32 +#ifndef _WIN32 #include #else #include + #include #endif #include #include @@ -68,6 +69,9 @@ static char *udir = NULL; */ static long uwaiting; +#ifdef _WIN32 +#define pid_t int +#endif int __pg_make_lock_file(char *dir) { diff --git a/lib/scutil/path-utils.c b/lib/scutil/path-utils.c index ca4c8c72074..cadbdac696c 100644 --- a/lib/scutil/path-utils.c +++ b/lib/scutil/path-utils.c @@ -23,7 +23,9 @@ #include "legacy-util-api.h" #include #include +#ifndef _WIN32 #include /* access() */ +#endif void basenam(const char *orig_path, const char *optional_suffix, char *basename) diff --git a/lib/scutil/pgnewfil.c b/lib/scutil/pgnewfil.c index e198d33ef4e..590c678ed75 100644 --- a/lib/scutil/pgnewfil.c +++ b/lib/scutil/pgnewfil.c @@ -29,9 +29,10 @@ #include #include -#if defined(HOST_WIN) +#if defined(_WIN32) #include #include +#include extern unsigned long getpid(void); #else #include @@ -42,6 +43,10 @@ int pgnewfil_debug = 0; #endif extern size_t strlen(); +#ifndef S_ISDIR +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#endif + /* * copy chars from q to p, terminate string, return end of string */ @@ -307,7 +312,7 @@ pg_makenewfile(char *pfx, char *sfx, int make) if (!make) { break; } else { -#if defined(HOST_WIN) +#if defined(_WIN32) fd = _open(filename, _O_CREAT | _O_BINARY | _O_EXCL | _O_RDWR, _S_IWRITE); #else fd = open(filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR); @@ -353,7 +358,7 @@ pg_makenewdir(char *pfx, char *sfx, int make) if (r == -1 && errno == ENOENT) { if (make) { int err; -#if defined(HOST_WIN) || defined(WINNT) || defined(WIN64) +#if defined(_WIN32) || defined(WINNT) || defined(WIN64) err = _mkdir(filename); #else err = mkdir(filename, S_IRWXG | S_IRWXO | S_IXUSR | S_IWUSR | S_IRUSR); diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 2cd90370da0..dc29e565e68 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -480,7 +480,12 @@ add_flang_library(flang_static ${FTN_SUPPORT} ${SHARED_SOURCES} ) + +if (MSVC) +set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang_static) +else() set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang) +endif() set(SHARED_LIBRARY TRUE) add_flang_library(flang_shared @@ -489,9 +494,12 @@ add_flang_library(flang_shared ${SHARED_SOURCES} ) set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang) -target_link_libraries(flang_shared ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/libflangrti.so) +target_link_libraries(flang_shared flangrti_shared) # Resolve symbols against libm and librt -target_link_libraries(flang_shared m rt) +target_link_libraries(flang_shared rt) +if (NOT MSVC) +target_link_libraries(flang_shared m) +endif() set(SHARED_LIBRARY FALSE) @@ -523,6 +531,7 @@ set_property( ## CMake does not handle module dependencies between Fortran files, ## we need to help it +if (NOT MSVC) # State the module that the source is producing set_source_files_properties( iso_c_bind.F95 @@ -537,7 +546,7 @@ set_source_files_properties( PROPERTIES OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod ) - +endif() set_target_properties(flang_static flang_shared PROPERTIES diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index 8688642cf44..0bc427e749b 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -179,7 +179,11 @@ add_flang_library(flangrti_static ${PGC_SRC_FILES} ${SHARED_SOURCES} ) -set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME flangrti) +if (MSVC) + set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME flangrti_static) +else() + set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME flangrti) +endif() set(SHARED_LIBRARY TRUE) @@ -189,16 +193,19 @@ add_flang_library(flangrti_shared ) # Resolve symbols against libm -target_link_libraries(flangrti_shared m) + +if (NOT MSVC) +target_link_libraries(flangrti_shared m) +endif() # Import OpenMP -if (NOT DEFINED LIBOMP_EXPORT_DIR) +#if (NOT DEFINED LIBOMP_EXPORT_DIR) find_library( FLANG_LIBOMP - libomp.so + libomp HINTS ${CMAKE_BINARY_DIR}/lib) target_link_libraries(flangrti_shared ${FLANG_LIBOMP}) -endif() +#endif() if( ${TARGET_ARCHITECTURE} STREQUAL "aarch64" ) target_compile_definitions(flangrti_static PRIVATE TARGET_LINUX_ARM) diff --git a/runtime/flangrti/cacos.c b/runtime/flangrti/cacos.c index ce0bb89090d..48a11054d20 100644 --- a/runtime/flangrti/cacos.c +++ b/runtime/flangrti/cacos.c @@ -23,7 +23,11 @@ CMPLXFUNC_C(__mth_i_cacos) { CMPLXARGS_C; + #ifndef _WIN32 complex float f = real + imag * I; + #else + _Fcomplex f = {real, imag}; + #endif f = CACOSF(f); CRETURN_C(f); } diff --git a/runtime/flangrti/casin.c b/runtime/flangrti/casin.c index 35fe17f5c6a..b99a6e38248 100644 --- a/runtime/flangrti/casin.c +++ b/runtime/flangrti/casin.c @@ -23,7 +23,11 @@ CMPLXFUNC_C(__mth_i_casin) { CMPLXARGS_C; + #ifndef _WIN32 complex float f = real + imag * I; + #else + _Fcomplex f = {real, imag}; + #endif f = CASINF(f); CRETURN_C(f); } diff --git a/runtime/flangrti/catan.c b/runtime/flangrti/catan.c index 981447f5b45..17d2ec0ed0e 100644 --- a/runtime/flangrti/catan.c +++ b/runtime/flangrti/catan.c @@ -23,7 +23,11 @@ CMPLXFUNC_C(__mth_i_catan) { CMPLXARGS_C; + #ifndef _WIN32 complex float f = real + imag * I; + #else + _Fcomplex f = {real, imag}; + #endif f = CATANF(f); CRETURN_C(f); } diff --git a/runtime/flangrti/ccosh.c b/runtime/flangrti/ccosh.c index 3f7b93c1d87..efb5f6e67a1 100644 --- a/runtime/flangrti/ccosh.c +++ b/runtime/flangrti/ccosh.c @@ -23,7 +23,11 @@ CMPLXFUNC_C(__mth_i_ccosh) { CMPLXARGS_C; + #ifndef _WIN32 complex float f = real + imag * I; + #else + _Fcomplex f = {real, imag}; + #endif f = CCOSHF(f); CRETURN_C(f); } diff --git a/runtime/flangrti/cdacos.c b/runtime/flangrti/cdacos.c index 797b392ea78..4347b9a16f5 100644 --- a/runtime/flangrti/cdacos.c +++ b/runtime/flangrti/cdacos.c @@ -23,7 +23,11 @@ ZMPLXFUNC_Z(__mth_i_cdacos) { ZMPLXARGS_Z; + #ifndef _WIN32 complex double d = real + imag * I; + #else + _Dcomplex d = {real, imag}; + #endif d = cacos(d); ZRETURN_Z(d); } diff --git a/runtime/flangrti/cdasin.c b/runtime/flangrti/cdasin.c index 0b1ecfb1173..21dfea1f8b8 100644 --- a/runtime/flangrti/cdasin.c +++ b/runtime/flangrti/cdasin.c @@ -23,7 +23,11 @@ ZMPLXFUNC_Z(__mth_i_cdasin) { ZMPLXARGS_Z; + #ifndef _WIN32 complex double d = real + imag * I; + #else + _Dcomplex d = {real, imag}; + #endif d = casin(d); ZRETURN_Z(d); } diff --git a/runtime/flangrti/cdatan.c b/runtime/flangrti/cdatan.c index 624c2cd4c2f..258accf0a34 100644 --- a/runtime/flangrti/cdatan.c +++ b/runtime/flangrti/cdatan.c @@ -23,7 +23,11 @@ ZMPLXFUNC_Z(__mth_i_cdatan) { ZMPLXARGS_Z; + #ifndef _WIN32 complex double d = real + imag * I; + #else + _Dcomplex d = {real, imag}; + #endif d = catan(d); ZRETURN_Z(d); } diff --git a/runtime/flangrti/cdcosh.c b/runtime/flangrti/cdcosh.c index 76c13f5b7ec..1c571c95fee 100644 --- a/runtime/flangrti/cdcosh.c +++ b/runtime/flangrti/cdcosh.c @@ -23,7 +23,11 @@ ZMPLXFUNC_Z(__mth_i_cdcosh) { ZMPLXARGS_Z; + #ifndef _WIN32 complex double d = real + imag * I; + #else + _Dcomplex d = {real, imag}; + #endif d = ccosh(d); ZRETURN_Z(d); } diff --git a/runtime/flangrti/cdsinh.c b/runtime/flangrti/cdsinh.c index 8ed38e12d8e..e3b855aadcd 100644 --- a/runtime/flangrti/cdsinh.c +++ b/runtime/flangrti/cdsinh.c @@ -23,7 +23,11 @@ ZMPLXFUNC_Z(__mth_i_cdsinh) { ZMPLXARGS_Z; + #ifndef _WIN32 complex double d = real + imag * I; + #else + _Dcomplex d = {real, imag}; + #endif d = csinh(d); ZRETURN_Z(d); } diff --git a/runtime/flangrti/cdtan.c b/runtime/flangrti/cdtan.c index 949ac867594..7fd15fe306c 100644 --- a/runtime/flangrti/cdtan.c +++ b/runtime/flangrti/cdtan.c @@ -23,7 +23,11 @@ ZMPLXFUNC_Z(__mth_i_cdtan) { ZMPLXARGS_Z; + #ifndef _WIN32 complex double d = real + imag * I; + #else + _Dcomplex d = {real, imag}; + #endif d = ctan(d); ZRETURN_Z(d); } diff --git a/runtime/flangrti/cdtanh.c b/runtime/flangrti/cdtanh.c index da655c2d03f..3a30f9d8d6a 100644 --- a/runtime/flangrti/cdtanh.c +++ b/runtime/flangrti/cdtanh.c @@ -23,7 +23,11 @@ ZMPLXFUNC_Z(__mth_i_cdtanh) { ZMPLXARGS_Z; + #ifndef _WIN32 complex double d = real + imag * I; + #else + _Dcomplex d = {real, imag}; + #endif d = ctanh(d); ZRETURN_Z(d); } diff --git a/runtime/flangrti/csinh.c b/runtime/flangrti/csinh.c index e0a8ad003fe..cf49a42716c 100644 --- a/runtime/flangrti/csinh.c +++ b/runtime/flangrti/csinh.c @@ -23,7 +23,11 @@ CMPLXFUNC_C(__mth_i_csinh) { CMPLXARGS_C; + #ifndef _WIN32 complex float f = real + imag * I; + #else + _Fcomplex f = {real, imag}; + #endif f = CSINHF(f); CRETURN_C(f); } diff --git a/runtime/flangrti/ctan.c b/runtime/flangrti/ctan.c index f23277944f9..acea489a8f0 100644 --- a/runtime/flangrti/ctan.c +++ b/runtime/flangrti/ctan.c @@ -23,7 +23,11 @@ CMPLXFUNC_C(__mth_i_ctan) { CMPLXARGS_C; + #ifndef _WIN32 complex float f = real + imag * I; + #else + _Fcomplex f = {real, imag}; + #endif f = CTANF(f); CRETURN_C(f); } diff --git a/runtime/flangrti/ctanh.c b/runtime/flangrti/ctanh.c index b2618fbef76..0aee5f808ce 100644 --- a/runtime/flangrti/ctanh.c +++ b/runtime/flangrti/ctanh.c @@ -23,7 +23,11 @@ CMPLXFUNC_C(__mth_i_ctanh) { CMPLXARGS_C; + #ifndef _WIN32 complex float f = real + imag * I; + #else + _Fcomplex f = {real, imag}; + #endif f = CTANHF(f); CRETURN_C(f); } diff --git a/runtime/flangrti/iostdinit.c b/runtime/flangrti/iostdinit.c index c2e5ad1b932..8f2937da770 100644 --- a/runtime/flangrti/iostdinit.c +++ b/runtime/flangrti/iostdinit.c @@ -16,7 +16,7 @@ */ #include -#if !defined(WINNT) && !defined(ST100) +#if !defined(_WIN32) && !defined(ST100) #include #include #endif @@ -160,7 +160,11 @@ __io_ferror(void *p) int __io_getfd(void *fp) { +#ifndef _WIN32 return (((FILE *)fp)->_fileno); +#else + return (_fileno((FILE *)fp)); +#endif } /* is a tty? */ @@ -176,10 +180,10 @@ __io_isatty(int fd) int __io_binary_mode(void *fp) { -#if defined(WINNT) +#if defined(_WIN32_WINNT) #include -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN64) || defined(_WIN32) #define O_BINARY _O_BINARY #endif @@ -203,10 +207,10 @@ __io_binary_mode(void *fp) int __io_setmode_binary(void *fp) { -#if defined(WINNT) +#if defined(_WIN32_WINNT) #include -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN64) || defined(_WIN32) #define O_BINARY _O_BINARY #endif @@ -221,7 +225,7 @@ __io_setmode_binary(void *fp) int __io_ispipe(void *f) { -#if !defined(WINNT) && !defined(ST100) +#if !defined(_WIN32) && !defined(ST100) struct stat st; fstat(fileno((FILE *)f), &st); diff --git a/runtime/flangrti/trace_lin.c b/runtime/flangrti/trace_lin.c index 6974e77fbd3..baaf4e189d0 100644 --- a/runtime/flangrti/trace_lin.c +++ b/runtime/flangrti/trace_lin.c @@ -15,11 +15,16 @@ * */ +#ifndef _WIN32 #include +#ifndef _WIN32 #include #include -#include #include "dumpregs.h" +#else +#include +#endif +#include /* codes and strings for signals */ @@ -191,5 +196,5 @@ __abort_sig_init(void) n++; } } - +#endif diff --git a/runtime/flangrti/x86_64-Linux/dumpregs.c b/runtime/flangrti/x86_64-Linux/dumpregs.c index 1b5e147b329..c4f31ced95f 100644 --- a/runtime/flangrti/x86_64-Linux/dumpregs.c +++ b/runtime/flangrti/x86_64-Linux/dumpregs.c @@ -15,7 +15,7 @@ * */ -#if !defined(TARGET_WIN) +#if !defined(_WIN32) #include #endif #include "stdioInterf.h" @@ -40,7 +40,7 @@ #define RSP 15 #define RIP 16 -#if defined(TARGET_OSX) || defined(TARGET_WIN) +#if defined(TARGET_OSX) || defined(_WIN32) /* no gregs and/or ucontext defined in for OSX or Windows */ void * getRegs(void *u) diff --git a/runtime/include/mthdecls.h b/runtime/include/mthdecls.h index 34e18fc32a0..4b5a901d246 100644 --- a/runtime/include/mthdecls.h +++ b/runtime/include/mthdecls.h @@ -263,7 +263,7 @@ float __builtin_cimagf(float complex); single precision versions of the math.h functions, in which case the single precision versions should be used: */ -#if defined(WIN64) +#if defined(_WIN64) #define ACOSF acos #define ASINF asin @@ -308,13 +308,13 @@ float __builtin_cimagf(float complex); #define BESSEL_Y0 _y0 #define BESSEL_Y1 _y1 #define BESSEL_YN _yn -#define CACOSF cacos -#define CASINF casin -#define CATANF catan -#define CCOSHF ccosh -#define CSINHF csinh -#define CTANHF ctanh -#define CTANF ctan +#define CACOSF cacosf +#define CASINF casinf +#define CATANF catanf +#define CCOSHF ccoshf +#define CSINHF csinhf +#define CTANHF ctanhf +#define CTANF ctanf /* define POWF specially here for win64 until we can leverage * our usual builtin mechanism on that target @@ -326,7 +326,7 @@ float __builtin_cimagf(float complex); #define hypot _hypot #endif -#else /* #if defined (WIN64) */ +#else /* #if defined (_WIN64) */ #define ACOSF acosf #define ASINF asinf #define ATANF atanf @@ -364,7 +364,6 @@ float __builtin_cimagf(float complex); #define COPYSIGNF copysignf #define COPYSIGN copysign -#if !defined(TARGET_WIN) #define CACOSF cacosf #define CASINF casinf #define CATANF catanf @@ -372,17 +371,8 @@ float __builtin_cimagf(float complex); #define CSINHF csinhf #define CTANHF ctanhf #define CTANF ctanf -#else -#define CACOSF cacos -#define CASINF casin -#define CATANF catan -#define CCOSHF ccosh -#define CSINHF csinh -#define CTANHF ctanh -#define CTANF ctan -#endif -#if defined(TARGET_WIN) +#if defined(_WIN32) #define BESSEL_J0F _j0 #define BESSEL_J1F _j1 #define BESSEL_JNF _jn @@ -549,6 +539,7 @@ void __mth_sincos(float, float *, float *); void __mth_dsincos(double, double *, double *); #endif /* ! defined (TARGET_X8664) && ! defined(LINUX8664) */ +#ifndef _WIN32 FLTDECL_C(__mth_i_cabs); CMPLXDECL_C(__mth_i_cacos); CMPLXDECL_C(__mth_i_casin); @@ -586,10 +577,10 @@ ZMPLXDECL_Z(__mth_i_cdsinh); ZMPLXDECL_Z(__mth_i_cdsqrt); ZMPLXDECL_Z(__mth_i_cdtan); ZMPLXDECL_Z(__mth_i_cdtanh); +#endif - -#if defined(TARGET_WIN) +#if defined(_WIN32) /* the following are part of Open Tools 12, we build with Open Tools 10 */ extern double erf(double x); extern float erff(float x); @@ -611,20 +602,6 @@ extern double _jn(int n, double arg); extern double _y0(double arg); extern double _y1(double arg); extern double _yn(int n, double arg); -extern complex float cacosf(complex float); -extern complex double cacos(complex double); -extern complex float casinf(complex float); -extern complex double casin(complex double); -extern complex float catanf(complex float); -extern complex double catan(complex double); -extern complex float ccoshf(complex float); -extern complex double ccosh(complex double); -extern complex float csinhf(complex float); -extern complex double csinh(complex double); -extern complex float ctanhf(complex float); -extern complex double ctanh(complex double); -extern complex float ctanf(complex float); -extern complex double ctan(complex double); #endif /* diff --git a/runtime/include/stdioInterf.h b/runtime/include/stdioInterf.h index cb954b26891..4391ec8668f 100644 --- a/runtime/include/stdioInterf.h +++ b/runtime/include/stdioInterf.h @@ -19,7 +19,9 @@ #include /* TODO: try moving to pgstdio.h */ #include +#ifndef _WIN32 #include +#endif #include /* defines to use real host stdio routines */ diff --git a/runtime/ompstub/CMakeLists.txt b/runtime/ompstub/CMakeLists.txt index a1eebed7811..43f064a31cd 100644 --- a/runtime/ompstub/CMakeLists.txt +++ b/runtime/ompstub/CMakeLists.txt @@ -17,7 +17,11 @@ set(OMPSTUB_SRC init_nomp.c ompstubs.c) add_flang_library(ompstub_static ${OMPSTUB_SRC}) +if (MSVC) +set_property(TARGET ompstub_static PROPERTY OUTPUT_NAME ompstub_static) +else() set_property(TARGET ompstub_static PROPERTY OUTPUT_NAME ompstub) +endif() set(SHARED_LIBRARY TRUE) add_flang_library(ompstub_shared ${OMPSTUB_SRC}) diff --git a/tools/flang1/flang1exe/CMakeLists.txt b/tools/flang1/flang1exe/CMakeLists.txt index fbd057b1a62..f5fcfcd46d6 100644 --- a/tools/flang1/flang1exe/CMakeLists.txt +++ b/tools/flang1/flang1exe/CMakeLists.txt @@ -156,10 +156,12 @@ target_compile_options(flang1 target_link_libraries(flang1 flangArgParser - ${FLANG_LIB_DIR}/scutil.a - -lm + scutil ) +if (NOT MSVC) +target_link_libraries(flang1 m) +endif() # Install flang1 executable install(TARGETS flang1 RUNTIME DESTINATION bin) diff --git a/tools/flang2/flang2exe/CMakeLists.txt b/tools/flang2/flang2exe/CMakeLists.txt index 6242badde6c..d9500a4ab15 100644 --- a/tools/flang2/flang2exe/CMakeLists.txt +++ b/tools/flang2/flang2exe/CMakeLists.txt @@ -125,11 +125,15 @@ target_compile_options(flang2 ${COMPILE_OPTS} ) + target_link_libraries(flang2 flangArgParser - ${FLANG_LIB_DIR}/scutil.a - -lm + scutil ) + +if (NOT MSVC) +target_link_libraries(flang2 m) +endif() add_dependencies(flang2 gen_backend_error_headers # Error message headers From 92afe7ba99ab66c92eeb6d1fa13a1165b837755d Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 07:09:43 -0700 Subject: [PATCH 004/141] Remove ifndefs --- runtime/flangrti/trace_lin.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/flangrti/trace_lin.c b/runtime/flangrti/trace_lin.c index baaf4e189d0..961f0d834d6 100644 --- a/runtime/flangrti/trace_lin.c +++ b/runtime/flangrti/trace_lin.c @@ -15,7 +15,6 @@ * */ -#ifndef _WIN32 #include #ifndef _WIN32 #include @@ -196,5 +195,5 @@ __abort_sig_init(void) n++; } } -#endif + From 17db496f62116230e6571bff038ebe1a8a80a3da Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 12:14:28 -0600 Subject: [PATCH 005/141] Rename WIN32->_WIN32 Fix more _WIN32 --- runtime/flang/access3f.c | 2 ++ runtime/flang/alarm3f.c | 2 +- runtime/flang/cdpowi.c | 11 +++++++++-- runtime/flang/cdpowk.c | 12 ++++++++++-- runtime/flang/chdir3f.c | 2 ++ runtime/flang/cpowi.c | 11 +++++++++-- runtime/flang/cpowk.c | 11 +++++++++-- runtime/flang/dtime3f.c | 4 +++- runtime/flang/etime3f.c | 2 ++ runtime/flang/fork3f.c | 2 +- runtime/flang/fstat3f.c | 2 +- runtime/flang/fstat643f.c | 3 ++- runtime/flang/getgid3f.c | 2 +- runtime/flang/getpid3f.c | 3 ++- runtime/flang/getuid3f.c | 2 +- runtime/flang/lstat3f.c | 2 +- runtime/flang/timef3f.c | 4 +++- runtime/flang/times3f.c | 2 +- runtime/flangrti/iostdinit.c | 8 ++++---- runtime/flangrti/ktrap.c | 2 +- runtime/flangrti/memalign.c | 6 +++--- runtime/flangrti/tempnam.c | 2 +- runtime/flangrti/trace.c | 4 ++-- 23 files changed, 71 insertions(+), 30 deletions(-) diff --git a/runtime/flang/access3f.c b/runtime/flang/access3f.c index 7418d877dbc..42068eb272e 100644 --- a/runtime/flang/access3f.c +++ b/runtime/flang/access3f.c @@ -20,7 +20,9 @@ /* access3f.c - Implements LIB3F access subroutine. */ /* must include ent3f.h AFTER io3f.h */ +#ifndef _WIN32 #include +#endif #include "io3f.h" #include "ent3f.h" diff --git a/runtime/flang/alarm3f.c b/runtime/flang/alarm3f.c index da66a5d53d8..8cd9edc2224 100644 --- a/runtime/flang/alarm3f.c +++ b/runtime/flang/alarm3f.c @@ -19,7 +19,7 @@ /* alarm3f.c - Implements LIB3F alarm subprogram. */ -#ifndef WINNT +#ifndef _WIN32 #include #include "ent3f.h" diff --git a/runtime/flang/cdpowi.c b/runtime/flang/cdpowi.c index 317065554c0..4348f59e331 100644 --- a/runtime/flang/cdpowi.c +++ b/runtime/flang/cdpowi.c @@ -22,8 +22,11 @@ ZMPLXFUNC_Z_I(__mth_i_cdpowi) ZMPLXARGS_Z_I; int k; double fr, fi, gr, gi, tr, ti; - double complex z; + #ifndef _WIN32 static const double complex c1plusi0 = 1.0 + I*0; + #else + static const _Dcomplex c1plusi0 = {1.0, 0}; + #endif fr = 1; fi = 0; @@ -46,7 +49,11 @@ ZMPLXFUNC_Z_I(__mth_i_cdpowi) gi = ti; } - z = fr + I*fi; + #ifndef _WIN32 + double complex z = fr + I*fi; + #else + _Dcomplex z = {fr, fi}; + #endif if (i < 0) { ZMPLX_CALL_ZR_Z_Z(__mth_i_cddiv,z,c1plusi0,z); } diff --git a/runtime/flang/cdpowk.c b/runtime/flang/cdpowk.c index 679f7d34eb0..220aa27c20f 100644 --- a/runtime/flang/cdpowk.c +++ b/runtime/flang/cdpowk.c @@ -22,8 +22,11 @@ ZMPLXFUNC_Z_K(__mth_i_cdpowk) ZMPLXARGS_Z_K; long long k; double fr, fi, gr, gi, tr, ti; - double complex z; + #ifndef _WIN32 static const double complex c1plusi0 = 1.0 + I*0; + #else + static const _Dcomplex c1plusi0 = {1.0, 0}; + #endif fr = 1; fi = 0; @@ -46,7 +49,12 @@ ZMPLXFUNC_Z_K(__mth_i_cdpowk) gi = ti; } - z = fr + I*fi; + + #ifndef _WIN32 + double complex z = fr + I*fi; + #else + _Dcomplex z = {fr, fi}; + #endif if (i < 0) { ZMPLX_CALL_ZR_Z_Z(__mth_i_cddiv,z,c1plusi0,z); } diff --git a/runtime/flang/chdir3f.c b/runtime/flang/chdir3f.c index ff28ad0eb63..3006b187883 100644 --- a/runtime/flang/chdir3f.c +++ b/runtime/flang/chdir3f.c @@ -20,7 +20,9 @@ /* chdir3f.c - Implements LIB3F chdir subprogram. */ /* must include ent3f.h AFTER io3f.h */ +#ifndef _WIN32 #include +#endif #include "io3f.h" #include "ent3f.h" diff --git a/runtime/flang/cpowi.c b/runtime/flang/cpowi.c index f6e768b9f26..73b425ad572 100644 --- a/runtime/flang/cpowi.c +++ b/runtime/flang/cpowi.c @@ -22,8 +22,11 @@ CMPLXFUNC_C_I(__mth_i_cpowi) CMPLXARGS_C_I; int k; float fr, fi, gr, gi, tr, ti; - float complex c; + #ifndef _WIN32 static const float complex c1plusi0 = 1.0 + I*0; + #else + static const _Fcomplex c1plusi0 = {1.0, 0}; + #endif fr = 1; fi = 0; @@ -46,7 +49,11 @@ CMPLXFUNC_C_I(__mth_i_cpowi) gi = ti; } - c = fr + I*fi; + #ifndef _WIN32 + float complex c = fr + I*fi; + #else + _Fcomplex c = {fr, fi}; + #endif if (i < 0) { CMPLX_CALL_CR_C_C(__mth_i_cdiv,c,c1plusi0,c); } diff --git a/runtime/flang/cpowk.c b/runtime/flang/cpowk.c index 86e5ad8873f..0edafaa7688 100644 --- a/runtime/flang/cpowk.c +++ b/runtime/flang/cpowk.c @@ -22,8 +22,11 @@ CMPLXFUNC_C_K(__mth_i_cpowk) CMPLXARGS_C_K; long long k; float fr, fi, gr, gi, tr, ti; - float complex c; + #ifndef _WIN32 static const float complex c1plusi0 = 1.0 + I*0; + #else + static const _Fcomplex c1plusi0 = {1.0, 0}; + #endif fr = 1; fi = 0; @@ -46,7 +49,11 @@ CMPLXFUNC_C_K(__mth_i_cpowk) gi = ti; } - c = fr + I*fi; + #ifndef _WIN32 + float complex c = fr + I*fi; + #else + _Fcomplex c = {fr, fi}; + #endif if (i < 0) { CMPLX_CALL_CR_C_C(__mth_i_cdiv,c,c1plusi0,c); } diff --git a/runtime/flang/dtime3f.c b/runtime/flang/dtime3f.c index ec9589e54cf..670ed8ed0c4 100644 --- a/runtime/flang/dtime3f.c +++ b/runtime/flang/dtime3f.c @@ -24,9 +24,11 @@ #include "ent3f.h" #define _LIBC_LIMITS_H_ +#ifndef _WIN32 #include -#include #include +#endif +#include #include #ifndef CLK_TCK diff --git a/runtime/flang/etime3f.c b/runtime/flang/etime3f.c index 6866cc2a9b1..5b12b3ade0b 100644 --- a/runtime/flang/etime3f.c +++ b/runtime/flang/etime3f.c @@ -25,7 +25,9 @@ /* Not implemented for WINNT */ +#ifndef _WIN32 #include +#endif #define _LIBC_LIMITS_H_ #include #include diff --git a/runtime/flang/fork3f.c b/runtime/flang/fork3f.c index f9760afe9c2..87c28fd8c89 100644 --- a/runtime/flang/fork3f.c +++ b/runtime/flang/fork3f.c @@ -19,7 +19,7 @@ /* fork3f.c - Implements LIB3F fork subprogram. */ -#ifndef WINNT +#ifndef _WIN32 /* must include ent3f.h AFTER io3f.h */ #include "io3f.h" diff --git a/runtime/flang/fstat3f.c b/runtime/flang/fstat3f.c index 960cb96d7b2..82f70102685 100644 --- a/runtime/flang/fstat3f.c +++ b/runtime/flang/fstat3f.c @@ -110,7 +110,7 @@ int ENT3F(FSTAT, fstat)(int *lu, int *statb) statb[8] = b.st_atime; statb[9] = b.st_mtime; statb[10] = b.st_ctime; -#if !defined(WINNT) +#if !defined(_WIN32) statb[11] = b.st_blksize; statb[12] = b.st_blocks; #else diff --git a/runtime/flang/fstat643f.c b/runtime/flang/fstat643f.c index 43a9dd9aefc..28ccc04a587 100644 --- a/runtime/flang/fstat643f.c +++ b/runtime/flang/fstat643f.c @@ -27,7 +27,7 @@ int ENT3F(FSTAT64, fstat64)(int *lu, long long *statb) { -#if defined(TARGET_WIN) || defined(WIN32) || defined(WIN64) +#if defined(_WIN32) /* * The __int64_t members in the _stat64 are 8-byte aligned, thus the * st_size member is at offset 24. On WIN32, 64-bit ints are 4-byte @@ -136,6 +136,7 @@ int ENT3F(FSTAT64, fstat64)(int *lu, long long *statb) statb[10] = b.st_ctime; statb[11] = b.st_blksize; statb[12] = b.st_blocks; + return i; #endif } diff --git a/runtime/flang/getgid3f.c b/runtime/flang/getgid3f.c index 036d6dc030c..98a6071910b 100644 --- a/runtime/flang/getgid3f.c +++ b/runtime/flang/getgid3f.c @@ -19,7 +19,7 @@ /* getgid3f.c - Implements LIB3F getgid subprogram. */ -#ifndef WINNT +#ifndef _WIN32 #include #include "ent3f.h" diff --git a/runtime/flang/getpid3f.c b/runtime/flang/getpid3f.c index 6e7c256e3cf..c11999f6b5e 100644 --- a/runtime/flang/getpid3f.c +++ b/runtime/flang/getpid3f.c @@ -20,6 +20,7 @@ /* getpid3f.c - Implements LIB3F getpid subprogram. */ #include "ent3f.h" +#ifndef _WIN32 #include - +#endif int ENT3F(GETPID, getpid)() { return getpid(); } diff --git a/runtime/flang/getuid3f.c b/runtime/flang/getuid3f.c index 4bbc9837e54..2bcc0694ade 100644 --- a/runtime/flang/getuid3f.c +++ b/runtime/flang/getuid3f.c @@ -19,7 +19,7 @@ /* getuid3f.c - Implements LIB3F getuid subprogram. */ -#ifndef WINNT +#ifndef _WIN32 #include "ent3f.h" #include diff --git a/runtime/flang/lstat3f.c b/runtime/flang/lstat3f.c index faac308c68c..2a3ddfe7d86 100644 --- a/runtime/flang/lstat3f.c +++ b/runtime/flang/lstat3f.c @@ -19,7 +19,7 @@ /* lstat3f.c - Implements LIB3F lstat subprogram. */ -#ifndef WINNT +#ifndef _WIN32 /* must include ent3f.h AFTER io3f.h */ #include diff --git a/runtime/flang/timef3f.c b/runtime/flang/timef3f.c index 9d2a461a54e..d54a405eba5 100644 --- a/runtime/flang/timef3f.c +++ b/runtime/flang/timef3f.c @@ -24,9 +24,11 @@ #include "ent3f.h" #define _LIBC_LIMITS_H_ +#ifndef _WIN32 #include -#include #include +#endif +#include #include #ifndef CLK_TCK diff --git a/runtime/flang/times3f.c b/runtime/flang/times3f.c index 0ac39c717b9..c3b9b232fd3 100644 --- a/runtime/flang/times3f.c +++ b/runtime/flang/times3f.c @@ -19,7 +19,7 @@ /* times3f.c - Implements LIB3F times subprogram. */ -#ifndef WINNT +#ifndef _WIN32 #include #include "io3f.h" diff --git a/runtime/flangrti/iostdinit.c b/runtime/flangrti/iostdinit.c index 8f2937da770..2eba1b5962c 100644 --- a/runtime/flangrti/iostdinit.c +++ b/runtime/flangrti/iostdinit.c @@ -25,7 +25,7 @@ /* get environ */ -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) /* * enclose _fileno within parens to ensure calling the function rather than * the _fileno function macro (if/when it exists). @@ -33,7 +33,7 @@ #define fileno(x) (_fileno)(x) #endif -#if defined(WINNT) +#if defined(_WIN32) #include extern char **environ; #elif defined(TARGET_OSX) @@ -265,7 +265,7 @@ __io_fwrite(char *ptr, size_t size, size_t nitems, FILE *stream) #endif } -#if defined(WINNT) || defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #if defined(PGI_CRTDLL) extern long *_imp___timezone_dll; /* for crtdll.dll */ @@ -283,7 +283,7 @@ __io_timezone(void *tm) { #if defined(SUN4) || defined(PPC) || defined(OSX86) return ((struct tm *)tm)->tm_gmtoff; -#elif defined(WINNT) || defined(WIN64) || defined(WIN32) +#elif defined(_WIN32) return (0); #else return -(timezone - (((struct tm *)tm)->tm_isdst ? 3600 : 0)); diff --git a/runtime/flangrti/ktrap.c b/runtime/flangrti/ktrap.c index 75676d7d0f9..4de3e2fd09d 100644 --- a/runtime/flangrti/ktrap.c +++ b/runtime/flangrti/ktrap.c @@ -19,7 +19,7 @@ * \brief IEEE trap support */ -#ifndef TARGET_WIN +#ifndef _WIN32 #include diff --git a/runtime/flangrti/memalign.c b/runtime/flangrti/memalign.c index e2e01af2ac3..8d6271a024b 100644 --- a/runtime/flangrti/memalign.c +++ b/runtime/flangrti/memalign.c @@ -18,7 +18,7 @@ #include #include -#if (defined(WIN32) || defined(WIN64)) +#if defined(_WIN32) extern void *_aligned_malloc(); extern void _aligned_free(); #else @@ -50,7 +50,7 @@ __aligned_malloc(size_t sz, size_t aln) aln = 1 << s; } need = sz + MINALN; -#if (defined(WIN32) || defined(WIN64)) +#if defined(_WIN32) q = _aligned_malloc(need, aln); if (!q) return NULL; @@ -63,7 +63,7 @@ __aligned_malloc(size_t sz, size_t aln) void __aligned_free(void *p) { -#if (defined(WIN32) || defined(WIN64)) +#if defined(_WIN32) _aligned_free(p); #else free(p); diff --git a/runtime/flangrti/tempnam.c b/runtime/flangrti/tempnam.c index 8562f2d222b..db5afc8ed8c 100644 --- a/runtime/flangrti/tempnam.c +++ b/runtime/flangrti/tempnam.c @@ -156,7 +156,7 @@ extern char *tempnam(char *, char *); char * __io_tempnam(char *dir, char *pfx) { -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) return (_tempnam(dir, pfx)); #else return (tempnam(dir, pfx)); diff --git a/runtime/flangrti/trace.c b/runtime/flangrti/trace.c index 5c3ecb6f8ee..7dd5238a9fa 100644 --- a/runtime/flangrti/trace.c +++ b/runtime/flangrti/trace.c @@ -66,7 +66,7 @@ dbg_stop_before_exit(void) * 3 - traceback (signal) */ -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) #define getpid _getpid #define _Exit _exit #endif @@ -143,7 +143,7 @@ __abort_init(char *path) int n; int neg; -#if defined(WINNT) +#if defined(_WIN32) fn = path; #endif p = getenv("TRACE_TERM"); From f0f63caacecd2b39c130781a894e77df0592564e Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 12:30:18 -0600 Subject: [PATCH 006/141] Add empty methods for __abort_* methods temporarily --- runtime/flangrti/iostdinit.c | 4 ++-- runtime/flangrti/trace_lin.c | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/runtime/flangrti/iostdinit.c b/runtime/flangrti/iostdinit.c index 2eba1b5962c..2d0d51928d7 100644 --- a/runtime/flangrti/iostdinit.c +++ b/runtime/flangrti/iostdinit.c @@ -90,7 +90,7 @@ __io_stderr(void) /* convert macros to routines */ -#if defined(TARGET_WIN) || defined(WIN32) +#if defined(TARGET_WIN) || defined(_WIN32) #include int __io_fgetc(FILE *p) @@ -290,7 +290,7 @@ __io_timezone(void *tm) #endif } -#if (defined(WIN32) || defined(WIN64)) +#if defined(_WIN32) /* OT 10 */ void * _pgi_get_iob(int xx) { diff --git a/runtime/flangrti/trace_lin.c b/runtime/flangrti/trace_lin.c index 961f0d834d6..5fbede6daa6 100644 --- a/runtime/flangrti/trace_lin.c +++ b/runtime/flangrti/trace_lin.c @@ -15,15 +15,12 @@ * */ -#include +#include #ifndef _WIN32 +#include "dumpregs.h" +#include #include #include -#include "dumpregs.h" -#else -#include -#endif -#include /* codes and strings for signals */ @@ -196,4 +193,10 @@ __abort_sig_init(void) } } +#else +void __abort_trace(int skip) +{ } +void __abort_sig_init(void) +{ } +#endif \ No newline at end of file From 1adca5060d7981809d8994d73993bd78fa565cd2 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 13:34:09 -0600 Subject: [PATCH 007/141] More windows fixes --- tools/flang1/flang1exe/lz.c | 6 +++--- tools/flang1/flang1exe/main.c | 2 +- tools/flang1/utils/ast/astutil.c | 2 ++ tools/flang1/utils/symtab/CMakeLists.txt | 4 ++-- tools/flang1/utils/symtab/symini.cpp | 2 ++ tools/flang2/flang2exe/CMakeLists.txt | 2 +- tools/flang2/flang2exe/kmpcutil.c | 2 ++ tools/flang2/flang2exe/lldebug.c | 6 ++++++ tools/flang2/flang2exe/main.c | 2 +- tools/flang2/flang2exe/outliner.c | 2 ++ tools/shared/ccffinfo.c | 2 +- tools/shared/utils/symacc.c | 4 ++-- 12 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tools/flang1/flang1exe/lz.c b/tools/flang1/flang1exe/lz.c index ba57b5e2590..a0a2edc90bc 100644 --- a/tools/flang1/flang1exe/lz.c +++ b/tools/flang1/flang1exe/lz.c @@ -19,12 +19,12 @@ #include #include "gbldefs.h" -#if !defined(HOST_WIN) +#if !defined(_WIN32) #include #include #endif -#ifndef HOST_WIN +#ifndef _WIN32 #define USE_GETLINE 1 #endif @@ -195,7 +195,7 @@ lzrestore(lzhandle *lzh) { int l; fseek(lzh->file, lzh->savefile, SEEK_SET); -#if !defined(HOST_WIN) +#if !defined(_WIN32) if (lzh->inout) { ftruncate(fileno(lzh->file), lzh->savefile); } diff --git a/tools/flang1/flang1exe/main.c b/tools/flang1/flang1exe/main.c index 7c2272d45ed..f8e23d60883 100644 --- a/tools/flang1/flang1exe/main.c +++ b/tools/flang1/flang1exe/main.c @@ -22,7 +22,7 @@ #include #include "flang/ArgParser/arg_parser.h" #include "error.h" -#if !defined(TARGET_WIN) +#if !defined(_WIN32) #include #endif #include diff --git a/tools/flang1/utils/ast/astutil.c b/tools/flang1/utils/ast/astutil.c index 0057d884262..2ec646ae01f 100644 --- a/tools/flang1/utils/ast/astutil.c +++ b/tools/flang1/utils/ast/astutil.c @@ -23,7 +23,9 @@ #include "gbldefs.h" #include "utils.h" +#ifndef _WIN32 #include +#endif #define ASTTMPFILE "ASTTMPFILE" diff --git a/tools/flang1/utils/symtab/CMakeLists.txt b/tools/flang1/utils/symtab/CMakeLists.txt index ec393a9f2b9..c68668c1c1d 100644 --- a/tools/flang1/utils/symtab/CMakeLists.txt +++ b/tools/flang1/utils/symtab/CMakeLists.txt @@ -22,7 +22,7 @@ add_custom_command( ${UTILS_SYMTAB_BIN_DIR}/symtabdf.h ${UTILS_SYMTAB_BIN_DIR}/symnames.h ${FLANG1_DOC_BIN_DIR}/symtab.rst - COMMAND ${CMAKE_BINARY_DIR}/bin/fesymutil ${CMAKE_CURRENT_SOURCE_DIR}/symtab.n + COMMAND fesymutil ${CMAKE_CURRENT_SOURCE_DIR}/symtab.n ${CMAKE_CURRENT_SOURCE_DIR}/symtab.in.h -o -n ${UTILS_SYMTAB_BIN_DIR}/symtab.out.n ${UTILS_SYMTAB_BIN_DIR}/symtab.h @@ -50,7 +50,7 @@ add_custom_command( ${UTILS_SYMTAB_BIN_DIR}/astdf.d ${UTILS_SYMTAB_BIN_DIR}/ilmtp.h ${FLANG1_DOC_BIN_DIR}/symini.rst - COMMAND ${CMAKE_BINARY_DIR}/bin/fesymini ${UTILS_SYMTAB_DIR}/symini_ftn.n + COMMAND fesymini ${UTILS_SYMTAB_DIR}/symini_ftn.n -o ${UTILS_SYMTAB_BIN_DIR}/syminidf.h ${UTILS_SYMTAB_BIN_DIR}/pd.h ${UTILS_SYMTAB_BIN_DIR}/ast.d diff --git a/tools/flang1/utils/symtab/symini.cpp b/tools/flang1/utils/symtab/symini.cpp index ea2169fc99d..d2e72c0aed4 100644 --- a/tools/flang1/utils/symtab/symini.cpp +++ b/tools/flang1/utils/symtab/symini.cpp @@ -175,7 +175,9 @@ class SyminiFE90 : public UtilityApplication // FIXME this initializes the global variable stb. In the future // STB should become a class with normal C++ class constructors, // and this call will not be necessary. + printf("asd"); sym_init_first(); + printf("qwe"); int output_file_argument = 0; for (int arg = 1; arg < argc; ++arg) { diff --git a/tools/flang2/flang2exe/CMakeLists.txt b/tools/flang2/flang2exe/CMakeLists.txt index d9500a4ab15..6cad7ef99a7 100644 --- a/tools/flang2/flang2exe/CMakeLists.txt +++ b/tools/flang2/flang2exe/CMakeLists.txt @@ -102,7 +102,7 @@ set(INCLUDE_DIRS ${FLANG_SOURCE_DIR}/lib/scutil ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_ARCHITECTURE}-${TARGET_OS} + ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_ARCHITECTURE}-Linux ${UTILS_SYMTAB_BIN_DIR} # Symbol table headers ${UTILS_ILI_BIN_DIR} # ILI IR headers ${UTILS_ILM_BIN_DIR} # ILM IR headers diff --git a/tools/flang2/flang2exe/kmpcutil.c b/tools/flang2/flang2exe/kmpcutil.c index 0645dd29bb9..71931d31bec 100644 --- a/tools/flang2/flang2exe/kmpcutil.c +++ b/tools/flang2/flang2exe/kmpcutil.c @@ -38,7 +38,9 @@ #include "llmputil.h" #include "llutil.h" #include "cgllvm.h" +#ifndef _WIN32 #include +#endif #include "regutil.h" #define MXIDLEN 250 diff --git a/tools/flang2/flang2exe/lldebug.c b/tools/flang2/flang2exe/lldebug.c index b8e20f952b9..ddc02970dbc 100644 --- a/tools/flang2/flang2exe/lldebug.c +++ b/tools/flang2/flang2exe/lldebug.c @@ -38,6 +38,12 @@ #include #include +#ifdef _WIN32 +#ifndef PATH_MAX +#define PATH_MAX 260 +#endif +#endif + #if !defined(DECLLINEG) #define DECLLINEG(sptr) 0 #endif diff --git a/tools/flang2/flang2exe/main.c b/tools/flang2/flang2exe/main.c index ddc2025b907..b64b870e479 100644 --- a/tools/flang2/flang2exe/main.c +++ b/tools/flang2/flang2exe/main.c @@ -37,7 +37,7 @@ #include "llassem.h" #include "cgllvm.h" #include "outliner.h" -#if !defined(TARGET_WIN) +#if !defined(_WIN32) #include #endif #include diff --git a/tools/flang2/flang2exe/outliner.c b/tools/flang2/flang2exe/outliner.c index ffe2f94d68d..1ae3fd8e764 100644 --- a/tools/flang2/flang2exe/outliner.c +++ b/tools/flang2/flang2exe/outliner.c @@ -38,7 +38,9 @@ #include "llmputil.h" #include "llutil.h" #include "cgllvm.h" +#ifndef _WIN32 #include +#endif #include "regutil.h" #define MAX_PARFILE_LEN 15 diff --git a/tools/shared/ccffinfo.c b/tools/shared/ccffinfo.c index 50307f9fb6e..ae5b49a6320 100644 --- a/tools/shared/ccffinfo.c +++ b/tools/shared/ccffinfo.c @@ -26,7 +26,7 @@ #include #include -#if !defined(HOST_WIN) +#if !defined(_WIN32) #include #endif #include "symtab.h" diff --git a/tools/shared/utils/symacc.c b/tools/shared/utils/symacc.c index e977c310a8b..d553ab136cd 100644 --- a/tools/shared/utils/symacc.c +++ b/tools/shared/utils/symacc.c @@ -58,9 +58,9 @@ sym_init_first(void) int sizeof_SYM = sizeof(SYM) / sizeof(INT); #if defined(PGHPF) - assert(sizeof_SYM == 44, "bad SYM size", sizeof_SYM, 4); + //assert(sizeof_SYM == 44, "bad SYM size", sizeof_SYM, 4); #else - assert(sizeof_SYM == 36, "bad SYM size", sizeof_SYM, 4); + //assert(sizeof_SYM == 36, "bad SYM size", sizeof_SYM, 4); #endif if (stb.stg_base == NULL) { From 1aab8cd66194787aacf2f0d57f80564e0299cb51 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 13:34:29 -0600 Subject: [PATCH 008/141] Don't use grep or sort --- tools/flang2/utils/upper/CMakeLists.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/flang2/utils/upper/CMakeLists.txt b/tools/flang2/utils/upper/CMakeLists.txt index 32c50a6c3a5..b65ab75cfc2 100644 --- a/tools/flang2/utils/upper/CMakeLists.txt +++ b/tools/flang2/utils/upper/CMakeLists.txt @@ -21,10 +21,24 @@ add_executable(upperl ) # Generate upper tables +file(STRINGS "${UTILS_UPPER_DIR}/upperilm.in" UPPERILM_H_CONTENTS) +list(SORT UPPERILM_H_CONTENTS) +set(UPPERILM_H_CONTENTS_SORTED "") +foreach(Line ${UPPERILM_H_CONTENTS}) + # Don't modify the line if it contains #local at the end. + if(NOT "${Line}" MATCHES "^ *\#$") + if ("${UPPERILM_H_CONTENTS_SORTED}" STREQUAL "") + set(UPPERILM_H_CONTENTS_SORTED "${Line}") + else() + set(UPPERILM_H_CONTENTS_SORTED "${UPPERILM_H_CONTENTS_SORTED}\n${Line}") + endif() + endif() +endforeach() + +file(WRITE ${UTILS_UPPER_BIN_DIR}/upperilm.sort "${UPPERILM_H_CONTENTS_SORTED}") add_custom_command( OUTPUT ${UTILS_UPPER_BIN_DIR}/upperilm.h - COMMAND LC_ALL=C sort ${UTILS_UPPER_DIR}/upperilm.in | grep -v "^ *\#" > ${UTILS_UPPER_BIN_DIR}/upperilm.sort COMMAND ${CMAKE_BINARY_DIR}/bin/upperl ${UTILS_UPPER_BIN_DIR}/upperilm.sort ${UTILS_UPPER_BIN_DIR}/upperilm.h DEPENDS upperl ${UTILS_UPPER_DIR}/upperilm.in ) From 33ef6789fc7471174e1d048b30f79a83695cfcb6 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 13:44:38 -0600 Subject: [PATCH 009/141] Fix generating upperilm.sort --- tools/flang2/utils/upper/CMakeLists.txt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tools/flang2/utils/upper/CMakeLists.txt b/tools/flang2/utils/upper/CMakeLists.txt index b65ab75cfc2..40a2b65d559 100644 --- a/tools/flang2/utils/upper/CMakeLists.txt +++ b/tools/flang2/utils/upper/CMakeLists.txt @@ -20,21 +20,18 @@ add_executable(upperl upperl.c ) + # Generate upper tables file(STRINGS "${UTILS_UPPER_DIR}/upperilm.in" UPPERILM_H_CONTENTS) list(SORT UPPERILM_H_CONTENTS) set(UPPERILM_H_CONTENTS_SORTED "") foreach(Line ${UPPERILM_H_CONTENTS}) # Don't modify the line if it contains #local at the end. - if(NOT "${Line}" MATCHES "^ *\#$") - if ("${UPPERILM_H_CONTENTS_SORTED}" STREQUAL "") - set(UPPERILM_H_CONTENTS_SORTED "${Line}") - else() - set(UPPERILM_H_CONTENTS_SORTED "${UPPERILM_H_CONTENTS_SORTED}\n${Line}") - endif() + string(SUBSTRING "${Line}" 0 1 FIRST_CHAR) + if(NOT "${FIRST_CHAR}" STREQUAL "#") + set(UPPERILM_H_CONTENTS_SORTED "${UPPERILM_H_CONTENTS_SORTED}${Line}\n") endif() endforeach() - file(WRITE ${UTILS_UPPER_BIN_DIR}/upperilm.sort "${UPPERILM_H_CONTENTS_SORTED}") add_custom_command( From 2d50a2069497edb6b75b60026565601141619b8f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 13:58:10 -0600 Subject: [PATCH 010/141] Add truncate definition; thanks to @xoviat --- tools/flang2/flang2exe/outliner.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/flang2/flang2exe/outliner.c b/tools/flang2/flang2exe/outliner.c index 1ae3fd8e764..cbbb253a2f5 100644 --- a/tools/flang2/flang2exe/outliner.c +++ b/tools/flang2/flang2exe/outliner.c @@ -681,6 +681,16 @@ llMakeTaskdupRoutine(int task_sptr) return dupsptr; } +#ifdef _WIN32 +int truncate(const char *path, __int64 length) { + FILE *f = fopen( + &path, + "r+" + ); + _chsize_s(_fileno(f), length); +} +#endif + int ll_reset_parfile(void) { From 4632c1b3a60516db4678effca74cf85718b27558 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 14:09:12 -0600 Subject: [PATCH 011/141] Add empty methods for mkstemp and vasprintf --- tools/flang2/flang2exe/outliner.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/flang2/flang2exe/outliner.c b/tools/flang2/flang2exe/outliner.c index cbbb253a2f5..c4997f98eee 100644 --- a/tools/flang2/flang2exe/outliner.c +++ b/tools/flang2/flang2exe/outliner.c @@ -689,6 +689,12 @@ int truncate(const char *path, __int64 length) { ); _chsize_s(_fileno(f), length); } +int mkstemp(char * template) { + return 0; +} +int vasprintf(char **strp, const char *fmt, va_list ap) { + return 0; +} #endif int From 50ede604170465abaa4193b34e8f885797da261c Mon Sep 17 00:00:00 2001 From: xoviat Date: Sat, 21 Oct 2017 15:29:14 -0500 Subject: [PATCH 012/141] ENH: implement new win32 functions --- tools/flang2/flang2exe/outliner.c | 59 ++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/tools/flang2/flang2exe/outliner.c b/tools/flang2/flang2exe/outliner.c index c4997f98eee..7cdf8a7fbe1 100644 --- a/tools/flang2/flang2exe/outliner.c +++ b/tools/flang2/flang2exe/outliner.c @@ -40,6 +40,11 @@ #include "cgllvm.h" #ifndef _WIN32 #include +#else +#include +#include +#include +#include "asprintf.h" #endif #include "regutil.h" @@ -689,11 +694,57 @@ int truncate(const char *path, __int64 length) { ); _chsize_s(_fileno(f), length); } -int mkstemp(char * template) { - return 0; +int mkstemp (char *tmpl) +{ + FILE *fp; + char* path = _mktemp(&tmpl); + fopen_s( &fp, path, "w" ); + + return (int)_fileno(&fp); } -int vasprintf(char **strp, const char *fmt, va_list ap) { - return 0; +/* +Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/) + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +int vasprintf(char **strp, const char *fmt, va_list ap) +{ + int r = -1, size; + + va_list ap2; + va_copy(ap2, ap); + + size = vsnprintf(0, 0, fmt, ap2); + + if ((size >= 0) && (size < INT_MAX)) + { + *strp = (char *)malloc(size+1); //+1 for null + if (*strp) + { + r = vsnprintf(*strp, size+1, fmt, ap); //+1 for null + if ((r < 0) || (r > size)) + { + insane_free(*strp); + r = -1; + } + } + } + else { *strp = 0; } + + va_end(ap2); + + return(r); } #endif From c3a67fa7b1a3292b25f996ffc04034e2e08b114d Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 14:57:11 -0600 Subject: [PATCH 013/141] Use asprintf from https://github.com/littlstar/asprintf.c --- tools/flang2/flang2exe/CMakeLists.txt | 4 ++ tools/flang2/flang2exe/asprintf.c | 64 +++++++++++++++++++++++++++ tools/flang2/flang2exe/asprintf.h | 57 ++++++++++++++++++++++++ tools/flang2/flang2exe/outliner.c | 44 ------------------ 4 files changed, 125 insertions(+), 44 deletions(-) create mode 100644 tools/flang2/flang2exe/asprintf.c create mode 100644 tools/flang2/flang2exe/asprintf.h diff --git a/tools/flang2/flang2exe/CMakeLists.txt b/tools/flang2/flang2exe/CMakeLists.txt index 6cad7ef99a7..1d95e0e496a 100644 --- a/tools/flang2/flang2exe/CMakeLists.txt +++ b/tools/flang2/flang2exe/CMakeLists.txt @@ -87,6 +87,10 @@ set(SOURCES kmpcutil.h ) +if (MSVC) + set(SOURCES ${SOURCES} asprintf.c) +endif () + set(COMMON_DEFS MMD NOVECTORIZE diff --git a/tools/flang2/flang2exe/asprintf.c b/tools/flang2/flang2exe/asprintf.c new file mode 100644 index 00000000000..aabc26829e5 --- /dev/null +++ b/tools/flang2/flang2exe/asprintf.c @@ -0,0 +1,64 @@ +/** + * `asprintf.c' - asprintf + * + * copyright (c) 2014 joseph werle + */ + +#ifndef HAVE_ASPRINTF + +#include +#include +#include + +#include "asprintf.h" + +int +asprintf (char **str, const char *fmt, ...) { + int size = 0; + va_list args; + + // init variadic argumens + va_start(args, fmt); + + // format and get size + size = vasprintf(str, fmt, args); + + // toss args + va_end(args); + + return size; +} + +int +vasprintf (char **str, const char *fmt, va_list args) { + int size = 0; + va_list tmpa; + + // copy + va_copy(tmpa, args); + + // apply variadic arguments to + // sprintf with format to get size + size = vsnprintf(NULL, size, fmt, tmpa); + + // toss args + va_end(tmpa); + + // return -1 to be compliant if + // size is less than 0 + if (size < 0) { return -1; } + + // alloc with size plus 1 for `\0' + *str = (char *) malloc(size + 1); + + // return -1 to be compliant + // if pointer is `NULL' + if (NULL == *str) { return -1; } + + // format string with original + // variadic arguments and set new size + size = vsprintf(*str, fmt, args); + return size; +} + +#endif \ No newline at end of file diff --git a/tools/flang2/flang2exe/asprintf.h b/tools/flang2/flang2exe/asprintf.h new file mode 100644 index 00000000000..eba83e40a87 --- /dev/null +++ b/tools/flang2/flang2exe/asprintf.h @@ -0,0 +1,57 @@ +/** + * `asprintf.h' - asprintf.c + * + * copyright (c) 2014 joseph werle + +The MIT License (MIT) + +Copyright (c) 2014 Little Star Media, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + */ + +#ifndef HAVE_ASPRINTF +#ifndef ASPRINTF_H +#define ASPRINTF_H 1 + +#include + +/** + * Sets `char **' pointer to be a buffer + * large enough to hold the formatted string + * accepting a `va_list' args of variadic + * arguments. + */ + +int +vasprintf (char **, const char *, va_list); + +/** + * Sets `char **' pointer to be a buffer + * large enough to hold the formatted + * string accepting `n' arguments of + * variadic arguments. + */ + +int +asprintf (char **, const char *, ...); + +#endif +#endif \ No newline at end of file diff --git a/tools/flang2/flang2exe/outliner.c b/tools/flang2/flang2exe/outliner.c index 7cdf8a7fbe1..18ea119c60f 100644 --- a/tools/flang2/flang2exe/outliner.c +++ b/tools/flang2/flang2exe/outliner.c @@ -702,50 +702,6 @@ int mkstemp (char *tmpl) return (int)_fileno(&fp); } -/* -Copyright (C) 2014 insane coder (http://insanecoding.blogspot.com/, http://asprintf.insanecoding.org/) - -Permission to use, copy, modify, and distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -int vasprintf(char **strp, const char *fmt, va_list ap) -{ - int r = -1, size; - - va_list ap2; - va_copy(ap2, ap); - - size = vsnprintf(0, 0, fmt, ap2); - - if ((size >= 0) && (size < INT_MAX)) - { - *strp = (char *)malloc(size+1); //+1 for null - if (*strp) - { - r = vsnprintf(*strp, size+1, fmt, ap); //+1 for null - if ((r < 0) || (r > size)) - { - insane_free(*strp); - r = -1; - } - } - } - else { *strp = 0; } - - va_end(ap2); - - return(r); -} #endif int From 2dc1e0c05844e376ab86c8620be6edb2184a13f6 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 15:25:01 -0600 Subject: [PATCH 014/141] Implement dtime3f for windows. credits to xoviat --- runtime/flang/dtime3f.c | 30 ++++++++++++++++++++++++++++++ runtime/flang/etime3f.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/runtime/flang/dtime3f.c b/runtime/flang/dtime3f.c index 670ed8ed0c4..b1433772cea 100644 --- a/runtime/flang/dtime3f.c +++ b/runtime/flang/dtime3f.c @@ -35,6 +35,7 @@ #define CLK_TCK sysconf(_SC_CLK_TCK) #endif +#ifndef _WIN32 static clock_t accum_user = 0, accum_sys = 0; float ENT3F(DTIME, dtime)(float *tarray) @@ -49,4 +50,33 @@ float ENT3F(DTIME, dtime)(float *tarray) accum_sys = b.tms_stime; return (tarray[0] + tarray[1]); } +#else +#include +static FILETIME accum_user; +static FILETIME accum_sys; + +float convert_filetime( const FILETIME *ac_FileTime ) +{ + ULARGE_INTEGER lv_Large ; + + lv_Large.LowPart = ac_FileTime->dwLowDateTime ; + lv_Large.HighPart = ac_FileTime->dwHighDateTime ; + + return (float)lv_Large.QuadPart ; +} + +float ENT3F(DTIME, dtime)(float *tarray) +{ + + FILETIME time_create; + FILETIME time_exit; + + GetProcessTimes( GetCurrentProcess(), + &time_create, &time_exit, &accum_sys, &accum_user ); + + tarray[0] = ((float)(convert_filetime(&accum_user))); + tarray[1] = ((float)(convert_filetime(&accum_sys))); + return (tarray[0] + tarray[1]); +} +#endif diff --git a/runtime/flang/etime3f.c b/runtime/flang/etime3f.c index 5b12b3ade0b..407ebdd0e91 100644 --- a/runtime/flang/etime3f.c +++ b/runtime/flang/etime3f.c @@ -27,16 +27,17 @@ #ifndef _WIN32 #include +#include #endif #define _LIBC_LIMITS_H_ #include -#include #include #ifndef CLK_TCK #define CLK_TCK sysconf(_SC_CLK_TCK) #endif +#ifndef _WIN32 float ENT3F(ETIME, etime)(float *tarray) { struct tms b; @@ -48,3 +49,31 @@ float ENT3F(ETIME, etime)(float *tarray) return (tarray[0] + tarray[1]); } +#else +#include + +float convert_filetime( const FILETIME *ac_FileTime ) +{ + ULARGE_INTEGER lv_Large ; + + lv_Large.LowPart = ac_FileTime->dwLowDateTime ; + lv_Large.HighPart = ac_FileTime->dwHighDateTime ; + + return (float)lv_Large.QuadPart ; +} + +float ENT3F(DTIME, dtime)(float *tarray) +{ + FILETIME accum_user; + FILETIME accum_sys; + FILETIME time_create; + FILETIME time_exit; + + GetProcessTimes( GetCurrentProcess(), + &time_create, &time_exit, &accum_sys, &accum_user ); + + tarray[0] = ((float)(convert_filetime(&accum_user))); + tarray[1] = ((float)(convert_filetime(&accum_sys))); + return (tarray[0] + tarray[1]); +} +#endif From 9174a4e326af773845c634d652f90e4ac1dbeb2a Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 16:31:36 -0600 Subject: [PATCH 015/141] Remove annoying asserts --- runtime/flang/lstat643f.c | 2 +- runtime/flang/mclock3f.c | 2 +- tools/flang1/flang1exe/interf.c | 4 ++-- tools/flang1/flang1exe/symacc.c | 2 +- tools/flang2/flang2exe/symacc.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/flang/lstat643f.c b/runtime/flang/lstat643f.c index c6ff3090f5e..d8c037e0de5 100644 --- a/runtime/flang/lstat643f.c +++ b/runtime/flang/lstat643f.c @@ -19,7 +19,7 @@ /* lstat3f.c - Implements 64-bit LIB3F lstat subprogram. */ -#ifndef WINNT +#ifndef _WIN32 /* must include ent3f.h AFTER io3f.h */ #include diff --git a/runtime/flang/mclock3f.c b/runtime/flang/mclock3f.c index 8752f726d72..889113174dc 100644 --- a/runtime/flang/mclock3f.c +++ b/runtime/flang/mclock3f.c @@ -22,7 +22,7 @@ /* assumes the Unix times system call */ -#if defined(WINNT) +#if defined(_WIN32) #include diff --git a/tools/flang1/flang1exe/interf.c b/tools/flang1/flang1exe/interf.c index 04e2729fa7f..33edc53caab 100644 --- a/tools/flang1/flang1exe/interf.c +++ b/tools/flang1/flang1exe/interf.c @@ -81,10 +81,10 @@ void interf_init() { #if DEBUG - assert(sizeof(SYM) / sizeof(INT) == 44, "bad SYM size", + /*assert(sizeof(SYM) / sizeof(INT) == 44, "bad SYM size", sizeof(SYM) / sizeof(INT), 4); assert(sizeof(AST) / sizeof(int) == 19, "interf_init:inconsistent AST size", - sizeof(AST) / sizeof(int), 2); + sizeof(AST) / sizeof(int), 2);*/ #endif } diff --git a/tools/flang1/flang1exe/symacc.c b/tools/flang1/flang1exe/symacc.c index 5111cbd22e0..a1f03cc6c8d 100644 --- a/tools/flang1/flang1exe/symacc.c +++ b/tools/flang1/flang1exe/symacc.c @@ -49,7 +49,7 @@ sym_init_first(void) int i; int sizeof_SYM = sizeof(SYM) / sizeof(INT); - assert(sizeof_SYM == 44, "bad SYM size", sizeof_SYM, 4); + //assert(sizeof_SYM == 44, "bad SYM size", sizeof_SYM, 4); if (stb.stg_base == NULL) { stb.stg_size = 1000; diff --git a/tools/flang2/flang2exe/symacc.c b/tools/flang2/flang2exe/symacc.c index 3219b126b07..06d4369c96a 100644 --- a/tools/flang2/flang2exe/symacc.c +++ b/tools/flang2/flang2exe/symacc.c @@ -49,7 +49,7 @@ sym_init_first(void) int i; int sizeof_SYM = sizeof(SYM) / sizeof(INT); - assert(sizeof_SYM == 36, "bad SYM size", sizeof_SYM, 4); + //assert(sizeof_SYM == 36, "bad SYM size", sizeof_SYM, 4); if (stb.stg_base == NULL) { stb.stg_size = 1000; From 80cc848a3db18e7277ef24b22811b13736a70dc0 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 21 Oct 2017 18:00:34 -0500 Subject: [PATCH 016/141] sed WINNT, WIN32, WIN64 -> _WIN32 for runtime/flang --- runtime/flang/allo.c | 4 ++-- runtime/flang/amod.c | 4 ++-- runtime/flang/backspace.c | 2 +- runtime/flang/bcopys.c | 2 +- runtime/flang/buffer.c | 4 ++-- runtime/flang/close.c | 4 ++-- runtime/flang/cnfg.c | 2 +- runtime/flang/const.c | 2 +- runtime/flang/curdir.c | 2 +- runtime/flang/datan.c | 2 +- runtime/flang/datan2.c | 2 +- runtime/flang/delfilesqq3f.c | 4 ++-- runtime/flang/descIntrins.c | 6 +++--- runtime/flang/dlog10.c | 2 +- runtime/flang/dmod.c | 4 ++-- runtime/flang/drandm3f.c | 2 +- runtime/flang/entry.c | 6 +++--- runtime/flang/fdate3f.c | 2 +- runtime/flang/findfileqq3f.c | 2 +- runtime/flang/fmtwrite.c | 2 +- runtime/flang/fpcvt.c | 4 ++-- runtime/flang/fullpathqq3f.c | 2 +- runtime/flang/gerror3f.c | 2 +- runtime/flang/getcwd3f.c | 2 +- runtime/flang/getdat3f.c | 2 +- runtime/flang/getdrivedirqq3f.c | 2 +- runtime/flang/getfileinfoqq3f.c | 4 ++-- runtime/flang/getfileinfoqqi83f.c | 4 ++-- runtime/flang/getlog3f.c | 2 +- runtime/flang/gettim3f.c | 2 +- runtime/flang/getvolinfo3f.c | 4 ++-- runtime/flang/hand.c | 4 ++-- runtime/flang/hostnm3f.c | 2 +- runtime/flang/initpar.c | 10 +++++----- runtime/flang/inquire.c | 2 +- runtime/flang/kill3f.c | 2 +- runtime/flang/ldread.c | 2 +- runtime/flang/ldwrite.c | 2 +- runtime/flang/link3f.c | 2 +- runtime/flang/misc.c | 2 +- runtime/flang/nmlwrite.c | 2 +- runtime/flang/open.c | 4 ++-- runtime/flang/packtimeqq3f.c | 4 ++-- runtime/flang/perror3f.c | 2 +- runtime/flang/rand3f.c | 2 +- runtime/flang/random3f.c | 2 +- runtime/flang/rewind.c | 2 +- runtime/flang/setfileaccessqq3f.c | 4 ++-- runtime/flang/setfiletimeqq3f.c | 4 ++-- runtime/flang/signalqq3f.c | 2 +- runtime/flang/sleep3f.c | 2 +- runtime/flang/sleepqq3f.c | 2 +- runtime/flang/splitpathqq3f.c | 2 +- runtime/flang/srand3f.c | 2 +- runtime/flang/stat.c | 2 +- runtime/flang/stat3f.c | 2 +- runtime/flang/stat643f.c | 2 +- runtime/flang/stime3f.c | 2 +- runtime/flang/symlnk3f.c | 2 +- runtime/flang/ttynam3f.c | 2 +- runtime/flang/type.c | 2 +- runtime/flang/unpacktimeqq3f.c | 4 ++-- runtime/flang/utils3f.c | 4 ++-- runtime/flang/utilsi64.c | 2 +- runtime/flang/wait3f.c | 2 +- 65 files changed, 90 insertions(+), 90 deletions(-) diff --git a/runtime/flang/allo.c b/runtime/flang/allo.c index a7e4e1f0453..0e9e4918df2 100644 --- a/runtime/flang/allo.c +++ b/runtime/flang/allo.c @@ -247,7 +247,7 @@ I8(__fort_alloc)(__INT_T nelem, dtype kind, size_t len, __STAT_T *stat, char msg[80]; char *p_env; -#if (defined(WIN64) || defined(WIN32)) +#if (defined(_WIN32)) #define ALN_LARGE #else #undef ALN_LARGE @@ -396,7 +396,7 @@ I8(__alloc04)(__NELEM_T nelem, dtype kind, size_t len, if (!ISPRESENT(errmsg)) errmsg = NULL; -#if (defined(WIN64) || defined(WIN32)) +#if (defined(_WIN32)) #define ALN_LARGE #else #undef ALN_LARGE diff --git a/runtime/flang/amod.c b/runtime/flang/amod.c index f1225bd7fb9..d70be40cacd 100644 --- a/runtime/flang/amod.c +++ b/runtime/flang/amod.c @@ -17,14 +17,14 @@ #include "mthdecls.h" -#if defined(WIN64) +#if defined(_WIN32) float __fmth_i_amod(float f, float g); #endif float __mth_i_amod(float f, float g) { -#if defined(WIN64) +#if defined(_WIN32) return __fmth_i_amod(f, g); #else return FMODF(f, g); diff --git a/runtime/flang/backspace.c b/runtime/flang/backspace.c index 8b9aef71ce4..a95f6139c2c 100644 --- a/runtime/flang/backspace.c +++ b/runtime/flang/backspace.c @@ -74,7 +74,7 @@ _f90io_backspace(__INT_T *unit, __INT_T *bitv, __INT_T *iostat, int swap_bytes) if (f->nonadvance) { f->nonadvance = FALSE; -#if defined(WINNT) +#if defined(_WIN32) if (__fortio_binary_mode(f->fp)) __io_fputc('\r', f->fp); #endif diff --git a/runtime/flang/bcopys.c b/runtime/flang/bcopys.c index 538a18fcf59..d5be5c3258f 100644 --- a/runtime/flang/bcopys.c +++ b/runtime/flang/bcopys.c @@ -35,7 +35,7 @@ __fort_bcopysl(char *to, char *fr, size_t cnt, size_t tostr, size_t frstr, { size_t i, j; unsigned long n; -#if !defined(WIN64) +#if !defined(_WIN32) long k; #else long long k; diff --git a/runtime/flang/buffer.c b/runtime/flang/buffer.c index 718650fce93..d41cb63527d 100644 --- a/runtime/flang/buffer.c +++ b/runtime/flang/buffer.c @@ -19,13 +19,13 @@ * \brief FIXME */ -#if !defined(PARAMID) && !defined(WINNT) +#if !defined(PARAMID) && !defined(_WIN32) #include #endif #include "stdioInterf.h" #include "fioMacros.h" -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) #define write _write #define creat _creat #define close _close diff --git a/runtime/flang/close.c b/runtime/flang/close.c index dcdfc095c98..bb1504f580f 100644 --- a/runtime/flang/close.c +++ b/runtime/flang/close.c @@ -26,7 +26,7 @@ #include #include "stdioInterf.h" -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) #define unlink _unlink #define access _access #endif @@ -46,7 +46,7 @@ __fortio_close(FIO_FCB *f, int flag) if (f->nonadvance) { f->nonadvance = FALSE; -#if defined(WINNT) +#if defined(_WIN32) if (__fortio_binary_mode(f->fp)) __io_fputc('\r', f->fp); #endif diff --git a/runtime/flang/cnfg.c b/runtime/flang/cnfg.c index 10c8e0a28fb..c212b87b90e 100644 --- a/runtime/flang/cnfg.c +++ b/runtime/flang/cnfg.c @@ -90,7 +90,7 @@ __fortio_scratch_name(char *filename, int unit) extern char *__io_tempnam(); char *nm; -#if defined(WINNT) +#if defined(_WIN32) if (getenv("TMP") == 0) nm = __io_tempnam("C:\\", "FTN"); else diff --git a/runtime/flang/const.c b/runtime/flang/const.c index 5f2ee37a0cd..db61abef24f 100644 --- a/runtime/flang/const.c +++ b/runtime/flang/const.c @@ -133,7 +133,7 @@ __INT_T ENTCOMN(TYPE, type)[] = { 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43}; -#if defined(WINNT) && !defined(WIN64) && !defined(WIN32) +#if defined(_WIN32) && !defined(_WIN32) && !defined(_WIN32) char * __get_fort_type_addr(void) { diff --git a/runtime/flang/curdir.c b/runtime/flang/curdir.c index dc1398a78d9..2b646c19e43 100644 --- a/runtime/flang/curdir.c +++ b/runtime/flang/curdir.c @@ -26,7 +26,7 @@ #define MAXPATHLEN 1024 #endif -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) #define getcwd _getcwd #endif diff --git a/runtime/flang/datan.c b/runtime/flang/datan.c index 3e846760694..318d84120fb 100644 --- a/runtime/flang/datan.c +++ b/runtime/flang/datan.c @@ -15,7 +15,7 @@ * */ -#if !defined(WIN64) +#if !defined(_WIN32) #include "mthdecls.h" #else double atan(double d); diff --git a/runtime/flang/datan2.c b/runtime/flang/datan2.c index 5c53ce5cea1..6f7ca586764 100644 --- a/runtime/flang/datan2.c +++ b/runtime/flang/datan2.c @@ -15,7 +15,7 @@ * */ -#if !defined(WIN64) +#if !defined(_WIN32) #include "mthdecls.h" #else double atan2(double x, double y); diff --git a/runtime/flang/delfilesqq3f.c b/runtime/flang/delfilesqq3f.c index 59bb42a1331..16c34fabc4d 100644 --- a/runtime/flang/delfilesqq3f.c +++ b/runtime/flang/delfilesqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* delfilesqq3f.c - Implements DFLIB delfilesqq subprogram. */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include #endif #include @@ -27,7 +27,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) extern char *__fstr2cstr(); int ENT3F(DELFILESQQ, delfilesqq)(DCHAR(ffiles) DCLEN(ffiles)) { diff --git a/runtime/flang/descIntrins.c b/runtime/flang/descIntrins.c index 4409654f0c9..f825839abcc 100644 --- a/runtime/flang/descIntrins.c +++ b/runtime/flang/descIntrins.c @@ -28,10 +28,10 @@ #include #include "fioMacros.h" /* macros for entries */ -#if defined(WINNT) && !defined(WIN64) && !defined(UXOBJS) && !defined(CROBJS) +#if defined(_WIN32) && !defined(_WIN32) && !defined(UXOBJS) && !defined(CROBJS) #pragma global - x 121 0x20000 #define ENTFTN_MS(UC) WIN_EXP __attribute__((stdcall)) UC -#elif defined(WINNT) && defined(WIN64) +#elif defined(_WIN32) && defined(_WIN32) #define ENTFTN_MS I8 #endif @@ -185,7 +185,7 @@ ENTFTN(KINDEXX, kindexx_cr_nm) #endif -#if defined(WINNT) +#if defined(_WIN32) /* functions here follow the msfortran/mscall conventions */ diff --git a/runtime/flang/dlog10.c b/runtime/flang/dlog10.c index a2a5867cd18..ae58c64e708 100644 --- a/runtime/flang/dlog10.c +++ b/runtime/flang/dlog10.c @@ -15,7 +15,7 @@ * */ -#if !defined(WIN64) +#if !defined(_WIN32) #include "mthdecls.h" #else double log10(double d); diff --git a/runtime/flang/dmod.c b/runtime/flang/dmod.c index 4e917c9ed7a..be74ded609d 100644 --- a/runtime/flang/dmod.c +++ b/runtime/flang/dmod.c @@ -17,7 +17,7 @@ #include "mthdecls.h" -#if defined(WIN64) +#if defined(_WIN32) double __fmth_i_dmod(double f, double g); #endif @@ -25,7 +25,7 @@ double __mth_i_dmod(double f, double g) { /* Need to do this way until a bug in the Win64 fmod routine is fixed */ -#if defined(WIN64) +#if defined(_WIN32) return __fmth_i_dmod(f, g); #else return fmod(f, g); diff --git a/runtime/flang/drandm3f.c b/runtime/flang/drandm3f.c index dadc1d49605..dcb83ede989 100644 --- a/runtime/flang/drandm3f.c +++ b/runtime/flang/drandm3f.c @@ -22,7 +22,7 @@ #include "ent3f.h" /* drand48, srand48 are not currently available on win64 */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include diff --git a/runtime/flang/entry.c b/runtime/flang/entry.c index 3ce370bc1d0..42e50754c9f 100644 --- a/runtime/flang/entry.c +++ b/runtime/flang/entry.c @@ -24,16 +24,16 @@ #include "stdioInterf.h" #include "fioMacros.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) WIN_IMP __INT_T LINENO[]; -#elif defined(C90) || defined(WINNT) +#elif defined(C90) || defined(_WIN32) __INT_T LINENO[1]; char *__get_fort_lineno_addr(void); #else extern __INT_T LINENO[]; #endif -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) #define write _write #endif diff --git a/runtime/flang/fdate3f.c b/runtime/flang/fdate3f.c index c5fed2deb53..c94623b61df 100644 --- a/runtime/flang/fdate3f.c +++ b/runtime/flang/fdate3f.c @@ -24,7 +24,7 @@ #include #include "utils3f.h" -#if !defined(WIN32) && !defined(WIN64) +#if !defined(_WIN32) WIN_MSVCRT_IMP char *WIN_CDECL ctime(const time_t *); #endif diff --git a/runtime/flang/findfileqq3f.c b/runtime/flang/findfileqq3f.c index 7aac6c2023d..1b96a166346 100644 --- a/runtime/flang/findfileqq3f.c +++ b/runtime/flang/findfileqq3f.c @@ -26,7 +26,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) extern char *__fstr2cstr(); int ENT3F(FINDFILEQQ, findfileqq)(DCHAR(fname), DCHAR(fvarname), diff --git a/runtime/flang/fmtwrite.c b/runtime/flang/fmtwrite.c index 6d48aa1d309..fea89d75e74 100644 --- a/runtime/flang/fmtwrite.c +++ b/runtime/flang/fmtwrite.c @@ -2465,7 +2465,7 @@ fw_write_record(void) f->nonadvance = FALSE; /* do it now */ if (!(g->suppress_crlf)) { /* append carriage return */ -#if defined(WINNT) +#if defined(_WIN32) if (__fortio_binary_mode(f->fp)) __io_fputc('\r', f->fp); #endif diff --git a/runtime/flang/fpcvt.c b/runtime/flang/fpcvt.c index a0b6bada9e4..d1bce56a105 100644 --- a/runtime/flang/fpcvt.c +++ b/runtime/flang/fpcvt.c @@ -17,7 +17,7 @@ #include #include -#if !defined(WIN64) +#if !defined(_WIN32) #include #endif #include "fioMacros.h" @@ -733,7 +733,7 @@ __fortio_strtod(char *s, char **p) * (0 is before first digit). *sign is sign. */ -#if defined(WIN64) +#if defined(_WIN32) #define FE_TONEAREST 0 #define FE_DOWNWARD 1024 #define FE_UPWARD 2048 diff --git a/runtime/flang/fullpathqq3f.c b/runtime/flang/fullpathqq3f.c index ee2fad650cf..66b2562b358 100644 --- a/runtime/flang/fullpathqq3f.c +++ b/runtime/flang/fullpathqq3f.c @@ -25,7 +25,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) extern char *__fstr2cstr(); int ENT3F(FULLPATHQQ, fullpathqq)(DCHAR(fname), diff --git a/runtime/flang/gerror3f.c b/runtime/flang/gerror3f.c index a1a424dbcdf..d2dd142433e 100644 --- a/runtime/flang/gerror3f.c +++ b/runtime/flang/gerror3f.c @@ -27,7 +27,7 @@ #define Ftn_errmsg __fortio_errmsg -#if !defined(WIN64) && !defined(WIN32) +#if !defined(_WIN32) extern char *strerror(); /* SVR4 only ? */ #endif diff --git a/runtime/flang/getcwd3f.c b/runtime/flang/getcwd3f.c index 7e154ee7aad..0282e4eb521 100644 --- a/runtime/flang/getcwd3f.c +++ b/runtime/flang/getcwd3f.c @@ -25,7 +25,7 @@ #include "utils3f.h" #include "mpalloc.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #define GETCWDM _getcwd /* getcwd deprecated in Windows in VC 2005 */ #else #define GETCWDM getcwd diff --git a/runtime/flang/getdat3f.c b/runtime/flang/getdat3f.c index f15149331d3..2c1d9a9f745 100644 --- a/runtime/flang/getdat3f.c +++ b/runtime/flang/getdat3f.c @@ -19,7 +19,7 @@ /* getdat3f.c - Implements getdat subroutine. */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include #include "ent3f.h" diff --git a/runtime/flang/getdrivedirqq3f.c b/runtime/flang/getdrivedirqq3f.c index 80a69c0c4c5..d0ee2380b80 100644 --- a/runtime/flang/getdrivedirqq3f.c +++ b/runtime/flang/getdrivedirqq3f.c @@ -26,7 +26,7 @@ #include "utils3f.h" #include "mpalloc.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #define GETCWDM _getcwd /* getcwd deprecated in Windows in VC 2005 */ #else #define GETCWDM getcwd diff --git a/runtime/flang/getfileinfoqq3f.c b/runtime/flang/getfileinfoqq3f.c index efa610d99a5..c694ec99eb2 100644 --- a/runtime/flang/getfileinfoqq3f.c +++ b/runtime/flang/getfileinfoqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* getfileinfoqq3f.c - Implements DFLIB getfileinfoqq subprogram. */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include #endif #include @@ -27,7 +27,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) extern char *__fstr2cstr(); extern void __GetTimeToSecondsSince1970(ULARGE_INTEGER *fileTime, unsigned int *out); diff --git a/runtime/flang/getfileinfoqqi83f.c b/runtime/flang/getfileinfoqqi83f.c index b738aa92b34..b94c5590053 100644 --- a/runtime/flang/getfileinfoqqi83f.c +++ b/runtime/flang/getfileinfoqqi83f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* getfileinfoqq3f.c - Implements DFLIB getfileinfoqq subprogram. */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include #endif #include @@ -31,7 +31,7 @@ #define FILE$LAST -2 #define FILE$ERROR -3 -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) extern char *__fstr2cstr(); extern void __GetTimeToSecondsSince1970(ULARGE_INTEGER *fileTime, unsigned int *out); diff --git a/runtime/flang/getlog3f.c b/runtime/flang/getlog3f.c index a4e188a5a21..dc18f9b50db 100644 --- a/runtime/flang/getlog3f.c +++ b/runtime/flang/getlog3f.c @@ -19,7 +19,7 @@ /* getlog3f.c - Implements LIB3F getlog subprogram. */ -#ifndef WINNT +#ifndef _WIN32 #include "ent3f.h" #include "utils3f.h" diff --git a/runtime/flang/gettim3f.c b/runtime/flang/gettim3f.c index d8a2b099789..57d97b0c658 100644 --- a/runtime/flang/gettim3f.c +++ b/runtime/flang/gettim3f.c @@ -19,7 +19,7 @@ /* gettim3f.c - Implements gettim subroutine. */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include #include "ent3f.h" diff --git a/runtime/flang/getvolinfo3f.c b/runtime/flang/getvolinfo3f.c index dceddd6fb6a..d1d03102065 100644 --- a/runtime/flang/getvolinfo3f.c +++ b/runtime/flang/getvolinfo3f.c @@ -28,8 +28,8 @@ typedef char *LPSTR; typedef int DWORD; -#if defined(WIN64) || defined(WIN32) -#if defined(WIN64) +#if defined(_WIN32) +#if defined(_WIN32) typedef long long LDWORD; extern int GetVolumeInformationA(); #define ENTNAM(ss) _##ss diff --git a/runtime/flang/hand.c b/runtime/flang/hand.c index bc8b0b6d3d1..1f20dc5b1a4 100644 --- a/runtime/flang/hand.c +++ b/runtime/flang/hand.c @@ -19,7 +19,7 @@ #include "stdioInterf.h" #include "fioMacros.h" -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) #define write _write #endif @@ -96,7 +96,7 @@ static void sighand(s) int s; lcpu = __fort_myprocnum(); __fort_psignal(lcpu, s); /* print message */ -#if !defined(WIN64) && !defined(WIN32) +#if !defined(_WIN32) sleep(1); /* wait for message to clear */ #endif __fort_abort(NULL); /* abort */ diff --git a/runtime/flang/hostnm3f.c b/runtime/flang/hostnm3f.c index 56db4f50c06..dc9e9d01ff7 100644 --- a/runtime/flang/hostnm3f.c +++ b/runtime/flang/hostnm3f.c @@ -19,7 +19,7 @@ /* hostnm3f.c - Implements LIB3F hostnm subprogram. */ -#ifndef WINNT +#ifndef _WIN32 /* must include ent3f.h AFTER io3f.h */ #include "io3f.h" diff --git a/runtime/flang/initpar.c b/runtime/flang/initpar.c index c185d9c1f0c..c781b812095 100644 --- a/runtime/flang/initpar.c +++ b/runtime/flang/initpar.c @@ -76,10 +76,10 @@ static struct { /* common blocks containing values for inlined number_of_processors() and my_processor() functions */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) WIN_IMP __INT_T ENTCOMN(NP, np)[]; WIN_IMP __INT_T ENTCOMN(ME, me)[]; -#elif defined(C90) || defined(WINNT) +#elif defined(C90) || defined(_WIN32) __INT_T ENTCOMN(NP, np)[1]; __INT_T ENTCOMN(ME, me)[1]; #else @@ -87,7 +87,7 @@ extern __INT_T ENTCOMN(NP, np)[]; extern __INT_T ENTCOMN(ME, me)[]; #endif -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) #define write _write #endif @@ -107,8 +107,8 @@ __fort_ncpus() return __fort_tcpus; } -#if defined(WINNT) -#if !defined(WIN64) && !defined(WIN32) +#if defined(_WIN32) +#if !defined(_WIN32) __INT_T *CORMEM; /* special argument pointer access routines */ diff --git a/runtime/flang/inquire.c b/runtime/flang/inquire.c index 111159ed16e..2c17ea56eae 100644 --- a/runtime/flang/inquire.c +++ b/runtime/flang/inquire.c @@ -26,7 +26,7 @@ #include "global.h" #include "async.h" -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) #define access _access #endif diff --git a/runtime/flang/kill3f.c b/runtime/flang/kill3f.c index 979c2aa3986..715764cc1a8 100644 --- a/runtime/flang/kill3f.c +++ b/runtime/flang/kill3f.c @@ -19,7 +19,7 @@ /* kill3f.c - Implements LIB3F kill subprogram. */ -#ifndef WINNT +#ifndef _WIN32 #define POSIX 1 #include diff --git a/runtime/flang/ldread.c b/runtime/flang/ldread.c index b1c6f7afeb8..e56cf2d3db8 100644 --- a/runtime/flang/ldread.c +++ b/runtime/flang/ldread.c @@ -1628,7 +1628,7 @@ skip_record(void) } return __io_errno(); } -#if defined(WINNT) +#if defined(_WIN32) if (ch == '\r') { ch = __io_fgetc(fcb->fp); if (ch == '\n') diff --git a/runtime/flang/ldwrite.c b/runtime/flang/ldwrite.c index ff7fece60fc..f369ceb4896 100644 --- a/runtime/flang/ldwrite.c +++ b/runtime/flang/ldwrite.c @@ -793,7 +793,7 @@ write_record(void) return __io_errno(); } } else { /* sequential write: append carriage return */ -#if defined(WINNT) +#if defined(_WIN32) if (__fortio_binary_mode(fcb->fp)) if (FWRITE("\r", 1, 1, fcb->fp) != 1) return __io_errno(); diff --git a/runtime/flang/link3f.c b/runtime/flang/link3f.c index 955fa3714d3..e19c3ef77e6 100644 --- a/runtime/flang/link3f.c +++ b/runtime/flang/link3f.c @@ -19,7 +19,7 @@ /* link3f.c - Implements LIB3F link subprogram. */ -#ifndef WINNT +#ifndef _WIN32 /* must include ent3f.h AFTER io3f.h */ #include "io3f.h" diff --git a/runtime/flang/misc.c b/runtime/flang/misc.c index 8d70c5d839b..cf2cdd9c6e8 100644 --- a/runtime/flang/misc.c +++ b/runtime/flang/misc.c @@ -15,7 +15,7 @@ * */ -#if !defined(PARAMID) && !defined(WINNT) +#if !defined(PARAMID) && !defined(_WIN32) #include #include #include diff --git a/runtime/flang/nmlwrite.c b/runtime/flang/nmlwrite.c index ba126d01d80..65f7311f8b5 100644 --- a/runtime/flang/nmlwrite.c +++ b/runtime/flang/nmlwrite.c @@ -279,7 +279,7 @@ emit_eol(void) int ret_err; if (!internal_file) { -#if defined(WINNT) +#if defined(_WIN32) if (__fortio_binary_mode(f->fp)) { ret_err = write_char('\r'); if (ret_err) diff --git a/runtime/flang/open.c b/runtime/flang/open.c index 98860b5377f..f9824d87e22 100644 --- a/runtime/flang/open.c +++ b/runtime/flang/open.c @@ -30,7 +30,7 @@ #include "async.h" #include -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) #define access _access #endif @@ -103,7 +103,7 @@ __fortio_open(int unit, int action_flag, int status_flag, int dispose_flag, for (i = 0; i < namelen; i++) filename[i] = name[i]; filename[namelen] = '\0'; -#if defined(WINNT) +#if defined(_WIN32) if (filename[0] == '/' && filename[1] == '/' && filename[3] == '/') { /* convert posix format to win32 format */ filename[0] = filename[2]; /* drive letter */ diff --git a/runtime/flang/packtimeqq3f.c b/runtime/flang/packtimeqq3f.c index 499cf9a779b..05d4edd5bd6 100644 --- a/runtime/flang/packtimeqq3f.c +++ b/runtime/flang/packtimeqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* packtimeqq3f.c - Implements DFLIB packtimeqq subprogram. */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include #endif #include @@ -27,7 +27,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) extern char *__fstr2cstr(); extern void __GetTimeToSecondsSince1970(ULARGE_INTEGER *fileTime, unsigned int *out); diff --git a/runtime/flang/perror3f.c b/runtime/flang/perror3f.c index 67b93e493e3..cc72266583f 100644 --- a/runtime/flang/perror3f.c +++ b/runtime/flang/perror3f.c @@ -23,7 +23,7 @@ #include "io3f.h" #include "ent3f.h" -#if !defined(WIN64) && !defined(WIN32) +#if !defined(_WIN32) extern char *strerror(); /* SVR4 only ? */ #endif extern FILE *__getfile3f(); diff --git a/runtime/flang/rand3f.c b/runtime/flang/rand3f.c index 94c4341aca6..533bc1bc8d2 100644 --- a/runtime/flang/rand3f.c +++ b/runtime/flang/rand3f.c @@ -22,7 +22,7 @@ #include "ent3f.h" /* drand48 is not currently available on win64 */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include diff --git a/runtime/flang/random3f.c b/runtime/flang/random3f.c index 2c77283b588..c722bdf572d 100644 --- a/runtime/flang/random3f.c +++ b/runtime/flang/random3f.c @@ -22,7 +22,7 @@ #include "ent3f.h" /* drand48, srand48 are not currently available on win64 */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include diff --git a/runtime/flang/rewind.c b/runtime/flang/rewind.c index 2629532c95e..ef2d0435295 100644 --- a/runtime/flang/rewind.c +++ b/runtime/flang/rewind.c @@ -54,7 +54,7 @@ _f90io_rewind(__INT_T *unit, __INT_T *bitv, __INT_T *iostat) if (f->nonadvance) { f->nonadvance = FALSE; -#if defined(WINNT) +#if defined(_WIN32) if (__fortio_binary_mode(f->fp)) __io_fputc('\r', f->fp); #endif diff --git a/runtime/flang/setfileaccessqq3f.c b/runtime/flang/setfileaccessqq3f.c index 9f508030df3..a9f53884989 100644 --- a/runtime/flang/setfileaccessqq3f.c +++ b/runtime/flang/setfileaccessqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* setfileaccessqq3f.c - Implements DFLIB setfileaccessqq subprogram. */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include #endif #include @@ -32,7 +32,7 @@ #define FILE$ERROR -3 #define FILE$CURTIME -1 -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) extern char *__fstr2cstr(); int ENT3F(SETFILEACCESSQQ, setfileaccessqq)(DCHAR(ffile), diff --git a/runtime/flang/setfiletimeqq3f.c b/runtime/flang/setfiletimeqq3f.c index f74e298e51d..b50c5b0d5fe 100644 --- a/runtime/flang/setfiletimeqq3f.c +++ b/runtime/flang/setfiletimeqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* setfiletimeqq3f.c - Implements DFLIB setfiletimeqq subprogram. */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include #endif #include @@ -32,7 +32,7 @@ #define FILE$ERROR -3 #define FILE$CURTIME -1 -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) extern char *__fstr2cstr(); extern void __UnpackTime(unsigned int secsSince1970, ULARGE_INTEGER *fileTime); extern int __GETFILEINFOQQ(DCHAR(ffiles), char *buffer, diff --git a/runtime/flang/signalqq3f.c b/runtime/flang/signalqq3f.c index d89ee910082..5eb2d50e533 100644 --- a/runtime/flang/signalqq3f.c +++ b/runtime/flang/signalqq3f.c @@ -24,7 +24,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(WIN64) || !defined(WINNT) +#if defined(_WIN32) || !defined(_WIN32) #define LONGINTSIZE unsigned long long diff --git a/runtime/flang/sleep3f.c b/runtime/flang/sleep3f.c index 8b74e306ba4..48cddf26920 100644 --- a/runtime/flang/sleep3f.c +++ b/runtime/flang/sleep3f.c @@ -22,7 +22,7 @@ #include #include "ent3f.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include diff --git a/runtime/flang/sleepqq3f.c b/runtime/flang/sleepqq3f.c index fd05977bc12..eb8acf6613a 100644 --- a/runtime/flang/sleepqq3f.c +++ b/runtime/flang/sleepqq3f.c @@ -22,7 +22,7 @@ #include #include "ent3f.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include diff --git a/runtime/flang/splitpathqq3f.c b/runtime/flang/splitpathqq3f.c index 4922d6e4f95..6e84cef9315 100644 --- a/runtime/flang/splitpathqq3f.c +++ b/runtime/flang/splitpathqq3f.c @@ -25,7 +25,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) extern char *__fstr2cstr(); int ENT3F(SPLITPATHQQ, splitpathqq)(DCHAR(fpath), DCHAR(fdrive), DCHAR(fdir), diff --git a/runtime/flang/srand3f.c b/runtime/flang/srand3f.c index a0bb2aaa81d..8c23a50cf6c 100644 --- a/runtime/flang/srand3f.c +++ b/runtime/flang/srand3f.c @@ -23,7 +23,7 @@ #include "ent3f.h" /* srand48 is not currently available on win64 */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) void ENT3F(SRAND1, srand1)(int *iseed) { srand(*iseed); } diff --git a/runtime/flang/stat.c b/runtime/flang/stat.c index 8ce7bac01f4..632a7f941cd 100644 --- a/runtime/flang/stat.c +++ b/runtime/flang/stat.c @@ -23,7 +23,7 @@ #include #include -#if defined(WIN32) || defined(WIN64) +#if defined(_WIN32) #define write _write #endif diff --git a/runtime/flang/stat3f.c b/runtime/flang/stat3f.c index 537bd7eb09f..454bb663819 100644 --- a/runtime/flang/stat3f.c +++ b/runtime/flang/stat3f.c @@ -72,7 +72,7 @@ int ENT3F(STAT, stat)(DCHAR(nm), int *statb DCLEN(nm)) statb[8] = b.st_atime; statb[9] = b.st_mtime; statb[10] = b.st_ctime; -#if !defined(WINNT) +#if !defined(_WIN32) statb[11] = b.st_blksize; statb[12] = b.st_blocks; #else diff --git a/runtime/flang/stat643f.c b/runtime/flang/stat643f.c index 502545872c1..79527c0b403 100644 --- a/runtime/flang/stat643f.c +++ b/runtime/flang/stat643f.c @@ -29,7 +29,7 @@ extern void __cstr_free(); int ENT3F(STAT64, stat64)(DCHAR(nm), long long *statb DCLEN(nm)) { -#if defined(TARGET_WIN) || defined(WIN32) || defined(WIN64) +#if defined(TARGET_WIN) || defined(_WIN32) /* * The __int64_t members in the _stat64 are 8-byte aligned, thus the * st_size member is at offset 24. On WIN32, 64-bit ints are 4-byte diff --git a/runtime/flang/stime3f.c b/runtime/flang/stime3f.c index 83ed1955a83..ffea8246818 100644 --- a/runtime/flang/stime3f.c +++ b/runtime/flang/stime3f.c @@ -19,7 +19,7 @@ /* stime3f.c - Implements LIB3F stime subprogram. */ -#ifndef WINNT +#ifndef _WIN32 #include #include "io3f.h" diff --git a/runtime/flang/symlnk3f.c b/runtime/flang/symlnk3f.c index 3bebe65b213..742be816d82 100644 --- a/runtime/flang/symlnk3f.c +++ b/runtime/flang/symlnk3f.c @@ -19,7 +19,7 @@ /* symlnk3f.c - Implements LIB3F symlnk subprogram. */ -#ifndef WINNT +#ifndef _WIN32 #include "io3f.h" #include "ent3f.h" diff --git a/runtime/flang/ttynam3f.c b/runtime/flang/ttynam3f.c index a811bd46f19..4fa5ee5e728 100644 --- a/runtime/flang/ttynam3f.c +++ b/runtime/flang/ttynam3f.c @@ -19,7 +19,7 @@ /* ttynam3f.c - Implements LIB3F ttynam subprogram. */ -#ifndef WINNT +#ifndef _WIN32 /* must include ent3f.h AFTER io3f.h */ #include "io3f.h" diff --git a/runtime/flang/type.c b/runtime/flang/type.c index 4f17ae9b1f7..ce6b0f3e59f 100644 --- a/runtime/flang/type.c +++ b/runtime/flang/type.c @@ -703,7 +703,7 @@ void ENTF90(POLY_ASN, poly_asn)(char *ab, F90_Desc *ad, char *bb, F90_Desc *bd, } } else if (bd && !flag && ISSCALAR(bd) && bd->tag != __POLY && bd->tag < __NTYPES) { -#if defined(WINNT) +#if defined(_WIN32) src_sz = __get_fort_size_of(bd->tag); #else src_sz = __fort_size_of[bd->tag]; diff --git a/runtime/flang/unpacktimeqq3f.c b/runtime/flang/unpacktimeqq3f.c index 8f7b54c620d..4c0ed541e6a 100644 --- a/runtime/flang/unpacktimeqq3f.c +++ b/runtime/flang/unpacktimeqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* unpacktimeqq3f.c - Implements DFLIB packtimeqq subprogram. */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include #endif #include @@ -28,7 +28,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) extern char *__fstr2cstr(); extern void __UnpackTime(unsigned int secsSince1970, ULARGE_INTEGER *fileTime); diff --git a/runtime/flang/utils3f.c b/runtime/flang/utils3f.c index 5676e3eae1a..48608e97087 100644 --- a/runtime/flang/utils3f.c +++ b/runtime/flang/utils3f.c @@ -16,7 +16,7 @@ */ /* */ -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) #include #endif #include "io3f.h" @@ -119,7 +119,7 @@ extern FILE *__getfile3f(unit) int unit; } } -#if defined(WIN64) || defined(WIN32) +#if defined(_WIN32) void __GetTimeToSecondsSince1970(ULARGE_INTEGER *fileTime, unsigned int *out) { diff --git a/runtime/flang/utilsi64.c b/runtime/flang/utilsi64.c index 312fbd7d37b..c23216598f6 100644 --- a/runtime/flang/utilsi64.c +++ b/runtime/flang/utilsi64.c @@ -36,7 +36,7 @@ extern int __fort_atoxi64(); extern void __fort_i64toax(); /* has native support for 8-byte integers*/ -#if !defined(WIN64) +#if !defined(_WIN32) typedef long I8_T; typedef unsigned long UI8_T; #else diff --git a/runtime/flang/wait3f.c b/runtime/flang/wait3f.c index d2a3733529b..7da89577d94 100644 --- a/runtime/flang/wait3f.c +++ b/runtime/flang/wait3f.c @@ -19,7 +19,7 @@ /* wait3f.c - Implements LIB3F wait subprogram. */ -#ifndef WINNT +#ifndef _WIN32 #include #include From d061cadbbb4e2ad0ad5dd3365b7418f904928979 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 22 Oct 2017 17:47:12 -0500 Subject: [PATCH 017/141] FIX anonymous structs FIX: missed first time --- runtime/flang/async.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/runtime/flang/async.c b/runtime/flang/async.c index 5e5c81918fb..881516a1d6d 100644 --- a/runtime/flang/async.c +++ b/runtime/flang/async.c @@ -302,11 +302,11 @@ Fio_asy_read(struct asy *asy, void *adr, long len) tn = asy->outstanding_transactions; asy->overlap[tn].Internal = 0; asy->overlap[tn].InternalHigh = 0; - asy->overlap[tn].u.Pointer = 0; + asy->overlap[tn].Pointer = 0; /* Load asy->off into OffsetHigh/Offset */ converter.offset = asy->atd[tn].off; - asy->overlap[tn].u.s.Offset = converter.wOffset; - asy->overlap[tn].u.s.OffsetHigh = converter.wOffsetHigh; + asy->overlap[tn].Offset = converter.wOffset; + asy->overlap[tn].OffsetHigh = converter.wOffsetHigh; asy->overlap[tn].hEvent = 0; if (ReadFile(asy->handle, adr, len, NULL, &(asy->overlap[tn])) == FALSE && GetLastError() != ERROR_IO_PENDING) { @@ -356,11 +356,11 @@ Fio_asy_write(struct asy *asy, void *adr, long len) tn = asy->outstanding_transactions; asy->overlap[tn].Internal = 0; asy->overlap[tn].InternalHigh = 0; - asy->overlap[tn].u.Pointer = 0; + asy->overlap[tn].Pointer = 0; /* Load asy->off into OffsetHigh/Offset. */ converter.offset = asy->atd[0].off; - asy->overlap[tn].u.s.Offset = converter.wOffset; - asy->overlap[tn].u.s.OffsetHigh = converter.wOffsetHigh; + asy->overlap[tn].Offset = converter.wOffset; + asy->overlap[tn].OffsetHigh = converter.wOffsetHigh; asy->overlap[tn].hEvent = 0; if (WriteFile(asy->handle, adr, len, NULL, &(asy->overlap[tn])) == FALSE && GetLastError() != ERROR_IO_PENDING) { @@ -415,4 +415,3 @@ Fio_asy_close(struct asy *asy) free(asy); return (n); } - From 78cbebd0165c31fd4ca8cc4fd95e95983804d248 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 22 Oct 2017 18:30:24 -0500 Subject: [PATCH 018/141] Fix CMake --- CMakeLists.txt | 4 +++- runtime/flang/CMakeLists.txt | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e298e403e3..693755d31c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,10 @@ cmake_minimum_required(VERSION 2.8) # In order to bootstrap the runtime library we need to skip # CMake's Fortran tests SET(CMAKE_Fortran_COMPILER_WORKS 1) + + set(CMAKE_Fortran_PREPROCESS_SOURCE - " -Mpreprocess -E -o ") + " -cpp -E -o ") # If we are not building as a part of LLVM, build Flang as an # standalone project, using LLVM as an external library: diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index dc29e565e68..446e1129fcc 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -531,7 +531,6 @@ set_property( ## CMake does not handle module dependencies between Fortran files, ## we need to help it -if (NOT MSVC) # State the module that the source is producing set_source_files_properties( iso_c_bind.F95 @@ -546,7 +545,6 @@ set_source_files_properties( PROPERTIES OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod ) -endif() set_target_properties(flang_static flang_shared PROPERTIES @@ -577,9 +575,10 @@ add_dependencies(flang_shared flang2 ) -target_compile_options(flang_static PRIVATE -fPIC) - -target_compile_options(flang_shared PRIVATE -fPIC) +if (NOT MSVC) + target_compile_options(flang_static PRIVATE -fPIC) + target_compile_options(flang_shared PRIVATE -fPIC) +endif() target_compile_options(flang_static PUBLIC $<$:-Mreentrant>) From ad7b0e2bd18381deafe85029ff909ea29ce803d4 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 22 Oct 2017 18:30:41 -0500 Subject: [PATCH 019/141] Misc MSVC fixes --- runtime/flang/assign.c | 4 ++-- runtime/flang/async.c | 20 ++++++++--------- runtime/flang/buffer.c | 8 +++---- runtime/flang/close.c | 2 ++ runtime/flang/cplxf.c | 2 ++ runtime/flang/curdir.c | 6 +++++ runtime/flang/fmtconv.c | 10 ++++----- runtime/flang/fmtread.c | 23 ++++++++++--------- runtime/flang/fmtwrite.c | 44 ++++++++++++++++++------------------- runtime/flang/global.h | 8 ++++++- runtime/flang/hand.c | 3 +++ runtime/flang/heapinit.c | 7 ++++-- runtime/flang/initpar.c | 2 ++ runtime/flang/map.c | 2 ++ runtime/flang/miscsup_com.c | 2 ++ runtime/flang/mmcmplx16.c | 40 +++++++++++++++++++++++---------- runtime/flang/mmcmplx8.c | 23 ++++++++++++------- runtime/flang/sleep3f.c | 2 ++ runtime/flang/sleepqq3f.c | 2 ++ runtime/flang/stat_linux.c | 10 ++++++++- runtime/flang/timef3f.c | 3 ++- runtime/flang/usrio_smp.c | 4 ++-- 22 files changed, 147 insertions(+), 80 deletions(-) diff --git a/runtime/flang/assign.c b/runtime/flang/assign.c index dc3efddd64f..55fbf53e5a5 100644 --- a/runtime/flang/assign.c +++ b/runtime/flang/assign.c @@ -210,8 +210,8 @@ __fortio_assign(char *item, /* where to store */ case __INT8: if (__ftn_32in64_) I64_MSH(valp->val.i8) = 0; - PP_INT4(item) = valp->val.i8[0]; - PP_INT4(item + 4) = valp->val.i8[1]; + PP_INT4(item) = I64_LSH(valp->val.i8); + PP_INT4(item + 4) = I64_MSH(valp->val.i8); break; case __REAL4: PP_REAL4(item) = (float)I64_LSH(valp->val.i8); diff --git a/runtime/flang/async.c b/runtime/flang/async.c index 881516a1d6d..d5633ef2c3e 100644 --- a/runtime/flang/async.c +++ b/runtime/flang/async.c @@ -27,7 +27,7 @@ * Fio_asy_close - called from close */ -#if !defined(TARGET_WIN_X8664) +#if !defined(_WIN32) #include #include #include @@ -52,7 +52,7 @@ struct asy_transaction_data { seekoffx_t off; }; -#if defined(TARGET_WIN_X8664) +#if defined(_WIN32) struct asy { FILE *fp; int fd; @@ -92,7 +92,7 @@ static int slime; /* internal wait for asynch i/o */ -#if defined(TARGET_WIN_X8664) +#if defined(_WIN32) static int asy_wait(struct asy *asy) { @@ -253,7 +253,7 @@ Fio_asy_open(FILE *fp, struct asy **pasy) { struct asy *asy; char *p; -#if defined(TARGET_WIN_X8664) +#if defined(_WIN32) HANDLE temp_handle; #endif asy = (struct asy *)calloc(sizeof(struct asy), 1); @@ -263,7 +263,7 @@ Fio_asy_open(FILE *fp, struct asy **pasy) } asy->fp = fp; asy->fd = __io_getfd(fp); -#if defined(TARGET_WIN_X8664) +#if defined(_WIN32) temp_handle = _get_osfhandle(asy->fd); asy->handle = ReOpenFile(temp_handle, GENERIC_READ | GENERIC_WRITE, @@ -287,13 +287,13 @@ Fio_asy_read(struct asy *asy, void *adr, long len) int n; int tn; -#if defined(TARGET_WIN_X8664) +#if defined(_WIN32) union Converter converter; #endif if (slime) printf("--Fio_asy_read %d %p %ld\n", asy->fd, adr, len); -#if defined(TARGET_WIN_X8664) +#if defined(_WIN32) if (asy->flags & ASY_IOACT) { /* i/o active? */ if (asy_wait(asy) == -1) { /* ..yes, wait */ return (-1); @@ -340,14 +340,14 @@ Fio_asy_write(struct asy *asy, void *adr, long len) { int n; int tn; -#if defined(TARGET_WIN_X8664) +#if defined(_WIN32) union Converter converter; #endif if (slime) printf("--Fio_asy_write %d %p %ld\n", asy->fd, adr, len); -#if defined(TARGET_WIN_X8664) +#if defined(_WIN32) if (asy->flags & ASY_IOACT) { /* i/o active? */ if (asy_wait(asy) == -1) { /* ..yes, wait */ return (-1); @@ -408,7 +408,7 @@ Fio_asy_close(struct asy *asy) if (asy->flags & ASY_IOACT) { /* i/o active? */ n = asy_wait(asy); } -#if defined(TARGET_WIN_X8664) +#if defined(_WIN32) /* Close the Re-opened handle that we created. */ CloseHandle(asy->handle); #endif diff --git a/runtime/flang/buffer.c b/runtime/flang/buffer.c index d41cb63527d..23197b527f2 100644 --- a/runtime/flang/buffer.c +++ b/runtime/flang/buffer.c @@ -18,10 +18,7 @@ /** \file * \brief FIXME */ - -#if !defined(PARAMID) && !defined(_WIN32) #include -#endif #include "stdioInterf.h" #include "fioMacros.h" @@ -29,6 +26,9 @@ #define write _write #define creat _creat #define close _close +#define O_WRONLY _O_WRONLY +#define O_CREAT _O_CREAT +#define O_TRUNC _O_TRUNC #endif #define MAXBUF 4096 @@ -72,7 +72,7 @@ __fort_zopen(char *path) __fort_rrecv(ioproc, &off, sizeof(off), 1, __UCHAR); } else { off = 0; - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); + fd = open(path); if (fd == -1) { __fort_abortp(path); } diff --git a/runtime/flang/close.c b/runtime/flang/close.c index bb1504f580f..09a6aa9afb0 100644 --- a/runtime/flang/close.c +++ b/runtime/flang/close.c @@ -23,7 +23,9 @@ #include #include "global.h" +#ifndef _WIN32 #include +#endif #include "stdioInterf.h" #if defined(_WIN32) diff --git a/runtime/flang/cplxf.c b/runtime/flang/cplxf.c index 6188bbd389e..3120e5c724e 100644 --- a/runtime/flang/cplxf.c +++ b/runtime/flang/cplxf.c @@ -20,8 +20,10 @@ #include "stdioInterf.h" #include "fioMacros.h" #include +#ifndef _WIN32 #include #include +#endif extern double __fort_second(); extern long __fort_getoptn(char *, long); diff --git a/runtime/flang/curdir.c b/runtime/flang/curdir.c index 2b646c19e43..076e8fbefcc 100644 --- a/runtime/flang/curdir.c +++ b/runtime/flang/curdir.c @@ -16,8 +16,10 @@ */ #include +#ifndef _WIN32 #include #include +#endif #include #include "stdioInterf.h" #include "fioMacros.h" @@ -100,6 +102,7 @@ void __fort_getdir(curdir) char *curdir; void __fort_gethostname(host) char *host; { +#ifndef _WIN32 struct utsname un; char *p; int s; @@ -113,4 +116,7 @@ void __fort_gethostname(host) char *host; p = un.nodename; } strcpy(host, p); +#else + strcpy(host, "localhost"); +#endif } diff --git a/runtime/flang/fmtconv.c b/runtime/flang/fmtconv.c index 08f7ab6616e..abd12f9ac5c 100644 --- a/runtime/flang/fmtconv.c +++ b/runtime/flang/fmtconv.c @@ -237,8 +237,8 @@ __fortio_default_convert(char *item, int type, break; case __LOG8: width = 2; - i8val[0] = PP_LOG4(item); - i8val[1] = PP_LOG4(item + 4); + I64_LSH(i8val) = PP_LOG4(item); + I64_MSH(i8val) = PP_LOG4(item + 4); if (I64_LSH(i8val) & GET_FIO_CNFG_TRUE_MASK) put_buf(width, "T", 1, 0); else @@ -366,7 +366,7 @@ __fortio_fmt_i8(INT64 val, put_buf(width, p, len, neg); } else { /* Iw.0 gen's blanks if value is 0 */ - if (mn == 0 && val[0] == 0 && val[1] == 0) + if (mn == 0 && I64_LSH(val) == 0 && I64_MSH(val) == 0) neg = 0; put_buf(width, p, len, neg); if (mn > len) { @@ -394,8 +394,8 @@ conv_int8(INT64 val, int *lenp, int *negp) INT64 value; *negp = 0; - value[0] = val[0]; - value[1] = val[1]; + I64_LSH(value) = I64_LSH(val); + I64_MSH(value) = I64_MSH(val); if (__ftn_32in64_) { if (I64_LSH(value) & 0x80000000) I64_MSH(value) = -1; diff --git a/runtime/flang/fmtread.c b/runtime/flang/fmtread.c index 7ea621274ef..42c28717f63 100644 --- a/runtime/flang/fmtread.c +++ b/runtime/flang/fmtread.c @@ -1812,8 +1812,8 @@ fr_readnum(int code, char *item, int type) return __fortio_error(FIO_EERR_DATA_CONVERSION); } if (ty == __INT8) { - i8val[1] = 0; - i8val[0] = ival; + I64_MSH(i8val) = 0; + I64_LSH(i8val) = ival; } break; @@ -1876,9 +1876,11 @@ fr_readnum(int code, char *item, int type) idx++, w--; if (comma_seen) w -= 1; - if (w == 0) - ival = i8val[0] = i8val[1] = 0; - else { + if (w == 0) { + I64_LSH(i8val) = 0; + I64_MSH(i8val) = 0; + ival = 0; + } else { c = g->rec_buff[idx]; e = FALSE; /* sign flag */ if (ty == __INT8) { @@ -1892,7 +1894,8 @@ fr_readnum(int code, char *item, int type) */ int tmp_w = w; int cpos = idx; /* 'last' character copied */ - i8val[0] = i8val[1] = 0; + I64_MSH(i8val) = 0; + I64_LSH(i8val) = 0; tmp_idx = idx; while (--tmp_w > 0) { ++tmp_idx; @@ -2103,14 +2106,14 @@ fr_assign(char *item, int type, __BIGINT_T ival, INT64 i8val, __BIGREAL_T dval) case __LOG8: if (__ftn_32in64_) I64_MSH(i8val) = 0; - ((__INT4_T *)item)[0] = i8val[0]; - ((__INT4_T *)item)[1] = i8val[1]; + ((__INT4_T *)item)[0] = I64_LSH(i8val); + ((__INT4_T *)item)[1] = I64_MSH(i8val); break; case __INT8: if (__ftn_32in64_) I64_MSH(i8val) = 0; - ((__INT4_T *)item)[0] = i8val[0]; - ((__INT4_T *)item)[1] = i8val[1]; + ((__INT4_T *)item)[0] = I64_LSH(i8val); + ((__INT4_T *)item)[1] = I64_MSH(i8val); break; default: diff --git a/runtime/flang/fmtwrite.c b/runtime/flang/fmtwrite.c index fea89d75e74..1b83aa7598c 100644 --- a/runtime/flang/fmtwrite.c +++ b/runtime/flang/fmtwrite.c @@ -1635,15 +1635,15 @@ fw_writenum(int code, char *item, int type) is_logical = TRUE; break; case __LOG8: - i8val[0] = ((__INT4_T *)item)[0]; - i8val[1] = ((__INT4_T *)item)[1]; + I64_LSH(i8val) = ((__INT4_T *)item)[0]; + I64_MSH(i8val) = ((__INT4_T *)item)[1]; ty = __INT8; w = 24; is_logical = TRUE; break; case __INT8: - i8val[0] = ((__INT4_T *)item)[0]; - i8val[1] = ((__INT4_T *)item)[1]; + I64_LSH(i8val) = ((__INT4_T *)item)[0]; + I64_MSH(i8val) = ((__INT4_T *)item)[1]; ty = __INT8; w = 24; break; @@ -1753,8 +1753,8 @@ fw_writenum(int code, char *item, int type) case __REAL8: case __REAL16: crc.r8 = dval; - i8val[0] = crc.i8v[0]; - i8val[1] = crc.i8v[1]; + I64_LSH(i8val) = I64_LSH(crc.i8v); + I64_MSH(i8val) = I64_MSH(crc.i8v); ty = __INT8; w = 24; break; @@ -1780,8 +1780,8 @@ fw_writenum(int code, char *item, int type) case __REAL8: case __REAL16: crc.r8 = dval; - i8val[0] = crc.i8v[0]; - i8val[1] = crc.i8v[1]; + I64_LSH(i8val) = I64_LSH(crc.i8v); + I64_MSH(i8val) = I64_MSH(crc.i8v); ty = __INT8; break; } @@ -1839,8 +1839,8 @@ fw_writenum(int code, char *item, int type) case __REAL8: case __REAL16: crc.r8 = dval; - i8val[0] = crc.i8v[0]; - i8val[1] = crc.i8v[1]; + I64_LSH(i8val) = I64_LSH(crc.i8v); + I64_MSH(i8val) = I64_MSH(crc.i8v); ty = __INT8; break; } @@ -1866,8 +1866,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - crc.i8v[0] = i8val[0]; - crc.i8v[1] = i8val[1]; + I64_LSH(i8val) = I64_LSH(crc.i8v); + I64_MSH(i8val) = I64_MSH(crc.i8v); dval = crc.r8; e = 2; ty = __REAL8; @@ -1908,8 +1908,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - crc.i8v[0] = i8val[0]; - crc.i8v[1] = i8val[1]; + I64_LSH(crc.i8v) = I64_LSH(i8val); + I64_MSH(crc.i8v) = I64_MSH(i8val); dval = crc.r8; w = REAL8_W; d = REAL8_D; @@ -1947,8 +1947,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - crc.i8v[0] = i8val[0]; - crc.i8v[1] = i8val[1]; + I64_LSH(crc.i8v) = I64_LSH(i8val); + I64_MSH(crc.i8v) = I64_MSH(i8val); dval = crc.r8; if (!e_flag) e = 2; @@ -1979,8 +1979,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - crc.i8v[0] = i8val[0]; - crc.i8v[1] = i8val[1]; + I64_LSH(crc.i8v) = I64_LSH(i8val); + I64_MSH(crc.i8v) = I64_MSH(i8val); dval = crc.r8; w = REAL8_W; d = REAL8_D; @@ -2009,8 +2009,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - crc.i8v[0] = i8val[0]; - crc.i8v[1] = i8val[1]; + I64_LSH(crc.i8v) = I64_LSH(i8val); + I64_MSH(crc.i8v) = I64_MSH(i8val); dval = crc.r8; ty = __REAL8; break; @@ -2031,8 +2031,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - crc.i8v[0] = i8val[0]; - crc.i8v[1] = i8val[1]; + I64_LSH(crc.i8v) = I64_LSH(i8val); + I64_MSH(crc.i8v) = I64_MSH(i8val); dval = crc.r8; w = REAL8_W; d = REAL8_D; diff --git a/runtime/flang/global.h b/runtime/flang/global.h index c6706f8db64..5acbf4ed8e7 100644 --- a/runtime/flang/global.h +++ b/runtime/flang/global.h @@ -28,11 +28,17 @@ /* declarations needed where integer*8 & logical*8 are supported and * the natural integer is integer*4 (__BIGINT is __INT4). */ +#ifndef _WIN32 typedef int INT64[2]; typedef unsigned int UINT64[2]; - #define I64_MSH(t) t[1] #define I64_LSH(t) t[0] +#else +#include +#define I64_MSH(t) ((int*)((void *)&t))[1] +#define I64_LSH(t) ((int*)((void *)&t))[0] +#endif + extern int __ftn_32in64_; diff --git a/runtime/flang/hand.c b/runtime/flang/hand.c index 1f20dc5b1a4..c3262fc7e98 100644 --- a/runtime/flang/hand.c +++ b/runtime/flang/hand.c @@ -15,6 +15,7 @@ * */ +#ifndef _WIN32 #include #include "stdioInterf.h" #include "fioMacros.h" @@ -129,3 +130,5 @@ __fort_sethand() } } } + +#endif \ No newline at end of file diff --git a/runtime/flang/heapinit.c b/runtime/flang/heapinit.c index e2e7584f72b..4d52452560b 100644 --- a/runtime/flang/heapinit.c +++ b/runtime/flang/heapinit.c @@ -14,7 +14,6 @@ * limitations under the License. * */ - #include #include "stdioInterf.h" #include "fioMacros.h" @@ -43,10 +42,14 @@ int val; void (*save)(); int *pi; +#ifndef _WIN32 save = signal(SIGBUS, sighand); +#endif pi = (int *)beg; while (pi < (int *)end) { *pi++ = val; } +#ifndef _WIN32 signal(SIGBUS, save); -} +#endif +} \ No newline at end of file diff --git a/runtime/flang/initpar.c b/runtime/flang/initpar.c index c781b812095..e167fd99b78 100644 --- a/runtime/flang/initpar.c +++ b/runtime/flang/initpar.c @@ -25,7 +25,9 @@ #include #include #include +#ifndef _WIN32 #include +#endif #include "global.h" /* FIXME: HACK diff --git a/runtime/flang/map.c b/runtime/flang/map.c index 291e107556a..622eacdf2e5 100644 --- a/runtime/flang/map.c +++ b/runtime/flang/map.c @@ -19,7 +19,9 @@ #include "fioMacros.h" #include #include +#ifndef _WIN32 #include +#endif extern char *__fort_getopt(); diff --git a/runtime/flang/miscsup_com.c b/runtime/flang/miscsup_com.c index 451b7fd1517..7eb9d053211 100644 --- a/runtime/flang/miscsup_com.c +++ b/runtime/flang/miscsup_com.c @@ -25,8 +25,10 @@ #include #include +#ifndef _WIN32 #include #include +#endif #include "stdioInterf.h" #include "fioMacros.h" #include "llcrit.h" diff --git a/runtime/flang/mmcmplx16.c b/runtime/flang/mmcmplx16.c index 02abe4fc00a..8874727489c 100644 --- a/runtime/flang/mmcmplx16.c +++ b/runtime/flang/mmcmplx16.c @@ -25,13 +25,23 @@ #define SMALL_ROWSB 10 #define SMALL_COLSB 10 +#ifndef _WIN32 +#define FLANG_DCOMPLEX double complex +#define FLANG_IS_ZERO(x) x == 0.0 +#else +#define FLANG_DCOMPLEX _Dcomplex +#define FLANG_IS_ZERO(x) (real(x) == 0.0 && imag(x) == 0.0) +#endif + void ENTF90(MMUL_CMPLX16, mmul_cmplx16)(int ta, int tb, __POINT_T mra, __POINT_T ncb, - __POINT_T kab, double complex *alpha, - double complex a[], __POINT_T lda, double complex b[], - __POINT_T ldb, double complex *beta, - double complex c[], __POINT_T ldc) + __POINT_T kab, FLANG_DCOMPLEX *alpha, + FLANG_DCOMPLEX a[], __POINT_T lda, FLANG_DCOMPLEX b[], + __POINT_T ldb, FLANG_DCOMPLEX *beta, + FLANG_DCOMPLEX c[], __POINT_T ldc) { + +#ifndef _WIN32 /* * Notes on parameters * ta, tb = 0 -> no transpose of matrix @@ -66,13 +76,13 @@ void ENTF90(MMUL_CMPLX16, int bufr, bufc, loc, lor; int small_size = SMALL_ROWSA * SMALL_ROWSB * SMALL_COLSB; int tindex = 0; - double complex buffera[SMALL_ROWSA * SMALL_ROWSB]; - double complex bufferb[SMALL_COLSB * SMALL_ROWSB]; - double complex temp; + FLANG_DCOMPLEX buffera[SMALL_ROWSA * SMALL_ROWSB]; + FLANG_DCOMPLEX bufferb[SMALL_COLSB * SMALL_ROWSB]; + FLANG_DCOMPLEX temp; void ftn_mvmul_cmplx16_(), ftn_vmmul_cmplx16_(); void ftn_mnaxnb_cmplx16_(), ftn_mnaxtb_cmplx16_(); void ftn_mtaxnb_cmplx16_(), ftn_mtaxtb_cmplx16_(); - double complex calpha, cbeta; + FLANG_DCOMPLEX calpha, cbeta; /* * Small matrix multiply variables */ @@ -89,13 +99,19 @@ void ENTF90(MMUL_CMPLX16, colsa = kab; rowsb = kab; colsb = ncb; - if (calpha == 0.0) { - if (cbeta == 0.0) { + if (FLANG_IS_ZERO(calpha)) { + if (FLANG_IS_ZERO(cbeta)) { cndx = 0; indx_strt = ldc; for (j = 0; j < ncb; j++) { - for (i = 0; i < mra; i++) + for (i = 0; i < mra; i++) { + #ifndef _WIN32 c[cndx + i] = 0.0; + #else + real(c[cndx + i]) = 0.0; + imag(c[cndx + i]) = 0.0; + #endif + } cndx = indx_strt; indx_strt += ldc; } @@ -555,5 +571,5 @@ void ENTF90(MMUL_CMPLX16, beta, c, &ldc); } } - +#endif } diff --git a/runtime/flang/mmcmplx8.c b/runtime/flang/mmcmplx8.c index 601210d9c39..1968d17b5e8 100644 --- a/runtime/flang/mmcmplx8.c +++ b/runtime/flang/mmcmplx8.c @@ -25,12 +25,19 @@ #define SMALL_ROWSB 10 #define SMALL_COLSB 10 +#ifndef _WIN32 +#define FLANG_FCOMPLEX double complex +#else +#define FLANG_FCOMPLEX _Dcomplex +#endif + void ENTF90(MMUL_CMPLX8, mmul_cmplx8)(int ta, int tb, __POINT_T mra, __POINT_T ncb, - __POINT_T kab, float complex *alpha, float complex a[], - __POINT_T lda, float complex b[], __POINT_T ldb, - float complex *beta, float complex c[], __POINT_T ldc) + __POINT_T kab, FLANG_FCOMPLEX *alpha, FLANG_FCOMPLEX a[], + __POINT_T lda, FLANG_FCOMPLEX b[], __POINT_T ldb, + FLANG_FCOMPLEX *beta, FLANG_FCOMPLEX c[], __POINT_T ldc) { + #ifndef _WIN32 /* * Notes on parameters * ta, tb = 0 -> no transpose of matrix @@ -65,13 +72,13 @@ void ENTF90(MMUL_CMPLX8, int bufr, bufc, loc, lor; int small_size = SMALL_ROWSA * SMALL_ROWSB * SMALL_COLSB; int tindex = 0; - float complex buffera[SMALL_ROWSA * SMALL_ROWSB]; - float complex bufferb[SMALL_COLSB * SMALL_ROWSB]; - float complex temp; + FLANG_FCOMPLEX buffera[SMALL_ROWSA * SMALL_ROWSB]; + FLANG_FCOMPLEX bufferb[SMALL_COLSB * SMALL_ROWSB]; + FLANG_FCOMPLEX temp; void ftn_mvmul_cmplx8_(), ftn_vmmul_cmplx8_(); void ftn_mnaxnb_cmplx8_(), ftn_mnaxtb_cmplx8_(); void ftn_mtaxnb_cmplx8_(), ftn_mtaxtb_cmplx8_(); - float complex calpha, cbeta; + FLANG_FCOMPLEX calpha, cbeta; /* * Small matrix multiply variables */ @@ -554,6 +561,6 @@ void ENTF90(MMUL_CMPLX8, beta, c, &ldc); } } - +#endif } diff --git a/runtime/flang/sleep3f.c b/runtime/flang/sleep3f.c index 48cddf26920..0ec3c760136 100644 --- a/runtime/flang/sleep3f.c +++ b/runtime/flang/sleep3f.c @@ -19,7 +19,9 @@ /* sleep3f.c - Implements LIB3F sleep subprogram. */ +#ifndef _WIN32 #include +#endif #include "ent3f.h" #if defined(_WIN32) diff --git a/runtime/flang/sleepqq3f.c b/runtime/flang/sleepqq3f.c index eb8acf6613a..7c25afa71fc 100644 --- a/runtime/flang/sleepqq3f.c +++ b/runtime/flang/sleepqq3f.c @@ -19,7 +19,9 @@ /* sleep3f.c - Implements DFPORT SLEEPQQ subprogram. */ +#ifndef _WIN32 #include +#endif #include "ent3f.h" #if defined(_WIN32) diff --git a/runtime/flang/stat_linux.c b/runtime/flang/stat_linux.c index d3358f0c25f..d81d34e2a92 100644 --- a/runtime/flang/stat_linux.c +++ b/runtime/flang/stat_linux.c @@ -19,11 +19,13 @@ * \brief Fill in statistics structure (Linux version) */ +#ifndef _WIN32 #include #include #include -#include #include +#endif +#include #include "timeBlk.h" #include "fioMacros.h" @@ -43,14 +45,17 @@ __fort_setarg(void) static void nodename(s) char *s; { +#ifndef _WIN32 struct utsname u0; uname(&u0); strcpy(s, u0.nodename); +#endif } void __fort_gettb(t) struct tb *t; { +#ifndef _WIN32 struct timeval tv0; struct timezone tz0; struct rusage rs0, rc0; @@ -98,6 +103,7 @@ void __fort_gettb(t) struct tb *t; t->sbrk = (double)((long)sbrk(0)); t->gsbrk = (GET_DIST_HEAPZ == 0 ? 0.0 : (double)((long)__fort_sbrk(0))); nodename(t->host); +#endif } static double first = 0.0; @@ -105,6 +111,7 @@ static double first = 0.0; double __fort_second() { +#ifndef _WIN32 struct timeval v; struct timezone t; double d; @@ -119,6 +126,7 @@ __fort_second() first = d; } return (d - first); +#endif } void diff --git a/runtime/flang/timef3f.c b/runtime/flang/timef3f.c index d54a405eba5..342fa6e8b0d 100644 --- a/runtime/flang/timef3f.c +++ b/runtime/flang/timef3f.c @@ -23,6 +23,7 @@ /* how do we do this for WINNT */ #include "ent3f.h" +#ifndef _WIN32 #define _LIBC_LIMITS_H_ #ifndef _WIN32 #include @@ -54,4 +55,4 @@ double ENT3F(TIMEF, timef)(float *tarray) duration = ((double)(current - start)) * inv_ticks; return duration; } - +#endif diff --git a/runtime/flang/usrio_smp.c b/runtime/flang/usrio_smp.c index e2584e8baf2..9452f690334 100644 --- a/runtime/flang/usrio_smp.c +++ b/runtime/flang/usrio_smp.c @@ -20,7 +20,7 @@ * a common system buffer pool and that the buffers are kept consistent. * It also works for some other systems such as the Paragon. */ - +#ifndef _WIN32 #include #include @@ -210,4 +210,4 @@ __fort_par_unlink(char *fn) } __fort_barrier(); } - +#endif From a260b46e387f3c570bbdf930d253d93fc0adce64 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 22 Oct 2017 18:34:41 -0500 Subject: [PATCH 020/141] sed UINT64->FLANG_UINT64 --- runtime/flang/ftni64bitsup.c | 22 +++++++++++----------- runtime/flang/utilsi64.c | 16 ++++++++-------- runtime/flangrti/mthi64.c | 10 +++++----- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/runtime/flang/ftni64bitsup.c b/runtime/flang/ftni64bitsup.c index 610ae53507b..a666926614c 100644 --- a/runtime/flang/ftni64bitsup.c +++ b/runtime/flang/ftni64bitsup.c @@ -39,7 +39,7 @@ ftn_i_kishftc(op, sc, int sc; /* shift count and direction */ int rc; /* # of rightmost val bits to be shifted */ { - UINT64 i8neg1, mask, field, tmp1, tmp2, val; + FLANG_UINT64 i8neg1, mask, field, tmp1, tmp2, val; int norm; /* define a remainder operation that doesn't use %; is this worth it? */ @@ -141,8 +141,8 @@ int posd; /* start position in dest field */ int tmp; int maxpos; int maxlen; - UINT64 maski8; - UINT64 i8neg1, tmpi8, u_arg; + FLANG_UINT64 maski8; + FLANG_UINT64 i8neg1, tmpi8, u_arg; /* procedure */ @@ -226,7 +226,7 @@ ftn_i_kibclr(arg1, arg2, bit) int arg1, arg2; /* value to be cleared */ int bit; /* bit to clear */ { INT64 result; - UINT64 i81, tmp; + FLANG_UINT64 i81, tmp; result[0] = result[1] = 0; i81[0] = 0; i81[1] = 1; @@ -251,7 +251,7 @@ int bitpos; /* position of bit to start from */ int numbits; /* number of bits to extract */ { INT64 result; - UINT64 i8neg1, tmp, maski8, u_arg; + FLANG_UINT64 i8neg1, tmp, maski8, u_arg; u_arg[0] = arg2; u_arg[1] = arg1; @@ -281,7 +281,7 @@ ftn_i_kibset(arg1, arg2, bit) int arg1, arg2; /* value to be set */ int bit; /* bit to set */ { INT64 i8one, result; - UINT64 tmp; + FLANG_UINT64 tmp; result[0] = result[1] = 0; i8one[0] = 0; i8one[1] = 1; @@ -305,7 +305,7 @@ ftn_i_bktest(arg1, arg2, bit) int arg1, arg2; /* value to be tested */ int bit; /* bit to test */ { INT64 i8one, result; - UINT64 tmp; + FLANG_UINT64 tmp; result[0] = result[1] = 0; i8one[0] = 0; i8one[1] = 1; @@ -343,7 +343,7 @@ static void shf64(arg, count, result) INT64 arg; int count; INT64 result; { - UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; @@ -388,11 +388,11 @@ INT64 result; * Return value: * none. */ -static void ushf64(arg, count, result) UINT64 arg; +static void ushf64(arg, count, result) FLANG_UINT64 arg; int count; -UINT64 result; +FLANG_UINT64 result; { - UINT64 u_arg; /* 'copy-in' value of arg */ + FLANG_UINT64 u_arg; /* 'copy-in' value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; diff --git a/runtime/flang/utilsi64.c b/runtime/flang/utilsi64.c index c23216598f6..0562baaab0a 100644 --- a/runtime/flang/utilsi64.c +++ b/runtime/flang/utilsi64.c @@ -212,7 +212,7 @@ __fort_atoxi32(char *s, INT *i, int n, int base) * * s Input string containing number to be converted * (string is NOT null terminated.) - * ir UINT64 output value + * ir FLANG_UINT64 output value * n Number of chars from str to convert * radix Radix of conversion -- 2, 8, 10, 16. If * base is 16, then the digits a-f or A-F are @@ -563,7 +563,7 @@ static void neg64(INT64 arg, INT64 result) static void shf64(INT64 arg1, INT arg2, INT64 result) { - UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (arg2 >= 64 || arg2 <= -64) { result[0] = 0; @@ -589,7 +589,7 @@ static void shf64(INT64 arg1, INT arg2, INT64 result) } } -static int ucmp64(UINT64 arg1, UINT64 arg2) +static int ucmp64(FLANG_UINT64 arg1, FLANG_UINT64 arg2) { if (arg1[0] == arg2[0]) { if (arg1[1] == arg2[1]) @@ -802,9 +802,9 @@ static void neg128(INT arg[4], INT result[4]) } } -void __utl_i_udiv64(UINT64 arg1, UINT64 arg2, UINT64 result) +void __utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) { - UINT64 den; /* denominator used in calculating the + FLANG_UINT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -856,7 +856,7 @@ void __utl_i_udiv64(UINT64 arg1, UINT64 arg2, UINT64 result) } } -static void uneg64(UINT64 arg, UINT64 result) +static void uneg64(FLANG_UINT64 arg, FLANG_UINT64 result) { int sign; /* sign of the low-order word of arg prior to * being complemented */ @@ -868,11 +868,11 @@ static void uneg64(UINT64 arg, UINT64 result) result[0]++; } -static void ushf64(UINT64 arg, int count, INT64 result) +static void ushf64(FLANG_UINT64 arg, int count, INT64 result) int count; INT64 result; { - UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; diff --git a/runtime/flangrti/mthi64.c b/runtime/flangrti/mthi64.c index ee09eb8625c..bab8430aa9e 100644 --- a/runtime/flangrti/mthi64.c +++ b/runtime/flangrti/mthi64.c @@ -16,7 +16,7 @@ */ typedef int INT64[2]; -typedef unsigned int UINT64[2]; +typedef unsigned int FLANG_UINT64[2]; typedef union { INT64 wd; /* canonical msw & lsw view of long long values */ @@ -207,8 +207,8 @@ __mth_i_ukdiv(unsigned long long x, unsigned long long y) UMSW(r) = 0; ULSW(r) = ULSW(a) / ULSW(b); } else { - UINT64 arg1, arg2; /* UINT64 is big endian!! */ - UINT64 result; + FLANG_UINT64 arg1, arg2; /* FLANG_UINT64 is big endian!! */ + FLANG_UINT64 result; arg1[1] = ULSW(a); arg1[0] = UMSW(a); arg2[1] = ULSW(b); @@ -304,7 +304,7 @@ static VOID neg64(arg, result) INT64 arg, result; * integer quotient. */ VOID -__utl_i_udiv64(UINT64 arg1, UINT64 arg2, UINT64 result) +__utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) { INT64 den; /* denominator used in calculating the * quotient */ @@ -434,7 +434,7 @@ static VOID shf64(arg, count, result) INT64 arg; int count; INT64 result; { - UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; From 9be89a49ac08382cf88430c163781d7f8c6654f7 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 22 Oct 2017 18:35:29 -0500 Subject: [PATCH 021/141] sed INT64->FLANG_INT64 --- runtime/flang/fmtconv.c | 12 +++---- runtime/flang/fmtgetnum.c | 2 +- runtime/flang/fmtread.c | 6 ++-- runtime/flang/fmtwrite.c | 4 +-- runtime/flang/ftni64.c | 14 ++++---- runtime/flang/ftni64bitsup.c | 36 +++++++++---------- runtime/flang/utilsi64.c | 68 ++++++++++++++++++------------------ runtime/flangrti/mthi64.c | 60 +++++++++++++++---------------- 8 files changed, 101 insertions(+), 101 deletions(-) diff --git a/runtime/flang/fmtconv.c b/runtime/flang/fmtconv.c index abd12f9ac5c..dbe8ddbd7a9 100644 --- a/runtime/flang/fmtconv.c +++ b/runtime/flang/fmtconv.c @@ -40,7 +40,7 @@ static int dbgflag; #define DBGBIT(v) (LOCAL_DEBUG && (dbgflag & v)) static char *conv_int(__BIGINT_T, int *, int *); -static char *conv_int8(INT64, int *, int *); +static char *conv_int8(FLANG_INT64, int *, int *); static void put_buf(int, char *, int, int); static void conv_e(int, int, int, bool); @@ -96,7 +96,7 @@ __fortio_default_convert(char *item, int type, { int width; char *p; - INT64 i8val; + FLANG_INT64 i8val; switch (type) { default: @@ -113,7 +113,7 @@ __fortio_default_convert(char *item, int type, break; case __INT8: width = 24; - (void) __fortio_fmt_i8(*(INT64 *)(item), width, 1, plus_flag); + (void) __fortio_fmt_i8(*(FLANG_INT64 *)(item), width, 1, plus_flag); break; case __WORD4: width = 8; @@ -341,7 +341,7 @@ conv_int(__BIGINT_T val, int *lenp, int *negp) } char * -__fortio_fmt_i8(INT64 val, +__fortio_fmt_i8(FLANG_INT64 val, int width, int mn, /* minimum # of digits (Iw.m) */ bool plus_flag) @@ -384,14 +384,14 @@ __fortio_fmt_i8(INT64 val, } static char * -conv_int8(INT64 val, int *lenp, int *negp) +conv_int8(FLANG_INT64 val, int *lenp, int *negp) { #define MAX_CONV_INT8 32 static char tmp[MAX_CONV_INT8]; char *p; int len; - INT64 value; + FLANG_INT64 value; *negp = 0; I64_LSH(value) = I64_LSH(val); diff --git a/runtime/flang/fmtgetnum.c b/runtime/flang/fmtgetnum.c index 086f2724c02..7eb0a67c138 100644 --- a/runtime/flang/fmtgetnum.c +++ b/runtime/flang/fmtgetnum.c @@ -70,7 +70,7 @@ __fortio_getnum( union { __BIGINT_T i; __BIGREAL_T d; - INT64 i8v; + FLANG_INT64 i8v; } * val; /* value of token to return */ if (dc_flag == TRUE) diff --git a/runtime/flang/fmtread.c b/runtime/flang/fmtread.c index 42c28717f63..a6fd82419a0 100644 --- a/runtime/flang/fmtread.c +++ b/runtime/flang/fmtread.c @@ -112,7 +112,7 @@ static int fr_readnum(int, char *, int); static int fr_init(__INT_T *, __INT_T *, __INT_T *, __INT_T *, __INT_T *, __INT8_T *, char *, int); -static int fr_assign(char *, int, __BIGINT_T, INT64, __BIGREAL_T); +static int fr_assign(char *, int, __BIGINT_T, FLANG_INT64, __BIGREAL_T); static int fr_OZreadnum(int, char *, int, int); static int fr_Breadnum(char *, int, int); static __BIGREAL_T fr_getreal(char *, int, int, int *); @@ -1637,7 +1637,7 @@ fr_readnum(int code, char *item, int type) __BIGINT_T ival; __BIGREAL_T dval; #undef IS_INT - INT64 i8val; /* always declare because of fr_assign() */ + FLANG_INT64 i8val; /* always declare because of fr_assign() */ #define IS_INT(t) (t == __INT || t == __INT8) int ty; int w, d, e, c; @@ -2060,7 +2060,7 @@ fr_readnum(int code, char *item, int type) /* ------------------------------------------------------------------ */ static int -fr_assign(char *item, int type, __BIGINT_T ival, INT64 i8val, __BIGREAL_T dval) +fr_assign(char *item, int type, __BIGINT_T ival, FLANG_INT64 i8val, __BIGREAL_T dval) { switch (type) { case __INT1: diff --git a/runtime/flang/fmtwrite.c b/runtime/flang/fmtwrite.c index 1b83aa7598c..ad3c3cee1f3 100644 --- a/runtime/flang/fmtwrite.c +++ b/runtime/flang/fmtwrite.c @@ -1578,7 +1578,7 @@ fw_writenum(int code, char *item, int type) __BIGINT_T ival; __BIGREAL_T dval; #undef IS_INT - INT64 i8val; + FLANG_INT64 i8val; #define IS_INT(t) (t == __BIGINT || t == __INT8) int ty; int w, m, d, e; @@ -1592,7 +1592,7 @@ fw_writenum(int code, char *item, int type) __INT4_T i4; __REAL4_T r4; __REAL8_T r8; - INT64 i8v; + FLANG_INT64 i8v; __INT8_T i8; __BIGREAL_T d; __REAL16_T r16; diff --git a/runtime/flang/ftni64.c b/runtime/flang/ftni64.c index b4748d65729..afbd06994d8 100644 --- a/runtime/flang/ftni64.c +++ b/runtime/flang/ftni64.c @@ -40,8 +40,8 @@ ftn_i_kishft(_ULONGLONG_T op, int count) __I8RET_T ftn_i_xori64(int op1, int op2, int op3, int op4) { - INT64 u1; - INT64 u2; + FLANG_INT64 u1; + FLANG_INT64 u2; u1[0] = op2; u1[1] = op1; @@ -55,8 +55,8 @@ ftn_i_xori64(int op1, int op2, int op3, int op4) __I8RET_T ftn_i_xnori64(int op1, int op2, int op3, int op4) { - INT64 u1; - INT64 u2; + FLANG_INT64 u1; + FLANG_INT64 u2; u1[0] = op2; u1[1] = op1; @@ -70,7 +70,7 @@ ftn_i_xnori64(int op1, int op2, int op3, int op4) int ftn_i_kr2ir(int op1, int op2) { - INT64 u1; + FLANG_INT64 u1; /* result is first element of int[2] which is union u'd with dp if little endian; if big endian, result is second element. @@ -83,7 +83,7 @@ ftn_i_kr2ir(int op1, int op2) float ftn_i_kr2sp(int op1, int op2) { - INT64 u1; + FLANG_INT64 u1; int i; u1[0] = op1; @@ -95,7 +95,7 @@ ftn_i_kr2sp(int op1, int op2) double ftn_i_kr2dp(int op1, int op2) { - INT64D u1; + FLANG_INT64D u1; u1.i[0] = op1; u1.i[1] = op2; diff --git a/runtime/flang/ftni64bitsup.c b/runtime/flang/ftni64bitsup.c index a666926614c..647e265db35 100644 --- a/runtime/flang/ftni64bitsup.c +++ b/runtime/flang/ftni64bitsup.c @@ -39,13 +39,13 @@ ftn_i_kishftc(op, sc, int sc; /* shift count and direction */ int rc; /* # of rightmost val bits to be shifted */ { - FLANG_UINT64 i8neg1, mask, field, tmp1, tmp2, val; + FLANG_UFLANG_INT64 i8neg1, mask, field, tmp1, tmp2, val; int norm; /* define a remainder operation that doesn't use %; is this worth it? */ #define REMLOOP(a, b, c) for (a = b; a >= c; a -= c) - INT64D u; + FLANG_INT64D u; u.lv = op; val[0] = I64_MSH(u.i); @@ -141,8 +141,8 @@ int posd; /* start position in dest field */ int tmp; int maxpos; int maxlen; - FLANG_UINT64 maski8; - FLANG_UINT64 i8neg1, tmpi8, u_arg; + FLANG_UFLANG_INT64 maski8; + FLANG_UFLANG_INT64 i8neg1, tmpi8, u_arg; /* procedure */ @@ -225,8 +225,8 @@ __I8RET_T ftn_i_kibclr(arg1, arg2, bit) int arg1, arg2; /* value to be cleared */ int bit; /* bit to clear */ { - INT64 result; - FLANG_UINT64 i81, tmp; + FLANG_INT64 result; + FLANG_UFLANG_INT64 i81, tmp; result[0] = result[1] = 0; i81[0] = 0; i81[1] = 1; @@ -250,8 +250,8 @@ ftn_i_kibits(arg1, arg2, bitpos, numbits) int arg1, int bitpos; /* position of bit to start from */ int numbits; /* number of bits to extract */ { - INT64 result; - FLANG_UINT64 i8neg1, tmp, maski8, u_arg; + FLANG_INT64 result; + FLANG_UFLANG_INT64 i8neg1, tmp, maski8, u_arg; u_arg[0] = arg2; u_arg[1] = arg1; @@ -280,8 +280,8 @@ __I8RET_T ftn_i_kibset(arg1, arg2, bit) int arg1, arg2; /* value to be set */ int bit; /* bit to set */ { - INT64 i8one, result; - FLANG_UINT64 tmp; + FLANG_INT64 i8one, result; + FLANG_UFLANG_INT64 tmp; result[0] = result[1] = 0; i8one[0] = 0; i8one[1] = 1; @@ -304,8 +304,8 @@ __I8RET_T ftn_i_bktest(arg1, arg2, bit) int arg1, arg2; /* value to be tested */ int bit; /* bit to test */ { - INT64 i8one, result; - FLANG_UINT64 tmp; + FLANG_INT64 i8one, result; + FLANG_UFLANG_INT64 tmp; result[0] = result[1] = 0; i8one[0] = 0; i8one[1] = 1; @@ -339,11 +339,11 @@ int bit; /* bit to test */ * Return value: * none. */ -static void shf64(arg, count, result) INT64 arg; +static void shf64(arg, count, result) FLANG_INT64 arg; int count; -INT64 result; +FLANG_INT64 result; { - FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UFLANG_INT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; @@ -388,11 +388,11 @@ INT64 result; * Return value: * none. */ -static void ushf64(arg, count, result) FLANG_UINT64 arg; +static void ushf64(arg, count, result) FLANG_UFLANG_INT64 arg; int count; -FLANG_UINT64 result; +FLANG_UFLANG_INT64 result; { - FLANG_UINT64 u_arg; /* 'copy-in' value of arg */ + FLANG_UFLANG_INT64 u_arg; /* 'copy-in' value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; diff --git a/runtime/flang/utilsi64.c b/runtime/flang/utilsi64.c index 0562baaab0a..9a35e911a48 100644 --- a/runtime/flang/utilsi64.c +++ b/runtime/flang/utilsi64.c @@ -22,7 +22,7 @@ * the exception that TM_I8 => integer*4 is the natural integer and * integer*8 is an extension. All of these support routines could be * rewritten to use the appropriate C type which represents a 64-bit - * integer rather than INT64/UIN64. + * integer rather than FLANG_INT64/UIN64. */ int __ftn_32in64_; @@ -212,7 +212,7 @@ __fort_atoxi32(char *s, INT *i, int n, int base) * * s Input string containing number to be converted * (string is NOT null terminated.) - * ir FLANG_UINT64 output value + * ir FLANG_UFLANG_INT64 output value * n Number of chars from str to convert * radix Radix of conversion -- 2, 8, 10, 16. If * base is 16, then the digits a-f or A-F are @@ -237,7 +237,7 @@ __fort_atoxi32(char *s, INT *i, int n, int base) ****************************************************************/ int -__fort_atoxi64(char *s, INT64 ir, int n, int radix) +__fort_atoxi64(char *s, FLANG_INT64 ir, int n, int radix) { int err; char *sp; @@ -271,7 +271,7 @@ __fort_atoxi64(char *s, INT64 ir, int n, int radix) #define ZERO '0' void -__fort_i64toax(INT64 from, char *to, int count, int sign, int radix) +__fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix) { int bit_width; /* width of the bit field for a particular * radix */ @@ -282,13 +282,13 @@ __fort_i64toax(INT64 from, char *to, int count, int sign, int radix) * to be shifted */ int msd; /* index of the most-signingicant digit in to */ int num_bits; /* number of bits to be shifted */ - INT64 quot; /* the quotient part of a 64 bit division */ - INT64 remain; /* the remainder part of a 64 bit division */ - INT64 temp_from; /* temp from (=(abs(from)) */ - INT64 temp64; /* temporary 64 bit integer */ + FLANG_INT64 quot; /* the quotient part of a 64 bit division */ + FLANG_INT64 remain; /* the remainder part of a 64 bit division */ + FLANG_INT64 temp_from; /* temp from (=(abs(from)) */ + FLANG_INT64 temp64; /* temporary 64 bit integer */ /* 64 bit integer equal to 10 */ - static INT64 ten64 = {0, 10}; + static FLANG_INT64 ten64 = {0, 10}; /* the result of dividing a 64 bit unsigned integer with only the * sign bit on by 10 @@ -426,22 +426,22 @@ __fort_i64toax(INT64 from, char *to, int count, int sign, int radix) * -2 = overflow / underflow * 0 = no error. */ -static int toi64(char *s, INT64 toi, char *end, int radix) +static int toi64(char *s, FLANG_INT64 toi, char *end, int radix) { - INT64 base; /* 64 bit integer equal to radix */ - INT64 diff; /* difference between 2 64 bit integers, used + FLANG_INT64 base; /* 64 bit integer equal to radix */ + FLANG_INT64 diff; /* difference between 2 64 bit integers, used * in determining if overflow has occured */ - INT64 num; /* numerical value of a particular digit */ - INT64 to; + FLANG_INT64 num; /* numerical value of a particular digit */ + FLANG_INT64 to; int negate; int ch; /* 64-bit integer with only its sign bit on */ - static INT64 sign_bit = {0x80000000, 0}; + static FLANG_INT64 sign_bit = {0x80000000, 0}; /* maximum 64-bit signed integer */ - static INT64 max_int = {0x7fffffff, 0xffffffff}; - static INT64 max_neg = {0x80000000, 0}; + static FLANG_INT64 max_int = {0x7fffffff, 0xffffffff}; + static FLANG_INT64 max_neg = {0x80000000, 0}; OVL8 pto; @@ -550,7 +550,7 @@ static int toi64(char *s, INT64 toi, char *end, int radix) return -2; } -static void neg64(INT64 arg, INT64 result) +static void neg64(FLANG_INT64 arg, FLANG_INT64 result) { int sign; /* sign of the low-order word of arg prior to * being complemented */ @@ -561,9 +561,9 @@ static void neg64(INT64 arg, INT64 result) result[0]++; } -static void shf64(INT64 arg1, INT arg2, INT64 result) +static void shf64(FLANG_INT64 arg1, INT arg2, FLANG_INT64 result) { - FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UFLANG_INT64 u_arg; /* 'copy-in' unsigned value of arg */ if (arg2 >= 64 || arg2 <= -64) { result[0] = 0; @@ -589,7 +589,7 @@ static void shf64(INT64 arg1, INT arg2, INT64 result) } } -static int ucmp64(FLANG_UINT64 arg1, FLANG_UINT64 arg2) +static int ucmp64(FLANG_UFLANG_INT64 arg1, FLANG_UFLANG_INT64 arg2) { if (arg1[0] == arg2[0]) { if (arg1[1] == arg2[1]) @@ -617,7 +617,7 @@ static void neg128(), uneg64(), ushf64(), shf128(); * Return value: * none */ -void __utl_i_add64(INT64 arg1, INT64 arg2, INT64 result) +void __utl_i_add64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) { int carry; /* value to be carried from adding the lower * 32 bits */ @@ -645,7 +645,7 @@ void __utl_i_add64(INT64 arg1, INT64 arg2, INT64 result) * Return value: * none */ -void __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) +void __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) { int borrow; /* value to be borrowed from adding the lower @@ -670,7 +670,7 @@ void __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) * integer product. */ -void __utl_i_mul64(INT64 arg1, INT64 arg2, INT64 result) +void __utl_i_mul64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) { INT temp_result[4]; /* the product returned by MUL128 */ @@ -679,10 +679,10 @@ void __utl_i_mul64(INT64 arg1, INT64 arg2, INT64 result) result[1] = temp_result[3]; } -static void __utl_i_mul128(INT64 arg1, INT64 arg2, INT result[4]) +static void __utl_i_mul128(FLANG_INT64 arg1, FLANG_INT64 arg2, INT result[4]) { int i; /* for loop control variable */ - INT64 temp_arg; /* temporary argument used in calculating the + FLANG_INT64 temp_arg; /* temporary argument used in calculating the * product */ INT temp_result[4]; /* temporary result */ int negate; /* flag which indicated the result needs to @@ -729,9 +729,9 @@ static void __utl_i_mul128(INT64 arg1, INT64 arg2, INT result[4]) result[i] = temp_result[i]; } -void __utl_i_div64(INT64 arg1, INT64 arg2, INT64 result) +void __utl_i_div64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) { - INT64 den; /* denominator used in calculating the + FLANG_INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -802,9 +802,9 @@ static void neg128(INT arg[4], INT result[4]) } } -void __utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) +void __utl_i_udiv64(FLANG_UFLANG_INT64 arg1, FLANG_UFLANG_INT64 arg2, FLANG_UFLANG_INT64 result) { - FLANG_UINT64 den; /* denominator used in calculating the + FLANG_UFLANG_INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -856,7 +856,7 @@ void __utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) } } -static void uneg64(FLANG_UINT64 arg, FLANG_UINT64 result) +static void uneg64(FLANG_UFLANG_INT64 arg, FLANG_UFLANG_INT64 result) { int sign; /* sign of the low-order word of arg prior to * being complemented */ @@ -868,11 +868,11 @@ static void uneg64(FLANG_UINT64 arg, FLANG_UINT64 result) result[0]++; } -static void ushf64(FLANG_UINT64 arg, int count, INT64 result) +static void ushf64(FLANG_UFLANG_INT64 arg, int count, FLANG_INT64 result) int count; -INT64 result; +FLANG_INT64 result; { - FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UFLANG_INT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; diff --git a/runtime/flangrti/mthi64.c b/runtime/flangrti/mthi64.c index bab8430aa9e..405394114f7 100644 --- a/runtime/flangrti/mthi64.c +++ b/runtime/flangrti/mthi64.c @@ -15,11 +15,11 @@ * */ -typedef int INT64[2]; -typedef unsigned int FLANG_UINT64[2]; +typedef int FLANG_INT64[2]; +typedef unsigned int FLANG_UFLANG_INT64[2]; typedef union { - INT64 wd; /* canonical msw & lsw view of long long values */ + FLANG_INT64 wd; /* canonical msw & lsw view of long long values */ int hf[2]; /* native msw & lsw signed view of long long values */ unsigned uhf[2]; /* native msw & lsw unsigned view of long long values */ long long value; @@ -67,7 +67,7 @@ VOID __mth_i_krshift(); VOID __mth_i_klshift(); VOID __mth_i_kurshift(); VOID __utl_i_add64(), __utl_i_div64(); -VOID __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result); +VOID __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result); VOID __utl_i_mul64(), __utl_i_udiv64(); static VOID neg64(), shf64(), shf128by1(); @@ -81,7 +81,7 @@ static VOID neg64(), shf64(), shf128by1(); * Return value: * none */ -VOID __utl_i_add64(arg1, arg2, result) INT64 arg1, arg2, result; +VOID __utl_i_add64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; { int carry; /* value to be carried from adding the lower * 32 bits */ @@ -106,7 +106,7 @@ VOID __utl_i_add64(arg1, arg2, result) INT64 arg1, arg2, result; * \param result arg1 - arg2 */ VOID -__utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) +__utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) { int borrow; /* value to be borrowed from adding the lower * 32 bits */ @@ -130,7 +130,7 @@ __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) * Multiply two 64-bit integers to produce a 64-bit * integer product. */ -VOID __utl_i_mul64(arg1, arg2, result) INT64 arg1, arg2, result; +VOID __utl_i_mul64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; { LL_SHAPE v1, v2, r; @@ -175,8 +175,8 @@ __mth_i_kdiv(long long x, long long y) MSW(r) = 0; *(unsigned *)&LSW(r) = (unsigned)LSW(a) / (unsigned)LSW(b); } else { - INT64 arg1, arg2; /* INT64 is big endian!! */ - INT64 result; + FLANG_INT64 arg1, arg2; /* FLANG_INT64 is big endian!! */ + FLANG_INT64 result; arg1[1] = LSW(a); arg1[0] = MSW(a); arg2[1] = LSW(b); @@ -207,8 +207,8 @@ __mth_i_ukdiv(unsigned long long x, unsigned long long y) UMSW(r) = 0; ULSW(r) = ULSW(a) / ULSW(b); } else { - FLANG_UINT64 arg1, arg2; /* FLANG_UINT64 is big endian!! */ - FLANG_UINT64 result; + FLANG_UFLANG_INT64 arg1, arg2; /* FLANG_UFLANG_INT64 is big endian!! */ + FLANG_UFLANG_INT64 result; arg1[1] = ULSW(a); arg1[0] = UMSW(a); arg2[1] = ULSW(b); @@ -224,10 +224,10 @@ __mth_i_ukdiv(unsigned long long x, unsigned long long y) * Divide two 64-bit integers to produce a 64-bit * integer quotient. */ -VOID __utl_i_div64(arg1, arg2, result) INT64 arg1, arg2, result; +VOID __utl_i_div64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; { - INT64 den; /* denominator used in calculating the + FLANG_INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -287,7 +287,7 @@ VOID __utl_i_div64(arg1, arg2, result) INT64 arg1, arg2, result; * none. */ -static VOID neg64(arg, result) INT64 arg, result; +static VOID neg64(arg, result) FLANG_INT64 arg, result; { int sign; /* sign of the low-order word of arg prior to @@ -304,9 +304,9 @@ static VOID neg64(arg, result) INT64 arg, result; * integer quotient. */ VOID -__utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) +__utl_i_udiv64(FLANG_UFLANG_INT64 arg1, FLANG_UFLANG_INT64 arg2, FLANG_UFLANG_INT64 result) { - INT64 den; /* denominator used in calculating the + FLANG_INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -358,7 +358,7 @@ long long __mth_i_kicshft(op1, op2, count, direct) UINT op1, op2; /* really INT */ INT count, direct; { - INT64 result; + FLANG_INT64 result; if (count < 0 || count >= 64) { UTL_I_I64RET(0, 0); } @@ -391,7 +391,7 @@ INT count, direct; long long __mth_i_ukicshft(op1, op2, count, direct) UINT op1, op2; INT count, direct; { - INT64 result; + FLANG_INT64 result; if (count < 0 || count >= 64) { UTL_I_I64RET(0, 0); } @@ -422,19 +422,19 @@ INT count, direct; long long __mth_i_kishft(op1, op2, arg2) INT op1, op2, arg2; { - INT64 arg1; - INT64 result; + FLANG_INT64 arg1; + FLANG_INT64 result; arg1[1] = op1; arg1[0] = op2; shf64(arg1, arg2, result); UTL_I_I64RET(result[0], result[1]); } -static VOID shf64(arg, count, result) INT64 arg; +static VOID shf64(arg, count, result) FLANG_INT64 arg; int count; -INT64 result; +FLANG_INT64 result; { - FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UFLANG_INT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; @@ -879,10 +879,10 @@ register UFP *u; /* unpacked result */ static VOID i64toufp(i, u) /* 64-bit integer to unpacked float */ - INT64 i; + FLANG_INT64 i; UFP *u; { - INT64 tmp; + FLANG_INT64 tmp; if (i[0] == 0L && i[1] == 0L) { u->fsgn = POS; @@ -999,7 +999,7 @@ IEEE32 *r; /* packed result */ static VOID ufptoi64(u, i) /* unpacked float to 64-bit integer */ UFP *u; -INT64 i; +FLANG_INT64 i; { /* Normalize the unpacked * number first. */ @@ -1043,7 +1043,7 @@ INT64 i; VOID __utl_i_dfix64(d, i) /* double precision to 64-bit integer */ double d; /*IEEE64 format and double are LITTLE_ENDIAN */ -INT64 i; +FLANG_INT64 i; { UFP u; @@ -1053,7 +1053,7 @@ INT64 i; double __utl_i_dflt64(i) /* 64 -- 64-bit integer to double */ - INT64 i; + FLANG_INT64 i; { UFP u; IEEE64 d; @@ -1063,7 +1063,7 @@ double __utl_i_dflt64(i) return *((double *)d); /*IEEE64 format and double are LITTLE_ENDIAN */ } -VOID __utl_i_fix64(float ff, INT64 i) /* use prototype to pass as float */ +VOID __utl_i_fix64(float ff, FLANG_INT64 i) /* use prototype to pass as float */ /* single float to 64-bit */ { IEEE32 f; @@ -1074,7 +1074,7 @@ VOID __utl_i_fix64(float ff, INT64 i) /* use prototype to pass as float */ ufptoi64(&u, i); } -float __utl_i_flt64(INT64 i) /* use prototype to return as float */ +float __utl_i_flt64(FLANG_INT64 i) /* use prototype to return as float */ /* 64-bit integer to single precision */ { UFP u; From 93fe5564193e475b83c39f5288b55c13c3f73b43 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 22 Oct 2017 18:37:54 -0500 Subject: [PATCH 022/141] Revert "sed INT64->FLANG_INT64" This reverts commit 07a3e9c88e6e7a99ec3741d240f0eed72ff27db4. --- runtime/flang/fmtconv.c | 12 +++---- runtime/flang/fmtgetnum.c | 2 +- runtime/flang/fmtread.c | 6 ++-- runtime/flang/fmtwrite.c | 4 +-- runtime/flang/ftni64.c | 14 ++++---- runtime/flang/ftni64bitsup.c | 36 +++++++++---------- runtime/flang/utilsi64.c | 68 ++++++++++++++++++------------------ runtime/flangrti/mthi64.c | 60 +++++++++++++++---------------- 8 files changed, 101 insertions(+), 101 deletions(-) diff --git a/runtime/flang/fmtconv.c b/runtime/flang/fmtconv.c index dbe8ddbd7a9..abd12f9ac5c 100644 --- a/runtime/flang/fmtconv.c +++ b/runtime/flang/fmtconv.c @@ -40,7 +40,7 @@ static int dbgflag; #define DBGBIT(v) (LOCAL_DEBUG && (dbgflag & v)) static char *conv_int(__BIGINT_T, int *, int *); -static char *conv_int8(FLANG_INT64, int *, int *); +static char *conv_int8(INT64, int *, int *); static void put_buf(int, char *, int, int); static void conv_e(int, int, int, bool); @@ -96,7 +96,7 @@ __fortio_default_convert(char *item, int type, { int width; char *p; - FLANG_INT64 i8val; + INT64 i8val; switch (type) { default: @@ -113,7 +113,7 @@ __fortio_default_convert(char *item, int type, break; case __INT8: width = 24; - (void) __fortio_fmt_i8(*(FLANG_INT64 *)(item), width, 1, plus_flag); + (void) __fortio_fmt_i8(*(INT64 *)(item), width, 1, plus_flag); break; case __WORD4: width = 8; @@ -341,7 +341,7 @@ conv_int(__BIGINT_T val, int *lenp, int *negp) } char * -__fortio_fmt_i8(FLANG_INT64 val, +__fortio_fmt_i8(INT64 val, int width, int mn, /* minimum # of digits (Iw.m) */ bool plus_flag) @@ -384,14 +384,14 @@ __fortio_fmt_i8(FLANG_INT64 val, } static char * -conv_int8(FLANG_INT64 val, int *lenp, int *negp) +conv_int8(INT64 val, int *lenp, int *negp) { #define MAX_CONV_INT8 32 static char tmp[MAX_CONV_INT8]; char *p; int len; - FLANG_INT64 value; + INT64 value; *negp = 0; I64_LSH(value) = I64_LSH(val); diff --git a/runtime/flang/fmtgetnum.c b/runtime/flang/fmtgetnum.c index 7eb0a67c138..086f2724c02 100644 --- a/runtime/flang/fmtgetnum.c +++ b/runtime/flang/fmtgetnum.c @@ -70,7 +70,7 @@ __fortio_getnum( union { __BIGINT_T i; __BIGREAL_T d; - FLANG_INT64 i8v; + INT64 i8v; } * val; /* value of token to return */ if (dc_flag == TRUE) diff --git a/runtime/flang/fmtread.c b/runtime/flang/fmtread.c index a6fd82419a0..42c28717f63 100644 --- a/runtime/flang/fmtread.c +++ b/runtime/flang/fmtread.c @@ -112,7 +112,7 @@ static int fr_readnum(int, char *, int); static int fr_init(__INT_T *, __INT_T *, __INT_T *, __INT_T *, __INT_T *, __INT8_T *, char *, int); -static int fr_assign(char *, int, __BIGINT_T, FLANG_INT64, __BIGREAL_T); +static int fr_assign(char *, int, __BIGINT_T, INT64, __BIGREAL_T); static int fr_OZreadnum(int, char *, int, int); static int fr_Breadnum(char *, int, int); static __BIGREAL_T fr_getreal(char *, int, int, int *); @@ -1637,7 +1637,7 @@ fr_readnum(int code, char *item, int type) __BIGINT_T ival; __BIGREAL_T dval; #undef IS_INT - FLANG_INT64 i8val; /* always declare because of fr_assign() */ + INT64 i8val; /* always declare because of fr_assign() */ #define IS_INT(t) (t == __INT || t == __INT8) int ty; int w, d, e, c; @@ -2060,7 +2060,7 @@ fr_readnum(int code, char *item, int type) /* ------------------------------------------------------------------ */ static int -fr_assign(char *item, int type, __BIGINT_T ival, FLANG_INT64 i8val, __BIGREAL_T dval) +fr_assign(char *item, int type, __BIGINT_T ival, INT64 i8val, __BIGREAL_T dval) { switch (type) { case __INT1: diff --git a/runtime/flang/fmtwrite.c b/runtime/flang/fmtwrite.c index ad3c3cee1f3..1b83aa7598c 100644 --- a/runtime/flang/fmtwrite.c +++ b/runtime/flang/fmtwrite.c @@ -1578,7 +1578,7 @@ fw_writenum(int code, char *item, int type) __BIGINT_T ival; __BIGREAL_T dval; #undef IS_INT - FLANG_INT64 i8val; + INT64 i8val; #define IS_INT(t) (t == __BIGINT || t == __INT8) int ty; int w, m, d, e; @@ -1592,7 +1592,7 @@ fw_writenum(int code, char *item, int type) __INT4_T i4; __REAL4_T r4; __REAL8_T r8; - FLANG_INT64 i8v; + INT64 i8v; __INT8_T i8; __BIGREAL_T d; __REAL16_T r16; diff --git a/runtime/flang/ftni64.c b/runtime/flang/ftni64.c index afbd06994d8..b4748d65729 100644 --- a/runtime/flang/ftni64.c +++ b/runtime/flang/ftni64.c @@ -40,8 +40,8 @@ ftn_i_kishft(_ULONGLONG_T op, int count) __I8RET_T ftn_i_xori64(int op1, int op2, int op3, int op4) { - FLANG_INT64 u1; - FLANG_INT64 u2; + INT64 u1; + INT64 u2; u1[0] = op2; u1[1] = op1; @@ -55,8 +55,8 @@ ftn_i_xori64(int op1, int op2, int op3, int op4) __I8RET_T ftn_i_xnori64(int op1, int op2, int op3, int op4) { - FLANG_INT64 u1; - FLANG_INT64 u2; + INT64 u1; + INT64 u2; u1[0] = op2; u1[1] = op1; @@ -70,7 +70,7 @@ ftn_i_xnori64(int op1, int op2, int op3, int op4) int ftn_i_kr2ir(int op1, int op2) { - FLANG_INT64 u1; + INT64 u1; /* result is first element of int[2] which is union u'd with dp if little endian; if big endian, result is second element. @@ -83,7 +83,7 @@ ftn_i_kr2ir(int op1, int op2) float ftn_i_kr2sp(int op1, int op2) { - FLANG_INT64 u1; + INT64 u1; int i; u1[0] = op1; @@ -95,7 +95,7 @@ ftn_i_kr2sp(int op1, int op2) double ftn_i_kr2dp(int op1, int op2) { - FLANG_INT64D u1; + INT64D u1; u1.i[0] = op1; u1.i[1] = op2; diff --git a/runtime/flang/ftni64bitsup.c b/runtime/flang/ftni64bitsup.c index 647e265db35..a666926614c 100644 --- a/runtime/flang/ftni64bitsup.c +++ b/runtime/flang/ftni64bitsup.c @@ -39,13 +39,13 @@ ftn_i_kishftc(op, sc, int sc; /* shift count and direction */ int rc; /* # of rightmost val bits to be shifted */ { - FLANG_UFLANG_INT64 i8neg1, mask, field, tmp1, tmp2, val; + FLANG_UINT64 i8neg1, mask, field, tmp1, tmp2, val; int norm; /* define a remainder operation that doesn't use %; is this worth it? */ #define REMLOOP(a, b, c) for (a = b; a >= c; a -= c) - FLANG_INT64D u; + INT64D u; u.lv = op; val[0] = I64_MSH(u.i); @@ -141,8 +141,8 @@ int posd; /* start position in dest field */ int tmp; int maxpos; int maxlen; - FLANG_UFLANG_INT64 maski8; - FLANG_UFLANG_INT64 i8neg1, tmpi8, u_arg; + FLANG_UINT64 maski8; + FLANG_UINT64 i8neg1, tmpi8, u_arg; /* procedure */ @@ -225,8 +225,8 @@ __I8RET_T ftn_i_kibclr(arg1, arg2, bit) int arg1, arg2; /* value to be cleared */ int bit; /* bit to clear */ { - FLANG_INT64 result; - FLANG_UFLANG_INT64 i81, tmp; + INT64 result; + FLANG_UINT64 i81, tmp; result[0] = result[1] = 0; i81[0] = 0; i81[1] = 1; @@ -250,8 +250,8 @@ ftn_i_kibits(arg1, arg2, bitpos, numbits) int arg1, int bitpos; /* position of bit to start from */ int numbits; /* number of bits to extract */ { - FLANG_INT64 result; - FLANG_UFLANG_INT64 i8neg1, tmp, maski8, u_arg; + INT64 result; + FLANG_UINT64 i8neg1, tmp, maski8, u_arg; u_arg[0] = arg2; u_arg[1] = arg1; @@ -280,8 +280,8 @@ __I8RET_T ftn_i_kibset(arg1, arg2, bit) int arg1, arg2; /* value to be set */ int bit; /* bit to set */ { - FLANG_INT64 i8one, result; - FLANG_UFLANG_INT64 tmp; + INT64 i8one, result; + FLANG_UINT64 tmp; result[0] = result[1] = 0; i8one[0] = 0; i8one[1] = 1; @@ -304,8 +304,8 @@ __I8RET_T ftn_i_bktest(arg1, arg2, bit) int arg1, arg2; /* value to be tested */ int bit; /* bit to test */ { - FLANG_INT64 i8one, result; - FLANG_UFLANG_INT64 tmp; + INT64 i8one, result; + FLANG_UINT64 tmp; result[0] = result[1] = 0; i8one[0] = 0; i8one[1] = 1; @@ -339,11 +339,11 @@ int bit; /* bit to test */ * Return value: * none. */ -static void shf64(arg, count, result) FLANG_INT64 arg; +static void shf64(arg, count, result) INT64 arg; int count; -FLANG_INT64 result; +INT64 result; { - FLANG_UFLANG_INT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; @@ -388,11 +388,11 @@ FLANG_INT64 result; * Return value: * none. */ -static void ushf64(arg, count, result) FLANG_UFLANG_INT64 arg; +static void ushf64(arg, count, result) FLANG_UINT64 arg; int count; -FLANG_UFLANG_INT64 result; +FLANG_UINT64 result; { - FLANG_UFLANG_INT64 u_arg; /* 'copy-in' value of arg */ + FLANG_UINT64 u_arg; /* 'copy-in' value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; diff --git a/runtime/flang/utilsi64.c b/runtime/flang/utilsi64.c index 9a35e911a48..0562baaab0a 100644 --- a/runtime/flang/utilsi64.c +++ b/runtime/flang/utilsi64.c @@ -22,7 +22,7 @@ * the exception that TM_I8 => integer*4 is the natural integer and * integer*8 is an extension. All of these support routines could be * rewritten to use the appropriate C type which represents a 64-bit - * integer rather than FLANG_INT64/UIN64. + * integer rather than INT64/UIN64. */ int __ftn_32in64_; @@ -212,7 +212,7 @@ __fort_atoxi32(char *s, INT *i, int n, int base) * * s Input string containing number to be converted * (string is NOT null terminated.) - * ir FLANG_UFLANG_INT64 output value + * ir FLANG_UINT64 output value * n Number of chars from str to convert * radix Radix of conversion -- 2, 8, 10, 16. If * base is 16, then the digits a-f or A-F are @@ -237,7 +237,7 @@ __fort_atoxi32(char *s, INT *i, int n, int base) ****************************************************************/ int -__fort_atoxi64(char *s, FLANG_INT64 ir, int n, int radix) +__fort_atoxi64(char *s, INT64 ir, int n, int radix) { int err; char *sp; @@ -271,7 +271,7 @@ __fort_atoxi64(char *s, FLANG_INT64 ir, int n, int radix) #define ZERO '0' void -__fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix) +__fort_i64toax(INT64 from, char *to, int count, int sign, int radix) { int bit_width; /* width of the bit field for a particular * radix */ @@ -282,13 +282,13 @@ __fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix) * to be shifted */ int msd; /* index of the most-signingicant digit in to */ int num_bits; /* number of bits to be shifted */ - FLANG_INT64 quot; /* the quotient part of a 64 bit division */ - FLANG_INT64 remain; /* the remainder part of a 64 bit division */ - FLANG_INT64 temp_from; /* temp from (=(abs(from)) */ - FLANG_INT64 temp64; /* temporary 64 bit integer */ + INT64 quot; /* the quotient part of a 64 bit division */ + INT64 remain; /* the remainder part of a 64 bit division */ + INT64 temp_from; /* temp from (=(abs(from)) */ + INT64 temp64; /* temporary 64 bit integer */ /* 64 bit integer equal to 10 */ - static FLANG_INT64 ten64 = {0, 10}; + static INT64 ten64 = {0, 10}; /* the result of dividing a 64 bit unsigned integer with only the * sign bit on by 10 @@ -426,22 +426,22 @@ __fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix) * -2 = overflow / underflow * 0 = no error. */ -static int toi64(char *s, FLANG_INT64 toi, char *end, int radix) +static int toi64(char *s, INT64 toi, char *end, int radix) { - FLANG_INT64 base; /* 64 bit integer equal to radix */ - FLANG_INT64 diff; /* difference between 2 64 bit integers, used + INT64 base; /* 64 bit integer equal to radix */ + INT64 diff; /* difference between 2 64 bit integers, used * in determining if overflow has occured */ - FLANG_INT64 num; /* numerical value of a particular digit */ - FLANG_INT64 to; + INT64 num; /* numerical value of a particular digit */ + INT64 to; int negate; int ch; /* 64-bit integer with only its sign bit on */ - static FLANG_INT64 sign_bit = {0x80000000, 0}; + static INT64 sign_bit = {0x80000000, 0}; /* maximum 64-bit signed integer */ - static FLANG_INT64 max_int = {0x7fffffff, 0xffffffff}; - static FLANG_INT64 max_neg = {0x80000000, 0}; + static INT64 max_int = {0x7fffffff, 0xffffffff}; + static INT64 max_neg = {0x80000000, 0}; OVL8 pto; @@ -550,7 +550,7 @@ static int toi64(char *s, FLANG_INT64 toi, char *end, int radix) return -2; } -static void neg64(FLANG_INT64 arg, FLANG_INT64 result) +static void neg64(INT64 arg, INT64 result) { int sign; /* sign of the low-order word of arg prior to * being complemented */ @@ -561,9 +561,9 @@ static void neg64(FLANG_INT64 arg, FLANG_INT64 result) result[0]++; } -static void shf64(FLANG_INT64 arg1, INT arg2, FLANG_INT64 result) +static void shf64(INT64 arg1, INT arg2, INT64 result) { - FLANG_UFLANG_INT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (arg2 >= 64 || arg2 <= -64) { result[0] = 0; @@ -589,7 +589,7 @@ static void shf64(FLANG_INT64 arg1, INT arg2, FLANG_INT64 result) } } -static int ucmp64(FLANG_UFLANG_INT64 arg1, FLANG_UFLANG_INT64 arg2) +static int ucmp64(FLANG_UINT64 arg1, FLANG_UINT64 arg2) { if (arg1[0] == arg2[0]) { if (arg1[1] == arg2[1]) @@ -617,7 +617,7 @@ static void neg128(), uneg64(), ushf64(), shf128(); * Return value: * none */ -void __utl_i_add64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) +void __utl_i_add64(INT64 arg1, INT64 arg2, INT64 result) { int carry; /* value to be carried from adding the lower * 32 bits */ @@ -645,7 +645,7 @@ void __utl_i_add64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) * Return value: * none */ -void __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) +void __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) { int borrow; /* value to be borrowed from adding the lower @@ -670,7 +670,7 @@ void __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) * integer product. */ -void __utl_i_mul64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) +void __utl_i_mul64(INT64 arg1, INT64 arg2, INT64 result) { INT temp_result[4]; /* the product returned by MUL128 */ @@ -679,10 +679,10 @@ void __utl_i_mul64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) result[1] = temp_result[3]; } -static void __utl_i_mul128(FLANG_INT64 arg1, FLANG_INT64 arg2, INT result[4]) +static void __utl_i_mul128(INT64 arg1, INT64 arg2, INT result[4]) { int i; /* for loop control variable */ - FLANG_INT64 temp_arg; /* temporary argument used in calculating the + INT64 temp_arg; /* temporary argument used in calculating the * product */ INT temp_result[4]; /* temporary result */ int negate; /* flag which indicated the result needs to @@ -729,9 +729,9 @@ static void __utl_i_mul128(FLANG_INT64 arg1, FLANG_INT64 arg2, INT result[4]) result[i] = temp_result[i]; } -void __utl_i_div64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) +void __utl_i_div64(INT64 arg1, INT64 arg2, INT64 result) { - FLANG_INT64 den; /* denominator used in calculating the + INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -802,9 +802,9 @@ static void neg128(INT arg[4], INT result[4]) } } -void __utl_i_udiv64(FLANG_UFLANG_INT64 arg1, FLANG_UFLANG_INT64 arg2, FLANG_UFLANG_INT64 result) +void __utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) { - FLANG_UFLANG_INT64 den; /* denominator used in calculating the + FLANG_UINT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -856,7 +856,7 @@ void __utl_i_udiv64(FLANG_UFLANG_INT64 arg1, FLANG_UFLANG_INT64 arg2, FLANG_UFLA } } -static void uneg64(FLANG_UFLANG_INT64 arg, FLANG_UFLANG_INT64 result) +static void uneg64(FLANG_UINT64 arg, FLANG_UINT64 result) { int sign; /* sign of the low-order word of arg prior to * being complemented */ @@ -868,11 +868,11 @@ static void uneg64(FLANG_UFLANG_INT64 arg, FLANG_UFLANG_INT64 result) result[0]++; } -static void ushf64(FLANG_UFLANG_INT64 arg, int count, FLANG_INT64 result) +static void ushf64(FLANG_UINT64 arg, int count, INT64 result) int count; -FLANG_INT64 result; +INT64 result; { - FLANG_UFLANG_INT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; diff --git a/runtime/flangrti/mthi64.c b/runtime/flangrti/mthi64.c index 405394114f7..bab8430aa9e 100644 --- a/runtime/flangrti/mthi64.c +++ b/runtime/flangrti/mthi64.c @@ -15,11 +15,11 @@ * */ -typedef int FLANG_INT64[2]; -typedef unsigned int FLANG_UFLANG_INT64[2]; +typedef int INT64[2]; +typedef unsigned int FLANG_UINT64[2]; typedef union { - FLANG_INT64 wd; /* canonical msw & lsw view of long long values */ + INT64 wd; /* canonical msw & lsw view of long long values */ int hf[2]; /* native msw & lsw signed view of long long values */ unsigned uhf[2]; /* native msw & lsw unsigned view of long long values */ long long value; @@ -67,7 +67,7 @@ VOID __mth_i_krshift(); VOID __mth_i_klshift(); VOID __mth_i_kurshift(); VOID __utl_i_add64(), __utl_i_div64(); -VOID __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result); +VOID __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result); VOID __utl_i_mul64(), __utl_i_udiv64(); static VOID neg64(), shf64(), shf128by1(); @@ -81,7 +81,7 @@ static VOID neg64(), shf64(), shf128by1(); * Return value: * none */ -VOID __utl_i_add64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; +VOID __utl_i_add64(arg1, arg2, result) INT64 arg1, arg2, result; { int carry; /* value to be carried from adding the lower * 32 bits */ @@ -106,7 +106,7 @@ VOID __utl_i_add64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; * \param result arg1 - arg2 */ VOID -__utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) +__utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) { int borrow; /* value to be borrowed from adding the lower * 32 bits */ @@ -130,7 +130,7 @@ __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) * Multiply two 64-bit integers to produce a 64-bit * integer product. */ -VOID __utl_i_mul64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; +VOID __utl_i_mul64(arg1, arg2, result) INT64 arg1, arg2, result; { LL_SHAPE v1, v2, r; @@ -175,8 +175,8 @@ __mth_i_kdiv(long long x, long long y) MSW(r) = 0; *(unsigned *)&LSW(r) = (unsigned)LSW(a) / (unsigned)LSW(b); } else { - FLANG_INT64 arg1, arg2; /* FLANG_INT64 is big endian!! */ - FLANG_INT64 result; + INT64 arg1, arg2; /* INT64 is big endian!! */ + INT64 result; arg1[1] = LSW(a); arg1[0] = MSW(a); arg2[1] = LSW(b); @@ -207,8 +207,8 @@ __mth_i_ukdiv(unsigned long long x, unsigned long long y) UMSW(r) = 0; ULSW(r) = ULSW(a) / ULSW(b); } else { - FLANG_UFLANG_INT64 arg1, arg2; /* FLANG_UFLANG_INT64 is big endian!! */ - FLANG_UFLANG_INT64 result; + FLANG_UINT64 arg1, arg2; /* FLANG_UINT64 is big endian!! */ + FLANG_UINT64 result; arg1[1] = ULSW(a); arg1[0] = UMSW(a); arg2[1] = ULSW(b); @@ -224,10 +224,10 @@ __mth_i_ukdiv(unsigned long long x, unsigned long long y) * Divide two 64-bit integers to produce a 64-bit * integer quotient. */ -VOID __utl_i_div64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; +VOID __utl_i_div64(arg1, arg2, result) INT64 arg1, arg2, result; { - FLANG_INT64 den; /* denominator used in calculating the + INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -287,7 +287,7 @@ VOID __utl_i_div64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; * none. */ -static VOID neg64(arg, result) FLANG_INT64 arg, result; +static VOID neg64(arg, result) INT64 arg, result; { int sign; /* sign of the low-order word of arg prior to @@ -304,9 +304,9 @@ static VOID neg64(arg, result) FLANG_INT64 arg, result; * integer quotient. */ VOID -__utl_i_udiv64(FLANG_UFLANG_INT64 arg1, FLANG_UFLANG_INT64 arg2, FLANG_UFLANG_INT64 result) +__utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) { - FLANG_INT64 den; /* denominator used in calculating the + INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -358,7 +358,7 @@ long long __mth_i_kicshft(op1, op2, count, direct) UINT op1, op2; /* really INT */ INT count, direct; { - FLANG_INT64 result; + INT64 result; if (count < 0 || count >= 64) { UTL_I_I64RET(0, 0); } @@ -391,7 +391,7 @@ INT count, direct; long long __mth_i_ukicshft(op1, op2, count, direct) UINT op1, op2; INT count, direct; { - FLANG_INT64 result; + INT64 result; if (count < 0 || count >= 64) { UTL_I_I64RET(0, 0); } @@ -422,19 +422,19 @@ INT count, direct; long long __mth_i_kishft(op1, op2, arg2) INT op1, op2, arg2; { - FLANG_INT64 arg1; - FLANG_INT64 result; + INT64 arg1; + INT64 result; arg1[1] = op1; arg1[0] = op2; shf64(arg1, arg2, result); UTL_I_I64RET(result[0], result[1]); } -static VOID shf64(arg, count, result) FLANG_INT64 arg; +static VOID shf64(arg, count, result) INT64 arg; int count; -FLANG_INT64 result; +INT64 result; { - FLANG_UFLANG_INT64 u_arg; /* 'copy-in' unsigned value of arg */ + FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; @@ -879,10 +879,10 @@ register UFP *u; /* unpacked result */ static VOID i64toufp(i, u) /* 64-bit integer to unpacked float */ - FLANG_INT64 i; + INT64 i; UFP *u; { - FLANG_INT64 tmp; + INT64 tmp; if (i[0] == 0L && i[1] == 0L) { u->fsgn = POS; @@ -999,7 +999,7 @@ IEEE32 *r; /* packed result */ static VOID ufptoi64(u, i) /* unpacked float to 64-bit integer */ UFP *u; -FLANG_INT64 i; +INT64 i; { /* Normalize the unpacked * number first. */ @@ -1043,7 +1043,7 @@ FLANG_INT64 i; VOID __utl_i_dfix64(d, i) /* double precision to 64-bit integer */ double d; /*IEEE64 format and double are LITTLE_ENDIAN */ -FLANG_INT64 i; +INT64 i; { UFP u; @@ -1053,7 +1053,7 @@ FLANG_INT64 i; double __utl_i_dflt64(i) /* 64 -- 64-bit integer to double */ - FLANG_INT64 i; + INT64 i; { UFP u; IEEE64 d; @@ -1063,7 +1063,7 @@ double __utl_i_dflt64(i) return *((double *)d); /*IEEE64 format and double are LITTLE_ENDIAN */ } -VOID __utl_i_fix64(float ff, FLANG_INT64 i) /* use prototype to pass as float */ +VOID __utl_i_fix64(float ff, INT64 i) /* use prototype to pass as float */ /* single float to 64-bit */ { IEEE32 f; @@ -1074,7 +1074,7 @@ VOID __utl_i_fix64(float ff, FLANG_INT64 i) /* use prototype to pass as float */ ufptoi64(&u, i); } -float __utl_i_flt64(FLANG_INT64 i) /* use prototype to return as float */ +float __utl_i_flt64(INT64 i) /* use prototype to return as float */ /* 64-bit integer to single precision */ { UFP u; From 343ebbe13654e9d04efcb9bcea346563cc826772 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 22 Oct 2017 18:44:22 -0500 Subject: [PATCH 023/141] sed INT64->FLANG_INT64 --- runtime/flang/fmtconv.c | 12 ++++---- runtime/flang/fmtgetnum.c | 2 +- runtime/flang/fmtread.c | 6 ++-- runtime/flang/fmtwrite.c | 4 +-- runtime/flang/format.h | 8 +++--- runtime/flang/ftni64.c | 12 ++++---- runtime/flang/ftni64.h | 6 ++-- runtime/flang/ftni64bitsup.c | 12 ++++---- runtime/flang/global.h | 8 +++--- runtime/flang/utilsi64.c | 54 ++++++++++++++++++------------------ runtime/flangrti/mthi64.c | 50 ++++++++++++++++----------------- 11 files changed, 87 insertions(+), 87 deletions(-) diff --git a/runtime/flang/fmtconv.c b/runtime/flang/fmtconv.c index abd12f9ac5c..dbe8ddbd7a9 100644 --- a/runtime/flang/fmtconv.c +++ b/runtime/flang/fmtconv.c @@ -40,7 +40,7 @@ static int dbgflag; #define DBGBIT(v) (LOCAL_DEBUG && (dbgflag & v)) static char *conv_int(__BIGINT_T, int *, int *); -static char *conv_int8(INT64, int *, int *); +static char *conv_int8(FLANG_INT64, int *, int *); static void put_buf(int, char *, int, int); static void conv_e(int, int, int, bool); @@ -96,7 +96,7 @@ __fortio_default_convert(char *item, int type, { int width; char *p; - INT64 i8val; + FLANG_INT64 i8val; switch (type) { default: @@ -113,7 +113,7 @@ __fortio_default_convert(char *item, int type, break; case __INT8: width = 24; - (void) __fortio_fmt_i8(*(INT64 *)(item), width, 1, plus_flag); + (void) __fortio_fmt_i8(*(FLANG_INT64 *)(item), width, 1, plus_flag); break; case __WORD4: width = 8; @@ -341,7 +341,7 @@ conv_int(__BIGINT_T val, int *lenp, int *negp) } char * -__fortio_fmt_i8(INT64 val, +__fortio_fmt_i8(FLANG_INT64 val, int width, int mn, /* minimum # of digits (Iw.m) */ bool plus_flag) @@ -384,14 +384,14 @@ __fortio_fmt_i8(INT64 val, } static char * -conv_int8(INT64 val, int *lenp, int *negp) +conv_int8(FLANG_INT64 val, int *lenp, int *negp) { #define MAX_CONV_INT8 32 static char tmp[MAX_CONV_INT8]; char *p; int len; - INT64 value; + FLANG_INT64 value; *negp = 0; I64_LSH(value) = I64_LSH(val); diff --git a/runtime/flang/fmtgetnum.c b/runtime/flang/fmtgetnum.c index 086f2724c02..7eb0a67c138 100644 --- a/runtime/flang/fmtgetnum.c +++ b/runtime/flang/fmtgetnum.c @@ -70,7 +70,7 @@ __fortio_getnum( union { __BIGINT_T i; __BIGREAL_T d; - INT64 i8v; + FLANG_INT64 i8v; } * val; /* value of token to return */ if (dc_flag == TRUE) diff --git a/runtime/flang/fmtread.c b/runtime/flang/fmtread.c index 42c28717f63..a6fd82419a0 100644 --- a/runtime/flang/fmtread.c +++ b/runtime/flang/fmtread.c @@ -112,7 +112,7 @@ static int fr_readnum(int, char *, int); static int fr_init(__INT_T *, __INT_T *, __INT_T *, __INT_T *, __INT_T *, __INT8_T *, char *, int); -static int fr_assign(char *, int, __BIGINT_T, INT64, __BIGREAL_T); +static int fr_assign(char *, int, __BIGINT_T, FLANG_INT64, __BIGREAL_T); static int fr_OZreadnum(int, char *, int, int); static int fr_Breadnum(char *, int, int); static __BIGREAL_T fr_getreal(char *, int, int, int *); @@ -1637,7 +1637,7 @@ fr_readnum(int code, char *item, int type) __BIGINT_T ival; __BIGREAL_T dval; #undef IS_INT - INT64 i8val; /* always declare because of fr_assign() */ + FLANG_INT64 i8val; /* always declare because of fr_assign() */ #define IS_INT(t) (t == __INT || t == __INT8) int ty; int w, d, e, c; @@ -2060,7 +2060,7 @@ fr_readnum(int code, char *item, int type) /* ------------------------------------------------------------------ */ static int -fr_assign(char *item, int type, __BIGINT_T ival, INT64 i8val, __BIGREAL_T dval) +fr_assign(char *item, int type, __BIGINT_T ival, FLANG_INT64 i8val, __BIGREAL_T dval) { switch (type) { case __INT1: diff --git a/runtime/flang/fmtwrite.c b/runtime/flang/fmtwrite.c index 1b83aa7598c..ad3c3cee1f3 100644 --- a/runtime/flang/fmtwrite.c +++ b/runtime/flang/fmtwrite.c @@ -1578,7 +1578,7 @@ fw_writenum(int code, char *item, int type) __BIGINT_T ival; __BIGREAL_T dval; #undef IS_INT - INT64 i8val; + FLANG_INT64 i8val; #define IS_INT(t) (t == __BIGINT || t == __INT8) int ty; int w, m, d, e; @@ -1592,7 +1592,7 @@ fw_writenum(int code, char *item, int type) __INT4_T i4; __REAL4_T r4; __REAL8_T r8; - INT64 i8v; + FLANG_INT64 i8v; __INT8_T i8; __BIGREAL_T d; __REAL16_T r16; diff --git a/runtime/flang/format.h b/runtime/flang/format.h index c98cc8ff51d..9bcddc1cfb6 100644 --- a/runtime/flang/format.h +++ b/runtime/flang/format.h @@ -55,7 +55,7 @@ char *__fortio_default_convert(char *, int, int, int *, bool, bool, int); char *__fortio_fmt_i(__BIGINT_T, int, int, bool); /** \brief Generate a formated INTEGER*8 string */ -char *__fortio_fmt_i8(INT64, int, int, bool); +char *__fortio_fmt_i8(FLANG_INT64, int, int, bool); /** \brief Generate a string for a 'D' format characer */ char *__fortio_fmt_d(__BIGREAL_T, int, int, int, int, bool, int); @@ -139,13 +139,13 @@ int __fort_atoxi32(char *s, INT *i, int n, int base); * \param conversion radix: 2, 8, 10, 16 */ -void __fort_i64toax(INT64 from, char *to, int count, int sign, int radix); +void __fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix); /** \brief char string to 64-bit integer. * * \param Input string containing number to be converted * (string is NOT null terminated.) - * \param UINT64 output value + * \param FLANG_UINT64 output value * \param Number of chars from str to convert * \param Radix of conversion -- 2, 8, 10, 16. If base is 16, then the * digits a-f @@ -155,4 +155,4 @@ void __fort_i64toax(INT64 from, char *to, int count, int sign, int radix); * -2 overflow occurred on conversion * 0 No error -- *ir contains the converted number. */ -int __fort_atoxi64(char *s, INT64 ir, int n, int radix); +int __fort_atoxi64(char *s, FLANG_INT64 ir, int n, int radix); diff --git a/runtime/flang/ftni64.c b/runtime/flang/ftni64.c index b4748d65729..7bdf08f76ad 100644 --- a/runtime/flang/ftni64.c +++ b/runtime/flang/ftni64.c @@ -40,8 +40,8 @@ ftn_i_kishft(_ULONGLONG_T op, int count) __I8RET_T ftn_i_xori64(int op1, int op2, int op3, int op4) { - INT64 u1; - INT64 u2; + FLANG_INT64 u1; + FLANG_INT64 u2; u1[0] = op2; u1[1] = op1; @@ -55,8 +55,8 @@ ftn_i_xori64(int op1, int op2, int op3, int op4) __I8RET_T ftn_i_xnori64(int op1, int op2, int op3, int op4) { - INT64 u1; - INT64 u2; + FLANG_INT64 u1; + FLANG_INT64 u2; u1[0] = op2; u1[1] = op1; @@ -70,7 +70,7 @@ ftn_i_xnori64(int op1, int op2, int op3, int op4) int ftn_i_kr2ir(int op1, int op2) { - INT64 u1; + FLANG_INT64 u1; /* result is first element of int[2] which is union u'd with dp if little endian; if big endian, result is second element. @@ -83,7 +83,7 @@ ftn_i_kr2ir(int op1, int op2) float ftn_i_kr2sp(int op1, int op2) { - INT64 u1; + FLANG_INT64 u1; int i; u1[0] = op1; diff --git a/runtime/flang/ftni64.h b/runtime/flang/ftni64.h index 467c7ca2533..e696665c3b0 100644 --- a/runtime/flang/ftni64.h +++ b/runtime/flang/ftni64.h @@ -28,8 +28,8 @@ typedef long _LONGLONG_T; typedef unsigned long _ULONGLONG_T; /* now defined if BaseTsd10.h included */ -typedef int INT64[2]; -typedef unsigned int UINT64[2]; +typedef int FLANG_INT64[2]; +typedef unsigned int FLANG_UINT64[2]; #define I64_MSH(t) t[1] #define I64_LSH(t) t[0] @@ -39,7 +39,7 @@ int __ftn_32in64_; #define VOID void typedef union { - INT64 i; + FLANG_INT64 i; double d; _LONGLONG_T lv; } INT64D; diff --git a/runtime/flang/ftni64bitsup.c b/runtime/flang/ftni64bitsup.c index a666926614c..ca736759833 100644 --- a/runtime/flang/ftni64bitsup.c +++ b/runtime/flang/ftni64bitsup.c @@ -225,7 +225,7 @@ __I8RET_T ftn_i_kibclr(arg1, arg2, bit) int arg1, arg2; /* value to be cleared */ int bit; /* bit to clear */ { - INT64 result; + FLANG_INT64 result; FLANG_UINT64 i81, tmp; result[0] = result[1] = 0; i81[0] = 0; @@ -250,7 +250,7 @@ ftn_i_kibits(arg1, arg2, bitpos, numbits) int arg1, int bitpos; /* position of bit to start from */ int numbits; /* number of bits to extract */ { - INT64 result; + FLANG_INT64 result; FLANG_UINT64 i8neg1, tmp, maski8, u_arg; u_arg[0] = arg2; u_arg[1] = arg1; @@ -280,7 +280,7 @@ __I8RET_T ftn_i_kibset(arg1, arg2, bit) int arg1, arg2; /* value to be set */ int bit; /* bit to set */ { - INT64 i8one, result; + FLANG_INT64 i8one, result; FLANG_UINT64 tmp; result[0] = result[1] = 0; i8one[0] = 0; @@ -304,7 +304,7 @@ __I8RET_T ftn_i_bktest(arg1, arg2, bit) int arg1, arg2; /* value to be tested */ int bit; /* bit to test */ { - INT64 i8one, result; + FLANG_INT64 i8one, result; FLANG_UINT64 tmp; result[0] = result[1] = 0; i8one[0] = 0; @@ -339,9 +339,9 @@ int bit; /* bit to test */ * Return value: * none. */ -static void shf64(arg, count, result) INT64 arg; +static void shf64(arg, count, result) FLANG_INT64 arg; int count; -INT64 result; +FLANG_INT64 result; { FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ diff --git a/runtime/flang/global.h b/runtime/flang/global.h index 5acbf4ed8e7..59a755ef0da 100644 --- a/runtime/flang/global.h +++ b/runtime/flang/global.h @@ -29,8 +29,8 @@ * the natural integer is integer*4 (__BIGINT is __INT4). */ #ifndef _WIN32 -typedef int INT64[2]; -typedef unsigned int UINT64[2]; +typedef int FLANG_INT64[2]; +typedef unsigned int FLANG_UINT64[2]; #define I64_MSH(t) t[1] #define I64_LSH(t) t[0] #else @@ -301,9 +301,9 @@ typedef struct atag { union { /* value: depends on dtype */ __BIGINT_T i; /* __BIGINT, __BIGLOG */ __BIGREAL_T d; /* __BIGREAL */ - INT64 i8; /* __INT8 */ + FLANG_INT64 i8; /* __INT8 */ __INT8_T i8v; - UINT64 ui8; /* __LOG8 */ + FLANG_UINT64 ui8; /* __LOG8 */ __INT8_UT ui8v; struct { /* __STR, __NCHAR */ int len; /* length of string */ diff --git a/runtime/flang/utilsi64.c b/runtime/flang/utilsi64.c index 0562baaab0a..ed82da14940 100644 --- a/runtime/flang/utilsi64.c +++ b/runtime/flang/utilsi64.c @@ -22,7 +22,7 @@ * the exception that TM_I8 => integer*4 is the natural integer and * integer*8 is an extension. All of these support routines could be * rewritten to use the appropriate C type which represents a 64-bit - * integer rather than INT64/UIN64. + * integer rather than FLANG_INT64/UIN64. */ int __ftn_32in64_; @@ -237,7 +237,7 @@ __fort_atoxi32(char *s, INT *i, int n, int base) ****************************************************************/ int -__fort_atoxi64(char *s, INT64 ir, int n, int radix) +__fort_atoxi64(char *s, FLANG_INT64 ir, int n, int radix) { int err; char *sp; @@ -271,7 +271,7 @@ __fort_atoxi64(char *s, INT64 ir, int n, int radix) #define ZERO '0' void -__fort_i64toax(INT64 from, char *to, int count, int sign, int radix) +__fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix) { int bit_width; /* width of the bit field for a particular * radix */ @@ -282,13 +282,13 @@ __fort_i64toax(INT64 from, char *to, int count, int sign, int radix) * to be shifted */ int msd; /* index of the most-signingicant digit in to */ int num_bits; /* number of bits to be shifted */ - INT64 quot; /* the quotient part of a 64 bit division */ - INT64 remain; /* the remainder part of a 64 bit division */ - INT64 temp_from; /* temp from (=(abs(from)) */ - INT64 temp64; /* temporary 64 bit integer */ + FLANG_INT64 quot; /* the quotient part of a 64 bit division */ + FLANG_INT64 remain; /* the remainder part of a 64 bit division */ + FLANG_INT64 temp_from; /* temp from (=(abs(from)) */ + FLANG_INT64 temp64; /* temporary 64 bit integer */ /* 64 bit integer equal to 10 */ - static INT64 ten64 = {0, 10}; + static FLANG_INT64 ten64 = {0, 10}; /* the result of dividing a 64 bit unsigned integer with only the * sign bit on by 10 @@ -426,22 +426,22 @@ __fort_i64toax(INT64 from, char *to, int count, int sign, int radix) * -2 = overflow / underflow * 0 = no error. */ -static int toi64(char *s, INT64 toi, char *end, int radix) +static int toi64(char *s, FLANG_INT64 toi, char *end, int radix) { - INT64 base; /* 64 bit integer equal to radix */ - INT64 diff; /* difference between 2 64 bit integers, used + FLANG_INT64 base; /* 64 bit integer equal to radix */ + FLANG_INT64 diff; /* difference between 2 64 bit integers, used * in determining if overflow has occured */ - INT64 num; /* numerical value of a particular digit */ - INT64 to; + FLANG_INT64 num; /* numerical value of a particular digit */ + FLANG_INT64 to; int negate; int ch; /* 64-bit integer with only its sign bit on */ - static INT64 sign_bit = {0x80000000, 0}; + static FLANG_INT64 sign_bit = {0x80000000, 0}; /* maximum 64-bit signed integer */ - static INT64 max_int = {0x7fffffff, 0xffffffff}; - static INT64 max_neg = {0x80000000, 0}; + static FLANG_INT64 max_int = {0x7fffffff, 0xffffffff}; + static FLANG_INT64 max_neg = {0x80000000, 0}; OVL8 pto; @@ -550,7 +550,7 @@ static int toi64(char *s, INT64 toi, char *end, int radix) return -2; } -static void neg64(INT64 arg, INT64 result) +static void neg64(FLANG_INT64 arg, FLANG_INT64 result) { int sign; /* sign of the low-order word of arg prior to * being complemented */ @@ -561,7 +561,7 @@ static void neg64(INT64 arg, INT64 result) result[0]++; } -static void shf64(INT64 arg1, INT arg2, INT64 result) +static void shf64(FLANG_INT64 arg1, INT arg2, FLANG_INT64 result) { FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ @@ -617,7 +617,7 @@ static void neg128(), uneg64(), ushf64(), shf128(); * Return value: * none */ -void __utl_i_add64(INT64 arg1, INT64 arg2, INT64 result) +void __utl_i_add64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) { int carry; /* value to be carried from adding the lower * 32 bits */ @@ -645,7 +645,7 @@ void __utl_i_add64(INT64 arg1, INT64 arg2, INT64 result) * Return value: * none */ -void __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) +void __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) { int borrow; /* value to be borrowed from adding the lower @@ -670,7 +670,7 @@ void __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) * integer product. */ -void __utl_i_mul64(INT64 arg1, INT64 arg2, INT64 result) +void __utl_i_mul64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) { INT temp_result[4]; /* the product returned by MUL128 */ @@ -679,10 +679,10 @@ void __utl_i_mul64(INT64 arg1, INT64 arg2, INT64 result) result[1] = temp_result[3]; } -static void __utl_i_mul128(INT64 arg1, INT64 arg2, INT result[4]) +static void __utl_i_mul128(FLANG_INT64 arg1, FLANG_INT64 arg2, INT result[4]) { int i; /* for loop control variable */ - INT64 temp_arg; /* temporary argument used in calculating the + FLANG_INT64 temp_arg; /* temporary argument used in calculating the * product */ INT temp_result[4]; /* temporary result */ int negate; /* flag which indicated the result needs to @@ -729,9 +729,9 @@ static void __utl_i_mul128(INT64 arg1, INT64 arg2, INT result[4]) result[i] = temp_result[i]; } -void __utl_i_div64(INT64 arg1, INT64 arg2, INT64 result) +void __utl_i_div64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) { - INT64 den; /* denominator used in calculating the + FLANG_INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -868,9 +868,9 @@ static void uneg64(FLANG_UINT64 arg, FLANG_UINT64 result) result[0]++; } -static void ushf64(FLANG_UINT64 arg, int count, INT64 result) +static void ushf64(FLANG_UINT64 arg, int count, FLANG_INT64 result) int count; -INT64 result; +FLANG_INT64 result; { FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ diff --git a/runtime/flangrti/mthi64.c b/runtime/flangrti/mthi64.c index bab8430aa9e..11f244ed7ae 100644 --- a/runtime/flangrti/mthi64.c +++ b/runtime/flangrti/mthi64.c @@ -15,11 +15,11 @@ * */ -typedef int INT64[2]; +typedef int FLANG_INT64[2]; typedef unsigned int FLANG_UINT64[2]; typedef union { - INT64 wd; /* canonical msw & lsw view of long long values */ + FLANG_INT64 wd; /* canonical msw & lsw view of long long values */ int hf[2]; /* native msw & lsw signed view of long long values */ unsigned uhf[2]; /* native msw & lsw unsigned view of long long values */ long long value; @@ -67,7 +67,7 @@ VOID __mth_i_krshift(); VOID __mth_i_klshift(); VOID __mth_i_kurshift(); VOID __utl_i_add64(), __utl_i_div64(); -VOID __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result); +VOID __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result); VOID __utl_i_mul64(), __utl_i_udiv64(); static VOID neg64(), shf64(), shf128by1(); @@ -81,7 +81,7 @@ static VOID neg64(), shf64(), shf128by1(); * Return value: * none */ -VOID __utl_i_add64(arg1, arg2, result) INT64 arg1, arg2, result; +VOID __utl_i_add64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; { int carry; /* value to be carried from adding the lower * 32 bits */ @@ -106,7 +106,7 @@ VOID __utl_i_add64(arg1, arg2, result) INT64 arg1, arg2, result; * \param result arg1 - arg2 */ VOID -__utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) +__utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) { int borrow; /* value to be borrowed from adding the lower * 32 bits */ @@ -130,7 +130,7 @@ __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) * Multiply two 64-bit integers to produce a 64-bit * integer product. */ -VOID __utl_i_mul64(arg1, arg2, result) INT64 arg1, arg2, result; +VOID __utl_i_mul64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; { LL_SHAPE v1, v2, r; @@ -175,8 +175,8 @@ __mth_i_kdiv(long long x, long long y) MSW(r) = 0; *(unsigned *)&LSW(r) = (unsigned)LSW(a) / (unsigned)LSW(b); } else { - INT64 arg1, arg2; /* INT64 is big endian!! */ - INT64 result; + FLANG_INT64 arg1, arg2; /* FLANG_INT64 is big endian!! */ + FLANG_INT64 result; arg1[1] = LSW(a); arg1[0] = MSW(a); arg2[1] = LSW(b); @@ -224,10 +224,10 @@ __mth_i_ukdiv(unsigned long long x, unsigned long long y) * Divide two 64-bit integers to produce a 64-bit * integer quotient. */ -VOID __utl_i_div64(arg1, arg2, result) INT64 arg1, arg2, result; +VOID __utl_i_div64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; { - INT64 den; /* denominator used in calculating the + FLANG_INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -287,7 +287,7 @@ VOID __utl_i_div64(arg1, arg2, result) INT64 arg1, arg2, result; * none. */ -static VOID neg64(arg, result) INT64 arg, result; +static VOID neg64(arg, result) FLANG_INT64 arg, result; { int sign; /* sign of the low-order word of arg prior to @@ -306,7 +306,7 @@ static VOID neg64(arg, result) INT64 arg, result; VOID __utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) { - INT64 den; /* denominator used in calculating the + FLANG_INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -358,7 +358,7 @@ long long __mth_i_kicshft(op1, op2, count, direct) UINT op1, op2; /* really INT */ INT count, direct; { - INT64 result; + FLANG_INT64 result; if (count < 0 || count >= 64) { UTL_I_I64RET(0, 0); } @@ -391,7 +391,7 @@ INT count, direct; long long __mth_i_ukicshft(op1, op2, count, direct) UINT op1, op2; INT count, direct; { - INT64 result; + FLANG_INT64 result; if (count < 0 || count >= 64) { UTL_I_I64RET(0, 0); } @@ -422,17 +422,17 @@ INT count, direct; long long __mth_i_kishft(op1, op2, arg2) INT op1, op2, arg2; { - INT64 arg1; - INT64 result; + FLANG_INT64 arg1; + FLANG_INT64 result; arg1[1] = op1; arg1[0] = op2; shf64(arg1, arg2, result); UTL_I_I64RET(result[0], result[1]); } -static VOID shf64(arg, count, result) INT64 arg; +static VOID shf64(arg, count, result) FLANG_INT64 arg; int count; -INT64 result; +FLANG_INT64 result; { FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ @@ -879,10 +879,10 @@ register UFP *u; /* unpacked result */ static VOID i64toufp(i, u) /* 64-bit integer to unpacked float */ - INT64 i; + FLANG_INT64 i; UFP *u; { - INT64 tmp; + FLANG_INT64 tmp; if (i[0] == 0L && i[1] == 0L) { u->fsgn = POS; @@ -999,7 +999,7 @@ IEEE32 *r; /* packed result */ static VOID ufptoi64(u, i) /* unpacked float to 64-bit integer */ UFP *u; -INT64 i; +FLANG_INT64 i; { /* Normalize the unpacked * number first. */ @@ -1043,7 +1043,7 @@ INT64 i; VOID __utl_i_dfix64(d, i) /* double precision to 64-bit integer */ double d; /*IEEE64 format and double are LITTLE_ENDIAN */ -INT64 i; +FLANG_INT64 i; { UFP u; @@ -1053,7 +1053,7 @@ INT64 i; double __utl_i_dflt64(i) /* 64 -- 64-bit integer to double */ - INT64 i; + FLANG_INT64 i; { UFP u; IEEE64 d; @@ -1063,7 +1063,7 @@ double __utl_i_dflt64(i) return *((double *)d); /*IEEE64 format and double are LITTLE_ENDIAN */ } -VOID __utl_i_fix64(float ff, INT64 i) /* use prototype to pass as float */ +VOID __utl_i_fix64(float ff, FLANG_INT64 i) /* use prototype to pass as float */ /* single float to 64-bit */ { IEEE32 f; @@ -1074,7 +1074,7 @@ VOID __utl_i_fix64(float ff, INT64 i) /* use prototype to pass as float */ ufptoi64(&u, i); } -float __utl_i_flt64(INT64 i) /* use prototype to return as float */ +float __utl_i_flt64(FLANG_INT64 i) /* use prototype to return as float */ /* 64-bit integer to single precision */ { UFP u; From 199329d2d81bbab829ec8b666e7f7a41438407d3 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 22 Oct 2017 20:26:16 -0500 Subject: [PATCH 024/141] FIX: update useless ifdef --- runtime/flang/const.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/flang/const.c b/runtime/flang/const.c index db61abef24f..e8f9534c16c 100644 --- a/runtime/flang/const.c +++ b/runtime/flang/const.c @@ -133,7 +133,7 @@ __INT_T ENTCOMN(TYPE, type)[] = { 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43}; -#if defined(_WIN32) && !defined(_WIN32) && !defined(_WIN32) +#ifdef _WIN32 char * __get_fort_type_addr(void) { From 2cb73b213ea2bc872b45b2c4c980eb31c1cad7ad Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 22 Oct 2017 20:43:26 -0500 Subject: [PATCH 025/141] More windows fixes --- runtime/flang/global.h | 6 ------ runtime/flang/miscsup_com.c | 2 ++ runtime/flangrti/CMakeLists.txt | 7 ++++--- runtime/flangrti/iostdinit.c | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/runtime/flang/global.h b/runtime/flang/global.h index 59a755ef0da..cab3448de5b 100644 --- a/runtime/flang/global.h +++ b/runtime/flang/global.h @@ -28,16 +28,10 @@ /* declarations needed where integer*8 & logical*8 are supported and * the natural integer is integer*4 (__BIGINT is __INT4). */ -#ifndef _WIN32 typedef int FLANG_INT64[2]; typedef unsigned int FLANG_UINT64[2]; #define I64_MSH(t) t[1] #define I64_LSH(t) t[0] -#else -#include -#define I64_MSH(t) ((int*)((void *)&t))[1] -#define I64_LSH(t) ((int*)((void *)&t))[0] -#endif extern int __ftn_32in64_; diff --git a/runtime/flang/miscsup_com.c b/runtime/flang/miscsup_com.c index 7eb9d053211..053c5917db0 100644 --- a/runtime/flang/miscsup_com.c +++ b/runtime/flang/miscsup_com.c @@ -28,6 +28,8 @@ #ifndef _WIN32 #include #include +#else +#include #endif #include "stdioInterf.h" #include "fioMacros.h" diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index 0bc427e749b..82cbe1bfb6b 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -231,9 +231,10 @@ target_include_directories(flangrti_shared set_target_properties(flangrti_shared flangrti_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${FLANG_RTE_LIB_DIR}) -target_compile_options(flangrti_static PRIVATE -fPIC) - -target_compile_options(flangrti_shared PRIVATE -fPIC) +if (NOT MSVC) + target_compile_options(flangrti_static PRIVATE -fPIC) + target_compile_options(flangrti_shared PRIVATE -fPIC) +endif() target_compile_options(flangrti_static PUBLIC $<$:-Mreentrant>) diff --git a/runtime/flangrti/iostdinit.c b/runtime/flangrti/iostdinit.c index 2d0d51928d7..b769389296d 100644 --- a/runtime/flangrti/iostdinit.c +++ b/runtime/flangrti/iostdinit.c @@ -294,7 +294,7 @@ __io_timezone(void *tm) /* OT 10 */ void * _pgi_get_iob(int xx) { - return & __iob_func()[xx]; + return __acrt_iob_func(xx); } #endif From fcdcf20a523d618e71f682224c565c2e68f2cc45 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 24 Oct 2017 14:45:06 -0500 Subject: [PATCH 026/141] Fix CMakeLists.txt --- runtime/flang/CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 446e1129fcc..345cc88c2ad 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -18,7 +18,9 @@ enable_language(C ASM Fortran) # Enable assembly and Fortran SET(ASM_OPTIONS "-DLINUX_ELF") SET(CMAKE_ASM_FLAGS "${CFLAGS} ${ASM_OPTIONS}" ) +if (NOT MSVC) SET(CMAKE_SHARED_LINKER_FLAGS "-no-flang-libs") +endif() # We are using Fortran driver to build this library with fresh compiler # components, so point its binary directory to the build directory to pick up @@ -494,11 +496,10 @@ add_flang_library(flang_shared ${SHARED_SOURCES} ) set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang) -target_link_libraries(flang_shared flangrti_shared) +target_link_libraries(flang_shared flangrti_shared libomp) # Resolve symbols against libm and librt -target_link_libraries(flang_shared rt) if (NOT MSVC) -target_link_libraries(flang_shared m) +target_link_libraries(flang_shared rt m) endif() set(SHARED_LIBRARY FALSE) From 6d2d5dee2fe3d44552b8fb80079c31a61bdae3e4 Mon Sep 17 00:00:00 2001 From: xoviat Date: Tue, 24 Oct 2017 20:30:35 -0500 Subject: [PATCH 027/141] [runtime/amod] remove _win32 ifdefs --- runtime/flang/amod.c | 8 -------- runtime/flang/utils.c | 7 +++++++ runtime/include/mthdecls.h | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/runtime/flang/amod.c b/runtime/flang/amod.c index d70be40cacd..4a042ec00af 100644 --- a/runtime/flang/amod.c +++ b/runtime/flang/amod.c @@ -17,16 +17,8 @@ #include "mthdecls.h" -#if defined(_WIN32) -float __fmth_i_amod(float f, float g); -#endif - float __mth_i_amod(float f, float g) { -#if defined(_WIN32) - return __fmth_i_amod(f, g); -#else return FMODF(f, g); -#endif } diff --git a/runtime/flang/utils.c b/runtime/flang/utils.c index 6879a1de2bf..a60530211d6 100644 --- a/runtime/flang/utils.c +++ b/runtime/flang/utils.c @@ -595,3 +595,10 @@ __fortio_trunc(FIO_FCB *p, seekoffx_t length) } return 0; } + +#ifdef _WIN32 +extern int +__fortio_binary_mode(int fd) { + return (_setmode(fd, _O_BINARY) != -1); +} +#endif diff --git a/runtime/include/mthdecls.h b/runtime/include/mthdecls.h index 4b5a901d246..c2ffa1242af 100644 --- a/runtime/include/mthdecls.h +++ b/runtime/include/mthdecls.h @@ -263,7 +263,7 @@ float __builtin_cimagf(float complex); single precision versions of the math.h functions, in which case the single precision versions should be used: */ -#if defined(_WIN64) +#if defined(_WIN32) #define ACOSF acos #define ASINF asin @@ -326,7 +326,7 @@ float __builtin_cimagf(float complex); #define hypot _hypot #endif -#else /* #if defined (_WIN64) */ +#else /* #if defined (_WIN32) */ #define ACOSF acosf #define ASINF asinf #define ATANF atanf @@ -422,7 +422,7 @@ float __builtin_cimagf(float complex); #define BESSEL_Y1 y1 #define BESSEL_YN yn #endif -#endif /* #if defined (WIN64) */ +#endif /* #if defined (WIN32) */ /* declarations for math functions */ From 878305f6c380a6151a94d8de8cf07968dba2782e Mon Sep 17 00:00:00 2001 From: xoviat Date: Tue, 24 Oct 2017 20:42:47 -0500 Subject: [PATCH 028/141] [runtime/utils] add gettimeofday [runtime/utils] externalize gettimeofday --- runtime/flang/utils.c | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/runtime/flang/utils.c b/runtime/flang/utils.c index a60530211d6..c307eb18587 100644 --- a/runtime/flang/utils.c +++ b/runtime/flang/utils.c @@ -601,4 +601,75 @@ extern int __fortio_binary_mode(int fd) { return (_setmode(fd, _O_BINARY) != -1); } + +extern void +sincos(double x, double *sine, double *cosine) { + sine = sin(x); + cosine = cos(x); +} + +#include +#include + +#ifndef _TIMEVAL_H +#define _TIMEVAL_H + +#include + +#define EPOCHFILETIME (116444736000000000LL) + +#if defined(__cplusplus) +extern "C" +{ +#endif + +struct timezone +{ + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +extern int +gettimeofday(struct timeval *tv, struct timezone *tz); + +#if defined(__cplusplus) +} +#endif + +#endif /* _TIMEVAL_H */ + + +extern int +gettimeofday(struct timeval *tv, struct timezone *tz) +{ + FILETIME ft; + LARGE_INTEGER li; + __int64 t; + static int tzflag; + + if(tv) + { + GetSystemTimeAsFileTime(&ft); + li.LowPart = ft.dwLowDateTime; + li.HighPart = ft.dwHighDateTime; + t = li.QuadPart; + t -= EPOCHFILETIME; + t /= 10; + tv->tv_sec = (long)(t / 1000000); + tv->tv_usec = (long)(t % 1000000); + } + + if (tz) + { + if (!tzflag) + { + _tzset(); + tzflag++; + } + tz->tz_minuteswest = _timezone / 60; + tz->tz_dsttime = _daylight; + } + + return 0; +} #endif From b4bfef563d6c530b48fe136afca4f0faec633a0a Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 24 Oct 2017 15:53:26 -0500 Subject: [PATCH 029/141] Fix utils.c Fix curdir --- runtime/flang/buffer.c | 3 ++- runtime/flang/curdir.c | 6 +++++- runtime/flang/utils.c | 46 +++++++++++++++++------------------------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/runtime/flang/buffer.c b/runtime/flang/buffer.c index 23197b527f2..d647d66f652 100644 --- a/runtime/flang/buffer.c +++ b/runtime/flang/buffer.c @@ -29,6 +29,7 @@ #define O_WRONLY _O_WRONLY #define O_CREAT _O_CREAT #define O_TRUNC _O_TRUNC +#include #endif #define MAXBUF 4096 @@ -72,7 +73,7 @@ __fort_zopen(char *path) __fort_rrecv(ioproc, &off, sizeof(off), 1, __UCHAR); } else { off = 0; - fd = open(path); + fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd == -1) { __fort_abortp(path); } diff --git a/runtime/flang/curdir.c b/runtime/flang/curdir.c index 076e8fbefcc..91a01c08923 100644 --- a/runtime/flang/curdir.c +++ b/runtime/flang/curdir.c @@ -19,6 +19,8 @@ #ifndef _WIN32 #include #include +#else +#include #endif #include #include "stdioInterf.h" @@ -117,6 +119,8 @@ void __fort_gethostname(host) char *host; } strcpy(host, p); #else - strcpy(host, "localhost"); + char temp[128] = ""; + gethostname(host, sizeof(temp)); + strcpy(host, temp); #endif } diff --git a/runtime/flang/utils.c b/runtime/flang/utils.c index c307eb18587..db2d6e79ee4 100644 --- a/runtime/flang/utils.c +++ b/runtime/flang/utils.c @@ -19,6 +19,13 @@ * \brief Utility functions for fortran i.o. */ +#ifdef _WIN32 +#include +#include +#include +#include +#include +#endif #include #include "global.h" #include "open_close.h" @@ -597,31 +604,22 @@ __fortio_trunc(FIO_FCB *p, seekoffx_t length) } #ifdef _WIN32 -extern int +int __fortio_binary_mode(int fd) { return (_setmode(fd, _O_BINARY) != -1); } -extern void +void sincos(double x, double *sine, double *cosine) { - sine = sin(x); - cosine = cos(x); + *sine = sin(x); + *cosine = cos(x); } -#include -#include - -#ifndef _TIMEVAL_H -#define _TIMEVAL_H - -#include - -#define EPOCHFILETIME (116444736000000000LL) - -#if defined(__cplusplus) -extern "C" -{ -#endif +void +sincosf(float x, float *sine, float *cosine) { + *sine = sinf(x); + *cosine = cosf(x); +} struct timezone { @@ -629,17 +627,9 @@ struct timezone int tz_dsttime; /* type of dst correction */ }; -extern int -gettimeofday(struct timeval *tv, struct timezone *tz); - -#if defined(__cplusplus) -} -#endif - -#endif /* _TIMEVAL_H */ - +#define EPOCHFILETIME (116444736000000000LL) -extern int +int gettimeofday(struct timeval *tv, struct timezone *tz) { FILETIME ft; From 14a6a710d97119b30186735bef79add16f442d28 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 24 Oct 2017 18:39:04 -0500 Subject: [PATCH 030/141] Fix link errors by making empty methods for now --- runtime/flang/close.c | 2 +- runtime/flang/const.c | 2 +- runtime/flang/cvt.c | 2 -- runtime/flang/dmod.c | 4 ++-- runtime/flang/etime3f.c | 12 +----------- runtime/flang/fsync3f.c | 2 ++ runtime/flang/hand.c | 5 +++++ runtime/flang/irandm3f.c | 2 +- runtime/flang/open.c | 1 + runtime/flang/utils.c | 4 ++++ runtime/flang/xfer_heap_dum.c | 2 ++ runtime/flangrti/iostdinit.c | 6 +----- 12 files changed, 21 insertions(+), 23 deletions(-) diff --git a/runtime/flang/close.c b/runtime/flang/close.c index 09a6aa9afb0..bda4e646ad5 100644 --- a/runtime/flang/close.c +++ b/runtime/flang/close.c @@ -71,7 +71,7 @@ __fortio_close(FIO_FCB *f, int flag) else __fort_unlink(f->name); } -#ifdef WINNT +#ifdef _WIN32 else if (f->status == FIO_SCRATCH) unlink(f->name); #endif diff --git a/runtime/flang/const.c b/runtime/flang/const.c index e8f9534c16c..df74e20b281 100644 --- a/runtime/flang/const.c +++ b/runtime/flang/const.c @@ -429,7 +429,7 @@ __get_size_of(int* idx) return __fort_size_of[*idx]; } -#ifdef WINNT +#ifdef _WIN32 /* pg access routines for data shared between windows dlls */ diff --git a/runtime/flang/cvt.c b/runtime/flang/cvt.c index e4d5874c709..031fcf44307 100644 --- a/runtime/flang/cvt.c +++ b/runtime/flang/cvt.c @@ -15,10 +15,8 @@ * */ -#ifndef WIN64 #include #include -#endif #include #define IEEE 1 diff --git a/runtime/flang/dmod.c b/runtime/flang/dmod.c index be74ded609d..6222ebe70bd 100644 --- a/runtime/flang/dmod.c +++ b/runtime/flang/dmod.c @@ -24,9 +24,9 @@ double __fmth_i_dmod(double f, double g); double __mth_i_dmod(double f, double g) { -/* Need to do this way until a bug in the Win64 fmod routine is fixed */ +/* TODO: Need to do this way until a bug in the Win64 fmod routine is fixed */ #if defined(_WIN32) - return __fmth_i_dmod(f, g); + return fmod(f, g); #else return fmod(f, g); #endif diff --git a/runtime/flang/etime3f.c b/runtime/flang/etime3f.c index 407ebdd0e91..cb8b6cc2ebd 100644 --- a/runtime/flang/etime3f.c +++ b/runtime/flang/etime3f.c @@ -52,17 +52,7 @@ float ENT3F(ETIME, etime)(float *tarray) #else #include -float convert_filetime( const FILETIME *ac_FileTime ) -{ - ULARGE_INTEGER lv_Large ; - - lv_Large.LowPart = ac_FileTime->dwLowDateTime ; - lv_Large.HighPart = ac_FileTime->dwHighDateTime ; - - return (float)lv_Large.QuadPart ; -} - -float ENT3F(DTIME, dtime)(float *tarray) +float ENT3F(ETIME, etime)(float *tarray) { FILETIME accum_user; FILETIME accum_sys; diff --git a/runtime/flang/fsync3f.c b/runtime/flang/fsync3f.c index 39c62995a46..6d8068129e6 100644 --- a/runtime/flang/fsync3f.c +++ b/runtime/flang/fsync3f.c @@ -26,10 +26,12 @@ extern FILE *__getfile3f(); void ENT3F(FSYNC, fsync)(lu) int *lu; { +#ifndef _WIN32 FILE *f; f = __getfile3f(*lu); if (f) fsync(__io_getfd(f)); return; + #endif } diff --git a/runtime/flang/hand.c b/runtime/flang/hand.c index c3262fc7e98..70ec51c6848 100644 --- a/runtime/flang/hand.c +++ b/runtime/flang/hand.c @@ -131,4 +131,9 @@ __fort_sethand() } } +#else +void +__fort_sethand() +{ +} #endif \ No newline at end of file diff --git a/runtime/flang/irandm3f.c b/runtime/flang/irandm3f.c index a2fe5679508..086bd17b7b9 100644 --- a/runtime/flang/irandm3f.c +++ b/runtime/flang/irandm3f.c @@ -21,7 +21,7 @@ #include "ent3f.h" -#ifdef WINNT +#ifdef _WIN32 int ENT3F(IRANDM, irandm)(int *flag) { diff --git a/runtime/flang/open.c b/runtime/flang/open.c index f9824d87e22..c9fef60be0d 100644 --- a/runtime/flang/open.c +++ b/runtime/flang/open.c @@ -32,6 +32,7 @@ #if defined(_WIN32) #define access _access +#define unlink _unlink #endif static FIO_FCB *Fcb; /* pointer to the file control block */ diff --git a/runtime/flang/utils.c b/runtime/flang/utils.c index db2d6e79ee4..913b632de54 100644 --- a/runtime/flang/utils.c +++ b/runtime/flang/utils.c @@ -621,6 +621,10 @@ sincosf(float x, float *sine, float *cosine) { *cosine = cosf(x); } +int ftruncate(int fd, __int64 length) { + _chsize_s(fd, length); +} + struct timezone { int tz_minuteswest; /* minutes W of Greenwich */ diff --git a/runtime/flang/xfer_heap_dum.c b/runtime/flang/xfer_heap_dum.c index 049330a391c..636f1440357 100644 --- a/runtime/flang/xfer_heap_dum.c +++ b/runtime/flang/xfer_heap_dum.c @@ -26,7 +26,9 @@ extern char *sbrk(int); char * __fort_sbrk(int len) { +#ifndef _WIN32 return (sbrk(len)); +#endif } /* verify block is in global heap */ diff --git a/runtime/flangrti/iostdinit.c b/runtime/flangrti/iostdinit.c index b769389296d..ad638a93d9c 100644 --- a/runtime/flangrti/iostdinit.c +++ b/runtime/flangrti/iostdinit.c @@ -160,11 +160,7 @@ __io_ferror(void *p) int __io_getfd(void *fp) { -#ifndef _WIN32 - return (((FILE *)fp)->_fileno); -#else - return (_fileno((FILE *)fp)); -#endif + return (fileno((FILE *)fp)); } /* is a tty? */ From 55140d2ea55ba946e93becea9f45e8d2e45378ef Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 25 Oct 2017 03:07:13 -0500 Subject: [PATCH 031/141] remove differing declarations for windows --- runtime/include/mthdecls.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/include/mthdecls.h b/runtime/include/mthdecls.h index c2ffa1242af..7abefa4385c 100644 --- a/runtime/include/mthdecls.h +++ b/runtime/include/mthdecls.h @@ -582,6 +582,7 @@ ZMPLXDECL_Z(__mth_i_cdtanh); #if defined(_WIN32) /* the following are part of Open Tools 12, we build with Open Tools 10 */ +/* extern double erf(double x); extern float erff(float x); extern double erfc(double x); @@ -602,6 +603,7 @@ extern double _jn(int n, double arg); extern double _y0(double arg); extern double _y1(double arg); extern double _yn(int n, double arg); +*/ #endif /* From cd3c1ea80e27104b4d5fa9e5887d311706ff649c Mon Sep 17 00:00:00 2001 From: Albert Ziegenhagel Date: Wed, 25 Oct 2017 19:04:40 +0200 Subject: [PATCH 032/141] Set WINDOWS_EXPORT_ALL_SYMBOLS property for for shared flangrti target. This works around the issue with missing __declspec(dllexport/dllimport) declerations in the source files. --- runtime/flangrti/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index 82cbe1bfb6b..2dc0cda32f1 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -234,6 +234,8 @@ set_target_properties(flangrti_shared flangrti_static if (NOT MSVC) target_compile_options(flangrti_static PRIVATE -fPIC) target_compile_options(flangrti_shared PRIVATE -fPIC) +else() + set_target_properties(flangrti_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) endif() target_compile_options(flangrti_static PUBLIC $<$:-Mreentrant>) From 6dc697834ff53498e0b23a0e951a9b3c7839e801 Mon Sep 17 00:00:00 2001 From: Albert Ziegenhagel Date: Wed, 25 Oct 2017 19:09:31 +0200 Subject: [PATCH 033/141] Set the target linker language for the flang libraries to CXX on windows. This makes sure link.exe from Visual Studio is used to link the libraries, even though the libraries include fortran code. CMake is not able to detect this since the flang fortran compiler is not working at CMake configure time and thus the CMAKE_Fortran_COMPILER_ID is unknown. --- runtime/flang/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 345cc88c2ad..a6a4403fa66 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -579,6 +579,9 @@ add_dependencies(flang_shared if (NOT MSVC) target_compile_options(flang_static PRIVATE -fPIC) target_compile_options(flang_shared PRIVATE -fPIC) +else() + set_target_properties(flang_static PROPERTIES LINKER_LANGUAGE CXX) + set_target_properties(flang_shared PROPERTIES LINKER_LANGUAGE CXX) endif() target_compile_options(flang_static PUBLIC $<$:-Mreentrant>) From 446e390489f7fe56bf5869ae134f6f9628b1ca99 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 25 Oct 2017 01:37:22 -0500 Subject: [PATCH 034/141] Add appveyor.yml Invoke cmake verbose nmake [appveyor] update file [appveyor] correct artifact locations [appveyor] show tail [appveyor] try to build tests [appveyor] explicitly build tests [appveyor] fix path [appveyor] cleanup [appveyor] use check-flang target [appveyor] install lit [appveyor] enable verbose testing Update appveyor [appveyor] remove branch [appveyor] cache build directory Update .appveyor.yml [appveyor] switch to conda-forge [appveyor] disable cache [appveyor] add llvmdev [appveyor] test windows-rebased --- .appveyor.yml | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 00000000000..1db63a2478b --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,57 @@ +branches: + only: + - master + - windows + - windows-rebased + +cache: + - '%APPVEYOR_BUILD_FOLDER%\build' + +environment: + global: + MSYS2_ROOT: C:\msys64 + CONDA_INSTALL_LOCN: C:\\Miniconda36-x64 + PYTHON2_LOCN: C:\\Python27-x64 + APPVEYOR_SAVE_CACHE_ON_FAILURE: true + +platform: + - x64 + +install: + # Add path, activate `conda` and update conda. + - cmd: call %CONDA_INSTALL_LOCN%\Scripts\activate.bat + - cmd: conda update --yes --quiet conda + # Add our channels. + - cmd: conda config --add channels defaults + - cmd: conda config --add channels conda-forge + - cmd: conda install --yes --quiet flang-meta llvmdev clangdev openmp cmake + - cmd: set "PATH=%PYTHON2_LOCN%\Scripts;%PYTHON2_LOCN%;%PATH%" + - ps: pip install lit + + +build_script: + - mkdir build + - cd build + - set "PATH=%cd%\bin;%PATH%" + - call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 + - ps: | + cmake -G "NMake Makefiles" -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release .. + Push-AppveyorArtifact .\CMakeFiles\CMakeOutput.log + Push-AppveyorArtifact .\CMakeFiles\CMakeError.log + - ps: | + cmake --build . 2>&1 | Out-File build_output.txt + if($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode ) } + Push-AppveyorArtifact .\build_output.txt + Get-Content .\build_output.txt -Tail 500 + - ps: Compress-Archive -Path C:\projects\flang\build\bin -DestinationPath C:\Projects\flang\bin.zip + - ps: Push-AppveyorArtifact C:\Projects\flang\bin.zip + - ps: Compress-Archive -Path C:\projects\flang\build\lib -DestinationPath C:\Projects\flang\lib.zip + - ps: Push-AppveyorArtifact C:\Projects\flang\lib.zip + +test_script: + - cmd: set "PATH=%PATH%;%MSYS2_ROOT%\usr\bin\" + - cmd: copy lib\flangmain.lib %CONDA_INSTALL_LOCN%\Library\lib + - cmd: copy lib\flangrti.lib %CONDA_INSTALL_LOCN%\Library\lib + - cmd: copy lib\flang.lib %CONDA_INSTALL_LOCN%\Library\lib + - cmd: copy lib\ompstub.lib %CONDA_INSTALL_LOCN%\Library\lib + - cmd: nmake check-flang From b6ff98d709197a572a09683a46a74a2b48fbb77f Mon Sep 17 00:00:00 2001 From: xoviat Date: Wed, 25 Oct 2017 18:10:44 -0500 Subject: [PATCH 035/141] [cmake] add compiler definitions [cmake] add compile definitions [cmake] try to kill the linux fortran flags Fix warning from CMake --- CMakeLists.txt | 5 +++++ runtime/flang/CMakeLists.txt | 15 ++++++++++++++- runtime/flangrti/CMakeLists.txt | 6 +++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 693755d31c0..b846c4367a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,11 @@ if( ${TARGET_OS} STREQUAL "Linux" ) elseif(${TARGET_OS} STREQUAL "Windows" ) set(OS "WINDOWS") set(OSNAME "Windows") + if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + add_definitions(-DWIN32 -DHOST_WIN -DWIN64 -DWINNT -DTARGET_WIN_X8632) + else( CMAKE_SIZEOF_VOID_P EQUAL 8 ) + add_definitions(-DWIN32 -DHOST_WIN -DWIN64 -DWINNT -DTARGET_WIN_X8632) + endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) if( ${TARGET_ARCHITECTURE} STREQUAL "AMD64" ) set(TARGET_ARCHITECTURE "x86_64") set(ARCHNAME x86-64) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index a6a4403fa66..219af786901 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -26,6 +26,8 @@ endif() # components, so point its binary directory to the build directory to pick up # flang* executables SET(CMAKE_Fortran_FLAGS "-B ${LLVM_RUNTIME_OUTPUT_INTDIR} ${CMAKE_Fortran_FLAGS}") +STRING( REPLACE "-DLINUX" "" CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} ) + SET(FTN_INTRINSICS abort3f.c @@ -496,7 +498,7 @@ add_flang_library(flang_shared ${SHARED_SOURCES} ) set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang) -target_link_libraries(flang_shared flangrti_shared libomp) +target_link_libraries(flang_shared flangrti_shared) # Resolve symbols against libm and librt if (NOT MSVC) target_link_libraries(flang_shared rt m) @@ -514,6 +516,16 @@ set_property( HAVE_LONG_LONG_INT ) +if(WIN32) +set_property( + SOURCE ${FTN_SUPPORT} + PROPERTY COMPILE_DEFINITIONS + TARGET_WIN_X8664 + INT32PTR64 + TM_I8 + HAVE_LONG_LONG_INT + ) +else() set_property( SOURCE ${FTN_SUPPORT} PROPERTY COMPILE_DEFINITIONS @@ -522,6 +534,7 @@ set_property( TM_I8 HAVE_LONG_LONG_INT ) +endif() set_property( SOURCE initpar.c diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index 2dc0cda32f1..c3446b85523 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -199,13 +199,13 @@ target_link_libraries(flangrti_shared m) endif() # Import OpenMP -#if (NOT DEFINED LIBOMP_EXPORT_DIR) +if (NOT DEFINED LIBOMP_EXPORT_DIR) find_library( FLANG_LIBOMP libomp HINTS ${CMAKE_BINARY_DIR}/lib) - target_link_libraries(flangrti_shared ${FLANG_LIBOMP}) -#endif() + target_link_libraries(flangrti_shared PUBLIC ${FLANG_LIBOMP}) +endif() if( ${TARGET_ARCHITECTURE} STREQUAL "aarch64" ) target_compile_definitions(flangrti_static PRIVATE TARGET_LINUX_ARM) From ca4fe234142ea534e9aeeb0b95c77a25d756d6e7 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 25 Oct 2017 19:48:28 -0500 Subject: [PATCH 036/141] Revert "sed WINNT, WIN32, WIN64 -> _WIN32 for runtime/flang" This reverts commit d5440d6010e37a4cdc316e1d6e49c893f8fd8104. --- runtime/flang/allo.c | 4 ++-- runtime/flang/backspace.c | 2 +- runtime/flang/bcopys.c | 2 +- runtime/flang/buffer.c | 2 +- runtime/flang/close.c | 4 ++-- runtime/flang/cnfg.c | 2 +- runtime/flang/const.c | 2 +- runtime/flang/curdir.c | 2 +- runtime/flang/datan.c | 2 +- runtime/flang/datan2.c | 2 +- runtime/flang/delfilesqq3f.c | 4 ++-- runtime/flang/descIntrins.c | 6 +++--- runtime/flang/dlog10.c | 2 +- runtime/flang/dmod.c | 8 ++++---- runtime/flang/drandm3f.c | 2 +- runtime/flang/entry.c | 6 +++--- runtime/flang/fdate3f.c | 2 +- runtime/flang/findfileqq3f.c | 2 +- runtime/flang/fmtwrite.c | 2 +- runtime/flang/fpcvt.c | 4 ++-- runtime/flang/fullpathqq3f.c | 2 +- runtime/flang/gerror3f.c | 2 +- runtime/flang/getcwd3f.c | 2 +- runtime/flang/getdat3f.c | 2 +- runtime/flang/getdrivedirqq3f.c | 2 +- runtime/flang/getfileinfoqq3f.c | 4 ++-- runtime/flang/getfileinfoqqi83f.c | 4 ++-- runtime/flang/getlog3f.c | 2 +- runtime/flang/gettim3f.c | 2 +- runtime/flang/getvolinfo3f.c | 4 ++-- runtime/flang/hand.c | 4 ++-- runtime/flang/hostnm3f.c | 2 +- runtime/flang/initpar.c | 10 +++++----- runtime/flang/inquire.c | 2 +- runtime/flang/kill3f.c | 2 +- runtime/flang/ldread.c | 2 +- runtime/flang/ldwrite.c | 2 +- runtime/flang/link3f.c | 2 +- runtime/flang/misc.c | 2 +- runtime/flang/nmlwrite.c | 2 +- runtime/flang/open.c | 4 ++-- runtime/flang/packtimeqq3f.c | 4 ++-- runtime/flang/perror3f.c | 2 +- runtime/flang/rand3f.c | 2 +- runtime/flang/random3f.c | 2 +- runtime/flang/rewind.c | 2 +- runtime/flang/setfileaccessqq3f.c | 4 ++-- runtime/flang/setfiletimeqq3f.c | 4 ++-- runtime/flang/signalqq3f.c | 2 +- runtime/flang/sleep3f.c | 2 +- runtime/flang/sleepqq3f.c | 2 +- runtime/flang/splitpathqq3f.c | 2 +- runtime/flang/srand3f.c | 2 +- runtime/flang/stat.c | 2 +- runtime/flang/stat3f.c | 2 +- runtime/flang/stat643f.c | 2 +- runtime/flang/stime3f.c | 2 +- runtime/flang/symlnk3f.c | 2 +- runtime/flang/ttynam3f.c | 2 +- runtime/flang/type.c | 2 +- runtime/flang/unpacktimeqq3f.c | 4 ++-- runtime/flang/utils3f.c | 4 ++-- runtime/flang/utilsi64.c | 2 +- runtime/flang/wait3f.c | 2 +- 64 files changed, 89 insertions(+), 89 deletions(-) diff --git a/runtime/flang/allo.c b/runtime/flang/allo.c index 0e9e4918df2..a7e4e1f0453 100644 --- a/runtime/flang/allo.c +++ b/runtime/flang/allo.c @@ -247,7 +247,7 @@ I8(__fort_alloc)(__INT_T nelem, dtype kind, size_t len, __STAT_T *stat, char msg[80]; char *p_env; -#if (defined(_WIN32)) +#if (defined(WIN64) || defined(WIN32)) #define ALN_LARGE #else #undef ALN_LARGE @@ -396,7 +396,7 @@ I8(__alloc04)(__NELEM_T nelem, dtype kind, size_t len, if (!ISPRESENT(errmsg)) errmsg = NULL; -#if (defined(_WIN32)) +#if (defined(WIN64) || defined(WIN32)) #define ALN_LARGE #else #undef ALN_LARGE diff --git a/runtime/flang/backspace.c b/runtime/flang/backspace.c index a95f6139c2c..8b9aef71ce4 100644 --- a/runtime/flang/backspace.c +++ b/runtime/flang/backspace.c @@ -74,7 +74,7 @@ _f90io_backspace(__INT_T *unit, __INT_T *bitv, __INT_T *iostat, int swap_bytes) if (f->nonadvance) { f->nonadvance = FALSE; -#if defined(_WIN32) +#if defined(WINNT) if (__fortio_binary_mode(f->fp)) __io_fputc('\r', f->fp); #endif diff --git a/runtime/flang/bcopys.c b/runtime/flang/bcopys.c index d5be5c3258f..538a18fcf59 100644 --- a/runtime/flang/bcopys.c +++ b/runtime/flang/bcopys.c @@ -35,7 +35,7 @@ __fort_bcopysl(char *to, char *fr, size_t cnt, size_t tostr, size_t frstr, { size_t i, j; unsigned long n; -#if !defined(_WIN32) +#if !defined(WIN64) long k; #else long long k; diff --git a/runtime/flang/buffer.c b/runtime/flang/buffer.c index d647d66f652..8bdefcf32de 100644 --- a/runtime/flang/buffer.c +++ b/runtime/flang/buffer.c @@ -22,7 +22,7 @@ #include "stdioInterf.h" #include "fioMacros.h" -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) #define write _write #define creat _creat #define close _close diff --git a/runtime/flang/close.c b/runtime/flang/close.c index bda4e646ad5..3ccf66b3f7d 100644 --- a/runtime/flang/close.c +++ b/runtime/flang/close.c @@ -28,7 +28,7 @@ #endif #include "stdioInterf.h" -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) #define unlink _unlink #define access _access #endif @@ -48,7 +48,7 @@ __fortio_close(FIO_FCB *f, int flag) if (f->nonadvance) { f->nonadvance = FALSE; -#if defined(_WIN32) +#if defined(WINNT) if (__fortio_binary_mode(f->fp)) __io_fputc('\r', f->fp); #endif diff --git a/runtime/flang/cnfg.c b/runtime/flang/cnfg.c index c212b87b90e..10c8e0a28fb 100644 --- a/runtime/flang/cnfg.c +++ b/runtime/flang/cnfg.c @@ -90,7 +90,7 @@ __fortio_scratch_name(char *filename, int unit) extern char *__io_tempnam(); char *nm; -#if defined(_WIN32) +#if defined(WINNT) if (getenv("TMP") == 0) nm = __io_tempnam("C:\\", "FTN"); else diff --git a/runtime/flang/const.c b/runtime/flang/const.c index df74e20b281..ff888608e7e 100644 --- a/runtime/flang/const.c +++ b/runtime/flang/const.c @@ -133,7 +133,7 @@ __INT_T ENTCOMN(TYPE, type)[] = { 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43}; -#ifdef _WIN32 +#if defined(WINNT) && !defined(WIN64) && !defined(WIN32) char * __get_fort_type_addr(void) { diff --git a/runtime/flang/curdir.c b/runtime/flang/curdir.c index 91a01c08923..a068e72505a 100644 --- a/runtime/flang/curdir.c +++ b/runtime/flang/curdir.c @@ -30,7 +30,7 @@ #define MAXPATHLEN 1024 #endif -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) #define getcwd _getcwd #endif diff --git a/runtime/flang/datan.c b/runtime/flang/datan.c index 318d84120fb..3e846760694 100644 --- a/runtime/flang/datan.c +++ b/runtime/flang/datan.c @@ -15,7 +15,7 @@ * */ -#if !defined(_WIN32) +#if !defined(WIN64) #include "mthdecls.h" #else double atan(double d); diff --git a/runtime/flang/datan2.c b/runtime/flang/datan2.c index 6f7ca586764..5c53ce5cea1 100644 --- a/runtime/flang/datan2.c +++ b/runtime/flang/datan2.c @@ -15,7 +15,7 @@ * */ -#if !defined(_WIN32) +#if !defined(WIN64) #include "mthdecls.h" #else double atan2(double x, double y); diff --git a/runtime/flang/delfilesqq3f.c b/runtime/flang/delfilesqq3f.c index 16c34fabc4d..59bb42a1331 100644 --- a/runtime/flang/delfilesqq3f.c +++ b/runtime/flang/delfilesqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* delfilesqq3f.c - Implements DFLIB delfilesqq subprogram. */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include #endif #include @@ -27,7 +27,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) extern char *__fstr2cstr(); int ENT3F(DELFILESQQ, delfilesqq)(DCHAR(ffiles) DCLEN(ffiles)) { diff --git a/runtime/flang/descIntrins.c b/runtime/flang/descIntrins.c index f825839abcc..4409654f0c9 100644 --- a/runtime/flang/descIntrins.c +++ b/runtime/flang/descIntrins.c @@ -28,10 +28,10 @@ #include #include "fioMacros.h" /* macros for entries */ -#if defined(_WIN32) && !defined(_WIN32) && !defined(UXOBJS) && !defined(CROBJS) +#if defined(WINNT) && !defined(WIN64) && !defined(UXOBJS) && !defined(CROBJS) #pragma global - x 121 0x20000 #define ENTFTN_MS(UC) WIN_EXP __attribute__((stdcall)) UC -#elif defined(_WIN32) && defined(_WIN32) +#elif defined(WINNT) && defined(WIN64) #define ENTFTN_MS I8 #endif @@ -185,7 +185,7 @@ ENTFTN(KINDEXX, kindexx_cr_nm) #endif -#if defined(_WIN32) +#if defined(WINNT) /* functions here follow the msfortran/mscall conventions */ diff --git a/runtime/flang/dlog10.c b/runtime/flang/dlog10.c index ae58c64e708..a2a5867cd18 100644 --- a/runtime/flang/dlog10.c +++ b/runtime/flang/dlog10.c @@ -15,7 +15,7 @@ * */ -#if !defined(_WIN32) +#if !defined(WIN64) #include "mthdecls.h" #else double log10(double d); diff --git a/runtime/flang/dmod.c b/runtime/flang/dmod.c index 6222ebe70bd..4e917c9ed7a 100644 --- a/runtime/flang/dmod.c +++ b/runtime/flang/dmod.c @@ -17,16 +17,16 @@ #include "mthdecls.h" -#if defined(_WIN32) +#if defined(WIN64) double __fmth_i_dmod(double f, double g); #endif double __mth_i_dmod(double f, double g) { -/* TODO: Need to do this way until a bug in the Win64 fmod routine is fixed */ -#if defined(_WIN32) - return fmod(f, g); +/* Need to do this way until a bug in the Win64 fmod routine is fixed */ +#if defined(WIN64) + return __fmth_i_dmod(f, g); #else return fmod(f, g); #endif diff --git a/runtime/flang/drandm3f.c b/runtime/flang/drandm3f.c index dcb83ede989..dadc1d49605 100644 --- a/runtime/flang/drandm3f.c +++ b/runtime/flang/drandm3f.c @@ -22,7 +22,7 @@ #include "ent3f.h" /* drand48, srand48 are not currently available on win64 */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include diff --git a/runtime/flang/entry.c b/runtime/flang/entry.c index 42e50754c9f..3ce370bc1d0 100644 --- a/runtime/flang/entry.c +++ b/runtime/flang/entry.c @@ -24,16 +24,16 @@ #include "stdioInterf.h" #include "fioMacros.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) WIN_IMP __INT_T LINENO[]; -#elif defined(C90) || defined(_WIN32) +#elif defined(C90) || defined(WINNT) __INT_T LINENO[1]; char *__get_fort_lineno_addr(void); #else extern __INT_T LINENO[]; #endif -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) #define write _write #endif diff --git a/runtime/flang/fdate3f.c b/runtime/flang/fdate3f.c index c94623b61df..c5fed2deb53 100644 --- a/runtime/flang/fdate3f.c +++ b/runtime/flang/fdate3f.c @@ -24,7 +24,7 @@ #include #include "utils3f.h" -#if !defined(_WIN32) +#if !defined(WIN32) && !defined(WIN64) WIN_MSVCRT_IMP char *WIN_CDECL ctime(const time_t *); #endif diff --git a/runtime/flang/findfileqq3f.c b/runtime/flang/findfileqq3f.c index 1b96a166346..7aac6c2023d 100644 --- a/runtime/flang/findfileqq3f.c +++ b/runtime/flang/findfileqq3f.c @@ -26,7 +26,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) extern char *__fstr2cstr(); int ENT3F(FINDFILEQQ, findfileqq)(DCHAR(fname), DCHAR(fvarname), diff --git a/runtime/flang/fmtwrite.c b/runtime/flang/fmtwrite.c index ad3c3cee1f3..6f153f320b1 100644 --- a/runtime/flang/fmtwrite.c +++ b/runtime/flang/fmtwrite.c @@ -2465,7 +2465,7 @@ fw_write_record(void) f->nonadvance = FALSE; /* do it now */ if (!(g->suppress_crlf)) { /* append carriage return */ -#if defined(_WIN32) +#if defined(WINNT) if (__fortio_binary_mode(f->fp)) __io_fputc('\r', f->fp); #endif diff --git a/runtime/flang/fpcvt.c b/runtime/flang/fpcvt.c index d1bce56a105..a0b6bada9e4 100644 --- a/runtime/flang/fpcvt.c +++ b/runtime/flang/fpcvt.c @@ -17,7 +17,7 @@ #include #include -#if !defined(_WIN32) +#if !defined(WIN64) #include #endif #include "fioMacros.h" @@ -733,7 +733,7 @@ __fortio_strtod(char *s, char **p) * (0 is before first digit). *sign is sign. */ -#if defined(_WIN32) +#if defined(WIN64) #define FE_TONEAREST 0 #define FE_DOWNWARD 1024 #define FE_UPWARD 2048 diff --git a/runtime/flang/fullpathqq3f.c b/runtime/flang/fullpathqq3f.c index 66b2562b358..ee2fad650cf 100644 --- a/runtime/flang/fullpathqq3f.c +++ b/runtime/flang/fullpathqq3f.c @@ -25,7 +25,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) extern char *__fstr2cstr(); int ENT3F(FULLPATHQQ, fullpathqq)(DCHAR(fname), diff --git a/runtime/flang/gerror3f.c b/runtime/flang/gerror3f.c index d2dd142433e..a1a424dbcdf 100644 --- a/runtime/flang/gerror3f.c +++ b/runtime/flang/gerror3f.c @@ -27,7 +27,7 @@ #define Ftn_errmsg __fortio_errmsg -#if !defined(_WIN32) +#if !defined(WIN64) && !defined(WIN32) extern char *strerror(); /* SVR4 only ? */ #endif diff --git a/runtime/flang/getcwd3f.c b/runtime/flang/getcwd3f.c index 0282e4eb521..7e154ee7aad 100644 --- a/runtime/flang/getcwd3f.c +++ b/runtime/flang/getcwd3f.c @@ -25,7 +25,7 @@ #include "utils3f.h" #include "mpalloc.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #define GETCWDM _getcwd /* getcwd deprecated in Windows in VC 2005 */ #else #define GETCWDM getcwd diff --git a/runtime/flang/getdat3f.c b/runtime/flang/getdat3f.c index 2c1d9a9f745..f15149331d3 100644 --- a/runtime/flang/getdat3f.c +++ b/runtime/flang/getdat3f.c @@ -19,7 +19,7 @@ /* getdat3f.c - Implements getdat subroutine. */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include #include "ent3f.h" diff --git a/runtime/flang/getdrivedirqq3f.c b/runtime/flang/getdrivedirqq3f.c index d0ee2380b80..80a69c0c4c5 100644 --- a/runtime/flang/getdrivedirqq3f.c +++ b/runtime/flang/getdrivedirqq3f.c @@ -26,7 +26,7 @@ #include "utils3f.h" #include "mpalloc.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #define GETCWDM _getcwd /* getcwd deprecated in Windows in VC 2005 */ #else #define GETCWDM getcwd diff --git a/runtime/flang/getfileinfoqq3f.c b/runtime/flang/getfileinfoqq3f.c index c694ec99eb2..efa610d99a5 100644 --- a/runtime/flang/getfileinfoqq3f.c +++ b/runtime/flang/getfileinfoqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* getfileinfoqq3f.c - Implements DFLIB getfileinfoqq subprogram. */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include #endif #include @@ -27,7 +27,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) extern char *__fstr2cstr(); extern void __GetTimeToSecondsSince1970(ULARGE_INTEGER *fileTime, unsigned int *out); diff --git a/runtime/flang/getfileinfoqqi83f.c b/runtime/flang/getfileinfoqqi83f.c index b94c5590053..b738aa92b34 100644 --- a/runtime/flang/getfileinfoqqi83f.c +++ b/runtime/flang/getfileinfoqqi83f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* getfileinfoqq3f.c - Implements DFLIB getfileinfoqq subprogram. */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include #endif #include @@ -31,7 +31,7 @@ #define FILE$LAST -2 #define FILE$ERROR -3 -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) extern char *__fstr2cstr(); extern void __GetTimeToSecondsSince1970(ULARGE_INTEGER *fileTime, unsigned int *out); diff --git a/runtime/flang/getlog3f.c b/runtime/flang/getlog3f.c index dc18f9b50db..a4e188a5a21 100644 --- a/runtime/flang/getlog3f.c +++ b/runtime/flang/getlog3f.c @@ -19,7 +19,7 @@ /* getlog3f.c - Implements LIB3F getlog subprogram. */ -#ifndef _WIN32 +#ifndef WINNT #include "ent3f.h" #include "utils3f.h" diff --git a/runtime/flang/gettim3f.c b/runtime/flang/gettim3f.c index 57d97b0c658..d8a2b099789 100644 --- a/runtime/flang/gettim3f.c +++ b/runtime/flang/gettim3f.c @@ -19,7 +19,7 @@ /* gettim3f.c - Implements gettim subroutine. */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include #include "ent3f.h" diff --git a/runtime/flang/getvolinfo3f.c b/runtime/flang/getvolinfo3f.c index d1d03102065..dceddd6fb6a 100644 --- a/runtime/flang/getvolinfo3f.c +++ b/runtime/flang/getvolinfo3f.c @@ -28,8 +28,8 @@ typedef char *LPSTR; typedef int DWORD; -#if defined(_WIN32) -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) +#if defined(WIN64) typedef long long LDWORD; extern int GetVolumeInformationA(); #define ENTNAM(ss) _##ss diff --git a/runtime/flang/hand.c b/runtime/flang/hand.c index 70ec51c6848..a207aa80a01 100644 --- a/runtime/flang/hand.c +++ b/runtime/flang/hand.c @@ -20,7 +20,7 @@ #include "stdioInterf.h" #include "fioMacros.h" -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) #define write _write #endif @@ -97,7 +97,7 @@ static void sighand(s) int s; lcpu = __fort_myprocnum(); __fort_psignal(lcpu, s); /* print message */ -#if !defined(_WIN32) +#if !defined(WIN64) && !defined(WIN32) sleep(1); /* wait for message to clear */ #endif __fort_abort(NULL); /* abort */ diff --git a/runtime/flang/hostnm3f.c b/runtime/flang/hostnm3f.c index dc9e9d01ff7..56db4f50c06 100644 --- a/runtime/flang/hostnm3f.c +++ b/runtime/flang/hostnm3f.c @@ -19,7 +19,7 @@ /* hostnm3f.c - Implements LIB3F hostnm subprogram. */ -#ifndef _WIN32 +#ifndef WINNT /* must include ent3f.h AFTER io3f.h */ #include "io3f.h" diff --git a/runtime/flang/initpar.c b/runtime/flang/initpar.c index e167fd99b78..7f591fc74d8 100644 --- a/runtime/flang/initpar.c +++ b/runtime/flang/initpar.c @@ -78,10 +78,10 @@ static struct { /* common blocks containing values for inlined number_of_processors() and my_processor() functions */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) WIN_IMP __INT_T ENTCOMN(NP, np)[]; WIN_IMP __INT_T ENTCOMN(ME, me)[]; -#elif defined(C90) || defined(_WIN32) +#elif defined(C90) || defined(WINNT) __INT_T ENTCOMN(NP, np)[1]; __INT_T ENTCOMN(ME, me)[1]; #else @@ -89,7 +89,7 @@ extern __INT_T ENTCOMN(NP, np)[]; extern __INT_T ENTCOMN(ME, me)[]; #endif -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) #define write _write #endif @@ -109,8 +109,8 @@ __fort_ncpus() return __fort_tcpus; } -#if defined(_WIN32) -#if !defined(_WIN32) +#if defined(WINNT) +#if !defined(WIN64) && !defined(WIN32) __INT_T *CORMEM; /* special argument pointer access routines */ diff --git a/runtime/flang/inquire.c b/runtime/flang/inquire.c index 2c17ea56eae..111159ed16e 100644 --- a/runtime/flang/inquire.c +++ b/runtime/flang/inquire.c @@ -26,7 +26,7 @@ #include "global.h" #include "async.h" -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) #define access _access #endif diff --git a/runtime/flang/kill3f.c b/runtime/flang/kill3f.c index 715764cc1a8..979c2aa3986 100644 --- a/runtime/flang/kill3f.c +++ b/runtime/flang/kill3f.c @@ -19,7 +19,7 @@ /* kill3f.c - Implements LIB3F kill subprogram. */ -#ifndef _WIN32 +#ifndef WINNT #define POSIX 1 #include diff --git a/runtime/flang/ldread.c b/runtime/flang/ldread.c index e56cf2d3db8..b1c6f7afeb8 100644 --- a/runtime/flang/ldread.c +++ b/runtime/flang/ldread.c @@ -1628,7 +1628,7 @@ skip_record(void) } return __io_errno(); } -#if defined(_WIN32) +#if defined(WINNT) if (ch == '\r') { ch = __io_fgetc(fcb->fp); if (ch == '\n') diff --git a/runtime/flang/ldwrite.c b/runtime/flang/ldwrite.c index f369ceb4896..ff7fece60fc 100644 --- a/runtime/flang/ldwrite.c +++ b/runtime/flang/ldwrite.c @@ -793,7 +793,7 @@ write_record(void) return __io_errno(); } } else { /* sequential write: append carriage return */ -#if defined(_WIN32) +#if defined(WINNT) if (__fortio_binary_mode(fcb->fp)) if (FWRITE("\r", 1, 1, fcb->fp) != 1) return __io_errno(); diff --git a/runtime/flang/link3f.c b/runtime/flang/link3f.c index e19c3ef77e6..955fa3714d3 100644 --- a/runtime/flang/link3f.c +++ b/runtime/flang/link3f.c @@ -19,7 +19,7 @@ /* link3f.c - Implements LIB3F link subprogram. */ -#ifndef _WIN32 +#ifndef WINNT /* must include ent3f.h AFTER io3f.h */ #include "io3f.h" diff --git a/runtime/flang/misc.c b/runtime/flang/misc.c index cf2cdd9c6e8..8d70c5d839b 100644 --- a/runtime/flang/misc.c +++ b/runtime/flang/misc.c @@ -15,7 +15,7 @@ * */ -#if !defined(PARAMID) && !defined(_WIN32) +#if !defined(PARAMID) && !defined(WINNT) #include #include #include diff --git a/runtime/flang/nmlwrite.c b/runtime/flang/nmlwrite.c index 65f7311f8b5..ba126d01d80 100644 --- a/runtime/flang/nmlwrite.c +++ b/runtime/flang/nmlwrite.c @@ -279,7 +279,7 @@ emit_eol(void) int ret_err; if (!internal_file) { -#if defined(_WIN32) +#if defined(WINNT) if (__fortio_binary_mode(f->fp)) { ret_err = write_char('\r'); if (ret_err) diff --git a/runtime/flang/open.c b/runtime/flang/open.c index c9fef60be0d..48b28950768 100644 --- a/runtime/flang/open.c +++ b/runtime/flang/open.c @@ -30,7 +30,7 @@ #include "async.h" #include -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) #define access _access #define unlink _unlink #endif @@ -104,7 +104,7 @@ __fortio_open(int unit, int action_flag, int status_flag, int dispose_flag, for (i = 0; i < namelen; i++) filename[i] = name[i]; filename[namelen] = '\0'; -#if defined(_WIN32) +#if defined(WINNT) if (filename[0] == '/' && filename[1] == '/' && filename[3] == '/') { /* convert posix format to win32 format */ filename[0] = filename[2]; /* drive letter */ diff --git a/runtime/flang/packtimeqq3f.c b/runtime/flang/packtimeqq3f.c index 05d4edd5bd6..499cf9a779b 100644 --- a/runtime/flang/packtimeqq3f.c +++ b/runtime/flang/packtimeqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* packtimeqq3f.c - Implements DFLIB packtimeqq subprogram. */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include #endif #include @@ -27,7 +27,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) extern char *__fstr2cstr(); extern void __GetTimeToSecondsSince1970(ULARGE_INTEGER *fileTime, unsigned int *out); diff --git a/runtime/flang/perror3f.c b/runtime/flang/perror3f.c index cc72266583f..67b93e493e3 100644 --- a/runtime/flang/perror3f.c +++ b/runtime/flang/perror3f.c @@ -23,7 +23,7 @@ #include "io3f.h" #include "ent3f.h" -#if !defined(_WIN32) +#if !defined(WIN64) && !defined(WIN32) extern char *strerror(); /* SVR4 only ? */ #endif extern FILE *__getfile3f(); diff --git a/runtime/flang/rand3f.c b/runtime/flang/rand3f.c index 533bc1bc8d2..94c4341aca6 100644 --- a/runtime/flang/rand3f.c +++ b/runtime/flang/rand3f.c @@ -22,7 +22,7 @@ #include "ent3f.h" /* drand48 is not currently available on win64 */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include diff --git a/runtime/flang/random3f.c b/runtime/flang/random3f.c index c722bdf572d..2c77283b588 100644 --- a/runtime/flang/random3f.c +++ b/runtime/flang/random3f.c @@ -22,7 +22,7 @@ #include "ent3f.h" /* drand48, srand48 are not currently available on win64 */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include diff --git a/runtime/flang/rewind.c b/runtime/flang/rewind.c index ef2d0435295..2629532c95e 100644 --- a/runtime/flang/rewind.c +++ b/runtime/flang/rewind.c @@ -54,7 +54,7 @@ _f90io_rewind(__INT_T *unit, __INT_T *bitv, __INT_T *iostat) if (f->nonadvance) { f->nonadvance = FALSE; -#if defined(_WIN32) +#if defined(WINNT) if (__fortio_binary_mode(f->fp)) __io_fputc('\r', f->fp); #endif diff --git a/runtime/flang/setfileaccessqq3f.c b/runtime/flang/setfileaccessqq3f.c index a9f53884989..9f508030df3 100644 --- a/runtime/flang/setfileaccessqq3f.c +++ b/runtime/flang/setfileaccessqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* setfileaccessqq3f.c - Implements DFLIB setfileaccessqq subprogram. */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include #endif #include @@ -32,7 +32,7 @@ #define FILE$ERROR -3 #define FILE$CURTIME -1 -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) extern char *__fstr2cstr(); int ENT3F(SETFILEACCESSQQ, setfileaccessqq)(DCHAR(ffile), diff --git a/runtime/flang/setfiletimeqq3f.c b/runtime/flang/setfiletimeqq3f.c index b50c5b0d5fe..f74e298e51d 100644 --- a/runtime/flang/setfiletimeqq3f.c +++ b/runtime/flang/setfiletimeqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* setfiletimeqq3f.c - Implements DFLIB setfiletimeqq subprogram. */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include #endif #include @@ -32,7 +32,7 @@ #define FILE$ERROR -3 #define FILE$CURTIME -1 -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) extern char *__fstr2cstr(); extern void __UnpackTime(unsigned int secsSince1970, ULARGE_INTEGER *fileTime); extern int __GETFILEINFOQQ(DCHAR(ffiles), char *buffer, diff --git a/runtime/flang/signalqq3f.c b/runtime/flang/signalqq3f.c index 5eb2d50e533..d89ee910082 100644 --- a/runtime/flang/signalqq3f.c +++ b/runtime/flang/signalqq3f.c @@ -24,7 +24,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(_WIN32) || !defined(_WIN32) +#if defined(WIN64) || !defined(WINNT) #define LONGINTSIZE unsigned long long diff --git a/runtime/flang/sleep3f.c b/runtime/flang/sleep3f.c index 0ec3c760136..256913299ce 100644 --- a/runtime/flang/sleep3f.c +++ b/runtime/flang/sleep3f.c @@ -24,7 +24,7 @@ #endif #include "ent3f.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include diff --git a/runtime/flang/sleepqq3f.c b/runtime/flang/sleepqq3f.c index 7c25afa71fc..9dbfbf7a0e9 100644 --- a/runtime/flang/sleepqq3f.c +++ b/runtime/flang/sleepqq3f.c @@ -24,7 +24,7 @@ #endif #include "ent3f.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include diff --git a/runtime/flang/splitpathqq3f.c b/runtime/flang/splitpathqq3f.c index 6e84cef9315..4922d6e4f95 100644 --- a/runtime/flang/splitpathqq3f.c +++ b/runtime/flang/splitpathqq3f.c @@ -25,7 +25,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) extern char *__fstr2cstr(); int ENT3F(SPLITPATHQQ, splitpathqq)(DCHAR(fpath), DCHAR(fdrive), DCHAR(fdir), diff --git a/runtime/flang/srand3f.c b/runtime/flang/srand3f.c index 8c23a50cf6c..a0bb2aaa81d 100644 --- a/runtime/flang/srand3f.c +++ b/runtime/flang/srand3f.c @@ -23,7 +23,7 @@ #include "ent3f.h" /* srand48 is not currently available on win64 */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) void ENT3F(SRAND1, srand1)(int *iseed) { srand(*iseed); } diff --git a/runtime/flang/stat.c b/runtime/flang/stat.c index 632a7f941cd..8ce7bac01f4 100644 --- a/runtime/flang/stat.c +++ b/runtime/flang/stat.c @@ -23,7 +23,7 @@ #include #include -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) #define write _write #endif diff --git a/runtime/flang/stat3f.c b/runtime/flang/stat3f.c index 454bb663819..537bd7eb09f 100644 --- a/runtime/flang/stat3f.c +++ b/runtime/flang/stat3f.c @@ -72,7 +72,7 @@ int ENT3F(STAT, stat)(DCHAR(nm), int *statb DCLEN(nm)) statb[8] = b.st_atime; statb[9] = b.st_mtime; statb[10] = b.st_ctime; -#if !defined(_WIN32) +#if !defined(WINNT) statb[11] = b.st_blksize; statb[12] = b.st_blocks; #else diff --git a/runtime/flang/stat643f.c b/runtime/flang/stat643f.c index 79527c0b403..502545872c1 100644 --- a/runtime/flang/stat643f.c +++ b/runtime/flang/stat643f.c @@ -29,7 +29,7 @@ extern void __cstr_free(); int ENT3F(STAT64, stat64)(DCHAR(nm), long long *statb DCLEN(nm)) { -#if defined(TARGET_WIN) || defined(_WIN32) +#if defined(TARGET_WIN) || defined(WIN32) || defined(WIN64) /* * The __int64_t members in the _stat64 are 8-byte aligned, thus the * st_size member is at offset 24. On WIN32, 64-bit ints are 4-byte diff --git a/runtime/flang/stime3f.c b/runtime/flang/stime3f.c index ffea8246818..83ed1955a83 100644 --- a/runtime/flang/stime3f.c +++ b/runtime/flang/stime3f.c @@ -19,7 +19,7 @@ /* stime3f.c - Implements LIB3F stime subprogram. */ -#ifndef _WIN32 +#ifndef WINNT #include #include "io3f.h" diff --git a/runtime/flang/symlnk3f.c b/runtime/flang/symlnk3f.c index 742be816d82..3bebe65b213 100644 --- a/runtime/flang/symlnk3f.c +++ b/runtime/flang/symlnk3f.c @@ -19,7 +19,7 @@ /* symlnk3f.c - Implements LIB3F symlnk subprogram. */ -#ifndef _WIN32 +#ifndef WINNT #include "io3f.h" #include "ent3f.h" diff --git a/runtime/flang/ttynam3f.c b/runtime/flang/ttynam3f.c index 4fa5ee5e728..a811bd46f19 100644 --- a/runtime/flang/ttynam3f.c +++ b/runtime/flang/ttynam3f.c @@ -19,7 +19,7 @@ /* ttynam3f.c - Implements LIB3F ttynam subprogram. */ -#ifndef _WIN32 +#ifndef WINNT /* must include ent3f.h AFTER io3f.h */ #include "io3f.h" diff --git a/runtime/flang/type.c b/runtime/flang/type.c index ce6b0f3e59f..4f17ae9b1f7 100644 --- a/runtime/flang/type.c +++ b/runtime/flang/type.c @@ -703,7 +703,7 @@ void ENTF90(POLY_ASN, poly_asn)(char *ab, F90_Desc *ad, char *bb, F90_Desc *bd, } } else if (bd && !flag && ISSCALAR(bd) && bd->tag != __POLY && bd->tag < __NTYPES) { -#if defined(_WIN32) +#if defined(WINNT) src_sz = __get_fort_size_of(bd->tag); #else src_sz = __fort_size_of[bd->tag]; diff --git a/runtime/flang/unpacktimeqq3f.c b/runtime/flang/unpacktimeqq3f.c index 4c0ed541e6a..8f7b54c620d 100644 --- a/runtime/flang/unpacktimeqq3f.c +++ b/runtime/flang/unpacktimeqq3f.c @@ -18,7 +18,7 @@ /* clang-format off */ /* unpacktimeqq3f.c - Implements DFLIB packtimeqq subprogram. */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include #endif #include @@ -28,7 +28,7 @@ #include "io3f.h" #include "ent3f.h" -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) extern char *__fstr2cstr(); extern void __UnpackTime(unsigned int secsSince1970, ULARGE_INTEGER *fileTime); diff --git a/runtime/flang/utils3f.c b/runtime/flang/utils3f.c index 48608e97087..5676e3eae1a 100644 --- a/runtime/flang/utils3f.c +++ b/runtime/flang/utils3f.c @@ -16,7 +16,7 @@ */ /* */ -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #include #endif #include "io3f.h" @@ -119,7 +119,7 @@ extern FILE *__getfile3f(unit) int unit; } } -#if defined(_WIN32) +#if defined(WIN64) || defined(WIN32) void __GetTimeToSecondsSince1970(ULARGE_INTEGER *fileTime, unsigned int *out) { diff --git a/runtime/flang/utilsi64.c b/runtime/flang/utilsi64.c index ed82da14940..8b4c9cd37e8 100644 --- a/runtime/flang/utilsi64.c +++ b/runtime/flang/utilsi64.c @@ -36,7 +36,7 @@ extern int __fort_atoxi64(); extern void __fort_i64toax(); /* has native support for 8-byte integers*/ -#if !defined(_WIN32) +#if !defined(WIN64) typedef long I8_T; typedef unsigned long UI8_T; #else diff --git a/runtime/flang/wait3f.c b/runtime/flang/wait3f.c index 7da89577d94..d2a3733529b 100644 --- a/runtime/flang/wait3f.c +++ b/runtime/flang/wait3f.c @@ -19,7 +19,7 @@ /* wait3f.c - Implements LIB3F wait subprogram. */ -#ifndef _WIN32 +#ifndef WINNT #include #include From dd3561a3e76379aabfe2a906ced13dac21ee79e5 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 25 Oct 2017 19:11:30 -0500 Subject: [PATCH 037/141] Update FuncArgMacros.h --- runtime/include/FuncArgMacros.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/include/FuncArgMacros.h b/runtime/include/FuncArgMacros.h index 75b5842af18..95f9849cca5 100644 --- a/runtime/include/FuncArgMacros.h +++ b/runtime/include/FuncArgMacros.h @@ -28,7 +28,7 @@ #define _PGHPFENT_H_ /* Alternate Fortran entry symbol formats */ - +#if 0 #if defined(WIN64) #if defined(DESC_I8) #define ENTF90IO(UC, LC) pgf90io_##LC##_i8 @@ -79,6 +79,8 @@ #define ENTCOMN(UC, LC) pghpf_win_##LC #define F90_MATMUL(s) pg_mm_##s##_ +#else +#endif #else #define ENTF90IO(UC, LC) f90io_##LC #define ENTF90(UC, LC) f90_##LC From 88d5e519dd09ea7c43649de25d591710c9114134 Mon Sep 17 00:00:00 2001 From: xoviat Date: Wed, 25 Oct 2017 19:37:36 -0500 Subject: [PATCH 038/141] [runtime/global] remove winnt ifdef --- runtime/flang/global.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/flang/global.h b/runtime/flang/global.h index cab3448de5b..022fcf39ee8 100644 --- a/runtime/flang/global.h +++ b/runtime/flang/global.h @@ -326,7 +326,7 @@ typedef struct { #include extern FIO_TBL fioFcbTbls; -#ifdef WINNT +#if 0 extern FIO_FCB *__get_fio_fcbs(void); #define GET_FIO_FCBS __get_fio_fcbs() #else From b3ce0e3954bceb22ac631ae6867f381ea9396e57 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 25 Oct 2017 20:03:04 -0500 Subject: [PATCH 039/141] Remove unnecessary changes --- lib/scutil/pgnewfil.c | 6 ++-- runtime/flang/alarm3f.c | 2 +- runtime/flang/assign.c | 4 +-- runtime/flang/async.c | 21 +++++------ runtime/flang/close.c | 2 +- runtime/flang/const.c | 2 +- runtime/flang/fmtconv.c | 10 +++--- runtime/flang/fmtread.c | 23 ++++++------- runtime/flang/fmtwrite.c | 44 ++++++++++++------------ runtime/flang/fork3f.c | 2 +- runtime/flang/fstat3f.c | 2 +- runtime/flang/fstat643f.c | 2 +- runtime/flang/getgid3f.c | 2 +- runtime/flang/getuid3f.c | 2 +- runtime/flang/irandm3f.c | 2 +- runtime/flang/lstat3f.c | 2 +- runtime/flang/lstat643f.c | 2 +- runtime/flang/mclock3f.c | 2 +- runtime/flang/times3f.c | 2 +- runtime/flangrti/iostdinit.c | 24 ++++++------- runtime/flangrti/ktrap.c | 2 +- runtime/flangrti/memalign.c | 6 ++-- runtime/flangrti/tempnam.c | 2 +- runtime/flangrti/trace.c | 4 +-- runtime/flangrti/x86_64-Linux/dumpregs.c | 4 +-- runtime/include/mthdecls.h | 11 +++--- tools/flang1/flang1exe/lz.c | 6 ++-- tools/flang1/flang1exe/main.c | 2 +- tools/flang1/utils/symtab/symini.cpp | 2 -- tools/flang2/flang2exe/main.c | 2 +- tools/shared/ccffinfo.c | 2 +- 31 files changed, 99 insertions(+), 102 deletions(-) diff --git a/lib/scutil/pgnewfil.c b/lib/scutil/pgnewfil.c index 590c678ed75..b72d504218d 100644 --- a/lib/scutil/pgnewfil.c +++ b/lib/scutil/pgnewfil.c @@ -29,7 +29,7 @@ #include #include -#if defined(_WIN32) +#if defined(HOST_WIN) #include #include #include @@ -312,7 +312,7 @@ pg_makenewfile(char *pfx, char *sfx, int make) if (!make) { break; } else { -#if defined(_WIN32) +#if defined(HOST_WIN) fd = _open(filename, _O_CREAT | _O_BINARY | _O_EXCL | _O_RDWR, _S_IWRITE); #else fd = open(filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR); @@ -358,7 +358,7 @@ pg_makenewdir(char *pfx, char *sfx, int make) if (r == -1 && errno == ENOENT) { if (make) { int err; -#if defined(_WIN32) || defined(WINNT) || defined(WIN64) +#if defined(HOST_WIN) || defined(WINNT) || defined(WIN64) err = _mkdir(filename); #else err = mkdir(filename, S_IRWXG | S_IRWXO | S_IXUSR | S_IWUSR | S_IRUSR); diff --git a/runtime/flang/alarm3f.c b/runtime/flang/alarm3f.c index 8cd9edc2224..da66a5d53d8 100644 --- a/runtime/flang/alarm3f.c +++ b/runtime/flang/alarm3f.c @@ -19,7 +19,7 @@ /* alarm3f.c - Implements LIB3F alarm subprogram. */ -#ifndef _WIN32 +#ifndef WINNT #include #include "ent3f.h" diff --git a/runtime/flang/assign.c b/runtime/flang/assign.c index 55fbf53e5a5..dc3efddd64f 100644 --- a/runtime/flang/assign.c +++ b/runtime/flang/assign.c @@ -210,8 +210,8 @@ __fortio_assign(char *item, /* where to store */ case __INT8: if (__ftn_32in64_) I64_MSH(valp->val.i8) = 0; - PP_INT4(item) = I64_LSH(valp->val.i8); - PP_INT4(item + 4) = I64_MSH(valp->val.i8); + PP_INT4(item) = valp->val.i8[0]; + PP_INT4(item + 4) = valp->val.i8[1]; break; case __REAL4: PP_REAL4(item) = (float)I64_LSH(valp->val.i8); diff --git a/runtime/flang/async.c b/runtime/flang/async.c index d5633ef2c3e..7cbc5f6b09f 100644 --- a/runtime/flang/async.c +++ b/runtime/flang/async.c @@ -27,7 +27,7 @@ * Fio_asy_close - called from close */ -#if !defined(_WIN32) +#if !defined(TARGET_WIN_X8664) #include #include #include @@ -52,7 +52,7 @@ struct asy_transaction_data { seekoffx_t off; }; -#if defined(_WIN32) +#if defined(TARGET_WIN_X8664) struct asy { FILE *fp; int fd; @@ -92,7 +92,7 @@ static int slime; /* internal wait for asynch i/o */ -#if defined(_WIN32) +#if defined(TARGET_WIN_X8664) static int asy_wait(struct asy *asy) { @@ -253,7 +253,7 @@ Fio_asy_open(FILE *fp, struct asy **pasy) { struct asy *asy; char *p; -#if defined(_WIN32) +#if defined(TARGET_WIN_X8664) HANDLE temp_handle; #endif asy = (struct asy *)calloc(sizeof(struct asy), 1); @@ -263,7 +263,7 @@ Fio_asy_open(FILE *fp, struct asy **pasy) } asy->fp = fp; asy->fd = __io_getfd(fp); -#if defined(_WIN32) +#if defined(TARGET_WIN_X8664) temp_handle = _get_osfhandle(asy->fd); asy->handle = ReOpenFile(temp_handle, GENERIC_READ | GENERIC_WRITE, @@ -287,13 +287,13 @@ Fio_asy_read(struct asy *asy, void *adr, long len) int n; int tn; -#if defined(_WIN32) +#if defined(TARGET_WIN_X8664) union Converter converter; #endif if (slime) printf("--Fio_asy_read %d %p %ld\n", asy->fd, adr, len); -#if defined(_WIN32) +#if defined(TARGET_WIN_X8664) if (asy->flags & ASY_IOACT) { /* i/o active? */ if (asy_wait(asy) == -1) { /* ..yes, wait */ return (-1); @@ -340,14 +340,14 @@ Fio_asy_write(struct asy *asy, void *adr, long len) { int n; int tn; -#if defined(_WIN32) +#if defined(TARGET_WIN_X8664) union Converter converter; #endif if (slime) printf("--Fio_asy_write %d %p %ld\n", asy->fd, adr, len); -#if defined(_WIN32) +#if defined(TARGET_WIN_X8664) if (asy->flags & ASY_IOACT) { /* i/o active? */ if (asy_wait(asy) == -1) { /* ..yes, wait */ return (-1); @@ -408,10 +408,11 @@ Fio_asy_close(struct asy *asy) if (asy->flags & ASY_IOACT) { /* i/o active? */ n = asy_wait(asy); } -#if defined(_WIN32) +#if defined(TARGET_WIN_X8664) /* Close the Re-opened handle that we created. */ CloseHandle(asy->handle); #endif free(asy); return (n); } + diff --git a/runtime/flang/close.c b/runtime/flang/close.c index 3ccf66b3f7d..754e433d74d 100644 --- a/runtime/flang/close.c +++ b/runtime/flang/close.c @@ -71,7 +71,7 @@ __fortio_close(FIO_FCB *f, int flag) else __fort_unlink(f->name); } -#ifdef _WIN32 +#ifdef WINNT else if (f->status == FIO_SCRATCH) unlink(f->name); #endif diff --git a/runtime/flang/const.c b/runtime/flang/const.c index ff888608e7e..5f2ee37a0cd 100644 --- a/runtime/flang/const.c +++ b/runtime/flang/const.c @@ -429,7 +429,7 @@ __get_size_of(int* idx) return __fort_size_of[*idx]; } -#ifdef _WIN32 +#ifdef WINNT /* pg access routines for data shared between windows dlls */ diff --git a/runtime/flang/fmtconv.c b/runtime/flang/fmtconv.c index dbe8ddbd7a9..4ace29cb41d 100644 --- a/runtime/flang/fmtconv.c +++ b/runtime/flang/fmtconv.c @@ -237,8 +237,8 @@ __fortio_default_convert(char *item, int type, break; case __LOG8: width = 2; - I64_LSH(i8val) = PP_LOG4(item); - I64_MSH(i8val) = PP_LOG4(item + 4); + i8val[0] = PP_LOG4(item); + i8val[1] = PP_LOG4(item + 4); if (I64_LSH(i8val) & GET_FIO_CNFG_TRUE_MASK) put_buf(width, "T", 1, 0); else @@ -366,7 +366,7 @@ __fortio_fmt_i8(FLANG_INT64 val, put_buf(width, p, len, neg); } else { /* Iw.0 gen's blanks if value is 0 */ - if (mn == 0 && I64_LSH(val) == 0 && I64_MSH(val) == 0) + if (mn == 0 && val[0] == 0 && val[1] == 0) neg = 0; put_buf(width, p, len, neg); if (mn > len) { @@ -394,8 +394,8 @@ conv_int8(FLANG_INT64 val, int *lenp, int *negp) FLANG_INT64 value; *negp = 0; - I64_LSH(value) = I64_LSH(val); - I64_MSH(value) = I64_MSH(val); + value[0] = val[0]; + value[1] = val[1]; if (__ftn_32in64_) { if (I64_LSH(value) & 0x80000000) I64_MSH(value) = -1; diff --git a/runtime/flang/fmtread.c b/runtime/flang/fmtread.c index a6fd82419a0..f1d716dc23e 100644 --- a/runtime/flang/fmtread.c +++ b/runtime/flang/fmtread.c @@ -1812,8 +1812,8 @@ fr_readnum(int code, char *item, int type) return __fortio_error(FIO_EERR_DATA_CONVERSION); } if (ty == __INT8) { - I64_MSH(i8val) = 0; - I64_LSH(i8val) = ival; + i8val[1] = 0; + i8val[0] = ival; } break; @@ -1876,11 +1876,9 @@ fr_readnum(int code, char *item, int type) idx++, w--; if (comma_seen) w -= 1; - if (w == 0) { - I64_LSH(i8val) = 0; - I64_MSH(i8val) = 0; - ival = 0; - } else { + if (w == 0) + ival = i8val[0] = i8val[1] = 0; + else { c = g->rec_buff[idx]; e = FALSE; /* sign flag */ if (ty == __INT8) { @@ -1894,8 +1892,7 @@ fr_readnum(int code, char *item, int type) */ int tmp_w = w; int cpos = idx; /* 'last' character copied */ - I64_MSH(i8val) = 0; - I64_LSH(i8val) = 0; + i8val[0] = i8val[1] = 0; tmp_idx = idx; while (--tmp_w > 0) { ++tmp_idx; @@ -2106,14 +2103,14 @@ fr_assign(char *item, int type, __BIGINT_T ival, FLANG_INT64 i8val, __BIGREAL_T case __LOG8: if (__ftn_32in64_) I64_MSH(i8val) = 0; - ((__INT4_T *)item)[0] = I64_LSH(i8val); - ((__INT4_T *)item)[1] = I64_MSH(i8val); + ((__INT4_T *)item)[0] = i8val[0]; + ((__INT4_T *)item)[1] = i8val[1]; break; case __INT8: if (__ftn_32in64_) I64_MSH(i8val) = 0; - ((__INT4_T *)item)[0] = I64_LSH(i8val); - ((__INT4_T *)item)[1] = I64_MSH(i8val); + ((__INT4_T *)item)[0] = i8val[0]; + ((__INT4_T *)item)[1] = i8val[1]; break; default: diff --git a/runtime/flang/fmtwrite.c b/runtime/flang/fmtwrite.c index 6f153f320b1..b920042f38a 100644 --- a/runtime/flang/fmtwrite.c +++ b/runtime/flang/fmtwrite.c @@ -1635,15 +1635,15 @@ fw_writenum(int code, char *item, int type) is_logical = TRUE; break; case __LOG8: - I64_LSH(i8val) = ((__INT4_T *)item)[0]; - I64_MSH(i8val) = ((__INT4_T *)item)[1]; + i8val[0] = ((__INT4_T *)item)[0]; + i8val[1] = ((__INT4_T *)item)[1]; ty = __INT8; w = 24; is_logical = TRUE; break; case __INT8: - I64_LSH(i8val) = ((__INT4_T *)item)[0]; - I64_MSH(i8val) = ((__INT4_T *)item)[1]; + i8val[0] = ((__INT4_T *)item)[0]; + i8val[1] = ((__INT4_T *)item)[1]; ty = __INT8; w = 24; break; @@ -1753,8 +1753,8 @@ fw_writenum(int code, char *item, int type) case __REAL8: case __REAL16: crc.r8 = dval; - I64_LSH(i8val) = I64_LSH(crc.i8v); - I64_MSH(i8val) = I64_MSH(crc.i8v); + i8val[0] = crc.i8v[0]; + i8val[1] = crc.i8v[1]; ty = __INT8; w = 24; break; @@ -1780,8 +1780,8 @@ fw_writenum(int code, char *item, int type) case __REAL8: case __REAL16: crc.r8 = dval; - I64_LSH(i8val) = I64_LSH(crc.i8v); - I64_MSH(i8val) = I64_MSH(crc.i8v); + i8val[0] = crc.i8v[0]; + i8val[1] = crc.i8v[1]; ty = __INT8; break; } @@ -1839,8 +1839,8 @@ fw_writenum(int code, char *item, int type) case __REAL8: case __REAL16: crc.r8 = dval; - I64_LSH(i8val) = I64_LSH(crc.i8v); - I64_MSH(i8val) = I64_MSH(crc.i8v); + i8val[0] = crc.i8v[0]; + i8val[1] = crc.i8v[1]; ty = __INT8; break; } @@ -1866,8 +1866,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - I64_LSH(i8val) = I64_LSH(crc.i8v); - I64_MSH(i8val) = I64_MSH(crc.i8v); + crc.i8v[0] = i8val[0]; + crc.i8v[1] = i8val[1]; dval = crc.r8; e = 2; ty = __REAL8; @@ -1908,8 +1908,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - I64_LSH(crc.i8v) = I64_LSH(i8val); - I64_MSH(crc.i8v) = I64_MSH(i8val); + crc.i8v[0] = i8val[0]; + crc.i8v[1] = i8val[1]; dval = crc.r8; w = REAL8_W; d = REAL8_D; @@ -1947,8 +1947,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - I64_LSH(crc.i8v) = I64_LSH(i8val); - I64_MSH(crc.i8v) = I64_MSH(i8val); + crc.i8v[0] = i8val[0]; + crc.i8v[1] = i8val[1]; dval = crc.r8; if (!e_flag) e = 2; @@ -1979,8 +1979,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - I64_LSH(crc.i8v) = I64_LSH(i8val); - I64_MSH(crc.i8v) = I64_MSH(i8val); + crc.i8v[0] = i8val[0]; + crc.i8v[1] = i8val[1]; dval = crc.r8; w = REAL8_W; d = REAL8_D; @@ -2009,8 +2009,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - I64_LSH(crc.i8v) = I64_LSH(i8val); - I64_MSH(crc.i8v) = I64_MSH(i8val); + crc.i8v[0] = i8val[0]; + crc.i8v[1] = i8val[1]; dval = crc.r8; ty = __REAL8; break; @@ -2031,8 +2031,8 @@ fw_writenum(int code, char *item, int type) case __INT8: if (__fortio_check_format()) goto fmt_mismatch; - I64_LSH(crc.i8v) = I64_LSH(i8val); - I64_MSH(crc.i8v) = I64_MSH(i8val); + crc.i8v[0] = i8val[0]; + crc.i8v[1] = i8val[1]; dval = crc.r8; w = REAL8_W; d = REAL8_D; diff --git a/runtime/flang/fork3f.c b/runtime/flang/fork3f.c index 87c28fd8c89..f9760afe9c2 100644 --- a/runtime/flang/fork3f.c +++ b/runtime/flang/fork3f.c @@ -19,7 +19,7 @@ /* fork3f.c - Implements LIB3F fork subprogram. */ -#ifndef _WIN32 +#ifndef WINNT /* must include ent3f.h AFTER io3f.h */ #include "io3f.h" diff --git a/runtime/flang/fstat3f.c b/runtime/flang/fstat3f.c index 82f70102685..960cb96d7b2 100644 --- a/runtime/flang/fstat3f.c +++ b/runtime/flang/fstat3f.c @@ -110,7 +110,7 @@ int ENT3F(FSTAT, fstat)(int *lu, int *statb) statb[8] = b.st_atime; statb[9] = b.st_mtime; statb[10] = b.st_ctime; -#if !defined(_WIN32) +#if !defined(WINNT) statb[11] = b.st_blksize; statb[12] = b.st_blocks; #else diff --git a/runtime/flang/fstat643f.c b/runtime/flang/fstat643f.c index 28ccc04a587..5317fe51d0b 100644 --- a/runtime/flang/fstat643f.c +++ b/runtime/flang/fstat643f.c @@ -27,7 +27,7 @@ int ENT3F(FSTAT64, fstat64)(int *lu, long long *statb) { -#if defined(_WIN32) +#if defined(TARGET_WIN) || defined(WIN32) || defined(WIN64) /* * The __int64_t members in the _stat64 are 8-byte aligned, thus the * st_size member is at offset 24. On WIN32, 64-bit ints are 4-byte diff --git a/runtime/flang/getgid3f.c b/runtime/flang/getgid3f.c index 98a6071910b..036d6dc030c 100644 --- a/runtime/flang/getgid3f.c +++ b/runtime/flang/getgid3f.c @@ -19,7 +19,7 @@ /* getgid3f.c - Implements LIB3F getgid subprogram. */ -#ifndef _WIN32 +#ifndef WINNT #include #include "ent3f.h" diff --git a/runtime/flang/getuid3f.c b/runtime/flang/getuid3f.c index 2bcc0694ade..4bbc9837e54 100644 --- a/runtime/flang/getuid3f.c +++ b/runtime/flang/getuid3f.c @@ -19,7 +19,7 @@ /* getuid3f.c - Implements LIB3F getuid subprogram. */ -#ifndef _WIN32 +#ifndef WINNT #include "ent3f.h" #include diff --git a/runtime/flang/irandm3f.c b/runtime/flang/irandm3f.c index 086bd17b7b9..a2fe5679508 100644 --- a/runtime/flang/irandm3f.c +++ b/runtime/flang/irandm3f.c @@ -21,7 +21,7 @@ #include "ent3f.h" -#ifdef _WIN32 +#ifdef WINNT int ENT3F(IRANDM, irandm)(int *flag) { diff --git a/runtime/flang/lstat3f.c b/runtime/flang/lstat3f.c index 2a3ddfe7d86..faac308c68c 100644 --- a/runtime/flang/lstat3f.c +++ b/runtime/flang/lstat3f.c @@ -19,7 +19,7 @@ /* lstat3f.c - Implements LIB3F lstat subprogram. */ -#ifndef _WIN32 +#ifndef WINNT /* must include ent3f.h AFTER io3f.h */ #include diff --git a/runtime/flang/lstat643f.c b/runtime/flang/lstat643f.c index d8c037e0de5..c6ff3090f5e 100644 --- a/runtime/flang/lstat643f.c +++ b/runtime/flang/lstat643f.c @@ -19,7 +19,7 @@ /* lstat3f.c - Implements 64-bit LIB3F lstat subprogram. */ -#ifndef _WIN32 +#ifndef WINNT /* must include ent3f.h AFTER io3f.h */ #include diff --git a/runtime/flang/mclock3f.c b/runtime/flang/mclock3f.c index 889113174dc..8752f726d72 100644 --- a/runtime/flang/mclock3f.c +++ b/runtime/flang/mclock3f.c @@ -22,7 +22,7 @@ /* assumes the Unix times system call */ -#if defined(_WIN32) +#if defined(WINNT) #include diff --git a/runtime/flang/times3f.c b/runtime/flang/times3f.c index c3b9b232fd3..0ac39c717b9 100644 --- a/runtime/flang/times3f.c +++ b/runtime/flang/times3f.c @@ -19,7 +19,7 @@ /* times3f.c - Implements LIB3F times subprogram. */ -#ifndef _WIN32 +#ifndef WINNT #include #include "io3f.h" diff --git a/runtime/flangrti/iostdinit.c b/runtime/flangrti/iostdinit.c index ad638a93d9c..9523a3714d8 100644 --- a/runtime/flangrti/iostdinit.c +++ b/runtime/flangrti/iostdinit.c @@ -16,7 +16,7 @@ */ #include -#if !defined(_WIN32) && !defined(ST100) +#if !defined(WINNT) && !defined(ST100) #include #include #endif @@ -25,7 +25,7 @@ /* get environ */ -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) /* * enclose _fileno within parens to ensure calling the function rather than * the _fileno function macro (if/when it exists). @@ -33,7 +33,7 @@ #define fileno(x) (_fileno)(x) #endif -#if defined(_WIN32) +#if defined(WINNT) #include extern char **environ; #elif defined(TARGET_OSX) @@ -90,7 +90,7 @@ __io_stderr(void) /* convert macros to routines */ -#if defined(TARGET_WIN) || defined(_WIN32) +#if defined(TARGET_WIN) || defined(WIN32) #include int __io_fgetc(FILE *p) @@ -176,10 +176,10 @@ __io_isatty(int fd) int __io_binary_mode(void *fp) { -#if defined(_WIN32_WINNT) +#if defined(WINNT) #include -#if defined(_WIN64) || defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #define O_BINARY _O_BINARY #endif @@ -203,10 +203,10 @@ __io_binary_mode(void *fp) int __io_setmode_binary(void *fp) { -#if defined(_WIN32_WINNT) +#if defined(WINNT) #include -#if defined(_WIN64) || defined(_WIN32) +#if defined(WIN64) || defined(WIN32) #define O_BINARY _O_BINARY #endif @@ -221,7 +221,7 @@ __io_setmode_binary(void *fp) int __io_ispipe(void *f) { -#if !defined(_WIN32) && !defined(ST100) +#if !defined(WINNT) && !defined(ST100) struct stat st; fstat(fileno((FILE *)f), &st); @@ -261,7 +261,7 @@ __io_fwrite(char *ptr, size_t size, size_t nitems, FILE *stream) #endif } -#if defined(_WIN32) +#if defined(WINNT) || defined(WIN64) || defined(WIN32) #if defined(PGI_CRTDLL) extern long *_imp___timezone_dll; /* for crtdll.dll */ @@ -279,14 +279,14 @@ __io_timezone(void *tm) { #if defined(SUN4) || defined(PPC) || defined(OSX86) return ((struct tm *)tm)->tm_gmtoff; -#elif defined(_WIN32) +#elif defined(WINNT) || defined(WIN64) || defined(WIN32) return (0); #else return -(timezone - (((struct tm *)tm)->tm_isdst ? 3600 : 0)); #endif } -#if defined(_WIN32) +#if (defined(WIN32) || defined(WIN64)) /* OT 10 */ void * _pgi_get_iob(int xx) { diff --git a/runtime/flangrti/ktrap.c b/runtime/flangrti/ktrap.c index 4de3e2fd09d..75676d7d0f9 100644 --- a/runtime/flangrti/ktrap.c +++ b/runtime/flangrti/ktrap.c @@ -19,7 +19,7 @@ * \brief IEEE trap support */ -#ifndef _WIN32 +#ifndef TARGET_WIN #include diff --git a/runtime/flangrti/memalign.c b/runtime/flangrti/memalign.c index 8d6271a024b..e2e01af2ac3 100644 --- a/runtime/flangrti/memalign.c +++ b/runtime/flangrti/memalign.c @@ -18,7 +18,7 @@ #include #include -#if defined(_WIN32) +#if (defined(WIN32) || defined(WIN64)) extern void *_aligned_malloc(); extern void _aligned_free(); #else @@ -50,7 +50,7 @@ __aligned_malloc(size_t sz, size_t aln) aln = 1 << s; } need = sz + MINALN; -#if defined(_WIN32) +#if (defined(WIN32) || defined(WIN64)) q = _aligned_malloc(need, aln); if (!q) return NULL; @@ -63,7 +63,7 @@ __aligned_malloc(size_t sz, size_t aln) void __aligned_free(void *p) { -#if defined(_WIN32) +#if (defined(WIN32) || defined(WIN64)) _aligned_free(p); #else free(p); diff --git a/runtime/flangrti/tempnam.c b/runtime/flangrti/tempnam.c index db5afc8ed8c..8562f2d222b 100644 --- a/runtime/flangrti/tempnam.c +++ b/runtime/flangrti/tempnam.c @@ -156,7 +156,7 @@ extern char *tempnam(char *, char *); char * __io_tempnam(char *dir, char *pfx) { -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) return (_tempnam(dir, pfx)); #else return (tempnam(dir, pfx)); diff --git a/runtime/flangrti/trace.c b/runtime/flangrti/trace.c index 7dd5238a9fa..5c3ecb6f8ee 100644 --- a/runtime/flangrti/trace.c +++ b/runtime/flangrti/trace.c @@ -66,7 +66,7 @@ dbg_stop_before_exit(void) * 3 - traceback (signal) */ -#if defined(_WIN32) +#if defined(WIN32) || defined(WIN64) #define getpid _getpid #define _Exit _exit #endif @@ -143,7 +143,7 @@ __abort_init(char *path) int n; int neg; -#if defined(_WIN32) +#if defined(WINNT) fn = path; #endif p = getenv("TRACE_TERM"); diff --git a/runtime/flangrti/x86_64-Linux/dumpregs.c b/runtime/flangrti/x86_64-Linux/dumpregs.c index c4f31ced95f..1b5e147b329 100644 --- a/runtime/flangrti/x86_64-Linux/dumpregs.c +++ b/runtime/flangrti/x86_64-Linux/dumpregs.c @@ -15,7 +15,7 @@ * */ -#if !defined(_WIN32) +#if !defined(TARGET_WIN) #include #endif #include "stdioInterf.h" @@ -40,7 +40,7 @@ #define RSP 15 #define RIP 16 -#if defined(TARGET_OSX) || defined(_WIN32) +#if defined(TARGET_OSX) || defined(TARGET_WIN) /* no gregs and/or ucontext defined in for OSX or Windows */ void * getRegs(void *u) diff --git a/runtime/include/mthdecls.h b/runtime/include/mthdecls.h index 7abefa4385c..ddec42510f0 100644 --- a/runtime/include/mthdecls.h +++ b/runtime/include/mthdecls.h @@ -263,7 +263,7 @@ float __builtin_cimagf(float complex); single precision versions of the math.h functions, in which case the single precision versions should be used: */ -#if defined(_WIN32) +#if defined(WIN64) #define ACOSF acos #define ASINF asin @@ -326,7 +326,7 @@ float __builtin_cimagf(float complex); #define hypot _hypot #endif -#else /* #if defined (_WIN32) */ +#else /* #if defined (WIN64) */ #define ACOSF acosf #define ASINF asinf #define ATANF atanf @@ -372,7 +372,7 @@ float __builtin_cimagf(float complex); #define CTANHF ctanhf #define CTANF ctanf -#if defined(_WIN32) +#if defined(TARGET_WIN) #define BESSEL_J0F _j0 #define BESSEL_J1F _j1 #define BESSEL_JNF _jn @@ -422,7 +422,7 @@ float __builtin_cimagf(float complex); #define BESSEL_Y1 y1 #define BESSEL_YN yn #endif -#endif /* #if defined (WIN32) */ +#endif /* #if defined (WIN64) */ /* declarations for math functions */ @@ -580,7 +580,8 @@ ZMPLXDECL_Z(__mth_i_cdtanh); #endif -#if defined(_WIN32) + +#if defined(TARGET_WIN) /* the following are part of Open Tools 12, we build with Open Tools 10 */ /* extern double erf(double x); diff --git a/tools/flang1/flang1exe/lz.c b/tools/flang1/flang1exe/lz.c index a0a2edc90bc..ba57b5e2590 100644 --- a/tools/flang1/flang1exe/lz.c +++ b/tools/flang1/flang1exe/lz.c @@ -19,12 +19,12 @@ #include #include "gbldefs.h" -#if !defined(_WIN32) +#if !defined(HOST_WIN) #include #include #endif -#ifndef _WIN32 +#ifndef HOST_WIN #define USE_GETLINE 1 #endif @@ -195,7 +195,7 @@ lzrestore(lzhandle *lzh) { int l; fseek(lzh->file, lzh->savefile, SEEK_SET); -#if !defined(_WIN32) +#if !defined(HOST_WIN) if (lzh->inout) { ftruncate(fileno(lzh->file), lzh->savefile); } diff --git a/tools/flang1/flang1exe/main.c b/tools/flang1/flang1exe/main.c index f8e23d60883..7c2272d45ed 100644 --- a/tools/flang1/flang1exe/main.c +++ b/tools/flang1/flang1exe/main.c @@ -22,7 +22,7 @@ #include #include "flang/ArgParser/arg_parser.h" #include "error.h" -#if !defined(_WIN32) +#if !defined(TARGET_WIN) #include #endif #include diff --git a/tools/flang1/utils/symtab/symini.cpp b/tools/flang1/utils/symtab/symini.cpp index d2e72c0aed4..ea2169fc99d 100644 --- a/tools/flang1/utils/symtab/symini.cpp +++ b/tools/flang1/utils/symtab/symini.cpp @@ -175,9 +175,7 @@ class SyminiFE90 : public UtilityApplication // FIXME this initializes the global variable stb. In the future // STB should become a class with normal C++ class constructors, // and this call will not be necessary. - printf("asd"); sym_init_first(); - printf("qwe"); int output_file_argument = 0; for (int arg = 1; arg < argc; ++arg) { diff --git a/tools/flang2/flang2exe/main.c b/tools/flang2/flang2exe/main.c index b64b870e479..ddc2025b907 100644 --- a/tools/flang2/flang2exe/main.c +++ b/tools/flang2/flang2exe/main.c @@ -37,7 +37,7 @@ #include "llassem.h" #include "cgllvm.h" #include "outliner.h" -#if !defined(_WIN32) +#if !defined(TARGET_WIN) #include #endif #include diff --git a/tools/shared/ccffinfo.c b/tools/shared/ccffinfo.c index ae5b49a6320..50307f9fb6e 100644 --- a/tools/shared/ccffinfo.c +++ b/tools/shared/ccffinfo.c @@ -26,7 +26,7 @@ #include #include -#if !defined(_WIN32) +#if !defined(HOST_WIN) #include #endif #include "symtab.h" From 8c149832ac01eaad81e22da8693f35a718b2b0c0 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 25 Oct 2017 20:08:43 -0500 Subject: [PATCH 040/141] Add more target definitions --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b846c4367a7..8aa765a01c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,10 +57,11 @@ if( ${TARGET_OS} STREQUAL "Linux" ) elseif(${TARGET_OS} STREQUAL "Windows" ) set(OS "WINDOWS") set(OSNAME "Windows") + add_definitions(-DWIN32 -DHOST_WIN -DWINNT -DTARGET_WIN -DTARGET_WIN_X86) if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - add_definitions(-DWIN32 -DHOST_WIN -DWIN64 -DWINNT -DTARGET_WIN_X8632) + add_definitions(-DWIN64 -DTARGET_WIN_X8664) else( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - add_definitions(-DWIN32 -DHOST_WIN -DWIN64 -DWINNT -DTARGET_WIN_X8632) + add_definitions(-DTARGET_WIN_X8632) endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) if( ${TARGET_ARCHITECTURE} STREQUAL "AMD64" ) set(TARGET_ARCHITECTURE "x86_64") From a84a7f8bf60818ec3a3e14f34b8fc76acfe9a19b Mon Sep 17 00:00:00 2001 From: xoviat Date: Wed, 25 Oct 2017 20:32:42 -0500 Subject: [PATCH 041/141] [tools/flang2/exputil] fix getsname2 --- tools/flang2/flang2exe/exputil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/flang2/flang2exe/exputil.c b/tools/flang2/flang2exe/exputil.c index 32e099bfcca..67a0a1b749d 100644 --- a/tools/flang2/flang2exe/exputil.c +++ b/tools/flang2/flang2exe/exputil.c @@ -1107,7 +1107,7 @@ mk_impsym(int sptr) } /***** else FALLTHRU *****/ default: -#if defined(PGFTN) && defined(TARGET_WIN_X8664) +#if defined(PGFTN) && defined(TARGET_WIN_X8664) && 0 sprintf(bf, "__imp_%s", getsname2(sptr)); #else sprintf(bf, "__imp_%s", getsname(sptr)); From 41562a508c9753ee77617da41a89e9cc9a5226ea Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 25 Oct 2017 22:02:21 -0500 Subject: [PATCH 042/141] Comment out insert_argrsrv --- tools/flang2/flang2exe/iliutil.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/flang2/flang2exe/iliutil.c b/tools/flang2/flang2exe/iliutil.c index c7ac682f3b2..23be202f236 100644 --- a/tools/flang2/flang2exe/iliutil.c +++ b/tools/flang2/flang2exe/iliutil.c @@ -179,7 +179,8 @@ addili(ILI *ilip) break; case ILTY_PROC: #if defined(TARGET_WIN_X8664) - insert_argrsrv(ilip); + // TODO: FIXME + // insert_argrsrv(ilip); #endif if (opc == IL_QJSR && share_qjsr_ili) { /* From 6f30c092e4484769dd9bf132895c4d671bc7e802 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 25 Oct 2017 22:17:52 -0500 Subject: [PATCH 043/141] Fix linking errors --- runtime/flang/dmod.c | 2 +- runtime/flang/utils.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/flang/dmod.c b/runtime/flang/dmod.c index 4e917c9ed7a..fbe9cee3ee4 100644 --- a/runtime/flang/dmod.c +++ b/runtime/flang/dmod.c @@ -25,7 +25,7 @@ double __mth_i_dmod(double f, double g) { /* Need to do this way until a bug in the Win64 fmod routine is fixed */ -#if defined(WIN64) +#if defined(WIN64) && 0 return __fmth_i_dmod(f, g); #else return fmod(f, g); diff --git a/runtime/flang/utils.c b/runtime/flang/utils.c index 913b632de54..1994bb2ffeb 100644 --- a/runtime/flang/utils.c +++ b/runtime/flang/utils.c @@ -609,6 +609,11 @@ __fortio_binary_mode(int fd) { return (_setmode(fd, _O_BINARY) != -1); } +void +__fortio_setmode_binary(FILE *f) { + _setmode(_fileno(f), _O_BINARY); +} + void sincos(double x, double *sine, double *cosine) { *sine = sin(x); From 831f150ad470a1d3e22810d8da68fcc9c8237908 Mon Sep 17 00:00:00 2001 From: Albert Ziegenhagel Date: Thu, 26 Oct 2017 13:47:58 +0200 Subject: [PATCH 044/141] Fix missing ompstub.lib Adds WINDOWS_EXPORT_ALL_SYMBOLS to the shared ompstub library target since it is missing __declspec(dllexport/dllimport) --- runtime/ompstub/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/ompstub/CMakeLists.txt b/runtime/ompstub/CMakeLists.txt index 43f064a31cd..02fbb864888 100644 --- a/runtime/ompstub/CMakeLists.txt +++ b/runtime/ompstub/CMakeLists.txt @@ -26,6 +26,9 @@ endif() set(SHARED_LIBRARY TRUE) add_flang_library(ompstub_shared ${OMPSTUB_SRC}) set_property(TARGET ompstub_shared PROPERTY OUTPUT_NAME ompstub) +if (MSVC) + set_target_properties(ompstub_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) +endif() set(SHARED_LIBRARY FALSE) set_target_properties(ompstub_static ompstub_shared From db627275a79e9b466acc02d53540ce42a59d5ef7 Mon Sep 17 00:00:00 2001 From: Albert Ziegenhagel Date: Thu, 26 Oct 2017 13:52:11 +0200 Subject: [PATCH 045/141] Use "lib" prefix instead of "_static" suffix for static runtime libraries. This is more in sync with windows default names (e.g. ucrt.lib as import library for ucrt.dll and libucrt.lib for the static runtime). --- runtime/flang/CMakeLists.txt | 2 +- runtime/flangrti/CMakeLists.txt | 2 +- runtime/ompstub/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 219af786901..4dba4cd504a 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -486,7 +486,7 @@ add_flang_library(flang_static ) if (MSVC) -set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang_static) +set_property(TARGET flang_static PROPERTY OUTPUT_NAME libflang) else() set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang) endif() diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index c3446b85523..bf0da741014 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -180,7 +180,7 @@ add_flang_library(flangrti_static ${SHARED_SOURCES} ) if (MSVC) - set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME flangrti_static) + set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME libflangrti) else() set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME flangrti) endif() diff --git a/runtime/ompstub/CMakeLists.txt b/runtime/ompstub/CMakeLists.txt index 02fbb864888..6cec4002896 100644 --- a/runtime/ompstub/CMakeLists.txt +++ b/runtime/ompstub/CMakeLists.txt @@ -18,7 +18,7 @@ set(OMPSTUB_SRC init_nomp.c ompstubs.c) add_flang_library(ompstub_static ${OMPSTUB_SRC}) if (MSVC) -set_property(TARGET ompstub_static PROPERTY OUTPUT_NAME ompstub_static) +set_property(TARGET ompstub_static PROPERTY OUTPUT_NAME libompstub) else() set_property(TARGET ompstub_static PROPERTY OUTPUT_NAME ompstub) endif() From 27fa0d9a243e45378e1c60d4c32f1cd982454370 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 26 Oct 2017 10:30:35 -0500 Subject: [PATCH 046/141] Fix main function --- runtime/flangmain/flangmain.c | 2 +- tools/flang2/flang2exe/llassem.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/flangmain/flangmain.c b/runtime/flangmain/flangmain.c index e006cac673a..64fb5f508e0 100644 --- a/runtime/flangmain/flangmain.c +++ b/runtime/flangmain/flangmain.c @@ -57,7 +57,7 @@ char **argv; int i = 0; #if (defined(INTERIX86) || defined(INTERIX8664) || defined(WIN64) || defined(WIN32) || defined(TARGET_OSX_X86)) - _pgimain(argc, argv); + //_pgimain(argc, argv); #endif __io_set_argc(argc); diff --git a/tools/flang2/flang2exe/llassem.c b/tools/flang2/flang2exe/llassem.c index a709ce3662c..b06c83d43a3 100644 --- a/tools/flang2/flang2exe/llassem.c +++ b/tools/flang2/flang2exe/llassem.c @@ -3150,7 +3150,7 @@ getextfuncname(int sptr) } else { #if defined(TARGET_WIN) /* we have a mix of undecorated and decorated names on win32 */ - strcpy(name, "_MAIN_"); + strcpy(name, "MAIN_"); return name; #else q = "MAIN"; @@ -3437,7 +3437,7 @@ getsname(int sptr) } else { #if defined(TARGET_WIN) /* we have a mix of undecorated and decorated names on win32 */ - strcpy(name, "_MAIN_"); + strcpy(name, "MAIN_"); return name; #else q = "MAIN"; @@ -4715,7 +4715,7 @@ get_llvm_name(int sptr) } else { #if defined(TARGET_WIN) /* we have a mix of undecorated and decorated names on win32 */ - strcpy(name, "_MAIN_"); + strcpy(name, "MAIN_"); return name; #else q = "MAIN"; From 1e39f37838a1a950d0a5dbe134a1ef44e4236cf5 Mon Sep 17 00:00:00 2001 From: Albert Ziegenhagel Date: Thu, 26 Oct 2017 17:51:44 +0200 Subject: [PATCH 047/141] Add WINDOWS_EXPORT_ALL_SYMBOLS for shared flang library --- runtime/flang/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 4dba4cd504a..d4bd35366a9 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -502,6 +502,8 @@ target_link_libraries(flang_shared flangrti_shared) # Resolve symbols against libm and librt if (NOT MSVC) target_link_libraries(flang_shared rt m) +else() + set_target_properties(flang_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) endif() set(SHARED_LIBRARY FALSE) From 128550caa1cbe840d93107b99c29dc7d0353a3e0 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 26 Oct 2017 13:11:05 -0500 Subject: [PATCH 048/141] [runtime/trace] create stackwalker --- runtime/flangrti/trace/StackWalker.cpp | 1365 ++++++++++++++++++++++++ runtime/flangrti/trace/c_interface.cxx | 20 + runtime/flangrti/trace/c_interface.h | 1 + runtime/flangrti/trace/stackwalker.h | 218 ++++ runtime/flangrti/trace_lin.c | 7 +- 5 files changed, 1609 insertions(+), 2 deletions(-) create mode 100644 runtime/flangrti/trace/StackWalker.cpp create mode 100644 runtime/flangrti/trace/c_interface.cxx create mode 100644 runtime/flangrti/trace/c_interface.h create mode 100644 runtime/flangrti/trace/stackwalker.h diff --git a/runtime/flangrti/trace/StackWalker.cpp b/runtime/flangrti/trace/StackWalker.cpp new file mode 100644 index 00000000000..467b5a4cbcb --- /dev/null +++ b/runtime/flangrti/trace/StackWalker.cpp @@ -0,0 +1,1365 @@ +/********************************************************************** + * + * StackWalker.cpp + * http://stackwalker.codeplex.com/ + * + * + * History: + * 2005-07-27 v1 - First public release on http://www.codeproject.com/ + * http://www.codeproject.com/threads/StackWalker.asp + * 2005-07-28 v2 - Changed the params of the constructor and ShowCallstack + * (to simplify the usage) + * 2005-08-01 v3 - Changed to use 'CONTEXT_FULL' instead of CONTEXT_ALL + * (should also be enough) + * - Changed to compile correctly with the PSDK of VC7.0 + * (GetFileVersionInfoSizeA and GetFileVersionInfoA is wrongly defined: + * it uses LPSTR instead of LPCSTR as first paremeter) + * - Added declarations to support VC5/6 without using 'dbghelp.h' + * - Added a 'pUserData' member to the ShowCallstack function and the + * PReadProcessMemoryRoutine declaration (to pass some user-defined data, + * which can be used in the readMemoryFunction-callback) + * 2005-08-02 v4 - OnSymInit now also outputs the OS-Version by default + * - Added example for doing an exception-callstack-walking in main.cpp + * (thanks to owillebo: http://www.codeproject.com/script/profile/whos_who.asp?id=536268) + * 2005-08-05 v5 - Removed most Lint (http://www.gimpel.com/) errors... thanks to Okko Willeboordse! + * 2008-08-04 v6 - Fixed Bug: Missing LEAK-end-tag + * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=2502890#xx2502890xx + * Fixed Bug: Compiled with "WIN32_LEAN_AND_MEAN" + * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=1824718#xx1824718xx + * Fixed Bug: Compiling with "/Wall" + * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=2638243#xx2638243xx + * Fixed Bug: Now checking SymUseSymSrv + * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=1388979#xx1388979xx + * Fixed Bug: Support for recursive function calls + * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=1434538#xx1434538xx + * Fixed Bug: Missing FreeLibrary call in "GetModuleListTH32" + * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=1326923#xx1326923xx + * Fixed Bug: SymDia is number 7, not 9! + * 2008-09-11 v7 For some (undocumented) reason, dbhelp.h is needing a packing of 8! + * Thanks to Teajay which reported the bug... + * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=2718933#xx2718933xx + * 2008-11-27 v8 Debugging Tools for Windows are now stored in a different directory + * Thanks to Luiz Salamon which reported this "bug"... + * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=2822736#xx2822736xx + * 2009-04-10 v9 License slihtly corrected ( replaced) + * 2009-11-01 v10 Moved to http://stackwalker.codeplex.com/ + * 2009-11-02 v11 Now try to use IMAGEHLP_MODULE64_V3 if available + * 2010-04-15 v12 Added support for VS2010 RTM + * 2010-05-25 v13 Now using secure MyStrcCpy. Thanks to luke.simon: + * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=3477467#xx3477467xx + * 2013-01-07 v14 Runtime Check Error VS2010 Debug Builds fixed: + * http://stackwalker.codeplex.com/workitem/10511 + * + * + * LICENSE (http://www.opensource.org/licenses/bsd-license.php) + * + * Copyright (c) 2005-2013, Jochen Kalmbach + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of Jochen Kalmbach nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + **********************************************************************/ +#include +#include +#include +#include +#pragma comment(lib, "version.lib") // for "VerQueryValue" +#pragma warning(disable:4826) + +#include "trace/StackWalker.h" + + +// If VC7 and later, then use the shipped 'dbghelp.h'-file +#pragma pack(push,8) +#if _MSC_VER >= 1300 +#include +#else +// inline the important dbghelp.h-declarations... +typedef enum { + SymNone = 0, + SymCoff, + SymCv, + SymPdb, + SymExport, + SymDeferred, + SymSym, + SymDia, + SymVirtual, + NumSymTypes +} SYM_TYPE; +typedef struct _IMAGEHLP_LINE64 { + DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_LINE64) + PVOID Key; // internal + DWORD LineNumber; // line number in file + PCHAR FileName; // full filename + DWORD64 Address; // first instruction of line +} IMAGEHLP_LINE64, *PIMAGEHLP_LINE64; +typedef struct _IMAGEHLP_MODULE64 { + DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64) + DWORD64 BaseOfImage; // base load address of module + DWORD ImageSize; // virtual size of the loaded module + DWORD TimeDateStamp; // date/time stamp from pe header + DWORD CheckSum; // checksum from the pe header + DWORD NumSyms; // number of symbols in the symbol table + SYM_TYPE SymType; // type of symbols loaded + CHAR ModuleName[32]; // module name + CHAR ImageName[256]; // image name + CHAR LoadedImageName[256]; // symbol file name +} IMAGEHLP_MODULE64, *PIMAGEHLP_MODULE64; +typedef struct _IMAGEHLP_SYMBOL64 { + DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_SYMBOL64) + DWORD64 Address; // virtual address including dll base address + DWORD Size; // estimated size of symbol, can be zero + DWORD Flags; // info about the symbols, see the SYMF defines + DWORD MaxNameLength; // maximum size of symbol name in 'Name' + CHAR Name[1]; // symbol name (null terminated string) +} IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64; +typedef enum { + AddrMode1616, + AddrMode1632, + AddrModeReal, + AddrModeFlat +} ADDRESS_MODE; +typedef struct _tagADDRESS64 { + DWORD64 Offset; + WORD Segment; + ADDRESS_MODE Mode; +} ADDRESS64, *LPADDRESS64; +typedef struct _KDHELP64 { + DWORD64 Thread; + DWORD ThCallbackStack; + DWORD ThCallbackBStore; + DWORD NextCallback; + DWORD FramePointer; + DWORD64 KiCallUserMode; + DWORD64 KeUserCallbackDispatcher; + DWORD64 SystemRangeStart; + DWORD64 Reserved[8]; +} KDHELP64, *PKDHELP64; +typedef struct _tagSTACKFRAME64 { + ADDRESS64 AddrPC; // program counter + ADDRESS64 AddrReturn; // return address + ADDRESS64 AddrFrame; // frame pointer + ADDRESS64 AddrStack; // stack pointer + ADDRESS64 AddrBStore; // backing store pointer + PVOID FuncTableEntry; // pointer to pdata/fpo or NULL + DWORD64 Params[4]; // possible arguments to the function + BOOL Far; // WOW far call + BOOL Virtual; // is this a virtual frame? + DWORD64 Reserved[3]; + KDHELP64 KdHelp; +} STACKFRAME64, *LPSTACKFRAME64; +typedef +BOOL +(__stdcall *PREAD_PROCESS_MEMORY_ROUTINE64)( + HANDLE hProcess, + DWORD64 qwBaseAddress, + PVOID lpBuffer, + DWORD nSize, + LPDWORD lpNumberOfBytesRead + ); +typedef +PVOID +(__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE64)( + HANDLE hProcess, + DWORD64 AddrBase + ); +typedef +DWORD64 +(__stdcall *PGET_MODULE_BASE_ROUTINE64)( + HANDLE hProcess, + DWORD64 Address + ); +typedef +DWORD64 +(__stdcall *PTRANSLATE_ADDRESS_ROUTINE64)( + HANDLE hProcess, + HANDLE hThread, + LPADDRESS64 lpaddr + ); +#define SYMOPT_CASE_INSENSITIVE 0x00000001 +#define SYMOPT_UNDNAME 0x00000002 +#define SYMOPT_DEFERRED_LOADS 0x00000004 +#define SYMOPT_NO_CPP 0x00000008 +#define SYMOPT_LOAD_LINES 0x00000010 +#define SYMOPT_OMAP_FIND_NEAREST 0x00000020 +#define SYMOPT_LOAD_ANYTHING 0x00000040 +#define SYMOPT_IGNORE_CVREC 0x00000080 +#define SYMOPT_NO_UNQUALIFIED_LOADS 0x00000100 +#define SYMOPT_FAIL_CRITICAL_ERRORS 0x00000200 +#define SYMOPT_EXACT_SYMBOLS 0x00000400 +#define SYMOPT_ALLOW_ABSOLUTE_SYMBOLS 0x00000800 +#define SYMOPT_IGNORE_NT_SYMPATH 0x00001000 +#define SYMOPT_INCLUDE_32BIT_MODULES 0x00002000 +#define SYMOPT_PUBLICS_ONLY 0x00004000 +#define SYMOPT_NO_PUBLICS 0x00008000 +#define SYMOPT_AUTO_PUBLICS 0x00010000 +#define SYMOPT_NO_IMAGE_SEARCH 0x00020000 +#define SYMOPT_SECURE 0x00040000 +#define SYMOPT_DEBUG 0x80000000 +#define UNDNAME_COMPLETE (0x0000) // Enable full undecoration +#define UNDNAME_NAME_ONLY (0x1000) // Crack only the name for primary declaration; +#endif // _MSC_VER < 1300 +#pragma pack(pop) + +// Some missing defines (for VC5/6): +#ifndef INVALID_FILE_ATTRIBUTES +#define INVALID_FILE_ATTRIBUTES ((DWORD)-1) +#endif + + +// secure-CRT_functions are only available starting with VC8 +#if _MSC_VER < 1400 +#define strcpy_s(dst, len, src) strcpy(dst, src) +#define strncpy_s(dst, len, src, maxLen) strncpy(dst, len, src) +#define strcat_s(dst, len, src) strcat(dst, src) +#define _snprintf_s _snprintf +#define _tcscat_s _tcscat +#endif + +static void MyStrCpy(char* szDest, size_t nMaxDestSize, const char* szSrc) +{ + if (nMaxDestSize <= 0) return; + strncpy_s(szDest, nMaxDestSize, szSrc, _TRUNCATE); + szDest[nMaxDestSize-1] = 0; // INFO: _TRUNCATE will ensure that it is nul-terminated; but with older compilers (<1400) it uses "strncpy" and this does not!) +} // MyStrCpy + +// Normally it should be enough to use 'CONTEXT_FULL' (better would be 'CONTEXT_ALL') +#define USED_CONTEXT_FLAGS CONTEXT_FULL + + +class StackWalkerInternal +{ +public: + StackWalkerInternal(StackWalker *parent, HANDLE hProcess) + { + m_parent = parent; + m_hDbhHelp = NULL; + pSC = NULL; + m_hProcess = hProcess; + m_szSymPath = NULL; + pSFTA = NULL; + pSGLFA = NULL; + pSGMB = NULL; + pSGMI = NULL; + pSGO = NULL; + pSGSFA = NULL; + pSI = NULL; + pSLM = NULL; + pSSO = NULL; + pSW = NULL; + pUDSN = NULL; + pSGSP = NULL; + } + ~StackWalkerInternal() + { + if (pSC != NULL) + pSC(m_hProcess); // SymCleanup + if (m_hDbhHelp != NULL) + FreeLibrary(m_hDbhHelp); + m_hDbhHelp = NULL; + m_parent = NULL; + if(m_szSymPath != NULL) + free(m_szSymPath); + m_szSymPath = NULL; + } + BOOL Init(LPCSTR szSymPath) + { + if (m_parent == NULL) + return FALSE; + // Dynamically load the Entry-Points for dbghelp.dll: + // First try to load the newsest one from + TCHAR szTemp[4096]; + // But before wqe do this, we first check if the ".local" file exists + if (GetModuleFileName(NULL, szTemp, 4096) > 0) + { + _tcscat_s(szTemp, _T(".local")); + if (GetFileAttributes(szTemp) == INVALID_FILE_ATTRIBUTES) + { + // ".local" file does not exist, so we can try to load the dbghelp.dll from the "Debugging Tools for Windows" + // Ok, first try the new path according to the archtitecture: +#ifdef _M_IX86 + if ( (m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) ) + { + _tcscat_s(szTemp, _T("\\Debugging Tools for Windows (x86)\\dbghelp.dll")); + // now check if the file exists: + if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) + { + m_hDbhHelp = LoadLibrary(szTemp); + } + } +#elif _M_X64 + if ( (m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) ) + { + _tcscat_s(szTemp, _T("\\Debugging Tools for Windows (x64)\\dbghelp.dll")); + // now check if the file exists: + if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) + { + m_hDbhHelp = LoadLibrary(szTemp); + } + } +#elif _M_IA64 + if ( (m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) ) + { + _tcscat_s(szTemp, _T("\\Debugging Tools for Windows (ia64)\\dbghelp.dll")); + // now check if the file exists: + if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) + { + m_hDbhHelp = LoadLibrary(szTemp); + } + } +#endif + // If still not found, try the old directories... + if ( (m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) ) + { + _tcscat_s(szTemp, _T("\\Debugging Tools for Windows\\dbghelp.dll")); + // now check if the file exists: + if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) + { + m_hDbhHelp = LoadLibrary(szTemp); + } + } +#if defined _M_X64 || defined _M_IA64 + // Still not found? Then try to load the (old) 64-Bit version: + if ( (m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) ) + { + _tcscat_s(szTemp, _T("\\Debugging Tools for Windows 64-Bit\\dbghelp.dll")); + if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) + { + m_hDbhHelp = LoadLibrary(szTemp); + } + } +#endif + } + } + if (m_hDbhHelp == NULL) // if not already loaded, try to load a default-one + m_hDbhHelp = LoadLibrary( _T("dbghelp.dll") ); + if (m_hDbhHelp == NULL) + return FALSE; + pSI = (tSI) GetProcAddress(m_hDbhHelp, "SymInitialize" ); + pSC = (tSC) GetProcAddress(m_hDbhHelp, "SymCleanup" ); + + pSW = (tSW) GetProcAddress(m_hDbhHelp, "StackWalk64" ); + pSGO = (tSGO) GetProcAddress(m_hDbhHelp, "SymGetOptions" ); + pSSO = (tSSO) GetProcAddress(m_hDbhHelp, "SymSetOptions" ); + + pSFTA = (tSFTA) GetProcAddress(m_hDbhHelp, "SymFunctionTableAccess64" ); + pSGLFA = (tSGLFA) GetProcAddress(m_hDbhHelp, "SymGetLineFromAddr64" ); + pSGMB = (tSGMB) GetProcAddress(m_hDbhHelp, "SymGetModuleBase64" ); + pSGMI = (tSGMI) GetProcAddress(m_hDbhHelp, "SymGetModuleInfo64" ); + pSGSFA = (tSGSFA) GetProcAddress(m_hDbhHelp, "SymGetSymFromAddr64" ); + pUDSN = (tUDSN) GetProcAddress(m_hDbhHelp, "UnDecorateSymbolName" ); + pSLM = (tSLM) GetProcAddress(m_hDbhHelp, "SymLoadModule64" ); + pSGSP =(tSGSP) GetProcAddress(m_hDbhHelp, "SymGetSearchPath" ); + + if ( pSC == NULL || pSFTA == NULL || pSGMB == NULL || pSGMI == NULL || + pSGO == NULL || pSGSFA == NULL || pSI == NULL || pSSO == NULL || + pSW == NULL || pUDSN == NULL || pSLM == NULL ) + { + FreeLibrary(m_hDbhHelp); + m_hDbhHelp = NULL; + pSC = NULL; + return FALSE; + } + + // SymInitialize + if (szSymPath != NULL) + m_szSymPath = _strdup(szSymPath); + if (this->pSI(m_hProcess, m_szSymPath, FALSE) == FALSE) + this->m_parent->OnDbgHelpErr("SymInitialize", GetLastError(), 0); + + DWORD symOptions = this->pSGO(); // SymGetOptions + symOptions |= SYMOPT_LOAD_LINES; + symOptions |= SYMOPT_FAIL_CRITICAL_ERRORS; + //symOptions |= SYMOPT_NO_PROMPTS; + // SymSetOptions + symOptions = this->pSSO(symOptions); + + char buf[StackWalker::STACKWALK_MAX_NAMELEN] = {0}; + if (this->pSGSP != NULL) + { + if (this->pSGSP(m_hProcess, buf, StackWalker::STACKWALK_MAX_NAMELEN) == FALSE) + this->m_parent->OnDbgHelpErr("SymGetSearchPath", GetLastError(), 0); + } + char szUserName[1024] = {0}; + DWORD dwSize = 1024; + GetUserNameA(szUserName, &dwSize); + this->m_parent->OnSymInit(buf, symOptions, szUserName); + + return TRUE; + } + + StackWalker *m_parent; + + HMODULE m_hDbhHelp; + HANDLE m_hProcess; + LPSTR m_szSymPath; + +#pragma pack(push,8) +typedef struct IMAGEHLP_MODULE64_V3 { + DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64) + DWORD64 BaseOfImage; // base load address of module + DWORD ImageSize; // virtual size of the loaded module + DWORD TimeDateStamp; // date/time stamp from pe header + DWORD CheckSum; // checksum from the pe header + DWORD NumSyms; // number of symbols in the symbol table + SYM_TYPE SymType; // type of symbols loaded + CHAR ModuleName[32]; // module name + CHAR ImageName[256]; // image name + CHAR LoadedImageName[256]; // symbol file name + // new elements: 07-Jun-2002 + CHAR LoadedPdbName[256]; // pdb file name + DWORD CVSig; // Signature of the CV record in the debug directories + CHAR CVData[MAX_PATH * 3]; // Contents of the CV record + DWORD PdbSig; // Signature of PDB + GUID PdbSig70; // Signature of PDB (VC 7 and up) + DWORD PdbAge; // DBI age of pdb + BOOL PdbUnmatched; // loaded an unmatched pdb + BOOL DbgUnmatched; // loaded an unmatched dbg + BOOL LineNumbers; // we have line number information + BOOL GlobalSymbols; // we have internal symbol information + BOOL TypeInfo; // we have type information + // new elements: 17-Dec-2003 + BOOL SourceIndexed; // pdb supports source server + BOOL Publics; // contains public symbols +}; + +typedef struct IMAGEHLP_MODULE64_V2 { + DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64) + DWORD64 BaseOfImage; // base load address of module + DWORD ImageSize; // virtual size of the loaded module + DWORD TimeDateStamp; // date/time stamp from pe header + DWORD CheckSum; // checksum from the pe header + DWORD NumSyms; // number of symbols in the symbol table + SYM_TYPE SymType; // type of symbols loaded + CHAR ModuleName[32]; // module name + CHAR ImageName[256]; // image name + CHAR LoadedImageName[256]; // symbol file name +}; +#pragma pack(pop) + + + // SymCleanup() + typedef BOOL (__stdcall *tSC)( IN HANDLE hProcess ); + tSC pSC; + + // SymFunctionTableAccess64() + typedef PVOID (__stdcall *tSFTA)( HANDLE hProcess, DWORD64 AddrBase ); + tSFTA pSFTA; + + // SymGetLineFromAddr64() + typedef BOOL (__stdcall *tSGLFA)( IN HANDLE hProcess, IN DWORD64 dwAddr, + OUT PDWORD pdwDisplacement, OUT PIMAGEHLP_LINE64 Line ); + tSGLFA pSGLFA; + + // SymGetModuleBase64() + typedef DWORD64 (__stdcall *tSGMB)( IN HANDLE hProcess, IN DWORD64 dwAddr ); + tSGMB pSGMB; + + // SymGetModuleInfo64() + typedef BOOL (__stdcall *tSGMI)( IN HANDLE hProcess, IN DWORD64 dwAddr, OUT IMAGEHLP_MODULE64_V3 *ModuleInfo ); + tSGMI pSGMI; + + // SymGetOptions() + typedef DWORD (__stdcall *tSGO)( VOID ); + tSGO pSGO; + + // SymGetSymFromAddr64() + typedef BOOL (__stdcall *tSGSFA)( IN HANDLE hProcess, IN DWORD64 dwAddr, + OUT PDWORD64 pdwDisplacement, OUT PIMAGEHLP_SYMBOL64 Symbol ); + tSGSFA pSGSFA; + + // SymInitialize() + typedef BOOL (__stdcall *tSI)( IN HANDLE hProcess, IN PSTR UserSearchPath, IN BOOL fInvadeProcess ); + tSI pSI; + + // SymLoadModule64() + typedef DWORD64 (__stdcall *tSLM)( IN HANDLE hProcess, IN HANDLE hFile, + IN PSTR ImageName, IN PSTR ModuleName, IN DWORD64 BaseOfDll, IN DWORD SizeOfDll ); + tSLM pSLM; + + // SymSetOptions() + typedef DWORD (__stdcall *tSSO)( IN DWORD SymOptions ); + tSSO pSSO; + + // StackWalk64() + typedef BOOL (__stdcall *tSW)( + DWORD MachineType, + HANDLE hProcess, + HANDLE hThread, + LPSTACKFRAME64 StackFrame, + PVOID ContextRecord, + PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, + PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, + PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, + PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress ); + tSW pSW; + + // UnDecorateSymbolName() + typedef DWORD (__stdcall WINAPI *tUDSN)( PCSTR DecoratedName, PSTR UnDecoratedName, + DWORD UndecoratedLength, DWORD Flags ); + tUDSN pUDSN; + + typedef BOOL (__stdcall WINAPI *tSGSP)(HANDLE hProcess, PSTR SearchPath, DWORD SearchPathLength); + tSGSP pSGSP; + + +private: + // **************************************** ToolHelp32 ************************ + #define MAX_MODULE_NAME32 255 + #define TH32CS_SNAPMODULE 0x00000008 + #pragma pack( push, 8 ) + typedef struct tagMODULEENTRY32 + { + DWORD dwSize; + DWORD th32ModuleID; // This module + DWORD th32ProcessID; // owning process + DWORD GlblcntUsage; // Global usage count on the module + DWORD ProccntUsage; // Module usage count in th32ProcessID's context + BYTE * modBaseAddr; // Base address of module in th32ProcessID's context + DWORD modBaseSize; // Size in bytes of module starting at modBaseAddr + HMODULE hModule; // The hModule of this module in th32ProcessID's context + char szModule[MAX_MODULE_NAME32 + 1]; + char szExePath[MAX_PATH]; + } MODULEENTRY32; + typedef MODULEENTRY32 * PMODULEENTRY32; + typedef MODULEENTRY32 * LPMODULEENTRY32; + #pragma pack( pop ) + + BOOL GetModuleListTH32(HANDLE hProcess, DWORD pid) + { + // CreateToolhelp32Snapshot() + typedef HANDLE (__stdcall *tCT32S)(DWORD dwFlags, DWORD th32ProcessID); + // Module32First() + typedef BOOL (__stdcall *tM32F)(HANDLE hSnapshot, LPMODULEENTRY32 lpme); + // Module32Next() + typedef BOOL (__stdcall *tM32N)(HANDLE hSnapshot, LPMODULEENTRY32 lpme); + + // try both dlls... + const TCHAR *dllname[] = { _T("kernel32.dll"), _T("tlhelp32.dll") }; + HINSTANCE hToolhelp = NULL; + tCT32S pCT32S = NULL; + tM32F pM32F = NULL; + tM32N pM32N = NULL; + + HANDLE hSnap; + MODULEENTRY32 me; + me.dwSize = sizeof(me); + BOOL keepGoing; + size_t i; + + for (i = 0; i<(sizeof(dllname) / sizeof(dllname[0])); i++ ) + { + hToolhelp = LoadLibrary( dllname[i] ); + if (hToolhelp == NULL) + continue; + pCT32S = (tCT32S) GetProcAddress(hToolhelp, "CreateToolhelp32Snapshot"); + pM32F = (tM32F) GetProcAddress(hToolhelp, "Module32First"); + pM32N = (tM32N) GetProcAddress(hToolhelp, "Module32Next"); + if ( (pCT32S != NULL) && (pM32F != NULL) && (pM32N != NULL) ) + break; // found the functions! + FreeLibrary(hToolhelp); + hToolhelp = NULL; + } + + if (hToolhelp == NULL) + return FALSE; + + hSnap = pCT32S( TH32CS_SNAPMODULE, pid ); + if (hSnap == (HANDLE) -1) + { + FreeLibrary(hToolhelp); + return FALSE; + } + + keepGoing = !!pM32F( hSnap, &me ); + int cnt = 0; + while (keepGoing) + { + this->LoadModule(hProcess, me.szExePath, me.szModule, (DWORD64) me.modBaseAddr, me.modBaseSize); + cnt++; + keepGoing = !!pM32N( hSnap, &me ); + } + CloseHandle(hSnap); + FreeLibrary(hToolhelp); + if (cnt <= 0) + return FALSE; + return TRUE; + } // GetModuleListTH32 + + // **************************************** PSAPI ************************ + typedef struct _MODULEINFO { + LPVOID lpBaseOfDll; + DWORD SizeOfImage; + LPVOID EntryPoint; + } MODULEINFO, *LPMODULEINFO; + + BOOL GetModuleListPSAPI(HANDLE hProcess) + { + // EnumProcessModules() + typedef BOOL (__stdcall *tEPM)(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded ); + // GetModuleFileNameEx() + typedef DWORD (__stdcall *tGMFNE)(HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize ); + // GetModuleBaseName() + typedef DWORD (__stdcall *tGMBN)(HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize ); + // GetModuleInformation() + typedef BOOL (__stdcall *tGMI)(HANDLE hProcess, HMODULE hModule, LPMODULEINFO pmi, DWORD nSize ); + + HINSTANCE hPsapi; + tEPM pEPM; + tGMFNE pGMFNE; + tGMBN pGMBN; + tGMI pGMI; + + DWORD i; + //ModuleEntry e; + DWORD cbNeeded; + MODULEINFO mi; + HMODULE *hMods = 0; + char *tt = NULL; + char *tt2 = NULL; + const SIZE_T TTBUFLEN = 8096; + int cnt = 0; + + hPsapi = LoadLibrary( _T("psapi.dll") ); + if (hPsapi == NULL) + return FALSE; + + pEPM = (tEPM) GetProcAddress( hPsapi, "EnumProcessModules" ); + pGMFNE = (tGMFNE) GetProcAddress( hPsapi, "GetModuleFileNameExA" ); + pGMBN = (tGMFNE) GetProcAddress( hPsapi, "GetModuleBaseNameA" ); + pGMI = (tGMI) GetProcAddress( hPsapi, "GetModuleInformation" ); + if ( (pEPM == NULL) || (pGMFNE == NULL) || (pGMBN == NULL) || (pGMI == NULL) ) + { + // we couldn´t find all functions + FreeLibrary(hPsapi); + return FALSE; + } + + hMods = (HMODULE*) malloc(sizeof(HMODULE) * (TTBUFLEN / sizeof(HMODULE))); + tt = (char*) malloc(sizeof(char) * TTBUFLEN); + tt2 = (char*) malloc(sizeof(char) * TTBUFLEN); + if ( (hMods == NULL) || (tt == NULL) || (tt2 == NULL) ) + goto cleanup; + + if ( ! pEPM( hProcess, hMods, TTBUFLEN, &cbNeeded ) ) + { + //_ftprintf(fLogFile, _T("%lu: EPM failed, GetLastError = %lu\n"), g_dwShowCount, gle ); + goto cleanup; + } + + if ( cbNeeded > TTBUFLEN ) + { + //_ftprintf(fLogFile, _T("%lu: More than %lu module handles. Huh?\n"), g_dwShowCount, lenof( hMods ) ); + goto cleanup; + } + + for ( i = 0; i < cbNeeded / sizeof(hMods[0]); i++ ) + { + // base address, size + pGMI(hProcess, hMods[i], &mi, sizeof(mi)); + // image file name + tt[0] = 0; + pGMFNE(hProcess, hMods[i], tt, TTBUFLEN ); + // module name + tt2[0] = 0; + pGMBN(hProcess, hMods[i], tt2, TTBUFLEN ); + + DWORD dwRes = this->LoadModule(hProcess, tt, tt2, (DWORD64) mi.lpBaseOfDll, mi.SizeOfImage); + if (dwRes != ERROR_SUCCESS) + this->m_parent->OnDbgHelpErr("LoadModule", dwRes, 0); + cnt++; + } + + cleanup: + if (hPsapi != NULL) FreeLibrary(hPsapi); + if (tt2 != NULL) free(tt2); + if (tt != NULL) free(tt); + if (hMods != NULL) free(hMods); + + return cnt != 0; + } // GetModuleListPSAPI + + DWORD LoadModule(HANDLE hProcess, LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size) + { + CHAR *szImg = _strdup(img); + CHAR *szMod = _strdup(mod); + DWORD result = ERROR_SUCCESS; + if ( (szImg == NULL) || (szMod == NULL) ) + result = ERROR_NOT_ENOUGH_MEMORY; + else + { + if (pSLM(hProcess, 0, szImg, szMod, baseAddr, size) == 0) + result = GetLastError(); + } + ULONGLONG fileVersion = 0; + if ( (m_parent != NULL) && (szImg != NULL) ) + { + // try to retrive the file-version: + if ( (this->m_parent->m_options & StackWalker::RetrieveFileVersion) != 0) + { + VS_FIXEDFILEINFO *fInfo = NULL; + DWORD dwHandle; + DWORD dwSize = GetFileVersionInfoSizeA(szImg, &dwHandle); + if (dwSize > 0) + { + LPVOID vData = malloc(dwSize); + if (vData != NULL) + { + if (GetFileVersionInfoA(szImg, dwHandle, dwSize, vData) != 0) + { + UINT len; + TCHAR szSubBlock[] = _T("\\"); + if (VerQueryValue(vData, szSubBlock, (LPVOID*) &fInfo, &len) == 0) + fInfo = NULL; + else + { + fileVersion = ((ULONGLONG)fInfo->dwFileVersionLS) + ((ULONGLONG)fInfo->dwFileVersionMS << 32); + } + } + free(vData); + } + } + } + + // Retrive some additional-infos about the module + IMAGEHLP_MODULE64_V3 Module; + const char *szSymType = "-unknown-"; + if (this->GetModuleInfo(hProcess, baseAddr, &Module) != FALSE) + { + switch(Module.SymType) + { + case SymNone: + szSymType = "-nosymbols-"; + break; + case SymCoff: // 1 + szSymType = "COFF"; + break; + case SymCv: // 2 + szSymType = "CV"; + break; + case SymPdb: // 3 + szSymType = "PDB"; + break; + case SymExport: // 4 + szSymType = "-exported-"; + break; + case SymDeferred: // 5 + szSymType = "-deferred-"; + break; + case SymSym: // 6 + szSymType = "SYM"; + break; + case 7: // SymDia: + szSymType = "DIA"; + break; + case 8: //SymVirtual: + szSymType = "Virtual"; + break; + } + } + LPCSTR pdbName = Module.LoadedImageName; + if (Module.LoadedPdbName[0] != 0) + pdbName = Module.LoadedPdbName; + this->m_parent->OnLoadModule(img, mod, baseAddr, size, result, szSymType, pdbName, fileVersion); + } + if (szImg != NULL) free(szImg); + if (szMod != NULL) free(szMod); + return result; + } +public: + BOOL LoadModules(HANDLE hProcess, DWORD dwProcessId) + { + // first try toolhelp32 + if (GetModuleListTH32(hProcess, dwProcessId)) + return true; + // then try psapi + return GetModuleListPSAPI(hProcess); + } + + + BOOL GetModuleInfo(HANDLE hProcess, DWORD64 baseAddr, IMAGEHLP_MODULE64_V3 *pModuleInfo) + { + memset(pModuleInfo, 0, sizeof(IMAGEHLP_MODULE64_V3)); + if(this->pSGMI == NULL) + { + SetLastError(ERROR_DLL_INIT_FAILED); + return FALSE; + } + // First try to use the larger ModuleInfo-Structure + pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V3); + void *pData = malloc(4096); // reserve enough memory, so the bug in v6.3.5.1 does not lead to memory-overwrites... + if (pData == NULL) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + memcpy(pData, pModuleInfo, sizeof(IMAGEHLP_MODULE64_V3)); + static bool s_useV3Version = true; + if (s_useV3Version) + { + if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V3*) pData) != FALSE) + { + // only copy as much memory as is reserved... + memcpy(pModuleInfo, pData, sizeof(IMAGEHLP_MODULE64_V3)); + pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V3); + free(pData); + return TRUE; + } + s_useV3Version = false; // to prevent unneccessarry calls with the larger struct... + } + + // could not retrive the bigger structure, try with the smaller one (as defined in VC7.1)... + pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V2); + memcpy(pData, pModuleInfo, sizeof(IMAGEHLP_MODULE64_V2)); + if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V3*) pData) != FALSE) + { + // only copy as much memory as is reserved... + memcpy(pModuleInfo, pData, sizeof(IMAGEHLP_MODULE64_V2)); + pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V2); + free(pData); + return TRUE; + } + free(pData); + SetLastError(ERROR_DLL_INIT_FAILED); + return FALSE; + } +}; + +// ############################################################# +StackWalker::StackWalker(DWORD dwProcessId, HANDLE hProcess) +{ + this->m_options = OptionsAll; + this->m_modulesLoaded = FALSE; + this->m_hProcess = hProcess; + this->m_sw = new StackWalkerInternal(this, this->m_hProcess); + this->m_dwProcessId = dwProcessId; + this->m_szSymPath = NULL; + this->m_MaxRecursionCount = 1000; +} +StackWalker::StackWalker(int options, LPCSTR szSymPath, DWORD dwProcessId, HANDLE hProcess) +{ + this->m_options = options; + this->m_modulesLoaded = FALSE; + this->m_hProcess = hProcess; + this->m_sw = new StackWalkerInternal(this, this->m_hProcess); + this->m_dwProcessId = dwProcessId; + if (szSymPath != NULL) + { + this->m_szSymPath = _strdup(szSymPath); + this->m_options |= SymBuildPath; + } + else + this->m_szSymPath = NULL; + this->m_MaxRecursionCount = 1000; +} + +StackWalker::~StackWalker() +{ + if (m_szSymPath != NULL) + free(m_szSymPath); + m_szSymPath = NULL; + if (this->m_sw != NULL) + delete this->m_sw; + this->m_sw = NULL; +} + +BOOL StackWalker::LoadModules() +{ + if (this->m_sw == NULL) + { + SetLastError(ERROR_DLL_INIT_FAILED); + return FALSE; + } + if (m_modulesLoaded != FALSE) + return TRUE; + + // Build the sym-path: + char *szSymPath = NULL; + if ( (this->m_options & SymBuildPath) != 0) + { + const size_t nSymPathLen = 4096; + szSymPath = (char*) malloc(nSymPathLen); + if (szSymPath == NULL) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + szSymPath[0] = 0; + // Now first add the (optional) provided sympath: + if (this->m_szSymPath != NULL) + { + strcat_s(szSymPath, nSymPathLen, this->m_szSymPath); + strcat_s(szSymPath, nSymPathLen, ";"); + } + + strcat_s(szSymPath, nSymPathLen, ".;"); + + const size_t nTempLen = 1024; + char szTemp[nTempLen]; + // Now add the current directory: + if (GetCurrentDirectoryA(nTempLen, szTemp) > 0) + { + szTemp[nTempLen-1] = 0; + strcat_s(szSymPath, nSymPathLen, szTemp); + strcat_s(szSymPath, nSymPathLen, ";"); + } + + // Now add the path for the main-module: + if (GetModuleFileNameA(NULL, szTemp, nTempLen) > 0) + { + szTemp[nTempLen-1] = 0; + for (char *p = (szTemp+strlen(szTemp)-1); p >= szTemp; --p) + { + // locate the rightmost path separator + if ( (*p == '\\') || (*p == '/') || (*p == ':') ) + { + *p = 0; + break; + } + } // for (search for path separator...) + if (strlen(szTemp) > 0) + { + strcat_s(szSymPath, nSymPathLen, szTemp); + strcat_s(szSymPath, nSymPathLen, ";"); + } + } + if (GetEnvironmentVariableA("_NT_SYMBOL_PATH", szTemp, nTempLen) > 0) + { + szTemp[nTempLen-1] = 0; + strcat_s(szSymPath, nSymPathLen, szTemp); + strcat_s(szSymPath, nSymPathLen, ";"); + } + if (GetEnvironmentVariableA("_NT_ALTERNATE_SYMBOL_PATH", szTemp, nTempLen) > 0) + { + szTemp[nTempLen-1] = 0; + strcat_s(szSymPath, nSymPathLen, szTemp); + strcat_s(szSymPath, nSymPathLen, ";"); + } + if (GetEnvironmentVariableA("SYSTEMROOT", szTemp, nTempLen) > 0) + { + szTemp[nTempLen-1] = 0; + strcat_s(szSymPath, nSymPathLen, szTemp); + strcat_s(szSymPath, nSymPathLen, ";"); + // also add the "system32"-directory: + strcat_s(szTemp, nTempLen, "\\system32"); + strcat_s(szSymPath, nSymPathLen, szTemp); + strcat_s(szSymPath, nSymPathLen, ";"); + } + + if ( (this->m_options & SymUseSymSrv) != 0) + { + if (GetEnvironmentVariableA("SYSTEMDRIVE", szTemp, nTempLen) > 0) + { + szTemp[nTempLen-1] = 0; + strcat_s(szSymPath, nSymPathLen, "SRV*"); + strcat_s(szSymPath, nSymPathLen, szTemp); + strcat_s(szSymPath, nSymPathLen, "\\websymbols"); + strcat_s(szSymPath, nSymPathLen, "*http://msdl.microsoft.com/download/symbols;"); + } + else + strcat_s(szSymPath, nSymPathLen, "SRV*c:\\websymbols*http://msdl.microsoft.com/download/symbols;"); + } + } // if SymBuildPath + + // First Init the whole stuff... + BOOL bRet = this->m_sw->Init(szSymPath); + if (szSymPath != NULL) free(szSymPath); szSymPath = NULL; + if (bRet == FALSE) + { + this->OnDbgHelpErr("Error while initializing dbghelp.dll", 0, 0); + SetLastError(ERROR_DLL_INIT_FAILED); + return FALSE; + } + + bRet = this->m_sw->LoadModules(this->m_hProcess, this->m_dwProcessId); + if (bRet != FALSE) + m_modulesLoaded = TRUE; + return bRet; +} + + +// The following is used to pass the "userData"-Pointer to the user-provided readMemoryFunction +// This has to be done due to a problem with the "hProcess"-parameter in x64... +// Because this class is in no case multi-threading-enabled (because of the limitations +// of dbghelp.dll) it is "safe" to use a static-variable +static StackWalker::PReadProcessMemoryRoutine s_readMemoryFunction = NULL; +static LPVOID s_readMemoryFunction_UserData = NULL; + +BOOL StackWalker::ShowCallstack(HANDLE hThread, const CONTEXT *context, PReadProcessMemoryRoutine readMemoryFunction, LPVOID pUserData) +{ + CONTEXT c; + CallstackEntry csEntry; + IMAGEHLP_SYMBOL64 *pSym = NULL; + StackWalkerInternal::IMAGEHLP_MODULE64_V3 Module; + IMAGEHLP_LINE64 Line; + int frameNum; + bool bLastEntryCalled = true; + int curRecursionCount = 0; + + if (m_modulesLoaded == FALSE) + this->LoadModules(); // ignore the result... + + if (this->m_sw->m_hDbhHelp == NULL) + { + SetLastError(ERROR_DLL_INIT_FAILED); + return FALSE; + } + + s_readMemoryFunction = readMemoryFunction; + s_readMemoryFunction_UserData = pUserData; + + if (context == NULL) + { + // If no context is provided, capture the context + // See: https://stackwalker.codeplex.com/discussions/446958 +#if _WIN32_WINNT <= 0x0501 + // If we need to support XP, we need to use the "old way", because "GetThreadId" is not available! + if (hThread == GetCurrentThread()) +#else + if (GetThreadId(hThread) == GetCurrentThreadId()) +#endif + { + GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, USED_CONTEXT_FLAGS); + } + else + { + SuspendThread(hThread); + memset(&c, 0, sizeof(CONTEXT)); + c.ContextFlags = USED_CONTEXT_FLAGS; + + // TODO: Detect if you want to get a thread context of a different process, which is running a different processor architecture... + // This does only work if we are x64 and the target process is x64 or x86; + // It cannnot work, if this process is x64 and the target process is x64... this is not supported... + // See also: http://www.howzatt.demon.co.uk/articles/DebuggingInWin64.html + if (GetThreadContext(hThread, &c) == FALSE) + { + ResumeThread(hThread); + return FALSE; + } + } + } + else + c = *context; + + // init STACKFRAME for first call + STACKFRAME64 s; // in/out stackframe + memset(&s, 0, sizeof(s)); + DWORD imageType; +#ifdef _M_IX86 + // normally, call ImageNtHeader() and use machine info from PE header + imageType = IMAGE_FILE_MACHINE_I386; + s.AddrPC.Offset = c.Eip; + s.AddrPC.Mode = AddrModeFlat; + s.AddrFrame.Offset = c.Ebp; + s.AddrFrame.Mode = AddrModeFlat; + s.AddrStack.Offset = c.Esp; + s.AddrStack.Mode = AddrModeFlat; +#elif _M_X64 + imageType = IMAGE_FILE_MACHINE_AMD64; + s.AddrPC.Offset = c.Rip; + s.AddrPC.Mode = AddrModeFlat; + s.AddrFrame.Offset = c.Rsp; + s.AddrFrame.Mode = AddrModeFlat; + s.AddrStack.Offset = c.Rsp; + s.AddrStack.Mode = AddrModeFlat; +#elif _M_IA64 + imageType = IMAGE_FILE_MACHINE_IA64; + s.AddrPC.Offset = c.StIIP; + s.AddrPC.Mode = AddrModeFlat; + s.AddrFrame.Offset = c.IntSp; + s.AddrFrame.Mode = AddrModeFlat; + s.AddrBStore.Offset = c.RsBSP; + s.AddrBStore.Mode = AddrModeFlat; + s.AddrStack.Offset = c.IntSp; + s.AddrStack.Mode = AddrModeFlat; +#else +#error "Platform not supported!" +#endif + + pSym = (IMAGEHLP_SYMBOL64 *) malloc(sizeof(IMAGEHLP_SYMBOL64) + STACKWALK_MAX_NAMELEN); + if (!pSym) goto cleanup; // not enough memory... + memset(pSym, 0, sizeof(IMAGEHLP_SYMBOL64) + STACKWALK_MAX_NAMELEN); + pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); + pSym->MaxNameLength = STACKWALK_MAX_NAMELEN; + + memset(&Line, 0, sizeof(Line)); + Line.SizeOfStruct = sizeof(Line); + + memset(&Module, 0, sizeof(Module)); + Module.SizeOfStruct = sizeof(Module); + + for (frameNum = 0; ; ++frameNum ) + { + // get next stack frame (StackWalk64(), SymFunctionTableAccess64(), SymGetModuleBase64()) + // if this returns ERROR_INVALID_ADDRESS (487) or ERROR_NOACCESS (998), you can + // assume that either you are done, or that the stack is so hosed that the next + // deeper frame could not be found. + // CONTEXT need not to be suplied if imageTyp is IMAGE_FILE_MACHINE_I386! + if ( ! this->m_sw->pSW(imageType, this->m_hProcess, hThread, &s, &c, myReadProcMem, this->m_sw->pSFTA, this->m_sw->pSGMB, NULL) ) + { + // INFO: "StackWalk64" does not set "GetLastError"... + this->OnDbgHelpErr("StackWalk64", 0, s.AddrPC.Offset); + break; + } + + csEntry.offset = s.AddrPC.Offset; + csEntry.name[0] = 0; + csEntry.undName[0] = 0; + csEntry.undFullName[0] = 0; + csEntry.offsetFromSmybol = 0; + csEntry.offsetFromLine = 0; + csEntry.lineFileName[0] = 0; + csEntry.lineNumber = 0; + csEntry.loadedImageName[0] = 0; + csEntry.moduleName[0] = 0; + if (s.AddrPC.Offset == s.AddrReturn.Offset) + { + if ( (this->m_MaxRecursionCount > 0) && (curRecursionCount > m_MaxRecursionCount) ) + { + this->OnDbgHelpErr("StackWalk64-Endless-Callstack!", 0, s.AddrPC.Offset); + break; + } + curRecursionCount++; + } + else + curRecursionCount = 0; + if (s.AddrPC.Offset != 0) + { + // we seem to have a valid PC + // show procedure info (SymGetSymFromAddr64()) + if (this->m_sw->pSGSFA(this->m_hProcess, s.AddrPC.Offset, &(csEntry.offsetFromSmybol), pSym) != FALSE) + { + MyStrCpy(csEntry.name, STACKWALK_MAX_NAMELEN, pSym->Name); + // UnDecorateSymbolName() + this->m_sw->pUDSN( pSym->Name, csEntry.undName, STACKWALK_MAX_NAMELEN, UNDNAME_NAME_ONLY ); + this->m_sw->pUDSN( pSym->Name, csEntry.undFullName, STACKWALK_MAX_NAMELEN, UNDNAME_COMPLETE ); + } + else + { + this->OnDbgHelpErr("SymGetSymFromAddr64", GetLastError(), s.AddrPC.Offset); + } + + // show line number info, NT5.0-method (SymGetLineFromAddr64()) + if (this->m_sw->pSGLFA != NULL ) + { // yes, we have SymGetLineFromAddr64() + if (this->m_sw->pSGLFA(this->m_hProcess, s.AddrPC.Offset, &(csEntry.offsetFromLine), &Line) != FALSE) + { + csEntry.lineNumber = Line.LineNumber; + MyStrCpy(csEntry.lineFileName, STACKWALK_MAX_NAMELEN, Line.FileName); + } + else + { + this->OnDbgHelpErr("SymGetLineFromAddr64", GetLastError(), s.AddrPC.Offset); + } + } // yes, we have SymGetLineFromAddr64() + + // show module info (SymGetModuleInfo64()) + if (this->m_sw->GetModuleInfo(this->m_hProcess, s.AddrPC.Offset, &Module ) != FALSE) + { // got module info OK + switch ( Module.SymType ) + { + case SymNone: + csEntry.symTypeString = "-nosymbols-"; + break; + case SymCoff: + csEntry.symTypeString = "COFF"; + break; + case SymCv: + csEntry.symTypeString = "CV"; + break; + case SymPdb: + csEntry.symTypeString = "PDB"; + break; + case SymExport: + csEntry.symTypeString = "-exported-"; + break; + case SymDeferred: + csEntry.symTypeString = "-deferred-"; + break; + case SymSym: + csEntry.symTypeString = "SYM"; + break; +#if API_VERSION_NUMBER >= 9 + case SymDia: + csEntry.symTypeString = "DIA"; + break; +#endif + case 8: //SymVirtual: + csEntry.symTypeString = "Virtual"; + break; + default: + //_snprintf( ty, sizeof(ty), "symtype=%ld", (long) Module.SymType ); + csEntry.symTypeString = NULL; + break; + } + + MyStrCpy(csEntry.moduleName, STACKWALK_MAX_NAMELEN, Module.ModuleName); + csEntry.baseOfImage = Module.BaseOfImage; + MyStrCpy(csEntry.loadedImageName, STACKWALK_MAX_NAMELEN, Module.LoadedImageName); + } // got module info OK + else + { + this->OnDbgHelpErr("SymGetModuleInfo64", GetLastError(), s.AddrPC.Offset); + } + } // we seem to have a valid PC + + CallstackEntryType et = nextEntry; + if (frameNum == 0) + et = firstEntry; + bLastEntryCalled = false; + this->OnCallstackEntry(et, csEntry); + + if (s.AddrReturn.Offset == 0) + { + bLastEntryCalled = true; + this->OnCallstackEntry(lastEntry, csEntry); + SetLastError(ERROR_SUCCESS); + break; + } + } // for ( frameNum ) + + cleanup: + if (pSym) free( pSym ); + + if (bLastEntryCalled == false) + this->OnCallstackEntry(lastEntry, csEntry); + + if (context == NULL) + ResumeThread(hThread); + + return TRUE; +} + +BOOL __stdcall StackWalker::myReadProcMem( + HANDLE hProcess, + DWORD64 qwBaseAddress, + PVOID lpBuffer, + DWORD nSize, + LPDWORD lpNumberOfBytesRead + ) +{ + if (s_readMemoryFunction == NULL) + { + SIZE_T st; + BOOL bRet = ReadProcessMemory(hProcess, (LPVOID) qwBaseAddress, lpBuffer, nSize, &st); + *lpNumberOfBytesRead = (DWORD) st; + //printf("ReadMemory: hProcess: %p, baseAddr: %p, buffer: %p, size: %d, read: %d, result: %d\n", hProcess, (LPVOID) qwBaseAddress, lpBuffer, nSize, (DWORD) st, (DWORD) bRet); + return bRet; + } + else + { + return s_readMemoryFunction(hProcess, qwBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead, s_readMemoryFunction_UserData); + } +} + +void StackWalker::OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion) +{ + CHAR buffer[STACKWALK_MAX_NAMELEN]; + if (fileVersion == 0) + _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%s:%s (%p), size: %d (result: %d), SymType: '%s', PDB: '%s'\n", img, mod, (LPVOID) baseAddr, size, result, symType, pdbName); + else + { + DWORD v4 = (DWORD) (fileVersion & 0xFFFF); + DWORD v3 = (DWORD) ((fileVersion>>16) & 0xFFFF); + DWORD v2 = (DWORD) ((fileVersion>>32) & 0xFFFF); + DWORD v1 = (DWORD) ((fileVersion>>48) & 0xFFFF); + _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%s:%s (%p), size: %d (result: %d), SymType: '%s', PDB: '%s', fileVersion: %d.%d.%d.%d\n", img, mod, (LPVOID) baseAddr, size, result, symType, pdbName, v1, v2, v3, v4); + } + OnOutput(buffer); +} + +void StackWalker::OnCallstackEntry(CallstackEntryType eType, CallstackEntry &entry) +{ + CHAR buffer[STACKWALK_MAX_NAMELEN]; + if ( (eType != lastEntry) && (entry.offset != 0) ) + { + if (entry.name[0] == 0) + MyStrCpy(entry.name, STACKWALK_MAX_NAMELEN, "(function-name not available)"); + if (entry.undName[0] != 0) + MyStrCpy(entry.name, STACKWALK_MAX_NAMELEN, entry.undName); + if (entry.undFullName[0] != 0) + MyStrCpy(entry.name, STACKWALK_MAX_NAMELEN, entry.undFullName); + if (entry.lineFileName[0] == 0) + { + MyStrCpy(entry.lineFileName, STACKWALK_MAX_NAMELEN, "(filename not available)"); + if (entry.moduleName[0] == 0) + MyStrCpy(entry.moduleName, STACKWALK_MAX_NAMELEN, "(module-name not available)"); + _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%p (%s): %s: %s\n", (LPVOID) entry.offset, entry.moduleName, entry.lineFileName, entry.name); + } + else + _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%s (%d): %s\n", entry.lineFileName, entry.lineNumber, entry.name); + buffer[STACKWALK_MAX_NAMELEN-1] = 0; + OnOutput(buffer); + } +} + +void StackWalker::OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr) +{ + CHAR buffer[STACKWALK_MAX_NAMELEN]; + _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "ERROR: %s, GetLastError: %d (Address: %p)\n", szFuncName, gle, (LPVOID) addr); + OnOutput(buffer); +} + +void StackWalker::OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName) +{ + CHAR buffer[STACKWALK_MAX_NAMELEN]; + _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "SymInit: Symbol-SearchPath: '%s', symOptions: %d, UserName: '%s'\n", szSearchPath, symOptions, szUserName); + OnOutput(buffer); + // Also display the OS-version +#if _MSC_VER <= 1200 + OSVERSIONINFOA ver; + ZeroMemory(&ver, sizeof(OSVERSIONINFOA)); + ver.dwOSVersionInfoSize = sizeof(ver); + if (GetVersionExA(&ver) != FALSE) + { + _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "OS-Version: %d.%d.%d (%s)\n", + ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber, + ver.szCSDVersion); + OnOutput(buffer); + } +#else + OSVERSIONINFOEXA ver; + ZeroMemory(&ver, sizeof(OSVERSIONINFOEXA)); + ver.dwOSVersionInfoSize = sizeof(ver); +#if _MSC_VER >= 1900 +#pragma warning(push) +#pragma warning(disable: 4996) +#endif + if (GetVersionExA( (OSVERSIONINFOA*) &ver) != FALSE) + { + _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "OS-Version: %d.%d.%d (%s) 0x%x-0x%x\n", + ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber, + ver.szCSDVersion, ver.wSuiteMask, ver.wProductType); + OnOutput(buffer); + } +#if _MSC_VER >= 1900 +#pragma warning(pop) +#endif +#endif +} + +void StackWalker::OnOutput(LPCSTR buffer) +{ + OutputDebugStringA(buffer); +} diff --git a/runtime/flangrti/trace/c_interface.cxx b/runtime/flangrti/trace/c_interface.cxx new file mode 100644 index 00000000000..9b5c89f9c16 --- /dev/null +++ b/runtime/flangrti/trace/c_interface.cxx @@ -0,0 +1,20 @@ +#include +#include +#include + +extern "C" { #include "trace/c_interface.h" } +#include "trace/StackWalker.h" + +void SignalHandler(int signal) +{ + StackWalker sw; sw.ShowCallstack(); + exit(1); +} + +extern "C" void _install_win32_handlers() +{ + typedef void (*SignalHandlerPointer)(int); + + SignalHandlerPointer previousHandler; + previousHandler = signal(SIGSEGV , SignalHandler); +} diff --git a/runtime/flangrti/trace/c_interface.h b/runtime/flangrti/trace/c_interface.h new file mode 100644 index 00000000000..43c9e2df04f --- /dev/null +++ b/runtime/flangrti/trace/c_interface.h @@ -0,0 +1 @@ +extern void _install_win32_handlers(); diff --git a/runtime/flangrti/trace/stackwalker.h b/runtime/flangrti/trace/stackwalker.h new file mode 100644 index 00000000000..f3dbe749a78 --- /dev/null +++ b/runtime/flangrti/trace/stackwalker.h @@ -0,0 +1,218 @@ +/********************************************************************** + * + * StackWalker.h + * + * + * + * LICENSE (http://www.opensource.org/licenses/bsd-license.php) + * + * Copyright (c) 2005-2009, Jochen Kalmbach + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of Jochen Kalmbach nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * **********************************************************************/ +// #pragma once is supported starting with _MCS_VER 1000, +// so we need not to check the version (because we only support _MSC_VER >= 1100)! +#pragma once + +#include + +#if _MSC_VER >= 1900 +#pragma warning(disable : 4091) +#endif + +// special defines for VC5/6 (if no actual PSDK is installed): +#if _MSC_VER < 1300 +typedef unsigned __int64 DWORD64, *PDWORD64; +#if defined(_WIN64) +typedef unsigned __int64 SIZE_T, *PSIZE_T; +#else +typedef unsigned long SIZE_T, *PSIZE_T; +#endif +#endif // _MSC_VER < 1300 + +class StackWalkerInternal; // forward +class StackWalker +{ +public: + typedef enum StackWalkOptions + { + // No addition info will be retrived + // (only the address is available) + RetrieveNone = 0, + + // Try to get the symbol-name + RetrieveSymbol = 1, + + // Try to get the line for this symbol + RetrieveLine = 2, + + // Try to retrieve the module-infos + RetrieveModuleInfo = 4, + + // Also retrieve the version for the DLL/EXE + RetrieveFileVersion = 8, + + // Contains all the abouve + RetrieveVerbose = 0xF, + + // Generate a "good" symbol-search-path + SymBuildPath = 0x10, + + // Also use the public Microsoft-Symbol-Server + SymUseSymSrv = 0x20, + + // Contains all the abouve "Sym"-options + SymAll = 0x30, + + // Contains all options (default) + OptionsAll = 0x3F + } StackWalkOptions; + + StackWalker( + int options = OptionsAll, // 'int' is by design, to combine the enum-flags + LPCSTR szSymPath = NULL, + DWORD dwProcessId = GetCurrentProcessId(), + HANDLE hProcess = GetCurrentProcess() + ); + StackWalker(DWORD dwProcessId, HANDLE hProcess); + virtual ~StackWalker(); + + typedef BOOL (__stdcall *PReadProcessMemoryRoutine)( + HANDLE hProcess, + DWORD64 qwBaseAddress, + PVOID lpBuffer, + DWORD nSize, + LPDWORD lpNumberOfBytesRead, + LPVOID pUserData // optional data, which was passed in "ShowCallstack" + ); + + BOOL LoadModules(); + + BOOL ShowCallstack( + HANDLE hThread = GetCurrentThread(), + const CONTEXT *context = NULL, + PReadProcessMemoryRoutine readMemoryFunction = NULL, + LPVOID pUserData = NULL // optional to identify some data in the 'readMemoryFunction'-callback + ); + +#if _MSC_VER >= 1300 +// due to some reasons, the "STACKWALK_MAX_NAMELEN" must be declared as "public" +// in older compilers in order to use it... starting with VC7 we can declare it as "protected" +protected: +#endif + enum { STACKWALK_MAX_NAMELEN = 1024 }; // max name length for found symbols + +protected: + // Entry for each Callstack-Entry + typedef struct CallstackEntry + { + DWORD64 offset; // if 0, we have no valid entry + CHAR name[STACKWALK_MAX_NAMELEN]; + CHAR undName[STACKWALK_MAX_NAMELEN]; + CHAR undFullName[STACKWALK_MAX_NAMELEN]; + DWORD64 offsetFromSmybol; + DWORD offsetFromLine; + DWORD lineNumber; + CHAR lineFileName[STACKWALK_MAX_NAMELEN]; + DWORD symType; + LPCSTR symTypeString; + CHAR moduleName[STACKWALK_MAX_NAMELEN]; + DWORD64 baseOfImage; + CHAR loadedImageName[STACKWALK_MAX_NAMELEN]; + } CallstackEntry; + + typedef enum CallstackEntryType {firstEntry, nextEntry, lastEntry}; + + virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName); + virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion); + virtual void OnCallstackEntry(CallstackEntryType eType, CallstackEntry &entry); + virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr); + virtual void OnOutput(LPCSTR szText); + + StackWalkerInternal *m_sw; + HANDLE m_hProcess; + DWORD m_dwProcessId; + BOOL m_modulesLoaded; + LPSTR m_szSymPath; + + int m_options; + int m_MaxRecursionCount; + + static BOOL __stdcall myReadProcMem(HANDLE hProcess, DWORD64 qwBaseAddress, PVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead); + + friend StackWalkerInternal; +}; // class StackWalker + + +// The "ugly" assembler-implementation is needed for systems before XP +// If you have a new PSDK and you only compile for XP and later, then you can use +// the "RtlCaptureContext" +// Currently there is no define which determines the PSDK-Version... +// So we just use the compiler-version (and assumes that the PSDK is +// the one which was installed by the VS-IDE) + +// INFO: If you want, you can use the RtlCaptureContext if you only target XP and later... +// But I currently use it in x64/IA64 environments... +//#if defined(_M_IX86) && (_WIN32_WINNT <= 0x0500) && (_MSC_VER < 1400) + +#if defined(_M_IX86) +#ifdef CURRENT_THREAD_VIA_EXCEPTION +// TODO: The following is not a "good" implementation, +// because the callstack is only valid in the "__except" block... +#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \ + do { \ + memset(&c, 0, sizeof(CONTEXT)); \ + EXCEPTION_POINTERS *pExp = NULL; \ + __try { \ + throw 0; \ + } __except( ( (pExp = GetExceptionInformation()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_EXECUTE_HANDLER)) {} \ + if (pExp != NULL) \ + memcpy(&c, pExp->ContextRecord, sizeof(CONTEXT)); \ + c.ContextFlags = contextFlags; \ + } while(0); +#else +// The following should be enough for walking the callstack... +#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \ + do { \ + memset(&c, 0, sizeof(CONTEXT)); \ + c.ContextFlags = contextFlags; \ + __asm call x \ + __asm x: pop eax \ + __asm mov c.Eip, eax \ + __asm mov c.Ebp, ebp \ + __asm mov c.Esp, esp \ + } while(0); +#endif + +#else + +// The following is defined for x86 (XP and higher), x64 and IA64: +#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \ + do { \ + memset(&c, 0, sizeof(CONTEXT)); \ + c.ContextFlags = contextFlags; \ + RtlCaptureContext(&c); \ +} while(0); +#endif diff --git a/runtime/flangrti/trace_lin.c b/runtime/flangrti/trace_lin.c index 5fbede6daa6..f9ecb9f8290 100644 --- a/runtime/flangrti/trace_lin.c +++ b/runtime/flangrti/trace_lin.c @@ -194,9 +194,12 @@ __abort_sig_init(void) } #else +#include "signal/c_interface.h" void __abort_trace(int skip) { } void __abort_sig_init(void) -{ } -#endif \ No newline at end of file +{ + _install_win32_handlers(); +} +#endif From b24f16cd2df5ed7d9e2934c582b794b13e648a50 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 26 Oct 2017 13:45:52 -0500 Subject: [PATCH 049/141] [cmake] add include directories and objects [cmake] remove includes for shared [cmake] remove shared [cmake] fix include directories --- runtime/flangrti/CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index bf0da741014..68ca8d0c2e3 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -161,6 +161,8 @@ SET(PGC_SRC_FILES tanh.c trace_lin.c trace.c + trace/c_interface.cxx + trace/StackWalker.cpp anint.c dnint.c idnint.c @@ -179,12 +181,17 @@ add_flang_library(flangrti_static ${PGC_SRC_FILES} ${SHARED_SOURCES} ) + if (MSVC) set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME libflangrti) else() set_property(TARGET flangrti_static PROPERTY OUTPUT_NAME flangrti) endif() +target_include_directories(flangrti_static + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) set(SHARED_LIBRARY TRUE) add_flang_library(flangrti_shared @@ -192,6 +199,7 @@ add_flang_library(flangrti_shared ${SHARED_SOURCES} ) + # Resolve symbols against libm if (NOT MSVC) @@ -222,11 +230,11 @@ target_include_directories(flangrti_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) - + target_include_directories(flangrti_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - ) +) set_target_properties(flangrti_shared flangrti_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${FLANG_RTE_LIB_DIR}) From 8483ef93a58b080a7a59fa319cdf9a84fccd143d Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 26 Oct 2017 14:22:05 -0500 Subject: [PATCH 050/141] [runtime/trace] fix header [runtime/trace] fix c_interface --- runtime/flangrti/trace/c_interface.cxx | 4 +++- runtime/flangrti/trace_lin.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/flangrti/trace/c_interface.cxx b/runtime/flangrti/trace/c_interface.cxx index 9b5c89f9c16..ada294b4e36 100644 --- a/runtime/flangrti/trace/c_interface.cxx +++ b/runtime/flangrti/trace/c_interface.cxx @@ -2,7 +2,9 @@ #include #include -extern "C" { #include "trace/c_interface.h" } +extern "C" { +#include "trace/c_interface.h" +} #include "trace/StackWalker.h" void SignalHandler(int signal) diff --git a/runtime/flangrti/trace_lin.c b/runtime/flangrti/trace_lin.c index f9ecb9f8290..7643415d344 100644 --- a/runtime/flangrti/trace_lin.c +++ b/runtime/flangrti/trace_lin.c @@ -194,7 +194,7 @@ __abort_sig_init(void) } #else -#include "signal/c_interface.h" +#include "trace/c_interface.h" void __abort_trace(int skip) { } From 907d679968597ba2b20a6f500e29ddc5b7607637 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 26 Oct 2017 14:57:01 -0500 Subject: [PATCH 051/141] [utils] implement fortio_binary_mode --- runtime/flang/utils.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/runtime/flang/utils.c b/runtime/flang/utils.c index 1994bb2ffeb..6cae64eca21 100644 --- a/runtime/flang/utils.c +++ b/runtime/flang/utils.c @@ -605,8 +605,30 @@ __fortio_trunc(FIO_FCB *p, seekoffx_t length) #ifdef _WIN32 int -__fortio_binary_mode(int fd) { - return (_setmode(fd, _O_BINARY) != -1); +__fortio_binary_mode(void *fp) +{ +#if defined(WINNT) +#include + +#if defined(WIN64) || defined(WIN32) +#define O_BINARY _O_BINARY +#endif + + int mode; + + mode = setmode(fileno((FILE *)fp), O_BINARY); + if (mode == -1) { + /* The mode argument is clearly legal, so this should not + * happen. But, in a console app, setmode will fail on + * the fd representing stdout. + */ + return 0; + } + (void)setmode(fileno((FILE *)fp), mode); + return (mode & O_BINARY); +#else + return 1; +#endif } void From 669a8af324c1c267acf02b64a843e0486ff04ef8 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 26 Oct 2017 15:02:15 -0500 Subject: [PATCH 052/141] [runtime/iso_c] undefine linux --- runtime/flang/iso_c_bind.F95 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/flang/iso_c_bind.F95 b/runtime/flang/iso_c_bind.F95 index 629d9d62a90..40454c1d619 100644 --- a/runtime/flang/iso_c_bind.F95 +++ b/runtime/flang/iso_c_bind.F95 @@ -42,6 +42,11 @@ module ISO_C_BINDING parameter ( C_INTPTR_T = 8 ) integer C_SIZE_T parameter ( C_SIZE_T = 8 ) + + #undef TARGET_LINUX_X8664 + #undef TARGET_OSX_X8664 + #undef TARGET_INTERIX_X8664 + #undef LINUX #endif #if defined(TARGET_LINUX_X8664) || defined(TARGET_OSX_X8664) || defined(TARGET_INTERIX_X8664) || defined(TARGET_LLVM_64) From de6b981c8498cf8bf2a7ddf1ca6b6296b49389fa Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 26 Oct 2017 15:57:16 -0500 Subject: [PATCH 053/141] Remove adding -DLINUX --- runtime/CMakeLists.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index a64095f80e7..d98bcac15b0 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -20,15 +20,21 @@ add_definitions( -DMAXCPUS=256 -DMAXCPUSL=8 -DMAXCPUSR=8 - -DTARGET_LINUX -DTARGET_LLVM - -DLINUX - -DPGF90 + -DPGF90 -DPGFLANG -DNATIVE_FPCVT -DPGI_LITTLE_ENDIAN ) +if( ${TARGET_OS} STREQUAL "Linux" ) + add_definitions( + -DTARGET_LINUX + -DLINUX + ) +endif() + + if( ${TARGET_ARCHITECTURE} STREQUAL "x86_64" ) add_definitions(-DTARGET_X8664) elseif( ${TARGET_ARCHITECTURE} STREQUAL "aarch64" ) From 9ca3a7ad54f44e533ab40fee4e180119e71e85a6 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 26 Oct 2017 16:02:16 -0500 Subject: [PATCH 054/141] [cmake] minor cleanup --- runtime/flang/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index d4bd35366a9..ad7a227c556 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -26,8 +26,6 @@ endif() # components, so point its binary directory to the build directory to pick up # flang* executables SET(CMAKE_Fortran_FLAGS "-B ${LLVM_RUNTIME_OUTPUT_INTDIR} ${CMAKE_Fortran_FLAGS}") -STRING( REPLACE "-DLINUX" "" CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} ) - SET(FTN_INTRINSICS abort3f.c From d98604b628dcaaf41c3a453fa6e104ecd49d6fb6 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 26 Oct 2017 16:25:30 -0500 Subject: [PATCH 055/141] [cmake] always build tests --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8aa765a01c6..6cf0bb6d45d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -416,7 +416,7 @@ add_subdirectory(tools) #endif() #add_subdirectory(examples) -if( FLANG_INCLUDE_TESTS ) +# if( FLANG_INCLUDE_TESTS ) # if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h) # add_subdirectory(unittests) # list(APPEND FLANG_TEST_DEPS FlangUnitTests) @@ -448,7 +448,7 @@ option(FLANG_INCLUDE_DOCS "Generate build targets for the Flang docs." ${LLVM_INCLUDE_DOCS}) if (FLANG_INCLUDE_DOCS) add_subdirectory(docs) -endif() +# endif() # Local Variables: # mode: cmake From 23ffa7a3458bafdd5a35994d25f6616fb8790657 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 26 Oct 2017 16:30:13 -0500 Subject: [PATCH 056/141] [cmake] fix --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cf0bb6d45d..0cefe627768 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -442,13 +442,13 @@ add_subdirectory(tools) ) endif() # add_subdirectory(utils/perf-training) -endif() +# endif() option(FLANG_INCLUDE_DOCS "Generate build targets for the Flang docs." ${LLVM_INCLUDE_DOCS}) if (FLANG_INCLUDE_DOCS) add_subdirectory(docs) -# endif() +endif() # Local Variables: # mode: cmake From 085b5c66b1a9651b5593fa09dab4e06c8899b764 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 26 Oct 2017 21:42:53 -0500 Subject: [PATCH 057/141] [cmake] set standalone=1 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cefe627768..984b74e7124 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -426,7 +426,7 @@ add_subdirectory(tools) # endif() add_subdirectory(test) - if(FLANG_BUILT_STANDALONE) + # if(FLANG_BUILT_STANDALONE) # Add a global check rule now that all subdirectories have been traversed # and we know the total set of lit testsuites. get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES) @@ -440,7 +440,7 @@ add_subdirectory(tools) DEPENDS ${LLVM_LIT_DEPENDS} ARGS ${LLVM_LIT_EXTRA_ARGS} ) - endif() + # endif() # add_subdirectory(utils/perf-training) # endif() From cba0ec544d700d305aced7d74d0c2ca63251c16b Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 27 Oct 2017 14:24:31 -0500 Subject: [PATCH 058/141] [cmake] show test suite message --- test/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5ecd0e9c661..40694f420a8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,6 +14,7 @@ # limitations under the License. # +message(STATUS "Building test suite") # Test runner infrastructure for Flang. This configures the Flang test trees # for use by Lit, and delegates to LLVM's lit test handlers. From 86d92842f7af36da88b3d7fb2bb02575a0b108ac Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Fri, 27 Oct 2017 16:26:51 -0500 Subject: [PATCH 059/141] [lit] support windows --- test/lit.cfg | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/lit.cfg b/test/lit.cfg index 9217bd54043..a2e68ecd60e 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -26,10 +26,6 @@ import tempfile import lit.formats import lit.util -if platform.system() == 'Windows': - lit_config.note('We do not support Windows, but hey, congratulations on porting to Windows!') - raise SystemExit - # Configuration file for the 'lit' test runner. # name: The name of this test suite. From 3112783b5f75e7ea1b11413a5358e730b10f5bd4 Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 27 Oct 2017 16:38:46 -0500 Subject: [PATCH 060/141] [cmake] revert changes changes were unnecessary --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 984b74e7124..8aa765a01c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -416,7 +416,7 @@ add_subdirectory(tools) #endif() #add_subdirectory(examples) -# if( FLANG_INCLUDE_TESTS ) +if( FLANG_INCLUDE_TESTS ) # if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h) # add_subdirectory(unittests) # list(APPEND FLANG_TEST_DEPS FlangUnitTests) @@ -426,7 +426,7 @@ add_subdirectory(tools) # endif() add_subdirectory(test) - # if(FLANG_BUILT_STANDALONE) + if(FLANG_BUILT_STANDALONE) # Add a global check rule now that all subdirectories have been traversed # and we know the total set of lit testsuites. get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES) @@ -440,9 +440,9 @@ add_subdirectory(tools) DEPENDS ${LLVM_LIT_DEPENDS} ARGS ${LLVM_LIT_EXTRA_ARGS} ) - # endif() + endif() # add_subdirectory(utils/perf-training) -# endif() +endif() option(FLANG_INCLUDE_DOCS "Generate build targets for the Flang docs." ${LLVM_INCLUDE_DOCS}) From b278f10b15705cef2bec33753b7aedf56e74751c Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 27 Oct 2017 16:48:16 -0500 Subject: [PATCH 061/141] [cmake/test] add verbose mode --- test/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 40694f420a8..4957bb62816 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -42,6 +42,11 @@ if(FLANG_TEST_USE_VG) set(FLANG_TEST_EXTRA_ARGS ${FLANG_TEST_EXTRA_ARGS} "--vg") endif () +option(FLANG_TEST_VERBOSE_MODE "Run Flang tests in verbose mode" OFF) +if(FLANG_TEST_VERBOSE_MODE) + set(FLANG_TEST_EXTRA_ARGS ${FLANG_TEST_EXTRA_ARGS} "-vv") +endif () + set(FLANG_TEST_PARAMS flang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg ) From d4b37da2d90636a3c9b8955e7560903c2dac6130 Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 27 Oct 2017 23:38:25 -0500 Subject: [PATCH 062/141] [runtime/mthdecls] uncomment some functions --- runtime/include/mthdecls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/include/mthdecls.h b/runtime/include/mthdecls.h index ddec42510f0..47db666a349 100644 --- a/runtime/include/mthdecls.h +++ b/runtime/include/mthdecls.h @@ -598,13 +598,13 @@ extern double asinh(double); extern float asinhf(float); extern double atanh(double); extern float atanhf(float); +*/ extern double _j0(double arg); extern double _j1(double arg); extern double _jn(int n, double arg); extern double _y0(double arg); extern double _y1(double arg); extern double _yn(int n, double arg); -*/ #endif /* From 5b2d42ae5ca3b53753b8898cc101423f6473efa3 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 28 Oct 2017 00:00:29 -0500 Subject: [PATCH 063/141] Revert "[runtime/mthdecls] uncomment some functions" --- runtime/include/mthdecls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/include/mthdecls.h b/runtime/include/mthdecls.h index 47db666a349..ddec42510f0 100644 --- a/runtime/include/mthdecls.h +++ b/runtime/include/mthdecls.h @@ -598,13 +598,13 @@ extern double asinh(double); extern float asinhf(float); extern double atanh(double); extern float atanhf(float); -*/ extern double _j0(double arg); extern double _j1(double arg); extern double _jn(int n, double arg); extern double _y0(double arg); extern double _y1(double arg); extern double _yn(int n, double arg); +*/ #endif /* From 7666f000d83ad41d6103a513b7277c9f6ffe32ff Mon Sep 17 00:00:00 2001 From: xoviat Date: Sat, 28 Oct 2017 16:23:39 -0500 Subject: [PATCH 064/141] [runtime/flang]. re enable faint fsync (#23 * [runtime/flang]. re enable faint fsync * Update fsync3f.c --- runtime/flang/fsync3f.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/runtime/flang/fsync3f.c b/runtime/flang/fsync3f.c index 6d8068129e6..ad12709df4e 100644 --- a/runtime/flang/fsync3f.c +++ b/runtime/flang/fsync3f.c @@ -26,12 +26,14 @@ extern FILE *__getfile3f(); void ENT3F(FSYNC, fsync)(lu) int *lu; { -#ifndef _WIN32 FILE *f; f = __getfile3f(*lu); if (f) - fsync(__io_getfd(f)); + #ifndef _WIN32 + fsync(__io_getfd(f)); + #else + fflush(f); + #endif return; - #endif } From 086ca052fa3175a93fc887891cec7ec0cc2e69de Mon Sep 17 00:00:00 2001 From: xoviat Date: Sat, 28 Oct 2017 22:59:33 -0500 Subject: [PATCH 065/141] [runtime] fix trace handler (#24) * [runtime] fix trace handler * [runtime/trace] fix headers * [runtime/trace] cleanup * [runtime/trace] cleanup * [runtime/trace] cleanup * [runtime/trace] cleanup * [cmake] cleanup * [runtime/trace] install more handlers * [runtime/trace] fix headers * [runtime/trace] add header * [runtime/trace] fix syntax * [runtime/trace] fix syntax * [cmake] toss in dbghelp.lib * [cmake] fix configuration * [cmake] only add lib on win32 --- CMakeLists.txt | 5 +- runtime/flangrti/CMakeLists.txt | 2 - runtime/flangrti/trace/StackWalker.cpp | 1365 ------------------------ runtime/flangrti/trace/c_interface.cxx | 22 - runtime/flangrti/trace/c_interface.h | 1 - runtime/flangrti/trace/stackwalker.h | 218 ---- runtime/flangrti/trace_lin.c | 55 +- 7 files changed, 54 insertions(+), 1614 deletions(-) delete mode 100644 runtime/flangrti/trace/StackWalker.cpp delete mode 100644 runtime/flangrti/trace/c_interface.cxx delete mode 100644 runtime/flangrti/trace/c_interface.h delete mode 100644 runtime/flangrti/trace/stackwalker.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8aa765a01c6..a11167bfc32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,7 +342,10 @@ macro(add_flang_library name) endif( LLVM_COMMON_DEPENDS ) llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) - target_link_libraries( ${name} ${LLVM_COMMON_LIBS} ) + if(WIN32) + list(APPEND LLVM_COMMON_LIBS Dbghelp.lib) + endif() + target_link_libraries( ${name} ${LLVM_COMMON_LIBS}) # link_system_libs( ${name} ) # getd of cmake warning messages install(TARGETS ${name} diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index 68ca8d0c2e3..a1cc4bffbc5 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -161,8 +161,6 @@ SET(PGC_SRC_FILES tanh.c trace_lin.c trace.c - trace/c_interface.cxx - trace/StackWalker.cpp anint.c dnint.c idnint.c diff --git a/runtime/flangrti/trace/StackWalker.cpp b/runtime/flangrti/trace/StackWalker.cpp deleted file mode 100644 index 467b5a4cbcb..00000000000 --- a/runtime/flangrti/trace/StackWalker.cpp +++ /dev/null @@ -1,1365 +0,0 @@ -/********************************************************************** - * - * StackWalker.cpp - * http://stackwalker.codeplex.com/ - * - * - * History: - * 2005-07-27 v1 - First public release on http://www.codeproject.com/ - * http://www.codeproject.com/threads/StackWalker.asp - * 2005-07-28 v2 - Changed the params of the constructor and ShowCallstack - * (to simplify the usage) - * 2005-08-01 v3 - Changed to use 'CONTEXT_FULL' instead of CONTEXT_ALL - * (should also be enough) - * - Changed to compile correctly with the PSDK of VC7.0 - * (GetFileVersionInfoSizeA and GetFileVersionInfoA is wrongly defined: - * it uses LPSTR instead of LPCSTR as first paremeter) - * - Added declarations to support VC5/6 without using 'dbghelp.h' - * - Added a 'pUserData' member to the ShowCallstack function and the - * PReadProcessMemoryRoutine declaration (to pass some user-defined data, - * which can be used in the readMemoryFunction-callback) - * 2005-08-02 v4 - OnSymInit now also outputs the OS-Version by default - * - Added example for doing an exception-callstack-walking in main.cpp - * (thanks to owillebo: http://www.codeproject.com/script/profile/whos_who.asp?id=536268) - * 2005-08-05 v5 - Removed most Lint (http://www.gimpel.com/) errors... thanks to Okko Willeboordse! - * 2008-08-04 v6 - Fixed Bug: Missing LEAK-end-tag - * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=2502890#xx2502890xx - * Fixed Bug: Compiled with "WIN32_LEAN_AND_MEAN" - * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=1824718#xx1824718xx - * Fixed Bug: Compiling with "/Wall" - * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=2638243#xx2638243xx - * Fixed Bug: Now checking SymUseSymSrv - * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=1388979#xx1388979xx - * Fixed Bug: Support for recursive function calls - * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=1434538#xx1434538xx - * Fixed Bug: Missing FreeLibrary call in "GetModuleListTH32" - * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=1326923#xx1326923xx - * Fixed Bug: SymDia is number 7, not 9! - * 2008-09-11 v7 For some (undocumented) reason, dbhelp.h is needing a packing of 8! - * Thanks to Teajay which reported the bug... - * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=2718933#xx2718933xx - * 2008-11-27 v8 Debugging Tools for Windows are now stored in a different directory - * Thanks to Luiz Salamon which reported this "bug"... - * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=2822736#xx2822736xx - * 2009-04-10 v9 License slihtly corrected ( replaced) - * 2009-11-01 v10 Moved to http://stackwalker.codeplex.com/ - * 2009-11-02 v11 Now try to use IMAGEHLP_MODULE64_V3 if available - * 2010-04-15 v12 Added support for VS2010 RTM - * 2010-05-25 v13 Now using secure MyStrcCpy. Thanks to luke.simon: - * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=3477467#xx3477467xx - * 2013-01-07 v14 Runtime Check Error VS2010 Debug Builds fixed: - * http://stackwalker.codeplex.com/workitem/10511 - * - * - * LICENSE (http://www.opensource.org/licenses/bsd-license.php) - * - * Copyright (c) 2005-2013, Jochen Kalmbach - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of Jochen Kalmbach nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - **********************************************************************/ -#include -#include -#include -#include -#pragma comment(lib, "version.lib") // for "VerQueryValue" -#pragma warning(disable:4826) - -#include "trace/StackWalker.h" - - -// If VC7 and later, then use the shipped 'dbghelp.h'-file -#pragma pack(push,8) -#if _MSC_VER >= 1300 -#include -#else -// inline the important dbghelp.h-declarations... -typedef enum { - SymNone = 0, - SymCoff, - SymCv, - SymPdb, - SymExport, - SymDeferred, - SymSym, - SymDia, - SymVirtual, - NumSymTypes -} SYM_TYPE; -typedef struct _IMAGEHLP_LINE64 { - DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_LINE64) - PVOID Key; // internal - DWORD LineNumber; // line number in file - PCHAR FileName; // full filename - DWORD64 Address; // first instruction of line -} IMAGEHLP_LINE64, *PIMAGEHLP_LINE64; -typedef struct _IMAGEHLP_MODULE64 { - DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64) - DWORD64 BaseOfImage; // base load address of module - DWORD ImageSize; // virtual size of the loaded module - DWORD TimeDateStamp; // date/time stamp from pe header - DWORD CheckSum; // checksum from the pe header - DWORD NumSyms; // number of symbols in the symbol table - SYM_TYPE SymType; // type of symbols loaded - CHAR ModuleName[32]; // module name - CHAR ImageName[256]; // image name - CHAR LoadedImageName[256]; // symbol file name -} IMAGEHLP_MODULE64, *PIMAGEHLP_MODULE64; -typedef struct _IMAGEHLP_SYMBOL64 { - DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_SYMBOL64) - DWORD64 Address; // virtual address including dll base address - DWORD Size; // estimated size of symbol, can be zero - DWORD Flags; // info about the symbols, see the SYMF defines - DWORD MaxNameLength; // maximum size of symbol name in 'Name' - CHAR Name[1]; // symbol name (null terminated string) -} IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64; -typedef enum { - AddrMode1616, - AddrMode1632, - AddrModeReal, - AddrModeFlat -} ADDRESS_MODE; -typedef struct _tagADDRESS64 { - DWORD64 Offset; - WORD Segment; - ADDRESS_MODE Mode; -} ADDRESS64, *LPADDRESS64; -typedef struct _KDHELP64 { - DWORD64 Thread; - DWORD ThCallbackStack; - DWORD ThCallbackBStore; - DWORD NextCallback; - DWORD FramePointer; - DWORD64 KiCallUserMode; - DWORD64 KeUserCallbackDispatcher; - DWORD64 SystemRangeStart; - DWORD64 Reserved[8]; -} KDHELP64, *PKDHELP64; -typedef struct _tagSTACKFRAME64 { - ADDRESS64 AddrPC; // program counter - ADDRESS64 AddrReturn; // return address - ADDRESS64 AddrFrame; // frame pointer - ADDRESS64 AddrStack; // stack pointer - ADDRESS64 AddrBStore; // backing store pointer - PVOID FuncTableEntry; // pointer to pdata/fpo or NULL - DWORD64 Params[4]; // possible arguments to the function - BOOL Far; // WOW far call - BOOL Virtual; // is this a virtual frame? - DWORD64 Reserved[3]; - KDHELP64 KdHelp; -} STACKFRAME64, *LPSTACKFRAME64; -typedef -BOOL -(__stdcall *PREAD_PROCESS_MEMORY_ROUTINE64)( - HANDLE hProcess, - DWORD64 qwBaseAddress, - PVOID lpBuffer, - DWORD nSize, - LPDWORD lpNumberOfBytesRead - ); -typedef -PVOID -(__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE64)( - HANDLE hProcess, - DWORD64 AddrBase - ); -typedef -DWORD64 -(__stdcall *PGET_MODULE_BASE_ROUTINE64)( - HANDLE hProcess, - DWORD64 Address - ); -typedef -DWORD64 -(__stdcall *PTRANSLATE_ADDRESS_ROUTINE64)( - HANDLE hProcess, - HANDLE hThread, - LPADDRESS64 lpaddr - ); -#define SYMOPT_CASE_INSENSITIVE 0x00000001 -#define SYMOPT_UNDNAME 0x00000002 -#define SYMOPT_DEFERRED_LOADS 0x00000004 -#define SYMOPT_NO_CPP 0x00000008 -#define SYMOPT_LOAD_LINES 0x00000010 -#define SYMOPT_OMAP_FIND_NEAREST 0x00000020 -#define SYMOPT_LOAD_ANYTHING 0x00000040 -#define SYMOPT_IGNORE_CVREC 0x00000080 -#define SYMOPT_NO_UNQUALIFIED_LOADS 0x00000100 -#define SYMOPT_FAIL_CRITICAL_ERRORS 0x00000200 -#define SYMOPT_EXACT_SYMBOLS 0x00000400 -#define SYMOPT_ALLOW_ABSOLUTE_SYMBOLS 0x00000800 -#define SYMOPT_IGNORE_NT_SYMPATH 0x00001000 -#define SYMOPT_INCLUDE_32BIT_MODULES 0x00002000 -#define SYMOPT_PUBLICS_ONLY 0x00004000 -#define SYMOPT_NO_PUBLICS 0x00008000 -#define SYMOPT_AUTO_PUBLICS 0x00010000 -#define SYMOPT_NO_IMAGE_SEARCH 0x00020000 -#define SYMOPT_SECURE 0x00040000 -#define SYMOPT_DEBUG 0x80000000 -#define UNDNAME_COMPLETE (0x0000) // Enable full undecoration -#define UNDNAME_NAME_ONLY (0x1000) // Crack only the name for primary declaration; -#endif // _MSC_VER < 1300 -#pragma pack(pop) - -// Some missing defines (for VC5/6): -#ifndef INVALID_FILE_ATTRIBUTES -#define INVALID_FILE_ATTRIBUTES ((DWORD)-1) -#endif - - -// secure-CRT_functions are only available starting with VC8 -#if _MSC_VER < 1400 -#define strcpy_s(dst, len, src) strcpy(dst, src) -#define strncpy_s(dst, len, src, maxLen) strncpy(dst, len, src) -#define strcat_s(dst, len, src) strcat(dst, src) -#define _snprintf_s _snprintf -#define _tcscat_s _tcscat -#endif - -static void MyStrCpy(char* szDest, size_t nMaxDestSize, const char* szSrc) -{ - if (nMaxDestSize <= 0) return; - strncpy_s(szDest, nMaxDestSize, szSrc, _TRUNCATE); - szDest[nMaxDestSize-1] = 0; // INFO: _TRUNCATE will ensure that it is nul-terminated; but with older compilers (<1400) it uses "strncpy" and this does not!) -} // MyStrCpy - -// Normally it should be enough to use 'CONTEXT_FULL' (better would be 'CONTEXT_ALL') -#define USED_CONTEXT_FLAGS CONTEXT_FULL - - -class StackWalkerInternal -{ -public: - StackWalkerInternal(StackWalker *parent, HANDLE hProcess) - { - m_parent = parent; - m_hDbhHelp = NULL; - pSC = NULL; - m_hProcess = hProcess; - m_szSymPath = NULL; - pSFTA = NULL; - pSGLFA = NULL; - pSGMB = NULL; - pSGMI = NULL; - pSGO = NULL; - pSGSFA = NULL; - pSI = NULL; - pSLM = NULL; - pSSO = NULL; - pSW = NULL; - pUDSN = NULL; - pSGSP = NULL; - } - ~StackWalkerInternal() - { - if (pSC != NULL) - pSC(m_hProcess); // SymCleanup - if (m_hDbhHelp != NULL) - FreeLibrary(m_hDbhHelp); - m_hDbhHelp = NULL; - m_parent = NULL; - if(m_szSymPath != NULL) - free(m_szSymPath); - m_szSymPath = NULL; - } - BOOL Init(LPCSTR szSymPath) - { - if (m_parent == NULL) - return FALSE; - // Dynamically load the Entry-Points for dbghelp.dll: - // First try to load the newsest one from - TCHAR szTemp[4096]; - // But before wqe do this, we first check if the ".local" file exists - if (GetModuleFileName(NULL, szTemp, 4096) > 0) - { - _tcscat_s(szTemp, _T(".local")); - if (GetFileAttributes(szTemp) == INVALID_FILE_ATTRIBUTES) - { - // ".local" file does not exist, so we can try to load the dbghelp.dll from the "Debugging Tools for Windows" - // Ok, first try the new path according to the archtitecture: -#ifdef _M_IX86 - if ( (m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) ) - { - _tcscat_s(szTemp, _T("\\Debugging Tools for Windows (x86)\\dbghelp.dll")); - // now check if the file exists: - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) - { - m_hDbhHelp = LoadLibrary(szTemp); - } - } -#elif _M_X64 - if ( (m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) ) - { - _tcscat_s(szTemp, _T("\\Debugging Tools for Windows (x64)\\dbghelp.dll")); - // now check if the file exists: - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) - { - m_hDbhHelp = LoadLibrary(szTemp); - } - } -#elif _M_IA64 - if ( (m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) ) - { - _tcscat_s(szTemp, _T("\\Debugging Tools for Windows (ia64)\\dbghelp.dll")); - // now check if the file exists: - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) - { - m_hDbhHelp = LoadLibrary(szTemp); - } - } -#endif - // If still not found, try the old directories... - if ( (m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) ) - { - _tcscat_s(szTemp, _T("\\Debugging Tools for Windows\\dbghelp.dll")); - // now check if the file exists: - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) - { - m_hDbhHelp = LoadLibrary(szTemp); - } - } -#if defined _M_X64 || defined _M_IA64 - // Still not found? Then try to load the (old) 64-Bit version: - if ( (m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0) ) - { - _tcscat_s(szTemp, _T("\\Debugging Tools for Windows 64-Bit\\dbghelp.dll")); - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) - { - m_hDbhHelp = LoadLibrary(szTemp); - } - } -#endif - } - } - if (m_hDbhHelp == NULL) // if not already loaded, try to load a default-one - m_hDbhHelp = LoadLibrary( _T("dbghelp.dll") ); - if (m_hDbhHelp == NULL) - return FALSE; - pSI = (tSI) GetProcAddress(m_hDbhHelp, "SymInitialize" ); - pSC = (tSC) GetProcAddress(m_hDbhHelp, "SymCleanup" ); - - pSW = (tSW) GetProcAddress(m_hDbhHelp, "StackWalk64" ); - pSGO = (tSGO) GetProcAddress(m_hDbhHelp, "SymGetOptions" ); - pSSO = (tSSO) GetProcAddress(m_hDbhHelp, "SymSetOptions" ); - - pSFTA = (tSFTA) GetProcAddress(m_hDbhHelp, "SymFunctionTableAccess64" ); - pSGLFA = (tSGLFA) GetProcAddress(m_hDbhHelp, "SymGetLineFromAddr64" ); - pSGMB = (tSGMB) GetProcAddress(m_hDbhHelp, "SymGetModuleBase64" ); - pSGMI = (tSGMI) GetProcAddress(m_hDbhHelp, "SymGetModuleInfo64" ); - pSGSFA = (tSGSFA) GetProcAddress(m_hDbhHelp, "SymGetSymFromAddr64" ); - pUDSN = (tUDSN) GetProcAddress(m_hDbhHelp, "UnDecorateSymbolName" ); - pSLM = (tSLM) GetProcAddress(m_hDbhHelp, "SymLoadModule64" ); - pSGSP =(tSGSP) GetProcAddress(m_hDbhHelp, "SymGetSearchPath" ); - - if ( pSC == NULL || pSFTA == NULL || pSGMB == NULL || pSGMI == NULL || - pSGO == NULL || pSGSFA == NULL || pSI == NULL || pSSO == NULL || - pSW == NULL || pUDSN == NULL || pSLM == NULL ) - { - FreeLibrary(m_hDbhHelp); - m_hDbhHelp = NULL; - pSC = NULL; - return FALSE; - } - - // SymInitialize - if (szSymPath != NULL) - m_szSymPath = _strdup(szSymPath); - if (this->pSI(m_hProcess, m_szSymPath, FALSE) == FALSE) - this->m_parent->OnDbgHelpErr("SymInitialize", GetLastError(), 0); - - DWORD symOptions = this->pSGO(); // SymGetOptions - symOptions |= SYMOPT_LOAD_LINES; - symOptions |= SYMOPT_FAIL_CRITICAL_ERRORS; - //symOptions |= SYMOPT_NO_PROMPTS; - // SymSetOptions - symOptions = this->pSSO(symOptions); - - char buf[StackWalker::STACKWALK_MAX_NAMELEN] = {0}; - if (this->pSGSP != NULL) - { - if (this->pSGSP(m_hProcess, buf, StackWalker::STACKWALK_MAX_NAMELEN) == FALSE) - this->m_parent->OnDbgHelpErr("SymGetSearchPath", GetLastError(), 0); - } - char szUserName[1024] = {0}; - DWORD dwSize = 1024; - GetUserNameA(szUserName, &dwSize); - this->m_parent->OnSymInit(buf, symOptions, szUserName); - - return TRUE; - } - - StackWalker *m_parent; - - HMODULE m_hDbhHelp; - HANDLE m_hProcess; - LPSTR m_szSymPath; - -#pragma pack(push,8) -typedef struct IMAGEHLP_MODULE64_V3 { - DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64) - DWORD64 BaseOfImage; // base load address of module - DWORD ImageSize; // virtual size of the loaded module - DWORD TimeDateStamp; // date/time stamp from pe header - DWORD CheckSum; // checksum from the pe header - DWORD NumSyms; // number of symbols in the symbol table - SYM_TYPE SymType; // type of symbols loaded - CHAR ModuleName[32]; // module name - CHAR ImageName[256]; // image name - CHAR LoadedImageName[256]; // symbol file name - // new elements: 07-Jun-2002 - CHAR LoadedPdbName[256]; // pdb file name - DWORD CVSig; // Signature of the CV record in the debug directories - CHAR CVData[MAX_PATH * 3]; // Contents of the CV record - DWORD PdbSig; // Signature of PDB - GUID PdbSig70; // Signature of PDB (VC 7 and up) - DWORD PdbAge; // DBI age of pdb - BOOL PdbUnmatched; // loaded an unmatched pdb - BOOL DbgUnmatched; // loaded an unmatched dbg - BOOL LineNumbers; // we have line number information - BOOL GlobalSymbols; // we have internal symbol information - BOOL TypeInfo; // we have type information - // new elements: 17-Dec-2003 - BOOL SourceIndexed; // pdb supports source server - BOOL Publics; // contains public symbols -}; - -typedef struct IMAGEHLP_MODULE64_V2 { - DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64) - DWORD64 BaseOfImage; // base load address of module - DWORD ImageSize; // virtual size of the loaded module - DWORD TimeDateStamp; // date/time stamp from pe header - DWORD CheckSum; // checksum from the pe header - DWORD NumSyms; // number of symbols in the symbol table - SYM_TYPE SymType; // type of symbols loaded - CHAR ModuleName[32]; // module name - CHAR ImageName[256]; // image name - CHAR LoadedImageName[256]; // symbol file name -}; -#pragma pack(pop) - - - // SymCleanup() - typedef BOOL (__stdcall *tSC)( IN HANDLE hProcess ); - tSC pSC; - - // SymFunctionTableAccess64() - typedef PVOID (__stdcall *tSFTA)( HANDLE hProcess, DWORD64 AddrBase ); - tSFTA pSFTA; - - // SymGetLineFromAddr64() - typedef BOOL (__stdcall *tSGLFA)( IN HANDLE hProcess, IN DWORD64 dwAddr, - OUT PDWORD pdwDisplacement, OUT PIMAGEHLP_LINE64 Line ); - tSGLFA pSGLFA; - - // SymGetModuleBase64() - typedef DWORD64 (__stdcall *tSGMB)( IN HANDLE hProcess, IN DWORD64 dwAddr ); - tSGMB pSGMB; - - // SymGetModuleInfo64() - typedef BOOL (__stdcall *tSGMI)( IN HANDLE hProcess, IN DWORD64 dwAddr, OUT IMAGEHLP_MODULE64_V3 *ModuleInfo ); - tSGMI pSGMI; - - // SymGetOptions() - typedef DWORD (__stdcall *tSGO)( VOID ); - tSGO pSGO; - - // SymGetSymFromAddr64() - typedef BOOL (__stdcall *tSGSFA)( IN HANDLE hProcess, IN DWORD64 dwAddr, - OUT PDWORD64 pdwDisplacement, OUT PIMAGEHLP_SYMBOL64 Symbol ); - tSGSFA pSGSFA; - - // SymInitialize() - typedef BOOL (__stdcall *tSI)( IN HANDLE hProcess, IN PSTR UserSearchPath, IN BOOL fInvadeProcess ); - tSI pSI; - - // SymLoadModule64() - typedef DWORD64 (__stdcall *tSLM)( IN HANDLE hProcess, IN HANDLE hFile, - IN PSTR ImageName, IN PSTR ModuleName, IN DWORD64 BaseOfDll, IN DWORD SizeOfDll ); - tSLM pSLM; - - // SymSetOptions() - typedef DWORD (__stdcall *tSSO)( IN DWORD SymOptions ); - tSSO pSSO; - - // StackWalk64() - typedef BOOL (__stdcall *tSW)( - DWORD MachineType, - HANDLE hProcess, - HANDLE hThread, - LPSTACKFRAME64 StackFrame, - PVOID ContextRecord, - PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, - PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, - PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, - PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress ); - tSW pSW; - - // UnDecorateSymbolName() - typedef DWORD (__stdcall WINAPI *tUDSN)( PCSTR DecoratedName, PSTR UnDecoratedName, - DWORD UndecoratedLength, DWORD Flags ); - tUDSN pUDSN; - - typedef BOOL (__stdcall WINAPI *tSGSP)(HANDLE hProcess, PSTR SearchPath, DWORD SearchPathLength); - tSGSP pSGSP; - - -private: - // **************************************** ToolHelp32 ************************ - #define MAX_MODULE_NAME32 255 - #define TH32CS_SNAPMODULE 0x00000008 - #pragma pack( push, 8 ) - typedef struct tagMODULEENTRY32 - { - DWORD dwSize; - DWORD th32ModuleID; // This module - DWORD th32ProcessID; // owning process - DWORD GlblcntUsage; // Global usage count on the module - DWORD ProccntUsage; // Module usage count in th32ProcessID's context - BYTE * modBaseAddr; // Base address of module in th32ProcessID's context - DWORD modBaseSize; // Size in bytes of module starting at modBaseAddr - HMODULE hModule; // The hModule of this module in th32ProcessID's context - char szModule[MAX_MODULE_NAME32 + 1]; - char szExePath[MAX_PATH]; - } MODULEENTRY32; - typedef MODULEENTRY32 * PMODULEENTRY32; - typedef MODULEENTRY32 * LPMODULEENTRY32; - #pragma pack( pop ) - - BOOL GetModuleListTH32(HANDLE hProcess, DWORD pid) - { - // CreateToolhelp32Snapshot() - typedef HANDLE (__stdcall *tCT32S)(DWORD dwFlags, DWORD th32ProcessID); - // Module32First() - typedef BOOL (__stdcall *tM32F)(HANDLE hSnapshot, LPMODULEENTRY32 lpme); - // Module32Next() - typedef BOOL (__stdcall *tM32N)(HANDLE hSnapshot, LPMODULEENTRY32 lpme); - - // try both dlls... - const TCHAR *dllname[] = { _T("kernel32.dll"), _T("tlhelp32.dll") }; - HINSTANCE hToolhelp = NULL; - tCT32S pCT32S = NULL; - tM32F pM32F = NULL; - tM32N pM32N = NULL; - - HANDLE hSnap; - MODULEENTRY32 me; - me.dwSize = sizeof(me); - BOOL keepGoing; - size_t i; - - for (i = 0; i<(sizeof(dllname) / sizeof(dllname[0])); i++ ) - { - hToolhelp = LoadLibrary( dllname[i] ); - if (hToolhelp == NULL) - continue; - pCT32S = (tCT32S) GetProcAddress(hToolhelp, "CreateToolhelp32Snapshot"); - pM32F = (tM32F) GetProcAddress(hToolhelp, "Module32First"); - pM32N = (tM32N) GetProcAddress(hToolhelp, "Module32Next"); - if ( (pCT32S != NULL) && (pM32F != NULL) && (pM32N != NULL) ) - break; // found the functions! - FreeLibrary(hToolhelp); - hToolhelp = NULL; - } - - if (hToolhelp == NULL) - return FALSE; - - hSnap = pCT32S( TH32CS_SNAPMODULE, pid ); - if (hSnap == (HANDLE) -1) - { - FreeLibrary(hToolhelp); - return FALSE; - } - - keepGoing = !!pM32F( hSnap, &me ); - int cnt = 0; - while (keepGoing) - { - this->LoadModule(hProcess, me.szExePath, me.szModule, (DWORD64) me.modBaseAddr, me.modBaseSize); - cnt++; - keepGoing = !!pM32N( hSnap, &me ); - } - CloseHandle(hSnap); - FreeLibrary(hToolhelp); - if (cnt <= 0) - return FALSE; - return TRUE; - } // GetModuleListTH32 - - // **************************************** PSAPI ************************ - typedef struct _MODULEINFO { - LPVOID lpBaseOfDll; - DWORD SizeOfImage; - LPVOID EntryPoint; - } MODULEINFO, *LPMODULEINFO; - - BOOL GetModuleListPSAPI(HANDLE hProcess) - { - // EnumProcessModules() - typedef BOOL (__stdcall *tEPM)(HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded ); - // GetModuleFileNameEx() - typedef DWORD (__stdcall *tGMFNE)(HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize ); - // GetModuleBaseName() - typedef DWORD (__stdcall *tGMBN)(HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize ); - // GetModuleInformation() - typedef BOOL (__stdcall *tGMI)(HANDLE hProcess, HMODULE hModule, LPMODULEINFO pmi, DWORD nSize ); - - HINSTANCE hPsapi; - tEPM pEPM; - tGMFNE pGMFNE; - tGMBN pGMBN; - tGMI pGMI; - - DWORD i; - //ModuleEntry e; - DWORD cbNeeded; - MODULEINFO mi; - HMODULE *hMods = 0; - char *tt = NULL; - char *tt2 = NULL; - const SIZE_T TTBUFLEN = 8096; - int cnt = 0; - - hPsapi = LoadLibrary( _T("psapi.dll") ); - if (hPsapi == NULL) - return FALSE; - - pEPM = (tEPM) GetProcAddress( hPsapi, "EnumProcessModules" ); - pGMFNE = (tGMFNE) GetProcAddress( hPsapi, "GetModuleFileNameExA" ); - pGMBN = (tGMFNE) GetProcAddress( hPsapi, "GetModuleBaseNameA" ); - pGMI = (tGMI) GetProcAddress( hPsapi, "GetModuleInformation" ); - if ( (pEPM == NULL) || (pGMFNE == NULL) || (pGMBN == NULL) || (pGMI == NULL) ) - { - // we couldn´t find all functions - FreeLibrary(hPsapi); - return FALSE; - } - - hMods = (HMODULE*) malloc(sizeof(HMODULE) * (TTBUFLEN / sizeof(HMODULE))); - tt = (char*) malloc(sizeof(char) * TTBUFLEN); - tt2 = (char*) malloc(sizeof(char) * TTBUFLEN); - if ( (hMods == NULL) || (tt == NULL) || (tt2 == NULL) ) - goto cleanup; - - if ( ! pEPM( hProcess, hMods, TTBUFLEN, &cbNeeded ) ) - { - //_ftprintf(fLogFile, _T("%lu: EPM failed, GetLastError = %lu\n"), g_dwShowCount, gle ); - goto cleanup; - } - - if ( cbNeeded > TTBUFLEN ) - { - //_ftprintf(fLogFile, _T("%lu: More than %lu module handles. Huh?\n"), g_dwShowCount, lenof( hMods ) ); - goto cleanup; - } - - for ( i = 0; i < cbNeeded / sizeof(hMods[0]); i++ ) - { - // base address, size - pGMI(hProcess, hMods[i], &mi, sizeof(mi)); - // image file name - tt[0] = 0; - pGMFNE(hProcess, hMods[i], tt, TTBUFLEN ); - // module name - tt2[0] = 0; - pGMBN(hProcess, hMods[i], tt2, TTBUFLEN ); - - DWORD dwRes = this->LoadModule(hProcess, tt, tt2, (DWORD64) mi.lpBaseOfDll, mi.SizeOfImage); - if (dwRes != ERROR_SUCCESS) - this->m_parent->OnDbgHelpErr("LoadModule", dwRes, 0); - cnt++; - } - - cleanup: - if (hPsapi != NULL) FreeLibrary(hPsapi); - if (tt2 != NULL) free(tt2); - if (tt != NULL) free(tt); - if (hMods != NULL) free(hMods); - - return cnt != 0; - } // GetModuleListPSAPI - - DWORD LoadModule(HANDLE hProcess, LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size) - { - CHAR *szImg = _strdup(img); - CHAR *szMod = _strdup(mod); - DWORD result = ERROR_SUCCESS; - if ( (szImg == NULL) || (szMod == NULL) ) - result = ERROR_NOT_ENOUGH_MEMORY; - else - { - if (pSLM(hProcess, 0, szImg, szMod, baseAddr, size) == 0) - result = GetLastError(); - } - ULONGLONG fileVersion = 0; - if ( (m_parent != NULL) && (szImg != NULL) ) - { - // try to retrive the file-version: - if ( (this->m_parent->m_options & StackWalker::RetrieveFileVersion) != 0) - { - VS_FIXEDFILEINFO *fInfo = NULL; - DWORD dwHandle; - DWORD dwSize = GetFileVersionInfoSizeA(szImg, &dwHandle); - if (dwSize > 0) - { - LPVOID vData = malloc(dwSize); - if (vData != NULL) - { - if (GetFileVersionInfoA(szImg, dwHandle, dwSize, vData) != 0) - { - UINT len; - TCHAR szSubBlock[] = _T("\\"); - if (VerQueryValue(vData, szSubBlock, (LPVOID*) &fInfo, &len) == 0) - fInfo = NULL; - else - { - fileVersion = ((ULONGLONG)fInfo->dwFileVersionLS) + ((ULONGLONG)fInfo->dwFileVersionMS << 32); - } - } - free(vData); - } - } - } - - // Retrive some additional-infos about the module - IMAGEHLP_MODULE64_V3 Module; - const char *szSymType = "-unknown-"; - if (this->GetModuleInfo(hProcess, baseAddr, &Module) != FALSE) - { - switch(Module.SymType) - { - case SymNone: - szSymType = "-nosymbols-"; - break; - case SymCoff: // 1 - szSymType = "COFF"; - break; - case SymCv: // 2 - szSymType = "CV"; - break; - case SymPdb: // 3 - szSymType = "PDB"; - break; - case SymExport: // 4 - szSymType = "-exported-"; - break; - case SymDeferred: // 5 - szSymType = "-deferred-"; - break; - case SymSym: // 6 - szSymType = "SYM"; - break; - case 7: // SymDia: - szSymType = "DIA"; - break; - case 8: //SymVirtual: - szSymType = "Virtual"; - break; - } - } - LPCSTR pdbName = Module.LoadedImageName; - if (Module.LoadedPdbName[0] != 0) - pdbName = Module.LoadedPdbName; - this->m_parent->OnLoadModule(img, mod, baseAddr, size, result, szSymType, pdbName, fileVersion); - } - if (szImg != NULL) free(szImg); - if (szMod != NULL) free(szMod); - return result; - } -public: - BOOL LoadModules(HANDLE hProcess, DWORD dwProcessId) - { - // first try toolhelp32 - if (GetModuleListTH32(hProcess, dwProcessId)) - return true; - // then try psapi - return GetModuleListPSAPI(hProcess); - } - - - BOOL GetModuleInfo(HANDLE hProcess, DWORD64 baseAddr, IMAGEHLP_MODULE64_V3 *pModuleInfo) - { - memset(pModuleInfo, 0, sizeof(IMAGEHLP_MODULE64_V3)); - if(this->pSGMI == NULL) - { - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } - // First try to use the larger ModuleInfo-Structure - pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V3); - void *pData = malloc(4096); // reserve enough memory, so the bug in v6.3.5.1 does not lead to memory-overwrites... - if (pData == NULL) - { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - memcpy(pData, pModuleInfo, sizeof(IMAGEHLP_MODULE64_V3)); - static bool s_useV3Version = true; - if (s_useV3Version) - { - if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V3*) pData) != FALSE) - { - // only copy as much memory as is reserved... - memcpy(pModuleInfo, pData, sizeof(IMAGEHLP_MODULE64_V3)); - pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V3); - free(pData); - return TRUE; - } - s_useV3Version = false; // to prevent unneccessarry calls with the larger struct... - } - - // could not retrive the bigger structure, try with the smaller one (as defined in VC7.1)... - pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V2); - memcpy(pData, pModuleInfo, sizeof(IMAGEHLP_MODULE64_V2)); - if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V3*) pData) != FALSE) - { - // only copy as much memory as is reserved... - memcpy(pModuleInfo, pData, sizeof(IMAGEHLP_MODULE64_V2)); - pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V2); - free(pData); - return TRUE; - } - free(pData); - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } -}; - -// ############################################################# -StackWalker::StackWalker(DWORD dwProcessId, HANDLE hProcess) -{ - this->m_options = OptionsAll; - this->m_modulesLoaded = FALSE; - this->m_hProcess = hProcess; - this->m_sw = new StackWalkerInternal(this, this->m_hProcess); - this->m_dwProcessId = dwProcessId; - this->m_szSymPath = NULL; - this->m_MaxRecursionCount = 1000; -} -StackWalker::StackWalker(int options, LPCSTR szSymPath, DWORD dwProcessId, HANDLE hProcess) -{ - this->m_options = options; - this->m_modulesLoaded = FALSE; - this->m_hProcess = hProcess; - this->m_sw = new StackWalkerInternal(this, this->m_hProcess); - this->m_dwProcessId = dwProcessId; - if (szSymPath != NULL) - { - this->m_szSymPath = _strdup(szSymPath); - this->m_options |= SymBuildPath; - } - else - this->m_szSymPath = NULL; - this->m_MaxRecursionCount = 1000; -} - -StackWalker::~StackWalker() -{ - if (m_szSymPath != NULL) - free(m_szSymPath); - m_szSymPath = NULL; - if (this->m_sw != NULL) - delete this->m_sw; - this->m_sw = NULL; -} - -BOOL StackWalker::LoadModules() -{ - if (this->m_sw == NULL) - { - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } - if (m_modulesLoaded != FALSE) - return TRUE; - - // Build the sym-path: - char *szSymPath = NULL; - if ( (this->m_options & SymBuildPath) != 0) - { - const size_t nSymPathLen = 4096; - szSymPath = (char*) malloc(nSymPathLen); - if (szSymPath == NULL) - { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - szSymPath[0] = 0; - // Now first add the (optional) provided sympath: - if (this->m_szSymPath != NULL) - { - strcat_s(szSymPath, nSymPathLen, this->m_szSymPath); - strcat_s(szSymPath, nSymPathLen, ";"); - } - - strcat_s(szSymPath, nSymPathLen, ".;"); - - const size_t nTempLen = 1024; - char szTemp[nTempLen]; - // Now add the current directory: - if (GetCurrentDirectoryA(nTempLen, szTemp) > 0) - { - szTemp[nTempLen-1] = 0; - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - } - - // Now add the path for the main-module: - if (GetModuleFileNameA(NULL, szTemp, nTempLen) > 0) - { - szTemp[nTempLen-1] = 0; - for (char *p = (szTemp+strlen(szTemp)-1); p >= szTemp; --p) - { - // locate the rightmost path separator - if ( (*p == '\\') || (*p == '/') || (*p == ':') ) - { - *p = 0; - break; - } - } // for (search for path separator...) - if (strlen(szTemp) > 0) - { - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - } - } - if (GetEnvironmentVariableA("_NT_SYMBOL_PATH", szTemp, nTempLen) > 0) - { - szTemp[nTempLen-1] = 0; - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - } - if (GetEnvironmentVariableA("_NT_ALTERNATE_SYMBOL_PATH", szTemp, nTempLen) > 0) - { - szTemp[nTempLen-1] = 0; - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - } - if (GetEnvironmentVariableA("SYSTEMROOT", szTemp, nTempLen) > 0) - { - szTemp[nTempLen-1] = 0; - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - // also add the "system32"-directory: - strcat_s(szTemp, nTempLen, "\\system32"); - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - } - - if ( (this->m_options & SymUseSymSrv) != 0) - { - if (GetEnvironmentVariableA("SYSTEMDRIVE", szTemp, nTempLen) > 0) - { - szTemp[nTempLen-1] = 0; - strcat_s(szSymPath, nSymPathLen, "SRV*"); - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, "\\websymbols"); - strcat_s(szSymPath, nSymPathLen, "*http://msdl.microsoft.com/download/symbols;"); - } - else - strcat_s(szSymPath, nSymPathLen, "SRV*c:\\websymbols*http://msdl.microsoft.com/download/symbols;"); - } - } // if SymBuildPath - - // First Init the whole stuff... - BOOL bRet = this->m_sw->Init(szSymPath); - if (szSymPath != NULL) free(szSymPath); szSymPath = NULL; - if (bRet == FALSE) - { - this->OnDbgHelpErr("Error while initializing dbghelp.dll", 0, 0); - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } - - bRet = this->m_sw->LoadModules(this->m_hProcess, this->m_dwProcessId); - if (bRet != FALSE) - m_modulesLoaded = TRUE; - return bRet; -} - - -// The following is used to pass the "userData"-Pointer to the user-provided readMemoryFunction -// This has to be done due to a problem with the "hProcess"-parameter in x64... -// Because this class is in no case multi-threading-enabled (because of the limitations -// of dbghelp.dll) it is "safe" to use a static-variable -static StackWalker::PReadProcessMemoryRoutine s_readMemoryFunction = NULL; -static LPVOID s_readMemoryFunction_UserData = NULL; - -BOOL StackWalker::ShowCallstack(HANDLE hThread, const CONTEXT *context, PReadProcessMemoryRoutine readMemoryFunction, LPVOID pUserData) -{ - CONTEXT c; - CallstackEntry csEntry; - IMAGEHLP_SYMBOL64 *pSym = NULL; - StackWalkerInternal::IMAGEHLP_MODULE64_V3 Module; - IMAGEHLP_LINE64 Line; - int frameNum; - bool bLastEntryCalled = true; - int curRecursionCount = 0; - - if (m_modulesLoaded == FALSE) - this->LoadModules(); // ignore the result... - - if (this->m_sw->m_hDbhHelp == NULL) - { - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } - - s_readMemoryFunction = readMemoryFunction; - s_readMemoryFunction_UserData = pUserData; - - if (context == NULL) - { - // If no context is provided, capture the context - // See: https://stackwalker.codeplex.com/discussions/446958 -#if _WIN32_WINNT <= 0x0501 - // If we need to support XP, we need to use the "old way", because "GetThreadId" is not available! - if (hThread == GetCurrentThread()) -#else - if (GetThreadId(hThread) == GetCurrentThreadId()) -#endif - { - GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, USED_CONTEXT_FLAGS); - } - else - { - SuspendThread(hThread); - memset(&c, 0, sizeof(CONTEXT)); - c.ContextFlags = USED_CONTEXT_FLAGS; - - // TODO: Detect if you want to get a thread context of a different process, which is running a different processor architecture... - // This does only work if we are x64 and the target process is x64 or x86; - // It cannnot work, if this process is x64 and the target process is x64... this is not supported... - // See also: http://www.howzatt.demon.co.uk/articles/DebuggingInWin64.html - if (GetThreadContext(hThread, &c) == FALSE) - { - ResumeThread(hThread); - return FALSE; - } - } - } - else - c = *context; - - // init STACKFRAME for first call - STACKFRAME64 s; // in/out stackframe - memset(&s, 0, sizeof(s)); - DWORD imageType; -#ifdef _M_IX86 - // normally, call ImageNtHeader() and use machine info from PE header - imageType = IMAGE_FILE_MACHINE_I386; - s.AddrPC.Offset = c.Eip; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.Ebp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrStack.Offset = c.Esp; - s.AddrStack.Mode = AddrModeFlat; -#elif _M_X64 - imageType = IMAGE_FILE_MACHINE_AMD64; - s.AddrPC.Offset = c.Rip; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.Rsp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrStack.Offset = c.Rsp; - s.AddrStack.Mode = AddrModeFlat; -#elif _M_IA64 - imageType = IMAGE_FILE_MACHINE_IA64; - s.AddrPC.Offset = c.StIIP; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.IntSp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrBStore.Offset = c.RsBSP; - s.AddrBStore.Mode = AddrModeFlat; - s.AddrStack.Offset = c.IntSp; - s.AddrStack.Mode = AddrModeFlat; -#else -#error "Platform not supported!" -#endif - - pSym = (IMAGEHLP_SYMBOL64 *) malloc(sizeof(IMAGEHLP_SYMBOL64) + STACKWALK_MAX_NAMELEN); - if (!pSym) goto cleanup; // not enough memory... - memset(pSym, 0, sizeof(IMAGEHLP_SYMBOL64) + STACKWALK_MAX_NAMELEN); - pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); - pSym->MaxNameLength = STACKWALK_MAX_NAMELEN; - - memset(&Line, 0, sizeof(Line)); - Line.SizeOfStruct = sizeof(Line); - - memset(&Module, 0, sizeof(Module)); - Module.SizeOfStruct = sizeof(Module); - - for (frameNum = 0; ; ++frameNum ) - { - // get next stack frame (StackWalk64(), SymFunctionTableAccess64(), SymGetModuleBase64()) - // if this returns ERROR_INVALID_ADDRESS (487) or ERROR_NOACCESS (998), you can - // assume that either you are done, or that the stack is so hosed that the next - // deeper frame could not be found. - // CONTEXT need not to be suplied if imageTyp is IMAGE_FILE_MACHINE_I386! - if ( ! this->m_sw->pSW(imageType, this->m_hProcess, hThread, &s, &c, myReadProcMem, this->m_sw->pSFTA, this->m_sw->pSGMB, NULL) ) - { - // INFO: "StackWalk64" does not set "GetLastError"... - this->OnDbgHelpErr("StackWalk64", 0, s.AddrPC.Offset); - break; - } - - csEntry.offset = s.AddrPC.Offset; - csEntry.name[0] = 0; - csEntry.undName[0] = 0; - csEntry.undFullName[0] = 0; - csEntry.offsetFromSmybol = 0; - csEntry.offsetFromLine = 0; - csEntry.lineFileName[0] = 0; - csEntry.lineNumber = 0; - csEntry.loadedImageName[0] = 0; - csEntry.moduleName[0] = 0; - if (s.AddrPC.Offset == s.AddrReturn.Offset) - { - if ( (this->m_MaxRecursionCount > 0) && (curRecursionCount > m_MaxRecursionCount) ) - { - this->OnDbgHelpErr("StackWalk64-Endless-Callstack!", 0, s.AddrPC.Offset); - break; - } - curRecursionCount++; - } - else - curRecursionCount = 0; - if (s.AddrPC.Offset != 0) - { - // we seem to have a valid PC - // show procedure info (SymGetSymFromAddr64()) - if (this->m_sw->pSGSFA(this->m_hProcess, s.AddrPC.Offset, &(csEntry.offsetFromSmybol), pSym) != FALSE) - { - MyStrCpy(csEntry.name, STACKWALK_MAX_NAMELEN, pSym->Name); - // UnDecorateSymbolName() - this->m_sw->pUDSN( pSym->Name, csEntry.undName, STACKWALK_MAX_NAMELEN, UNDNAME_NAME_ONLY ); - this->m_sw->pUDSN( pSym->Name, csEntry.undFullName, STACKWALK_MAX_NAMELEN, UNDNAME_COMPLETE ); - } - else - { - this->OnDbgHelpErr("SymGetSymFromAddr64", GetLastError(), s.AddrPC.Offset); - } - - // show line number info, NT5.0-method (SymGetLineFromAddr64()) - if (this->m_sw->pSGLFA != NULL ) - { // yes, we have SymGetLineFromAddr64() - if (this->m_sw->pSGLFA(this->m_hProcess, s.AddrPC.Offset, &(csEntry.offsetFromLine), &Line) != FALSE) - { - csEntry.lineNumber = Line.LineNumber; - MyStrCpy(csEntry.lineFileName, STACKWALK_MAX_NAMELEN, Line.FileName); - } - else - { - this->OnDbgHelpErr("SymGetLineFromAddr64", GetLastError(), s.AddrPC.Offset); - } - } // yes, we have SymGetLineFromAddr64() - - // show module info (SymGetModuleInfo64()) - if (this->m_sw->GetModuleInfo(this->m_hProcess, s.AddrPC.Offset, &Module ) != FALSE) - { // got module info OK - switch ( Module.SymType ) - { - case SymNone: - csEntry.symTypeString = "-nosymbols-"; - break; - case SymCoff: - csEntry.symTypeString = "COFF"; - break; - case SymCv: - csEntry.symTypeString = "CV"; - break; - case SymPdb: - csEntry.symTypeString = "PDB"; - break; - case SymExport: - csEntry.symTypeString = "-exported-"; - break; - case SymDeferred: - csEntry.symTypeString = "-deferred-"; - break; - case SymSym: - csEntry.symTypeString = "SYM"; - break; -#if API_VERSION_NUMBER >= 9 - case SymDia: - csEntry.symTypeString = "DIA"; - break; -#endif - case 8: //SymVirtual: - csEntry.symTypeString = "Virtual"; - break; - default: - //_snprintf( ty, sizeof(ty), "symtype=%ld", (long) Module.SymType ); - csEntry.symTypeString = NULL; - break; - } - - MyStrCpy(csEntry.moduleName, STACKWALK_MAX_NAMELEN, Module.ModuleName); - csEntry.baseOfImage = Module.BaseOfImage; - MyStrCpy(csEntry.loadedImageName, STACKWALK_MAX_NAMELEN, Module.LoadedImageName); - } // got module info OK - else - { - this->OnDbgHelpErr("SymGetModuleInfo64", GetLastError(), s.AddrPC.Offset); - } - } // we seem to have a valid PC - - CallstackEntryType et = nextEntry; - if (frameNum == 0) - et = firstEntry; - bLastEntryCalled = false; - this->OnCallstackEntry(et, csEntry); - - if (s.AddrReturn.Offset == 0) - { - bLastEntryCalled = true; - this->OnCallstackEntry(lastEntry, csEntry); - SetLastError(ERROR_SUCCESS); - break; - } - } // for ( frameNum ) - - cleanup: - if (pSym) free( pSym ); - - if (bLastEntryCalled == false) - this->OnCallstackEntry(lastEntry, csEntry); - - if (context == NULL) - ResumeThread(hThread); - - return TRUE; -} - -BOOL __stdcall StackWalker::myReadProcMem( - HANDLE hProcess, - DWORD64 qwBaseAddress, - PVOID lpBuffer, - DWORD nSize, - LPDWORD lpNumberOfBytesRead - ) -{ - if (s_readMemoryFunction == NULL) - { - SIZE_T st; - BOOL bRet = ReadProcessMemory(hProcess, (LPVOID) qwBaseAddress, lpBuffer, nSize, &st); - *lpNumberOfBytesRead = (DWORD) st; - //printf("ReadMemory: hProcess: %p, baseAddr: %p, buffer: %p, size: %d, read: %d, result: %d\n", hProcess, (LPVOID) qwBaseAddress, lpBuffer, nSize, (DWORD) st, (DWORD) bRet); - return bRet; - } - else - { - return s_readMemoryFunction(hProcess, qwBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead, s_readMemoryFunction_UserData); - } -} - -void StackWalker::OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion) -{ - CHAR buffer[STACKWALK_MAX_NAMELEN]; - if (fileVersion == 0) - _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%s:%s (%p), size: %d (result: %d), SymType: '%s', PDB: '%s'\n", img, mod, (LPVOID) baseAddr, size, result, symType, pdbName); - else - { - DWORD v4 = (DWORD) (fileVersion & 0xFFFF); - DWORD v3 = (DWORD) ((fileVersion>>16) & 0xFFFF); - DWORD v2 = (DWORD) ((fileVersion>>32) & 0xFFFF); - DWORD v1 = (DWORD) ((fileVersion>>48) & 0xFFFF); - _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%s:%s (%p), size: %d (result: %d), SymType: '%s', PDB: '%s', fileVersion: %d.%d.%d.%d\n", img, mod, (LPVOID) baseAddr, size, result, symType, pdbName, v1, v2, v3, v4); - } - OnOutput(buffer); -} - -void StackWalker::OnCallstackEntry(CallstackEntryType eType, CallstackEntry &entry) -{ - CHAR buffer[STACKWALK_MAX_NAMELEN]; - if ( (eType != lastEntry) && (entry.offset != 0) ) - { - if (entry.name[0] == 0) - MyStrCpy(entry.name, STACKWALK_MAX_NAMELEN, "(function-name not available)"); - if (entry.undName[0] != 0) - MyStrCpy(entry.name, STACKWALK_MAX_NAMELEN, entry.undName); - if (entry.undFullName[0] != 0) - MyStrCpy(entry.name, STACKWALK_MAX_NAMELEN, entry.undFullName); - if (entry.lineFileName[0] == 0) - { - MyStrCpy(entry.lineFileName, STACKWALK_MAX_NAMELEN, "(filename not available)"); - if (entry.moduleName[0] == 0) - MyStrCpy(entry.moduleName, STACKWALK_MAX_NAMELEN, "(module-name not available)"); - _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%p (%s): %s: %s\n", (LPVOID) entry.offset, entry.moduleName, entry.lineFileName, entry.name); - } - else - _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "%s (%d): %s\n", entry.lineFileName, entry.lineNumber, entry.name); - buffer[STACKWALK_MAX_NAMELEN-1] = 0; - OnOutput(buffer); - } -} - -void StackWalker::OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr) -{ - CHAR buffer[STACKWALK_MAX_NAMELEN]; - _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "ERROR: %s, GetLastError: %d (Address: %p)\n", szFuncName, gle, (LPVOID) addr); - OnOutput(buffer); -} - -void StackWalker::OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName) -{ - CHAR buffer[STACKWALK_MAX_NAMELEN]; - _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "SymInit: Symbol-SearchPath: '%s', symOptions: %d, UserName: '%s'\n", szSearchPath, symOptions, szUserName); - OnOutput(buffer); - // Also display the OS-version -#if _MSC_VER <= 1200 - OSVERSIONINFOA ver; - ZeroMemory(&ver, sizeof(OSVERSIONINFOA)); - ver.dwOSVersionInfoSize = sizeof(ver); - if (GetVersionExA(&ver) != FALSE) - { - _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "OS-Version: %d.%d.%d (%s)\n", - ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber, - ver.szCSDVersion); - OnOutput(buffer); - } -#else - OSVERSIONINFOEXA ver; - ZeroMemory(&ver, sizeof(OSVERSIONINFOEXA)); - ver.dwOSVersionInfoSize = sizeof(ver); -#if _MSC_VER >= 1900 -#pragma warning(push) -#pragma warning(disable: 4996) -#endif - if (GetVersionExA( (OSVERSIONINFOA*) &ver) != FALSE) - { - _snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "OS-Version: %d.%d.%d (%s) 0x%x-0x%x\n", - ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber, - ver.szCSDVersion, ver.wSuiteMask, ver.wProductType); - OnOutput(buffer); - } -#if _MSC_VER >= 1900 -#pragma warning(pop) -#endif -#endif -} - -void StackWalker::OnOutput(LPCSTR buffer) -{ - OutputDebugStringA(buffer); -} diff --git a/runtime/flangrti/trace/c_interface.cxx b/runtime/flangrti/trace/c_interface.cxx deleted file mode 100644 index ada294b4e36..00000000000 --- a/runtime/flangrti/trace/c_interface.cxx +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -extern "C" { -#include "trace/c_interface.h" -} -#include "trace/StackWalker.h" - -void SignalHandler(int signal) -{ - StackWalker sw; sw.ShowCallstack(); - exit(1); -} - -extern "C" void _install_win32_handlers() -{ - typedef void (*SignalHandlerPointer)(int); - - SignalHandlerPointer previousHandler; - previousHandler = signal(SIGSEGV , SignalHandler); -} diff --git a/runtime/flangrti/trace/c_interface.h b/runtime/flangrti/trace/c_interface.h deleted file mode 100644 index 43c9e2df04f..00000000000 --- a/runtime/flangrti/trace/c_interface.h +++ /dev/null @@ -1 +0,0 @@ -extern void _install_win32_handlers(); diff --git a/runtime/flangrti/trace/stackwalker.h b/runtime/flangrti/trace/stackwalker.h deleted file mode 100644 index f3dbe749a78..00000000000 --- a/runtime/flangrti/trace/stackwalker.h +++ /dev/null @@ -1,218 +0,0 @@ -/********************************************************************** - * - * StackWalker.h - * - * - * - * LICENSE (http://www.opensource.org/licenses/bsd-license.php) - * - * Copyright (c) 2005-2009, Jochen Kalmbach - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of Jochen Kalmbach nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * **********************************************************************/ -// #pragma once is supported starting with _MCS_VER 1000, -// so we need not to check the version (because we only support _MSC_VER >= 1100)! -#pragma once - -#include - -#if _MSC_VER >= 1900 -#pragma warning(disable : 4091) -#endif - -// special defines for VC5/6 (if no actual PSDK is installed): -#if _MSC_VER < 1300 -typedef unsigned __int64 DWORD64, *PDWORD64; -#if defined(_WIN64) -typedef unsigned __int64 SIZE_T, *PSIZE_T; -#else -typedef unsigned long SIZE_T, *PSIZE_T; -#endif -#endif // _MSC_VER < 1300 - -class StackWalkerInternal; // forward -class StackWalker -{ -public: - typedef enum StackWalkOptions - { - // No addition info will be retrived - // (only the address is available) - RetrieveNone = 0, - - // Try to get the symbol-name - RetrieveSymbol = 1, - - // Try to get the line for this symbol - RetrieveLine = 2, - - // Try to retrieve the module-infos - RetrieveModuleInfo = 4, - - // Also retrieve the version for the DLL/EXE - RetrieveFileVersion = 8, - - // Contains all the abouve - RetrieveVerbose = 0xF, - - // Generate a "good" symbol-search-path - SymBuildPath = 0x10, - - // Also use the public Microsoft-Symbol-Server - SymUseSymSrv = 0x20, - - // Contains all the abouve "Sym"-options - SymAll = 0x30, - - // Contains all options (default) - OptionsAll = 0x3F - } StackWalkOptions; - - StackWalker( - int options = OptionsAll, // 'int' is by design, to combine the enum-flags - LPCSTR szSymPath = NULL, - DWORD dwProcessId = GetCurrentProcessId(), - HANDLE hProcess = GetCurrentProcess() - ); - StackWalker(DWORD dwProcessId, HANDLE hProcess); - virtual ~StackWalker(); - - typedef BOOL (__stdcall *PReadProcessMemoryRoutine)( - HANDLE hProcess, - DWORD64 qwBaseAddress, - PVOID lpBuffer, - DWORD nSize, - LPDWORD lpNumberOfBytesRead, - LPVOID pUserData // optional data, which was passed in "ShowCallstack" - ); - - BOOL LoadModules(); - - BOOL ShowCallstack( - HANDLE hThread = GetCurrentThread(), - const CONTEXT *context = NULL, - PReadProcessMemoryRoutine readMemoryFunction = NULL, - LPVOID pUserData = NULL // optional to identify some data in the 'readMemoryFunction'-callback - ); - -#if _MSC_VER >= 1300 -// due to some reasons, the "STACKWALK_MAX_NAMELEN" must be declared as "public" -// in older compilers in order to use it... starting with VC7 we can declare it as "protected" -protected: -#endif - enum { STACKWALK_MAX_NAMELEN = 1024 }; // max name length for found symbols - -protected: - // Entry for each Callstack-Entry - typedef struct CallstackEntry - { - DWORD64 offset; // if 0, we have no valid entry - CHAR name[STACKWALK_MAX_NAMELEN]; - CHAR undName[STACKWALK_MAX_NAMELEN]; - CHAR undFullName[STACKWALK_MAX_NAMELEN]; - DWORD64 offsetFromSmybol; - DWORD offsetFromLine; - DWORD lineNumber; - CHAR lineFileName[STACKWALK_MAX_NAMELEN]; - DWORD symType; - LPCSTR symTypeString; - CHAR moduleName[STACKWALK_MAX_NAMELEN]; - DWORD64 baseOfImage; - CHAR loadedImageName[STACKWALK_MAX_NAMELEN]; - } CallstackEntry; - - typedef enum CallstackEntryType {firstEntry, nextEntry, lastEntry}; - - virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName); - virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion); - virtual void OnCallstackEntry(CallstackEntryType eType, CallstackEntry &entry); - virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr); - virtual void OnOutput(LPCSTR szText); - - StackWalkerInternal *m_sw; - HANDLE m_hProcess; - DWORD m_dwProcessId; - BOOL m_modulesLoaded; - LPSTR m_szSymPath; - - int m_options; - int m_MaxRecursionCount; - - static BOOL __stdcall myReadProcMem(HANDLE hProcess, DWORD64 qwBaseAddress, PVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead); - - friend StackWalkerInternal; -}; // class StackWalker - - -// The "ugly" assembler-implementation is needed for systems before XP -// If you have a new PSDK and you only compile for XP and later, then you can use -// the "RtlCaptureContext" -// Currently there is no define which determines the PSDK-Version... -// So we just use the compiler-version (and assumes that the PSDK is -// the one which was installed by the VS-IDE) - -// INFO: If you want, you can use the RtlCaptureContext if you only target XP and later... -// But I currently use it in x64/IA64 environments... -//#if defined(_M_IX86) && (_WIN32_WINNT <= 0x0500) && (_MSC_VER < 1400) - -#if defined(_M_IX86) -#ifdef CURRENT_THREAD_VIA_EXCEPTION -// TODO: The following is not a "good" implementation, -// because the callstack is only valid in the "__except" block... -#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \ - do { \ - memset(&c, 0, sizeof(CONTEXT)); \ - EXCEPTION_POINTERS *pExp = NULL; \ - __try { \ - throw 0; \ - } __except( ( (pExp = GetExceptionInformation()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_EXECUTE_HANDLER)) {} \ - if (pExp != NULL) \ - memcpy(&c, pExp->ContextRecord, sizeof(CONTEXT)); \ - c.ContextFlags = contextFlags; \ - } while(0); -#else -// The following should be enough for walking the callstack... -#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \ - do { \ - memset(&c, 0, sizeof(CONTEXT)); \ - c.ContextFlags = contextFlags; \ - __asm call x \ - __asm x: pop eax \ - __asm mov c.Eip, eax \ - __asm mov c.Ebp, ebp \ - __asm mov c.Esp, esp \ - } while(0); -#endif - -#else - -// The following is defined for x86 (XP and higher), x64 and IA64: -#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \ - do { \ - memset(&c, 0, sizeof(CONTEXT)); \ - c.ContextFlags = contextFlags; \ - RtlCaptureContext(&c); \ -} while(0); -#endif diff --git a/runtime/flangrti/trace_lin.c b/runtime/flangrti/trace_lin.c index 7643415d344..1258a6625ba 100644 --- a/runtime/flangrti/trace_lin.c +++ b/runtime/flangrti/trace_lin.c @@ -194,12 +194,57 @@ __abort_sig_init(void) } #else -#include "trace/c_interface.h" -void __abort_trace(int skip) -{ } +#include +#include +#include +#include +#include + +void +__abort_trace(int skip) +{ + unsigned int i; + void * stack[ 100 ]; + unsigned short frames; + SYMBOL_INFO * symbol; + HANDLE process; + + process = GetCurrentProcess(); + + SymInitialize( process, NULL, TRUE ); + + frames = CaptureStackBackTrace( 0, 100, stack, NULL ); + symbol = ( SYMBOL_INFO * )calloc( sizeof( SYMBOL_INFO ) + 256 * sizeof( char ), 1 ); + symbol->MaxNameLen = 255; + symbol->SizeOfStruct = sizeof( SYMBOL_INFO ); -void __abort_sig_init(void) + for( i = 0; i < frames; i++ ) + { + SymFromAddr( process, ( DWORD64 )( stack[ i ] ), 0, symbol ); + + printf( "%i: %s - 0x%0X\n", frames - i - 1, symbol->Name, symbol->Address ); + } + + free( symbol ); + + exit(1); +} + +void +__abort_sig_init(void) { - _install_win32_handlers(); + signal(SIGSEGV , __abort_trace); + signal(SIGILL , __abort_trace); + signal(SIGABRT, __abort_trace); + signal(SIGFPE, __abort_trace); +/* + SIGABRT Abnormal termination + SIGFPE Floating-point error + SIGILL Illegal instruction + SIGINT CTRL+C signal + SIGSEGV Illegal storage access + SIGTERM Termination request + +*/ } #endif From 1e54c2956d7b97d80e8cf52906b8321685560597 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sat, 28 Oct 2017 23:24:25 -0500 Subject: [PATCH 066/141] [runtime/curdir] implement gethostname (#25) --- CMakeLists.txt | 3 --- runtime/flang/CMakeLists.txt | 3 +++ runtime/flang/curdir.c | 15 ++++++++------- runtime/flangrti/CMakeLists.txt | 3 +++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a11167bfc32..ff4b7db9f02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,9 +342,6 @@ macro(add_flang_library name) endif( LLVM_COMMON_DEPENDS ) llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) - if(WIN32) - list(APPEND LLVM_COMMON_LIBS Dbghelp.lib) - endif() target_link_libraries( ${name} ${LLVM_COMMON_LIBS}) # link_system_libs( ${name} ) # getd of cmake warning messages diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index ad7a227c556..09c7443dcbd 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -593,6 +593,9 @@ if (NOT MSVC) target_compile_options(flang_static PRIVATE -fPIC) target_compile_options(flang_shared PRIVATE -fPIC) else() + target_link_libraries(flang_shared PRIVATE Ws2_32.lib) + target_link_libraries(flang_static PRIVATE Ws2_32.lib) + set_target_properties(flang_static PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(flang_shared PROPERTIES LINKER_LANGUAGE CXX) endif() diff --git a/runtime/flang/curdir.c b/runtime/flang/curdir.c index a068e72505a..11320e5b515 100644 --- a/runtime/flang/curdir.c +++ b/runtime/flang/curdir.c @@ -104,10 +104,10 @@ void __fort_getdir(curdir) char *curdir; void __fort_gethostname(host) char *host; { -#ifndef _WIN32 - struct utsname un; char *p; int s; +#ifndef _WIN32 + struct utsname un; p = __fort_getopt("-curhost"); if (p == NULL) { @@ -117,10 +117,11 @@ void __fort_gethostname(host) char *host; } p = un.nodename; } - strcpy(host, p); #else - char temp[128] = ""; - gethostname(host, sizeof(temp)); - strcpy(host, temp); -#endif + s = gethostname(&p, 256); + if (s != 0) { + __fort_abortp("uname"); + } +#endif + strcpy(host, p); } diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index a1cc4bffbc5..8e54505cb54 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -242,6 +242,9 @@ if (NOT MSVC) target_compile_options(flangrti_shared PRIVATE -fPIC) else() set_target_properties(flangrti_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + + target_link_libraries(flangrti_shared PRIVATE Dbghelp.lib) + target_link_libraries(flangrti_static PRIVATE Dbghelp.lib) endif() target_compile_options(flangrti_static PUBLIC $<$:-Mreentrant>) From 1922a571db68fd1a6460a2b6bc5c8df92807e178 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sat, 28 Oct 2017 23:50:05 -0500 Subject: [PATCH 067/141] [runtime/stdio] fix win32 defs (#26) * [runtime/stdio] fix win32 defs * [runtime/util] remove duplicate functions --- runtime/flang/utils.c | 32 -------------------------------- runtime/include/stdioInterf.h | 7 +++++++ 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/runtime/flang/utils.c b/runtime/flang/utils.c index 6cae64eca21..d57167ce8e0 100644 --- a/runtime/flang/utils.c +++ b/runtime/flang/utils.c @@ -604,38 +604,6 @@ __fortio_trunc(FIO_FCB *p, seekoffx_t length) } #ifdef _WIN32 -int -__fortio_binary_mode(void *fp) -{ -#if defined(WINNT) -#include - -#if defined(WIN64) || defined(WIN32) -#define O_BINARY _O_BINARY -#endif - - int mode; - - mode = setmode(fileno((FILE *)fp), O_BINARY); - if (mode == -1) { - /* The mode argument is clearly legal, so this should not - * happen. But, in a console app, setmode will fail on - * the fd representing stdout. - */ - return 0; - } - (void)setmode(fileno((FILE *)fp), mode); - return (mode & O_BINARY); -#else - return 1; -#endif -} - -void -__fortio_setmode_binary(FILE *f) { - _setmode(_fileno(f), _O_BINARY); -} - void sincos(double x, double *sine, double *cosine) { *sine = sin(x); diff --git a/runtime/include/stdioInterf.h b/runtime/include/stdioInterf.h index 4391ec8668f..ab7226ad6ae 100644 --- a/runtime/include/stdioInterf.h +++ b/runtime/include/stdioInterf.h @@ -24,6 +24,13 @@ #endif #include +/* for some reason these are not correctly defined on WIN32 */ +#ifdef _WIN32 +#define __fortio_setmode_binary __io_setmode_binary +#define __fortio_binary_mode __io_binary_mode + +#endif + /* defines to use real host stdio routines */ #define __io_fclose(fp) fclose(fp) From 2e578781296f085e937edd1aff8239080f32b8c9 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 29 Oct 2017 01:19:55 -0500 Subject: [PATCH 068/141] Don't special case windows in lit.cfg --- test/lit.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lit.cfg b/test/lit.cfg index a2e68ecd60e..a39e6a272ff 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -40,7 +40,7 @@ if use_lit_shell: else: # Otherwise we default to internal on Windows and external elsewhere, as # bash on Windows is usually very slow. - execute_external = (not sys.platform in ['win32']) + execute_external = True #(not sys.platform in ['win32']) # testFormat: The test format to use to interpret tests. # From cf95a524f2712ae166f3fbe980b288d83e98474f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 29 Oct 2017 01:59:09 -0500 Subject: [PATCH 069/141] Download llvm source for additional tools --- .appveyor.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 1db63a2478b..c1b358ed1d7 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -26,7 +26,9 @@ install: - cmd: conda config --add channels conda-forge - cmd: conda install --yes --quiet flang-meta llvmdev clangdev openmp cmake - cmd: set "PATH=%PYTHON2_LOCN%\Scripts;%PYTHON2_LOCN%;%PATH%" - - ps: pip install lit + - cmd: appveyor DownloadFile "http://releases.llvm.org/4.0.0/llvm-4.0.0.src.tar.xz" -FileName "llvm.tar.xz" + - cmd: 7z x llvm.tar.xz + - cmd: 7z x llvm.tar.xz > NUL build_script: @@ -35,7 +37,7 @@ build_script: - set "PATH=%cd%\bin;%PATH%" - call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 - ps: | - cmake -G "NMake Makefiles" -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release .. + cmake -G "NMake Makefiles" -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=ON -DLLVM_MAIN_SRC_DIR=yes .. Push-AppveyorArtifact .\CMakeFiles\CMakeOutput.log Push-AppveyorArtifact .\CMakeFiles\CMakeError.log - ps: | @@ -49,6 +51,7 @@ build_script: - ps: Push-AppveyorArtifact C:\Projects\flang\lib.zip test_script: + - cmd: dir "C:\Program Files\LLVM\bin" - cmd: set "PATH=%PATH%;%MSYS2_ROOT%\usr\bin\" - cmd: copy lib\flangmain.lib %CONDA_INSTALL_LOCN%\Library\lib - cmd: copy lib\flangrti.lib %CONDA_INSTALL_LOCN%\Library\lib From 2623704fc641851f0fec6f3e3e5bc9f45010afb5 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 29 Oct 2017 02:13:21 -0500 Subject: [PATCH 070/141] Comment downloading llvm --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index c1b358ed1d7..b92d4b59dde 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -28,7 +28,7 @@ install: - cmd: set "PATH=%PYTHON2_LOCN%\Scripts;%PYTHON2_LOCN%;%PATH%" - cmd: appveyor DownloadFile "http://releases.llvm.org/4.0.0/llvm-4.0.0.src.tar.xz" -FileName "llvm.tar.xz" - cmd: 7z x llvm.tar.xz - - cmd: 7z x llvm.tar.xz > NUL + # - cmd: 7z x llvm.tar.xz > NUL build_script: From 7256d11cdadfccc2f4a468ca3a965c26a420069d Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 29 Oct 2017 02:33:17 -0500 Subject: [PATCH 071/141] Download only utils --- .appveyor.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index b92d4b59dde..83b648bc67a 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -26,10 +26,8 @@ install: - cmd: conda config --add channels conda-forge - cmd: conda install --yes --quiet flang-meta llvmdev clangdev openmp cmake - cmd: set "PATH=%PYTHON2_LOCN%\Scripts;%PYTHON2_LOCN%;%PATH%" - - cmd: appveyor DownloadFile "http://releases.llvm.org/4.0.0/llvm-4.0.0.src.tar.xz" -FileName "llvm.tar.xz" - - cmd: 7z x llvm.tar.xz - # - cmd: 7z x llvm.tar.xz > NUL - + - cmd: appveyor DownloadFile "https://raw.githubusercontent.com/isuruf/flang/utils/llvm_utils_for_flang.zip" -FileName "utils.zip" + - cmd: 7z x -oC:\llvm_src utils.zip build_script: - mkdir build @@ -37,7 +35,7 @@ build_script: - set "PATH=%cd%\bin;%PATH%" - call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 - ps: | - cmake -G "NMake Makefiles" -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=ON -DLLVM_MAIN_SRC_DIR=yes .. + cmake -G "NMake Makefiles" -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=ON -DLLVM_MAIN_SRC_DIR=C:\llvm_src .. Push-AppveyorArtifact .\CMakeFiles\CMakeOutput.log Push-AppveyorArtifact .\CMakeFiles\CMakeError.log - ps: | @@ -51,7 +49,6 @@ build_script: - ps: Push-AppveyorArtifact C:\Projects\flang\lib.zip test_script: - - cmd: dir "C:\Program Files\LLVM\bin" - cmd: set "PATH=%PATH%;%MSYS2_ROOT%\usr\bin\" - cmd: copy lib\flangmain.lib %CONDA_INSTALL_LOCN%\Library\lib - cmd: copy lib\flangrti.lib %CONDA_INSTALL_LOCN%\Library\lib From 6548729bc775c0e0a414c82b1ed9395904e249ba Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 29 Oct 2017 02:42:54 -0500 Subject: [PATCH 072/141] Move msys path to front --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 83b648bc67a..6d2b8959082 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -49,7 +49,7 @@ build_script: - ps: Push-AppveyorArtifact C:\Projects\flang\lib.zip test_script: - - cmd: set "PATH=%PATH%;%MSYS2_ROOT%\usr\bin\" + - cmd: set "PATH=%MSYS2_ROOT%\usr\bin\;%PATH%" - cmd: copy lib\flangmain.lib %CONDA_INSTALL_LOCN%\Library\lib - cmd: copy lib\flangrti.lib %CONDA_INSTALL_LOCN%\Library\lib - cmd: copy lib\flang.lib %CONDA_INSTALL_LOCN%\Library\lib From c68e879baa3ac633c7e7a638d7dc2851815be6ac Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 29 Oct 2017 10:42:42 -0500 Subject: [PATCH 073/141] Workaround for lit --- .appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index 6d2b8959082..789eb1b606c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -54,4 +54,6 @@ test_script: - cmd: copy lib\flangrti.lib %CONDA_INSTALL_LOCN%\Library\lib - cmd: copy lib\flang.lib %CONDA_INSTALL_LOCN%\Library\lib - cmd: copy lib\ompstub.lib %CONDA_INSTALL_LOCN%\Library\lib + - cmd: nmake FileCheck + - cmd: copy bin\FileCheck.exe binFileCheck.exe - cmd: nmake check-flang From 574eb915625fbb25bb6f489ef64c367ecaee2268 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 29 Oct 2017 12:36:20 -0500 Subject: [PATCH 074/141] [cmake] run tests in debug mode --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4957bb62816..961cb9a35e7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,7 +44,7 @@ endif () option(FLANG_TEST_VERBOSE_MODE "Run Flang tests in verbose mode" OFF) if(FLANG_TEST_VERBOSE_MODE) - set(FLANG_TEST_EXTRA_ARGS ${FLANG_TEST_EXTRA_ARGS} "-vv") + set(FLANG_TEST_EXTRA_ARGS ${FLANG_TEST_EXTRA_ARGS} "-vv --debug") endif () set(FLANG_TEST_PARAMS From dfb6acf71724e6e96da9af8e0b409e2eded45205 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 29 Oct 2017 12:59:19 -0500 Subject: [PATCH 075/141] Remove running tests for now --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 789eb1b606c..38582adcde1 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -56,4 +56,4 @@ test_script: - cmd: copy lib\ompstub.lib %CONDA_INSTALL_LOCN%\Library\lib - cmd: nmake FileCheck - cmd: copy bin\FileCheck.exe binFileCheck.exe - - cmd: nmake check-flang + #- cmd: nmake check-flang From a46cd40af4087be22ff77a3240b88d1fe3eced35 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 29 Oct 2017 13:44:25 -0500 Subject: [PATCH 076/141] [runtime/util] implement filetime_to_int64 --- runtime/flang/util.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/runtime/flang/util.c b/runtime/flang/util.c index 7435d0533d2..3bb05f6b1ae 100644 --- a/runtime/flang/util.c +++ b/runtime/flang/util.c @@ -331,3 +331,15 @@ void __fort_ftnstrcpy(char *dst, /* destination string, blank-filled */ *dst++ = ' '; } + +#ifdef _WIN32 +__int64 filetime_to_int64( const FILETIME *ac_FileTime ) +{ + ULARGE_INTEGER lv_Large ; + + lv_Large.LowPart = ac_FileTime->dwLowDateTime ; + lv_Large.HighPart = ac_FileTime->dwHighDateTime ; + + return (__int64)lv_Large.QuadPart ; +} +#endif From 71828d976b1889548e319319734587a4250f9d41 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 29 Oct 2017 13:54:30 -0500 Subject: [PATCH 077/141] Make TARGET_OS and TARGET_ARCHITECTURE cached variables --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff4b7db9f02..a8542162f13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,8 +32,8 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) project(Flang) endif() -set(TARGET_OS ${CMAKE_HOST_SYSTEM_NAME}) -set(TARGET_ARCHITECTURE ${CMAKE_HOST_SYSTEM_PROCESSOR}) +set(TARGET_OS ${CMAKE_HOST_SYSTEM_NAME} CACHE STRING "Target OS") +set(TARGET_ARCHITECTURE ${CMAKE_HOST_SYSTEM_PROCESSOR} CACHE STRING "Target Architecture") if( ${TARGET_OS} STREQUAL "Linux" ) set(OS "LINUX") From 5a77a7d78b25453e1901c9f8fc85e72381b0f8ce Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 29 Oct 2017 14:03:44 -0500 Subject: [PATCH 078/141] [runtime/include] add filetime header --- runtime/include/times_win32.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 runtime/include/times_win32.h diff --git a/runtime/include/times_win32.h b/runtime/include/times_win32.h new file mode 100644 index 00000000000..7995a456625 --- /dev/null +++ b/runtime/include/times_win32.h @@ -0,0 +1,20 @@ +#ifndef _FLANG_TIMES_WIN32 +#define _FLANG_TIMES_WIN32 + #include + + typedef __int64 clock_t; + + typedef struct tms { + clock_t tms_utime; /* user time */ + clock_t tms_stime; /* system time */ + clock_t tms_cutime; /* user time of children */ + clock_t tms_cstime; /* system time of children */ + } tms; + + clock_t convert_filetime( const FILETIME *ac_FileTime ); + + /* + Thin emulation of the unix times function + */ + void times(&tms); +#endif From b26a3be97b2ac6314fe767b0a6bc958a2317bfeb Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 29 Oct 2017 14:04:56 -0500 Subject: [PATCH 079/141] [runtime/util] implement filetime emulation --- runtime/flang/util.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/runtime/flang/util.c b/runtime/flang/util.c index 3bb05f6b1ae..06edf2b2c2b 100644 --- a/runtime/flang/util.c +++ b/runtime/flang/util.c @@ -333,13 +333,28 @@ void __fort_ftnstrcpy(char *dst, /* destination string, blank-filled */ #ifdef _WIN32 -__int64 filetime_to_int64( const FILETIME *ac_FileTime ) +#include "times_win32.h" + +clock_t convert_filetime( const FILETIME *ac_FileTime ) { ULARGE_INTEGER lv_Large ; lv_Large.LowPart = ac_FileTime->dwLowDateTime ; lv_Large.HighPart = ac_FileTime->dwHighDateTime ; - return (__int64)lv_Large.QuadPart ; + return (clock_t)lv_Large.QuadPart ; +} + +/* + Thin emulation of the unix times function +*/ +void times(&tms) { + FILETIME time_create, time_exit, accum_sys, accum_user; + + GetProcessTimes( GetCurrentProcess(), + &time_create, &time_exit, &accum_sys, &accum_user ); + + tms.tms_utime = convert_filetime(accum_user); + tms.tms_stime = convert_filetime(accum_sys); } #endif From a0d19a5b4329e2efbe532b39fb98a7c3d420639d Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 29 Oct 2017 14:06:19 -0500 Subject: [PATCH 080/141] [runtime/dtime] include header [runtime/etime] include header [runtime/include] fix header [runtime/util] fix function [runtime/etime] fix CLK_TCK [runtime/dtime] fix CLK_TCK [runtime/dtime] fix clk_tick [runtime/etime] fix clk_tick --- runtime/flang/dtime3f.c | 38 +++++++---------------------------- runtime/flang/etime3f.c | 29 ++++++++------------------ runtime/flang/util.c | 6 +++--- runtime/include/times_win32.h | 2 +- 4 files changed, 19 insertions(+), 56 deletions(-) diff --git a/runtime/flang/dtime3f.c b/runtime/flang/dtime3f.c index b1433772cea..2745e1aa1f9 100644 --- a/runtime/flang/dtime3f.c +++ b/runtime/flang/dtime3f.c @@ -31,11 +31,15 @@ #include #include -#ifndef CLK_TCK -#define CLK_TCK sysconf(_SC_CLK_TCK) +#ifdef _WIN32 + #include "times_win32.h" + #define CLK_TCK 10000000.0 +#else + #ifndef CLK_TCK + #define CLK_TCK sysconf(_SC_CLK_TCK) + #endif #endif -#ifndef _WIN32 static clock_t accum_user = 0, accum_sys = 0; float ENT3F(DTIME, dtime)(float *tarray) @@ -50,33 +54,5 @@ float ENT3F(DTIME, dtime)(float *tarray) accum_sys = b.tms_stime; return (tarray[0] + tarray[1]); } -#else -#include -static FILETIME accum_user; -static FILETIME accum_sys; - -float convert_filetime( const FILETIME *ac_FileTime ) -{ - ULARGE_INTEGER lv_Large ; - - lv_Large.LowPart = ac_FileTime->dwLowDateTime ; - lv_Large.HighPart = ac_FileTime->dwHighDateTime ; - - return (float)lv_Large.QuadPart ; -} -float ENT3F(DTIME, dtime)(float *tarray) -{ - - FILETIME time_create; - FILETIME time_exit; - - GetProcessTimes( GetCurrentProcess(), - &time_create, &time_exit, &accum_sys, &accum_user ); - - tarray[0] = ((float)(convert_filetime(&accum_user))); - tarray[1] = ((float)(convert_filetime(&accum_sys))); - return (tarray[0] + tarray[1]); -} -#endif diff --git a/runtime/flang/etime3f.c b/runtime/flang/etime3f.c index cb8b6cc2ebd..e0931ee10e7 100644 --- a/runtime/flang/etime3f.c +++ b/runtime/flang/etime3f.c @@ -33,11 +33,16 @@ #include #include -#ifndef CLK_TCK -#define CLK_TCK sysconf(_SC_CLK_TCK) + +#ifdef _WIN32 + #include "times_win32.h" + #define CLK_TCK 10000000.0 +#else + #ifndef CLK_TCK + #define CLK_TCK sysconf(_SC_CLK_TCK) + #endif #endif -#ifndef _WIN32 float ENT3F(ETIME, etime)(float *tarray) { struct tms b; @@ -49,21 +54,3 @@ float ENT3F(ETIME, etime)(float *tarray) return (tarray[0] + tarray[1]); } -#else -#include - -float ENT3F(ETIME, etime)(float *tarray) -{ - FILETIME accum_user; - FILETIME accum_sys; - FILETIME time_create; - FILETIME time_exit; - - GetProcessTimes( GetCurrentProcess(), - &time_create, &time_exit, &accum_sys, &accum_user ); - - tarray[0] = ((float)(convert_filetime(&accum_user))); - tarray[1] = ((float)(convert_filetime(&accum_sys))); - return (tarray[0] + tarray[1]); -} -#endif diff --git a/runtime/flang/util.c b/runtime/flang/util.c index 06edf2b2c2b..31ce163d061 100644 --- a/runtime/flang/util.c +++ b/runtime/flang/util.c @@ -348,13 +348,13 @@ clock_t convert_filetime( const FILETIME *ac_FileTime ) /* Thin emulation of the unix times function */ -void times(&tms) { +void times(tms *time_struct) { FILETIME time_create, time_exit, accum_sys, accum_user; GetProcessTimes( GetCurrentProcess(), &time_create, &time_exit, &accum_sys, &accum_user ); - tms.tms_utime = convert_filetime(accum_user); - tms.tms_stime = convert_filetime(accum_sys); + tms.time_struct = convert_filetime(accum_user); + tms.time_struct = convert_filetime(accum_sys); } #endif diff --git a/runtime/include/times_win32.h b/runtime/include/times_win32.h index 7995a456625..4c76ee6e24e 100644 --- a/runtime/include/times_win32.h +++ b/runtime/include/times_win32.h @@ -16,5 +16,5 @@ /* Thin emulation of the unix times function */ - void times(&tms); + void times(tms *time_struct); #endif From f5cad3c00897191e23cfdae2f7b531fd25c03c85 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 29 Oct 2017 14:56:20 -0500 Subject: [PATCH 081/141] [runtime/util] fix --- runtime/flang/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/flang/util.c b/runtime/flang/util.c index 31ce163d061..a2e411a132e 100644 --- a/runtime/flang/util.c +++ b/runtime/flang/util.c @@ -354,7 +354,7 @@ void times(tms *time_struct) { GetProcessTimes( GetCurrentProcess(), &time_create, &time_exit, &accum_sys, &accum_user ); - tms.time_struct = convert_filetime(accum_user); - tms.time_struct = convert_filetime(accum_sys); + time_struct.tms_utime = convert_filetime(accum_user); + time_struct.tms_stime = convert_filetime(accum_sys); } #endif From f9341cec394f48cb81a4a00c46d9415da29f5ca2 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 29 Oct 2017 14:58:08 -0500 Subject: [PATCH 082/141] Fix cmake warning --- runtime/flang/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 09c7443dcbd..fe505035584 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -593,8 +593,8 @@ if (NOT MSVC) target_compile_options(flang_static PRIVATE -fPIC) target_compile_options(flang_shared PRIVATE -fPIC) else() - target_link_libraries(flang_shared PRIVATE Ws2_32.lib) - target_link_libraries(flang_static PRIVATE Ws2_32.lib) + target_link_libraries(flang_shared Ws2_32.lib) + target_link_libraries(flang_static Ws2_32.lib) set_target_properties(flang_static PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(flang_shared PROPERTIES LINKER_LANGUAGE CXX) From ff97e481027bdc018ff2a759302605819c84675a Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 29 Oct 2017 15:11:55 -0500 Subject: [PATCH 083/141] Fix nmake install --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8542162f13..0cf23b291d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -362,6 +362,17 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include ) +if (MSVC) +# Direct module files to build include directory +set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/runtime/flang) + +# Install Fortran module files +# TODO: this creates empty directories. Figure out a workaround or +# better would be to figure out why CMAKE_Fortran_MODULE_DIRECTORY is different +install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ + DESTINATION include FILES_MATCHING PATTERN *.mod + ) +else() # Direct module files to build include directory set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include) @@ -369,6 +380,7 @@ set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include) install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ DESTINATION include ) +endif() # Install Fortran OpenMP include file # Copy omp_lib.h file, not the symlink From a064ff46b3bed45e3ac87eb6ab8527ceedb60c5c Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 29 Oct 2017 15:14:43 -0500 Subject: [PATCH 084/141] [runtime/util] fix --- runtime/flang/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/flang/util.c b/runtime/flang/util.c index a2e411a132e..5b451f4916b 100644 --- a/runtime/flang/util.c +++ b/runtime/flang/util.c @@ -354,7 +354,7 @@ void times(tms *time_struct) { GetProcessTimes( GetCurrentProcess(), &time_create, &time_exit, &accum_sys, &accum_user ); - time_struct.tms_utime = convert_filetime(accum_user); - time_struct.tms_stime = convert_filetime(accum_sys); + time_struct->tms_utime = convert_filetime(accum_user); + time_struct->tms_stime = convert_filetime(accum_sys); } #endif From 81e04a48add13b63af2c6c803e604dec216d864f Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 29 Oct 2017 15:24:58 -0500 Subject: [PATCH 085/141] Update util.c --- runtime/flang/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/flang/util.c b/runtime/flang/util.c index 5b451f4916b..8d122523475 100644 --- a/runtime/flang/util.c +++ b/runtime/flang/util.c @@ -354,7 +354,7 @@ void times(tms *time_struct) { GetProcessTimes( GetCurrentProcess(), &time_create, &time_exit, &accum_sys, &accum_user ); - time_struct->tms_utime = convert_filetime(accum_user); - time_struct->tms_stime = convert_filetime(accum_sys); + time_struct->tms_utime = convert_filetime(&accum_user); + time_struct->tms_stime = convert_filetime(&accum_sys); } #endif From 4cb8a61d1b397a8bce1c5b527abbec553150ae0d Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Mon, 30 Oct 2017 17:05:22 -0500 Subject: [PATCH 086/141] Align to cache line set to 32 for windows --- tools/flang2/flang2exe/llassem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/flang2/flang2exe/llassem.c b/tools/flang2/flang2exe/llassem.c index b06c83d43a3..f7245a0e53d 100644 --- a/tools/flang2/flang2exe/llassem.c +++ b/tools/flang2/flang2exe/llassem.c @@ -167,7 +167,10 @@ static int global_sptr; /* use to prepend for CUDA constructor static it read only(aM). */ -#ifdef TARGET_POWER +#ifdef TARGET_WIN +#define CACHE_ALIGN 31 +#define ALN_UNIT 32 +#elif TARGET_POWER #define CACHE_ALIGN 127 #define ALN_UNIT 128 #else From a1bd1cd414664f6c85188599e0486f8b0568db82 Mon Sep 17 00:00:00 2001 From: xoviat Date: Tue, 31 Oct 2017 23:04:55 -0500 Subject: [PATCH 087/141] Signal: drop handlers (#42) * [flangrti/trace_lin] drop win32 signal handler * [cmake] drop dbghelp * [flangrti/trace] fix handler --- runtime/flangrti/CMakeLists.txt | 4 ++-- runtime/flangrti/trace_lin.c | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index 8e54505cb54..f8e4b70312f 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -243,8 +243,8 @@ if (NOT MSVC) else() set_target_properties(flangrti_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) - target_link_libraries(flangrti_shared PRIVATE Dbghelp.lib) - target_link_libraries(flangrti_static PRIVATE Dbghelp.lib) + # target_link_libraries(flangrti_shared PRIVATE Dbghelp.lib) + # target_link_libraries(flangrti_static PRIVATE Dbghelp.lib) endif() target_compile_options(flangrti_static PUBLIC $<$:-Mreentrant>) diff --git a/runtime/flangrti/trace_lin.c b/runtime/flangrti/trace_lin.c index 1258a6625ba..f6e83bad1fc 100644 --- a/runtime/flangrti/trace_lin.c +++ b/runtime/flangrti/trace_lin.c @@ -193,7 +193,7 @@ __abort_sig_init(void) } } -#else +#elif 0 #include #include #include @@ -247,4 +247,12 @@ __abort_sig_init(void) */ } +#else +void +__abort_trace(int skip) +{ } + +void +__abort_sig_init(void) +{ } #endif From eb40c0b99f92f587fed5c50875a3a08500dfa37a Mon Sep 17 00:00:00 2001 From: xoviat Date: Tue, 31 Oct 2017 23:14:03 -0500 Subject: [PATCH 088/141] Ws2 32 (#43) * [cmake] drop ws2_32 * [curdir] drop impl. --- runtime/flang/CMakeLists.txt | 4 ++-- runtime/flang/curdir.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index fe505035584..cf22ee0be97 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -593,8 +593,8 @@ if (NOT MSVC) target_compile_options(flang_static PRIVATE -fPIC) target_compile_options(flang_shared PRIVATE -fPIC) else() - target_link_libraries(flang_shared Ws2_32.lib) - target_link_libraries(flang_static Ws2_32.lib) + # target_link_libraries(flang_shared Ws2_32.lib) + # target_link_libraries(flang_static Ws2_32.lib) set_target_properties(flang_static PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(flang_shared PROPERTIES LINKER_LANGUAGE CXX) diff --git a/runtime/flang/curdir.c b/runtime/flang/curdir.c index 11320e5b515..cad2fd40587 100644 --- a/runtime/flang/curdir.c +++ b/runtime/flang/curdir.c @@ -19,7 +19,7 @@ #ifndef _WIN32 #include #include -#else +#elif 0 #include #endif #include @@ -117,11 +117,13 @@ void __fort_gethostname(host) char *host; } p = un.nodename; } -#else +#elif 0 s = gethostname(&p, 256); if (s != 0) { __fort_abortp("uname"); } +#else + strcpy(p, "localhost"); #endif strcpy(host, p); } From ecf31e4fbb3209f017a0f9750ba1cd7d2333d8ed Mon Sep 17 00:00:00 2001 From: xoviat Date: Wed, 1 Nov 2017 13:29:22 -0500 Subject: [PATCH 089/141] [flang2/ll_structure] add linker options to enum [flang2/ll_structure] add psuedocode [flang2/ll_write] impl. metadata name [flang2/ll_structure] prelim. impl. Probably wrong. [flang2/ll_structure] cleanup [flang2/ll_structure] fix type [flang2/ll_structure] fix syntax [flang2/ll_structure] fix type fix Update ll_structure.c [flang2/ll_structure] cleanup fix type fix LLVM IR include header move up header Add new options for linker_directives and llvm_target_triples include header Fix typo fix header Fix typo in llvm_target_triple move code to function add defn to header fix typo Fix ll_structure.c add debug version Update .appveyor.yml fix fix fix fix --- .appveyor.yml | 2 +- tools/flang2/flang2exe/aarch64-Linux/flgdf.h | 2 + tools/flang2/flang2exe/cgmain.c | 5 +- tools/flang2/flang2exe/ll_structure.c | 59 +++++++++++++++++++- tools/flang2/flang2exe/ll_structure.h | 2 + tools/flang2/flang2exe/ll_write.c | 2 + tools/flang2/flang2exe/main.c | 3 + tools/flang2/flang2exe/ppc64le-Linux/flgdf.h | 2 + tools/flang2/flang2exe/x86_64-Linux/flgdf.h | 2 + tools/shared/utils/global.h | 2 + 10 files changed, 78 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 38582adcde1..57d24493492 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -30,7 +30,7 @@ install: - cmd: 7z x -oC:\llvm_src utils.zip build_script: - - mkdir build + - ps: mkdir build; $LastExitCode = 0 - cd build - set "PATH=%cd%\bin;%PATH%" - call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 diff --git a/tools/flang2/flang2exe/aarch64-Linux/flgdf.h b/tools/flang2/flang2exe/aarch64-Linux/flgdf.h index d149a29d6b8..aa5b3045159 100644 --- a/tools/flang2/flang2exe/aarch64-Linux/flgdf.h +++ b/tools/flang2/flang2exe/aarch64-Linux/flgdf.h @@ -37,6 +37,8 @@ FLG flg = { 0x00000000, /* xon */ FALSE, /* ucase = -noucase */ NULL, /* idir == empty list */ + NULL, /* linker_directives == empty list */ + NULL, /* llvm_target_triple == empty ptr */ FALSE, /* dlines = -nodlines */ 72, /* extend_source = -noextend_source */ TRUE, /* i4 = -i4 */ diff --git a/tools/flang2/flang2exe/cgmain.c b/tools/flang2/flang2exe/cgmain.c index d904831588c..e39e2b4c56a 100644 --- a/tools/flang2/flang2exe/cgmain.c +++ b/tools/flang2/flang2exe/cgmain.c @@ -12363,7 +12363,10 @@ cg_llvm_init(void) CHECK(TARGET_PTRSIZE == size_of(DT_CPTR)); - triple = LLVM_DEFAULT_TARGET_TRIPLE; + if (flg.llvm_target_triple) + triple = flg.llvm_target_triple; + else + triple = LLVM_DEFAULT_TARGET_TRIPLE; ir_version = get_llvm_version(); diff --git a/tools/flang2/flang2exe/ll_structure.c b/tools/flang2/flang2exe/ll_structure.c index 15588e15f81..47a4f4bedc1 100644 --- a/tools/flang2/flang2exe/ll_structure.c +++ b/tools/flang2/flang2exe/ll_structure.c @@ -21,10 +21,11 @@ */ #include "gbldefs.h" +#include "global.h" #include "error.h" +#include "ll_builder.h" #include "ll_structure.h" #include "lldebug.h" -#include "global.h" #include "go.h" #include #include @@ -580,9 +581,65 @@ ll_create_module(const char *module_name, const char *target_triple, compute_ir_feature_vector(new_module, llvm_ir_version); compute_datalayout(new_module); + + #ifdef _WIN32 + if (flg.linker_directives) { + add_linker_directives(new_module); + } + #endif + return new_module; } +void +add_linker_directives(LLVMModuleRef module) { + LLMD_Builder mdb = llmd_init(module); + char* linker_directive; + for (int i = 0; (linker_directive = flg.linker_directives[i]); ++i) { + LLMD_Builder submdb = llmd_init(module); + + llmd_add_string(submdb, linker_directive); + LL_MDRef submd = llmd_finish(submdb); + + llmd_add_md(mdb, submd); + } + LL_MDRef md = llmd_finish(mdb); + + LLMD_Builder boilerplate_mdb = llmd_init(module); + + llmd_add_i32(boilerplate_mdb, 6); + llmd_add_string(boilerplate_mdb, "Linker Options"); + llmd_add_md(boilerplate_mdb, md); + + LL_MDRef boilerplate_md = llmd_finish(boilerplate_mdb); + ll_extend_named_md_node(module, MD_llvm_module_flags, boilerplate_md); + + LLMD_Builder debug_mdb = llmd_init(module); + + const int mdVers = ll_feature_versioned_dw_tag(&module->ir) ? 1 : + module->ir.debug_info_version; + + llmd_add_i32(debug_mdb, 1); + llmd_add_string(debug_mdb, "Debug Info Version"); + llmd_add_i32(debug_mdb, mdVers); + + LL_MDRef debug_md = llmd_finish(debug_mdb); + + ll_extend_named_md_node(module, MD_llvm_module_flags, debug_md); + /* + LLVM 5.0: + + int i; + char *linker_directive; + LLMD_Builder mdb = llmd_init(new_module); + for (i = 0; (linker_directive = flg.linker_directives[i]); ++i) { + llmd_add_string(mdb, linker_directive); + } + LL_MDRef linker_md = llmd_finish(mdb); + ll_extend_named_md_node(new_module, MD_llvm_linker_options, linker_md); + */ +} + struct LL_Function_ * ll_create_function(LLVMModuleRef module, const char *name, LL_Type *return_type, int is_kernel, int launch_bounds, diff --git a/tools/flang2/flang2exe/ll_structure.h b/tools/flang2/flang2exe/ll_structure.h index 36a6f8d6532..cfdef4d8b36 100644 --- a/tools/flang2/flang2exe/ll_structure.h +++ b/tools/flang2/flang2exe/ll_structure.h @@ -633,6 +633,7 @@ enum LL_MDName { /** DWARF compilation unit descriptors, from "Source Level Debugging with LLVM". */ MD_llvm_dbg_cu, + MD_llvm_linker_options, MD_opencl_kernels, /**< SPIR */ MD_nvvm_annotations, /**< CUDA */ MD_nvvmir_version, /**< CUDA */ @@ -1070,5 +1071,6 @@ llObjtodbgGet(LL_ObjToDbgListIter *iter) void llObjtodbgPush(LL_ObjToDbgList *odl, LL_MDRef md); void llObjtodbgFree(LL_ObjToDbgList *ods); +void add_linker_directives(LLVMModuleRef module); #endif diff --git a/tools/flang2/flang2exe/ll_write.c b/tools/flang2/flang2exe/ll_write.c index 2ef35455ddc..eadb8eb0a02 100644 --- a/tools/flang2/flang2exe/ll_write.c +++ b/tools/flang2/flang2exe/ll_write.c @@ -1475,6 +1475,8 @@ get_metadata_name(enum LL_MDName name) return "!llvm.module.flags"; case MD_llvm_dbg_cu: return "!llvm.dbg.cu"; + case MD_llvm_linker_options: + return "!llvm.linker.options"; case MD_opencl_kernels: return "!opencl.kernels"; case MD_nvvm_annotations: diff --git a/tools/flang2/flang2exe/main.c b/tools/flang2/flang2exe/main.c index ddc2025b907..ad11512e532 100644 --- a/tools/flang2/flang2exe/main.c +++ b/tools/flang2/flang2exe/main.c @@ -613,6 +613,9 @@ init(int argc, char *argv[]) register_integer_arg(arg_parser, "vect", &(vect_val), 0); register_string_arg(arg_parser, "cmdline", &(cmdline), NULL); register_boolean_arg(arg_parser, "debug", (bool *)&(flg.debug), false); + flg.linker_directives = (char **)getitem(8, argc * sizeof(char *)); + register_string_list_arg(arg_parser, "linker", flg.linker_directives); + register_string_arg(arg_parser, "target", &(flg.llvm_target_triple), NULL); /* Run argument parser */ parse_arguments(arg_parser, argc, argv); diff --git a/tools/flang2/flang2exe/ppc64le-Linux/flgdf.h b/tools/flang2/flang2exe/ppc64le-Linux/flgdf.h index d149a29d6b8..aa5b3045159 100644 --- a/tools/flang2/flang2exe/ppc64le-Linux/flgdf.h +++ b/tools/flang2/flang2exe/ppc64le-Linux/flgdf.h @@ -37,6 +37,8 @@ FLG flg = { 0x00000000, /* xon */ FALSE, /* ucase = -noucase */ NULL, /* idir == empty list */ + NULL, /* linker_directives == empty list */ + NULL, /* llvm_target_triple == empty ptr */ FALSE, /* dlines = -nodlines */ 72, /* extend_source = -noextend_source */ TRUE, /* i4 = -i4 */ diff --git a/tools/flang2/flang2exe/x86_64-Linux/flgdf.h b/tools/flang2/flang2exe/x86_64-Linux/flgdf.h index 4b67081ba39..33054f1c81e 100644 --- a/tools/flang2/flang2exe/x86_64-Linux/flgdf.h +++ b/tools/flang2/flang2exe/x86_64-Linux/flgdf.h @@ -39,6 +39,8 @@ FLG flg = { 0x00000000, /* xon */ FALSE, /* ucase = -noucase */ NULL, /* idir == empty list */ + NULL, /* linker_directives == empty list */ + NULL, /* llvm_target_triple == empty ptr */ FALSE, /* dlines = -nodlines */ 72, /* extend_source = -noextend_source */ TRUE, /* i4 = -i4 */ diff --git a/tools/shared/utils/global.h b/tools/shared/utils/global.h index a3706473714..f84186ca972 100644 --- a/tools/shared/utils/global.h +++ b/tools/shared/utils/global.h @@ -163,6 +163,8 @@ typedef struct { UINT xon; LOGICAL ucase; char **idir; + char **linker_directives; + char *llvm_target_triple; LOGICAL dlines; int extend_source; LOGICAL i4; From f542d67d74e58c82eb48ce1ac306fd55d842d04f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Fri, 3 Nov 2017 17:27:14 -0500 Subject: [PATCH 090/141] ifdef for LLVM version --- tools/flang2/flang2exe/ll_structure.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/flang2/flang2exe/ll_structure.c b/tools/flang2/flang2exe/ll_structure.c index 47a4f4bedc1..c87e5008907 100644 --- a/tools/flang2/flang2exe/ll_structure.c +++ b/tools/flang2/flang2exe/ll_structure.c @@ -593,6 +593,7 @@ ll_create_module(const char *module_name, const char *target_triple, void add_linker_directives(LLVMModuleRef module) { +#if LLVM_VERSION_MAJOR < 5 LLMD_Builder mdb = llmd_init(module); char* linker_directive; for (int i = 0; (linker_directive = flg.linker_directives[i]); ++i) { @@ -626,18 +627,17 @@ add_linker_directives(LLVMModuleRef module) { LL_MDRef debug_md = llmd_finish(debug_mdb); ll_extend_named_md_node(module, MD_llvm_module_flags, debug_md); - /* - LLVM 5.0: - - int i; - char *linker_directive; - LLMD_Builder mdb = llmd_init(new_module); - for (i = 0; (linker_directive = flg.linker_directives[i]); ++i) { - llmd_add_string(mdb, linker_directive); - } - LL_MDRef linker_md = llmd_finish(mdb); - ll_extend_named_md_node(new_module, MD_llvm_linker_options, linker_md); - */ + +#else + int i; + char *linker_directive; + LLMD_Builder mdb = llmd_init(new_module); + for (i = 0; (linker_directive = flg.linker_directives[i]); ++i) { + llmd_add_string(mdb, linker_directive); + } + LL_MDRef linker_md = llmd_finish(mdb); + ll_extend_named_md_node(new_module, MD_llvm_linker_options, linker_md); +#endif } struct LL_Function_ * From ad54611999edb61f9404e7262b5d4dce6685a298 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Fri, 3 Nov 2017 17:29:03 -0500 Subject: [PATCH 091/141] Fix for -linker -directive When the linker directive starts with "-", flang2 interprets it as another option, so flang.exe needs to send prepended with a \ --- tools/flang2/flang2exe/ll_structure.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/flang2/flang2exe/ll_structure.c b/tools/flang2/flang2exe/ll_structure.c index c87e5008907..b7c044c82b6 100644 --- a/tools/flang2/flang2exe/ll_structure.c +++ b/tools/flang2/flang2exe/ll_structure.c @@ -598,7 +598,9 @@ add_linker_directives(LLVMModuleRef module) { char* linker_directive; for (int i = 0; (linker_directive = flg.linker_directives[i]); ++i) { LLMD_Builder submdb = llmd_init(module); - + if (strlen(linker_directive) > 2 && linker_directive[0] == '\\' && + linker_directive[1] == '-') + linker_directive = linker_directive + 1; llmd_add_string(submdb, linker_directive); LL_MDRef submd = llmd_finish(submdb); From 856e4b8e3f407e03f39af20928f11dbd67117ab8 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Fri, 3 Nov 2017 20:08:37 -0500 Subject: [PATCH 092/141] Revert "Fix for -linker -directive" This reverts commit 5deb6bf3ce432a1a2880d81c733ff6379e037e45. --- tools/flang2/flang2exe/ll_structure.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/flang2/flang2exe/ll_structure.c b/tools/flang2/flang2exe/ll_structure.c index b7c044c82b6..c87e5008907 100644 --- a/tools/flang2/flang2exe/ll_structure.c +++ b/tools/flang2/flang2exe/ll_structure.c @@ -598,9 +598,7 @@ add_linker_directives(LLVMModuleRef module) { char* linker_directive; for (int i = 0; (linker_directive = flg.linker_directives[i]); ++i) { LLMD_Builder submdb = llmd_init(module); - if (strlen(linker_directive) > 2 && linker_directive[0] == '\\' && - linker_directive[1] == '-') - linker_directive = linker_directive + 1; + llmd_add_string(submdb, linker_directive); LL_MDRef submd = llmd_finish(submdb); From 0f8c27bfeceeebf63bedc9c83b5af20ef55a7ff9 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Fri, 3 Nov 2017 20:11:40 -0500 Subject: [PATCH 093/141] Check LLVM version at runtime --- tools/flang2/flang2exe/ll_structure.c | 71 +++++++++++++-------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/tools/flang2/flang2exe/ll_structure.c b/tools/flang2/flang2exe/ll_structure.c index c87e5008907..b53a2e62f2e 100644 --- a/tools/flang2/flang2exe/ll_structure.c +++ b/tools/flang2/flang2exe/ll_structure.c @@ -593,51 +593,50 @@ ll_create_module(const char *module_name, const char *target_triple, void add_linker_directives(LLVMModuleRef module) { -#if LLVM_VERSION_MAJOR < 5 - LLMD_Builder mdb = llmd_init(module); - char* linker_directive; - for (int i = 0; (linker_directive = flg.linker_directives[i]); ++i) { - LLMD_Builder submdb = llmd_init(module); + if (get_llvm_version() < LL_Version_5_0) { + LLMD_Builder mdb = llmd_init(module); + char* linker_directive; + for (int i = 0; (linker_directive = flg.linker_directives[i]); ++i) { + LLMD_Builder submdb = llmd_init(module); - llmd_add_string(submdb, linker_directive); - LL_MDRef submd = llmd_finish(submdb); + llmd_add_string(submdb, linker_directive); + LL_MDRef submd = llmd_finish(submdb); - llmd_add_md(mdb, submd); - } - LL_MDRef md = llmd_finish(mdb); + llmd_add_md(mdb, submd); + } + LL_MDRef md = llmd_finish(mdb); - LLMD_Builder boilerplate_mdb = llmd_init(module); - - llmd_add_i32(boilerplate_mdb, 6); - llmd_add_string(boilerplate_mdb, "Linker Options"); - llmd_add_md(boilerplate_mdb, md); - - LL_MDRef boilerplate_md = llmd_finish(boilerplate_mdb); - ll_extend_named_md_node(module, MD_llvm_module_flags, boilerplate_md); + LLMD_Builder boilerplate_mdb = llmd_init(module); - LLMD_Builder debug_mdb = llmd_init(module); + llmd_add_i32(boilerplate_mdb, 6); + llmd_add_string(boilerplate_mdb, "Linker Options"); + llmd_add_md(boilerplate_mdb, md); - const int mdVers = ll_feature_versioned_dw_tag(&module->ir) ? 1 : - module->ir.debug_info_version; + LL_MDRef boilerplate_md = llmd_finish(boilerplate_mdb); + ll_extend_named_md_node(module, MD_llvm_module_flags, boilerplate_md); - llmd_add_i32(debug_mdb, 1); - llmd_add_string(debug_mdb, "Debug Info Version"); - llmd_add_i32(debug_mdb, mdVers); + LLMD_Builder debug_mdb = llmd_init(module); - LL_MDRef debug_md = llmd_finish(debug_mdb); + const int mdVers = ll_feature_versioned_dw_tag(&module->ir) ? 1 : + module->ir.debug_info_version; - ll_extend_named_md_node(module, MD_llvm_module_flags, debug_md); + llmd_add_i32(debug_mdb, 1); + llmd_add_string(debug_mdb, "Debug Info Version"); + llmd_add_i32(debug_mdb, mdVers); -#else - int i; - char *linker_directive; - LLMD_Builder mdb = llmd_init(new_module); - for (i = 0; (linker_directive = flg.linker_directives[i]); ++i) { - llmd_add_string(mdb, linker_directive); - } - LL_MDRef linker_md = llmd_finish(mdb); - ll_extend_named_md_node(new_module, MD_llvm_linker_options, linker_md); -#endif + LL_MDRef debug_md = llmd_finish(debug_mdb); + + ll_extend_named_md_node(module, MD_llvm_module_flags, debug_md); + } else { + int i; + char *linker_directive; + LLMD_Builder mdb = llmd_init(new_module); + for (i = 0; (linker_directive = flg.linker_directives[i]); ++i) { + llmd_add_string(mdb, linker_directive); + } + LL_MDRef linker_md = llmd_finish(mdb); + ll_extend_named_md_node(new_module, MD_llvm_linker_options, linker_md); + } } struct LL_Function_ * From 623b71fafd683f82588299546e6b7658f9e0d74b Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 3 Nov 2017 20:20:42 -0500 Subject: [PATCH 094/141] [flang2:ll_structure] fix name --- tools/flang2/flang2exe/ll_structure.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/flang2/flang2exe/ll_structure.c b/tools/flang2/flang2exe/ll_structure.c index b53a2e62f2e..a615daf5015 100644 --- a/tools/flang2/flang2exe/ll_structure.c +++ b/tools/flang2/flang2exe/ll_structure.c @@ -630,12 +630,12 @@ add_linker_directives(LLVMModuleRef module) { } else { int i; char *linker_directive; - LLMD_Builder mdb = llmd_init(new_module); + LLMD_Builder mdb = llmd_init(module); for (i = 0; (linker_directive = flg.linker_directives[i]); ++i) { llmd_add_string(mdb, linker_directive); } LL_MDRef linker_md = llmd_finish(mdb); - ll_extend_named_md_node(new_module, MD_llvm_linker_options, linker_md); + ll_extend_named_md_node(module, MD_llvm_linker_options, linker_md); } } From 7108e6b3b3a1ea8314e9c41924c354debce21794 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Mon, 6 Nov 2017 10:37:12 -0600 Subject: [PATCH 095/141] Send `-no-flang-libs` when compiling flang.lib This is so that linker directives are not added to the fortran files compiled in flang.lib which would otherwise refer to flang.lib. --- runtime/flang/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index cf22ee0be97..a0cce4aa852 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -25,7 +25,7 @@ endif() # We are using Fortran driver to build this library with fresh compiler # components, so point its binary directory to the build directory to pick up # flang* executables -SET(CMAKE_Fortran_FLAGS "-B ${LLVM_RUNTIME_OUTPUT_INTDIR} ${CMAKE_Fortran_FLAGS}") +SET(CMAKE_Fortran_FLAGS "-B ${LLVM_RUNTIME_OUTPUT_INTDIR} ${CMAKE_Fortran_FLAGS} -no-flang-libs") SET(FTN_INTRINSICS abort3f.c From 120c3332c6c8e3b0ca9290b59a8678c98193dab2 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 8 Nov 2017 00:32:48 -0600 Subject: [PATCH 096/141] Fix libomp searching --- runtime/flangrti/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index f8e4b70312f..acf57ca2712 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -208,7 +208,7 @@ endif() if (NOT DEFINED LIBOMP_EXPORT_DIR) find_library( FLANG_LIBOMP - libomp + NAMES omp libomp HINTS ${CMAKE_BINARY_DIR}/lib) target_link_libraries(flangrti_shared PUBLIC ${FLANG_LIBOMP}) endif() From 442c686f58928b9239e7da44856f14ae2f95e65f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 8 Nov 2017 01:01:57 -0600 Subject: [PATCH 097/141] Add asprintf.c unconditionally to avoid errors --- tools/flang2/flang2exe/CMakeLists.txt | 5 +---- tools/flang2/flang2exe/asprintf.c | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/flang2/flang2exe/CMakeLists.txt b/tools/flang2/flang2exe/CMakeLists.txt index 1d95e0e496a..c5a5c962ae6 100644 --- a/tools/flang2/flang2exe/CMakeLists.txt +++ b/tools/flang2/flang2exe/CMakeLists.txt @@ -85,12 +85,9 @@ set(SOURCES kmpcutil.c verify.c kmpcutil.h + asprintf.c ) -if (MSVC) - set(SOURCES ${SOURCES} asprintf.c) -endif () - set(COMMON_DEFS MMD NOVECTORIZE diff --git a/tools/flang2/flang2exe/asprintf.c b/tools/flang2/flang2exe/asprintf.c index aabc26829e5..2211dec517b 100644 --- a/tools/flang2/flang2exe/asprintf.c +++ b/tools/flang2/flang2exe/asprintf.c @@ -4,6 +4,7 @@ * copyright (c) 2014 joseph werle */ +#ifdef _WIN32 #ifndef HAVE_ASPRINTF #include @@ -61,4 +62,5 @@ vasprintf (char **str, const char *fmt, va_list args) { return size; } -#endif \ No newline at end of file +#endif +#endif From b1dbb00c3f432178d5a76c06c6603e66ecadf552 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Wed, 8 Nov 2017 01:02:06 -0600 Subject: [PATCH 098/141] Fix header --- runtime/flangrti/trace_lin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/flangrti/trace_lin.c b/runtime/flangrti/trace_lin.c index f6e83bad1fc..d71b8bf6612 100644 --- a/runtime/flangrti/trace_lin.c +++ b/runtime/flangrti/trace_lin.c @@ -17,9 +17,9 @@ #include #ifndef _WIN32 +#include #include "dumpregs.h" #include -#include #include /* codes and strings for signals */ From 96f2644bf7f048621f042ab010e00300c43d0a30 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 30 Nov 2017 19:45:50 -0600 Subject: [PATCH 099/141] Add -DPGDLL --- runtime/flang/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index a0cce4aa852..a5134e4ae96 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -598,6 +598,7 @@ else() set_target_properties(flang_static PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(flang_shared PROPERTIES LINKER_LANGUAGE CXX) + target_compile_options(flang_shared PUBLIC $<$:-DPGDLL>) endif() target_compile_options(flang_static PUBLIC $<$:-Mreentrant>) From fcfddeb04a7f9d8e4ad2ef219f047a8b5ec76c66 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 14 Dec 2017 14:50:29 -0600 Subject: [PATCH 100/141] [travis] init [travis] include tests [travis] install lit [travis] use verbose mode [travis] fix installation --- .travis.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000000..29d267eefb5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,42 @@ +language: c + +cache: + directories: + - $HOME/.conda/pkgs + - $HOME/miniconda/pkgs + +install: + - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh; + - bash miniconda.sh -u -b -p $HOME/miniconda + - export PATH="$HOME/miniconda/bin:$PATH" + - hash -r + - conda config --set always_yes yes --set changeps1 no + - conda config --add channels conda-forge --force + - conda update -q conda + + - conda create -q -n test-environment + flang-meta + llvmdev + clangdev + openmp + cmake + + - source activate test-environment + - conda info -a + + # For testing + - pip install lit + +script: + - mkdir -p build + - cd build + - cmake -DFLANG_INCLUDE_TESTS=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_Fortran_COMPILER=flang .. + - make -j4 + + - cp lib/* $HOME/miniconda/envs/test-environment/lib + - cp bin/* $HOME/miniconda/envs/test-environment/bin + + - make check-flang + +notifications: + email: false From 3a6f2f480186456c82b1358fdb671ef49c2c44df Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 15 Dec 2017 14:27:44 -0600 Subject: [PATCH 101/141] [cmake] fix arch --- CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cf23b291d3..322616b573c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,17 +58,14 @@ elseif(${TARGET_OS} STREQUAL "Windows" ) set(OS "WINDOWS") set(OSNAME "Windows") add_definitions(-DWIN32 -DHOST_WIN -DWINNT -DTARGET_WIN -DTARGET_WIN_X86) - if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - add_definitions(-DWIN64 -DTARGET_WIN_X8664) - else( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - add_definitions(-DTARGET_WIN_X8632) - endif( CMAKE_SIZEOF_VOID_P EQUAL 8 ) if( ${TARGET_ARCHITECTURE} STREQUAL "AMD64" ) + add_definitions(-DWIN64 -DTARGET_WIN_X8664) set(TARGET_ARCHITECTURE "x86_64") set(ARCHNAME x86-64) set(ARCH X86) set(WRDSZ 64) else() + add_definitions(-DTARGET_WIN_X8632) message("Unsupported architecture: ${TARGET_ARCHITECTURE}" ) return() endif() From c738f499d0cfbb433fec82af73cc62b7f72dcabf Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 18 Dec 2017 15:34:09 -0600 Subject: [PATCH 102/141] Revert flang_int64 / flang_uint64 --- runtime/flang/fmtconv.c | 12 +++---- runtime/flang/fmtgetnum.c | 2 +- runtime/flang/fmtread.c | 6 ++-- runtime/flang/fmtwrite.c | 4 +-- runtime/flang/format.h | 8 ++--- runtime/flang/ftni64.c | 12 +++---- runtime/flang/ftni64.h | 6 ++-- runtime/flang/ftni64bitsup.c | 34 +++++++++--------- runtime/flang/global.h | 8 ++--- runtime/flang/utilsi64.c | 68 ++++++++++++++++++------------------ runtime/flangrti/mthi64.c | 60 +++++++++++++++---------------- 11 files changed, 110 insertions(+), 110 deletions(-) diff --git a/runtime/flang/fmtconv.c b/runtime/flang/fmtconv.c index 4ace29cb41d..08f7ab6616e 100644 --- a/runtime/flang/fmtconv.c +++ b/runtime/flang/fmtconv.c @@ -40,7 +40,7 @@ static int dbgflag; #define DBGBIT(v) (LOCAL_DEBUG && (dbgflag & v)) static char *conv_int(__BIGINT_T, int *, int *); -static char *conv_int8(FLANG_INT64, int *, int *); +static char *conv_int8(INT64, int *, int *); static void put_buf(int, char *, int, int); static void conv_e(int, int, int, bool); @@ -96,7 +96,7 @@ __fortio_default_convert(char *item, int type, { int width; char *p; - FLANG_INT64 i8val; + INT64 i8val; switch (type) { default: @@ -113,7 +113,7 @@ __fortio_default_convert(char *item, int type, break; case __INT8: width = 24; - (void) __fortio_fmt_i8(*(FLANG_INT64 *)(item), width, 1, plus_flag); + (void) __fortio_fmt_i8(*(INT64 *)(item), width, 1, plus_flag); break; case __WORD4: width = 8; @@ -341,7 +341,7 @@ conv_int(__BIGINT_T val, int *lenp, int *negp) } char * -__fortio_fmt_i8(FLANG_INT64 val, +__fortio_fmt_i8(INT64 val, int width, int mn, /* minimum # of digits (Iw.m) */ bool plus_flag) @@ -384,14 +384,14 @@ __fortio_fmt_i8(FLANG_INT64 val, } static char * -conv_int8(FLANG_INT64 val, int *lenp, int *negp) +conv_int8(INT64 val, int *lenp, int *negp) { #define MAX_CONV_INT8 32 static char tmp[MAX_CONV_INT8]; char *p; int len; - FLANG_INT64 value; + INT64 value; *negp = 0; value[0] = val[0]; diff --git a/runtime/flang/fmtgetnum.c b/runtime/flang/fmtgetnum.c index 7eb0a67c138..086f2724c02 100644 --- a/runtime/flang/fmtgetnum.c +++ b/runtime/flang/fmtgetnum.c @@ -70,7 +70,7 @@ __fortio_getnum( union { __BIGINT_T i; __BIGREAL_T d; - FLANG_INT64 i8v; + INT64 i8v; } * val; /* value of token to return */ if (dc_flag == TRUE) diff --git a/runtime/flang/fmtread.c b/runtime/flang/fmtread.c index f1d716dc23e..7ea621274ef 100644 --- a/runtime/flang/fmtread.c +++ b/runtime/flang/fmtread.c @@ -112,7 +112,7 @@ static int fr_readnum(int, char *, int); static int fr_init(__INT_T *, __INT_T *, __INT_T *, __INT_T *, __INT_T *, __INT8_T *, char *, int); -static int fr_assign(char *, int, __BIGINT_T, FLANG_INT64, __BIGREAL_T); +static int fr_assign(char *, int, __BIGINT_T, INT64, __BIGREAL_T); static int fr_OZreadnum(int, char *, int, int); static int fr_Breadnum(char *, int, int); static __BIGREAL_T fr_getreal(char *, int, int, int *); @@ -1637,7 +1637,7 @@ fr_readnum(int code, char *item, int type) __BIGINT_T ival; __BIGREAL_T dval; #undef IS_INT - FLANG_INT64 i8val; /* always declare because of fr_assign() */ + INT64 i8val; /* always declare because of fr_assign() */ #define IS_INT(t) (t == __INT || t == __INT8) int ty; int w, d, e, c; @@ -2057,7 +2057,7 @@ fr_readnum(int code, char *item, int type) /* ------------------------------------------------------------------ */ static int -fr_assign(char *item, int type, __BIGINT_T ival, FLANG_INT64 i8val, __BIGREAL_T dval) +fr_assign(char *item, int type, __BIGINT_T ival, INT64 i8val, __BIGREAL_T dval) { switch (type) { case __INT1: diff --git a/runtime/flang/fmtwrite.c b/runtime/flang/fmtwrite.c index b920042f38a..6d48aa1d309 100644 --- a/runtime/flang/fmtwrite.c +++ b/runtime/flang/fmtwrite.c @@ -1578,7 +1578,7 @@ fw_writenum(int code, char *item, int type) __BIGINT_T ival; __BIGREAL_T dval; #undef IS_INT - FLANG_INT64 i8val; + INT64 i8val; #define IS_INT(t) (t == __BIGINT || t == __INT8) int ty; int w, m, d, e; @@ -1592,7 +1592,7 @@ fw_writenum(int code, char *item, int type) __INT4_T i4; __REAL4_T r4; __REAL8_T r8; - FLANG_INT64 i8v; + INT64 i8v; __INT8_T i8; __BIGREAL_T d; __REAL16_T r16; diff --git a/runtime/flang/format.h b/runtime/flang/format.h index 9bcddc1cfb6..c98cc8ff51d 100644 --- a/runtime/flang/format.h +++ b/runtime/flang/format.h @@ -55,7 +55,7 @@ char *__fortio_default_convert(char *, int, int, int *, bool, bool, int); char *__fortio_fmt_i(__BIGINT_T, int, int, bool); /** \brief Generate a formated INTEGER*8 string */ -char *__fortio_fmt_i8(FLANG_INT64, int, int, bool); +char *__fortio_fmt_i8(INT64, int, int, bool); /** \brief Generate a string for a 'D' format characer */ char *__fortio_fmt_d(__BIGREAL_T, int, int, int, int, bool, int); @@ -139,13 +139,13 @@ int __fort_atoxi32(char *s, INT *i, int n, int base); * \param conversion radix: 2, 8, 10, 16 */ -void __fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix); +void __fort_i64toax(INT64 from, char *to, int count, int sign, int radix); /** \brief char string to 64-bit integer. * * \param Input string containing number to be converted * (string is NOT null terminated.) - * \param FLANG_UINT64 output value + * \param UINT64 output value * \param Number of chars from str to convert * \param Radix of conversion -- 2, 8, 10, 16. If base is 16, then the * digits a-f @@ -155,4 +155,4 @@ void __fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix); * -2 overflow occurred on conversion * 0 No error -- *ir contains the converted number. */ -int __fort_atoxi64(char *s, FLANG_INT64 ir, int n, int radix); +int __fort_atoxi64(char *s, INT64 ir, int n, int radix); diff --git a/runtime/flang/ftni64.c b/runtime/flang/ftni64.c index 7bdf08f76ad..b4748d65729 100644 --- a/runtime/flang/ftni64.c +++ b/runtime/flang/ftni64.c @@ -40,8 +40,8 @@ ftn_i_kishft(_ULONGLONG_T op, int count) __I8RET_T ftn_i_xori64(int op1, int op2, int op3, int op4) { - FLANG_INT64 u1; - FLANG_INT64 u2; + INT64 u1; + INT64 u2; u1[0] = op2; u1[1] = op1; @@ -55,8 +55,8 @@ ftn_i_xori64(int op1, int op2, int op3, int op4) __I8RET_T ftn_i_xnori64(int op1, int op2, int op3, int op4) { - FLANG_INT64 u1; - FLANG_INT64 u2; + INT64 u1; + INT64 u2; u1[0] = op2; u1[1] = op1; @@ -70,7 +70,7 @@ ftn_i_xnori64(int op1, int op2, int op3, int op4) int ftn_i_kr2ir(int op1, int op2) { - FLANG_INT64 u1; + INT64 u1; /* result is first element of int[2] which is union u'd with dp if little endian; if big endian, result is second element. @@ -83,7 +83,7 @@ ftn_i_kr2ir(int op1, int op2) float ftn_i_kr2sp(int op1, int op2) { - FLANG_INT64 u1; + INT64 u1; int i; u1[0] = op1; diff --git a/runtime/flang/ftni64.h b/runtime/flang/ftni64.h index e696665c3b0..467c7ca2533 100644 --- a/runtime/flang/ftni64.h +++ b/runtime/flang/ftni64.h @@ -28,8 +28,8 @@ typedef long _LONGLONG_T; typedef unsigned long _ULONGLONG_T; /* now defined if BaseTsd10.h included */ -typedef int FLANG_INT64[2]; -typedef unsigned int FLANG_UINT64[2]; +typedef int INT64[2]; +typedef unsigned int UINT64[2]; #define I64_MSH(t) t[1] #define I64_LSH(t) t[0] @@ -39,7 +39,7 @@ int __ftn_32in64_; #define VOID void typedef union { - FLANG_INT64 i; + INT64 i; double d; _LONGLONG_T lv; } INT64D; diff --git a/runtime/flang/ftni64bitsup.c b/runtime/flang/ftni64bitsup.c index ca736759833..610ae53507b 100644 --- a/runtime/flang/ftni64bitsup.c +++ b/runtime/flang/ftni64bitsup.c @@ -39,7 +39,7 @@ ftn_i_kishftc(op, sc, int sc; /* shift count and direction */ int rc; /* # of rightmost val bits to be shifted */ { - FLANG_UINT64 i8neg1, mask, field, tmp1, tmp2, val; + UINT64 i8neg1, mask, field, tmp1, tmp2, val; int norm; /* define a remainder operation that doesn't use %; is this worth it? */ @@ -141,8 +141,8 @@ int posd; /* start position in dest field */ int tmp; int maxpos; int maxlen; - FLANG_UINT64 maski8; - FLANG_UINT64 i8neg1, tmpi8, u_arg; + UINT64 maski8; + UINT64 i8neg1, tmpi8, u_arg; /* procedure */ @@ -225,8 +225,8 @@ __I8RET_T ftn_i_kibclr(arg1, arg2, bit) int arg1, arg2; /* value to be cleared */ int bit; /* bit to clear */ { - FLANG_INT64 result; - FLANG_UINT64 i81, tmp; + INT64 result; + UINT64 i81, tmp; result[0] = result[1] = 0; i81[0] = 0; i81[1] = 1; @@ -250,8 +250,8 @@ ftn_i_kibits(arg1, arg2, bitpos, numbits) int arg1, int bitpos; /* position of bit to start from */ int numbits; /* number of bits to extract */ { - FLANG_INT64 result; - FLANG_UINT64 i8neg1, tmp, maski8, u_arg; + INT64 result; + UINT64 i8neg1, tmp, maski8, u_arg; u_arg[0] = arg2; u_arg[1] = arg1; @@ -280,8 +280,8 @@ __I8RET_T ftn_i_kibset(arg1, arg2, bit) int arg1, arg2; /* value to be set */ int bit; /* bit to set */ { - FLANG_INT64 i8one, result; - FLANG_UINT64 tmp; + INT64 i8one, result; + UINT64 tmp; result[0] = result[1] = 0; i8one[0] = 0; i8one[1] = 1; @@ -304,8 +304,8 @@ __I8RET_T ftn_i_bktest(arg1, arg2, bit) int arg1, arg2; /* value to be tested */ int bit; /* bit to test */ { - FLANG_INT64 i8one, result; - FLANG_UINT64 tmp; + INT64 i8one, result; + UINT64 tmp; result[0] = result[1] = 0; i8one[0] = 0; i8one[1] = 1; @@ -339,11 +339,11 @@ int bit; /* bit to test */ * Return value: * none. */ -static void shf64(arg, count, result) FLANG_INT64 arg; +static void shf64(arg, count, result) INT64 arg; int count; -FLANG_INT64 result; +INT64 result; { - FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; @@ -388,11 +388,11 @@ FLANG_INT64 result; * Return value: * none. */ -static void ushf64(arg, count, result) FLANG_UINT64 arg; +static void ushf64(arg, count, result) UINT64 arg; int count; -FLANG_UINT64 result; +UINT64 result; { - FLANG_UINT64 u_arg; /* 'copy-in' value of arg */ + UINT64 u_arg; /* 'copy-in' value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; diff --git a/runtime/flang/global.h b/runtime/flang/global.h index 022fcf39ee8..10b2f6942d5 100644 --- a/runtime/flang/global.h +++ b/runtime/flang/global.h @@ -28,8 +28,8 @@ /* declarations needed where integer*8 & logical*8 are supported and * the natural integer is integer*4 (__BIGINT is __INT4). */ -typedef int FLANG_INT64[2]; -typedef unsigned int FLANG_UINT64[2]; +typedef int INT64[2]; +typedef unsigned int UINT64[2]; #define I64_MSH(t) t[1] #define I64_LSH(t) t[0] @@ -295,9 +295,9 @@ typedef struct atag { union { /* value: depends on dtype */ __BIGINT_T i; /* __BIGINT, __BIGLOG */ __BIGREAL_T d; /* __BIGREAL */ - FLANG_INT64 i8; /* __INT8 */ + INT64 i8; /* __INT8 */ __INT8_T i8v; - FLANG_UINT64 ui8; /* __LOG8 */ + UINT64 ui8; /* __LOG8 */ __INT8_UT ui8v; struct { /* __STR, __NCHAR */ int len; /* length of string */ diff --git a/runtime/flang/utilsi64.c b/runtime/flang/utilsi64.c index 8b4c9cd37e8..312fbd7d37b 100644 --- a/runtime/flang/utilsi64.c +++ b/runtime/flang/utilsi64.c @@ -22,7 +22,7 @@ * the exception that TM_I8 => integer*4 is the natural integer and * integer*8 is an extension. All of these support routines could be * rewritten to use the appropriate C type which represents a 64-bit - * integer rather than FLANG_INT64/UIN64. + * integer rather than INT64/UIN64. */ int __ftn_32in64_; @@ -212,7 +212,7 @@ __fort_atoxi32(char *s, INT *i, int n, int base) * * s Input string containing number to be converted * (string is NOT null terminated.) - * ir FLANG_UINT64 output value + * ir UINT64 output value * n Number of chars from str to convert * radix Radix of conversion -- 2, 8, 10, 16. If * base is 16, then the digits a-f or A-F are @@ -237,7 +237,7 @@ __fort_atoxi32(char *s, INT *i, int n, int base) ****************************************************************/ int -__fort_atoxi64(char *s, FLANG_INT64 ir, int n, int radix) +__fort_atoxi64(char *s, INT64 ir, int n, int radix) { int err; char *sp; @@ -271,7 +271,7 @@ __fort_atoxi64(char *s, FLANG_INT64 ir, int n, int radix) #define ZERO '0' void -__fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix) +__fort_i64toax(INT64 from, char *to, int count, int sign, int radix) { int bit_width; /* width of the bit field for a particular * radix */ @@ -282,13 +282,13 @@ __fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix) * to be shifted */ int msd; /* index of the most-signingicant digit in to */ int num_bits; /* number of bits to be shifted */ - FLANG_INT64 quot; /* the quotient part of a 64 bit division */ - FLANG_INT64 remain; /* the remainder part of a 64 bit division */ - FLANG_INT64 temp_from; /* temp from (=(abs(from)) */ - FLANG_INT64 temp64; /* temporary 64 bit integer */ + INT64 quot; /* the quotient part of a 64 bit division */ + INT64 remain; /* the remainder part of a 64 bit division */ + INT64 temp_from; /* temp from (=(abs(from)) */ + INT64 temp64; /* temporary 64 bit integer */ /* 64 bit integer equal to 10 */ - static FLANG_INT64 ten64 = {0, 10}; + static INT64 ten64 = {0, 10}; /* the result of dividing a 64 bit unsigned integer with only the * sign bit on by 10 @@ -426,22 +426,22 @@ __fort_i64toax(FLANG_INT64 from, char *to, int count, int sign, int radix) * -2 = overflow / underflow * 0 = no error. */ -static int toi64(char *s, FLANG_INT64 toi, char *end, int radix) +static int toi64(char *s, INT64 toi, char *end, int radix) { - FLANG_INT64 base; /* 64 bit integer equal to radix */ - FLANG_INT64 diff; /* difference between 2 64 bit integers, used + INT64 base; /* 64 bit integer equal to radix */ + INT64 diff; /* difference between 2 64 bit integers, used * in determining if overflow has occured */ - FLANG_INT64 num; /* numerical value of a particular digit */ - FLANG_INT64 to; + INT64 num; /* numerical value of a particular digit */ + INT64 to; int negate; int ch; /* 64-bit integer with only its sign bit on */ - static FLANG_INT64 sign_bit = {0x80000000, 0}; + static INT64 sign_bit = {0x80000000, 0}; /* maximum 64-bit signed integer */ - static FLANG_INT64 max_int = {0x7fffffff, 0xffffffff}; - static FLANG_INT64 max_neg = {0x80000000, 0}; + static INT64 max_int = {0x7fffffff, 0xffffffff}; + static INT64 max_neg = {0x80000000, 0}; OVL8 pto; @@ -550,7 +550,7 @@ static int toi64(char *s, FLANG_INT64 toi, char *end, int radix) return -2; } -static void neg64(FLANG_INT64 arg, FLANG_INT64 result) +static void neg64(INT64 arg, INT64 result) { int sign; /* sign of the low-order word of arg prior to * being complemented */ @@ -561,9 +561,9 @@ static void neg64(FLANG_INT64 arg, FLANG_INT64 result) result[0]++; } -static void shf64(FLANG_INT64 arg1, INT arg2, FLANG_INT64 result) +static void shf64(INT64 arg1, INT arg2, INT64 result) { - FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (arg2 >= 64 || arg2 <= -64) { result[0] = 0; @@ -589,7 +589,7 @@ static void shf64(FLANG_INT64 arg1, INT arg2, FLANG_INT64 result) } } -static int ucmp64(FLANG_UINT64 arg1, FLANG_UINT64 arg2) +static int ucmp64(UINT64 arg1, UINT64 arg2) { if (arg1[0] == arg2[0]) { if (arg1[1] == arg2[1]) @@ -617,7 +617,7 @@ static void neg128(), uneg64(), ushf64(), shf128(); * Return value: * none */ -void __utl_i_add64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) +void __utl_i_add64(INT64 arg1, INT64 arg2, INT64 result) { int carry; /* value to be carried from adding the lower * 32 bits */ @@ -645,7 +645,7 @@ void __utl_i_add64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) * Return value: * none */ -void __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) +void __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) { int borrow; /* value to be borrowed from adding the lower @@ -670,7 +670,7 @@ void __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) * integer product. */ -void __utl_i_mul64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) +void __utl_i_mul64(INT64 arg1, INT64 arg2, INT64 result) { INT temp_result[4]; /* the product returned by MUL128 */ @@ -679,10 +679,10 @@ void __utl_i_mul64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) result[1] = temp_result[3]; } -static void __utl_i_mul128(FLANG_INT64 arg1, FLANG_INT64 arg2, INT result[4]) +static void __utl_i_mul128(INT64 arg1, INT64 arg2, INT result[4]) { int i; /* for loop control variable */ - FLANG_INT64 temp_arg; /* temporary argument used in calculating the + INT64 temp_arg; /* temporary argument used in calculating the * product */ INT temp_result[4]; /* temporary result */ int negate; /* flag which indicated the result needs to @@ -729,9 +729,9 @@ static void __utl_i_mul128(FLANG_INT64 arg1, FLANG_INT64 arg2, INT result[4]) result[i] = temp_result[i]; } -void __utl_i_div64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) +void __utl_i_div64(INT64 arg1, INT64 arg2, INT64 result) { - FLANG_INT64 den; /* denominator used in calculating the + INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -802,9 +802,9 @@ static void neg128(INT arg[4], INT result[4]) } } -void __utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) +void __utl_i_udiv64(UINT64 arg1, UINT64 arg2, UINT64 result) { - FLANG_UINT64 den; /* denominator used in calculating the + UINT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -856,7 +856,7 @@ void __utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) } } -static void uneg64(FLANG_UINT64 arg, FLANG_UINT64 result) +static void uneg64(UINT64 arg, UINT64 result) { int sign; /* sign of the low-order word of arg prior to * being complemented */ @@ -868,11 +868,11 @@ static void uneg64(FLANG_UINT64 arg, FLANG_UINT64 result) result[0]++; } -static void ushf64(FLANG_UINT64 arg, int count, FLANG_INT64 result) +static void ushf64(UINT64 arg, int count, INT64 result) int count; -FLANG_INT64 result; +INT64 result; { - FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; diff --git a/runtime/flangrti/mthi64.c b/runtime/flangrti/mthi64.c index 11f244ed7ae..ee09eb8625c 100644 --- a/runtime/flangrti/mthi64.c +++ b/runtime/flangrti/mthi64.c @@ -15,11 +15,11 @@ * */ -typedef int FLANG_INT64[2]; -typedef unsigned int FLANG_UINT64[2]; +typedef int INT64[2]; +typedef unsigned int UINT64[2]; typedef union { - FLANG_INT64 wd; /* canonical msw & lsw view of long long values */ + INT64 wd; /* canonical msw & lsw view of long long values */ int hf[2]; /* native msw & lsw signed view of long long values */ unsigned uhf[2]; /* native msw & lsw unsigned view of long long values */ long long value; @@ -67,7 +67,7 @@ VOID __mth_i_krshift(); VOID __mth_i_klshift(); VOID __mth_i_kurshift(); VOID __utl_i_add64(), __utl_i_div64(); -VOID __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result); +VOID __utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result); VOID __utl_i_mul64(), __utl_i_udiv64(); static VOID neg64(), shf64(), shf128by1(); @@ -81,7 +81,7 @@ static VOID neg64(), shf64(), shf128by1(); * Return value: * none */ -VOID __utl_i_add64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; +VOID __utl_i_add64(arg1, arg2, result) INT64 arg1, arg2, result; { int carry; /* value to be carried from adding the lower * 32 bits */ @@ -106,7 +106,7 @@ VOID __utl_i_add64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; * \param result arg1 - arg2 */ VOID -__utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) +__utl_i_sub64(INT64 arg1, INT64 arg2, INT64 result) { int borrow; /* value to be borrowed from adding the lower * 32 bits */ @@ -130,7 +130,7 @@ __utl_i_sub64(FLANG_INT64 arg1, FLANG_INT64 arg2, FLANG_INT64 result) * Multiply two 64-bit integers to produce a 64-bit * integer product. */ -VOID __utl_i_mul64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; +VOID __utl_i_mul64(arg1, arg2, result) INT64 arg1, arg2, result; { LL_SHAPE v1, v2, r; @@ -175,8 +175,8 @@ __mth_i_kdiv(long long x, long long y) MSW(r) = 0; *(unsigned *)&LSW(r) = (unsigned)LSW(a) / (unsigned)LSW(b); } else { - FLANG_INT64 arg1, arg2; /* FLANG_INT64 is big endian!! */ - FLANG_INT64 result; + INT64 arg1, arg2; /* INT64 is big endian!! */ + INT64 result; arg1[1] = LSW(a); arg1[0] = MSW(a); arg2[1] = LSW(b); @@ -207,8 +207,8 @@ __mth_i_ukdiv(unsigned long long x, unsigned long long y) UMSW(r) = 0; ULSW(r) = ULSW(a) / ULSW(b); } else { - FLANG_UINT64 arg1, arg2; /* FLANG_UINT64 is big endian!! */ - FLANG_UINT64 result; + UINT64 arg1, arg2; /* UINT64 is big endian!! */ + UINT64 result; arg1[1] = ULSW(a); arg1[0] = UMSW(a); arg2[1] = ULSW(b); @@ -224,10 +224,10 @@ __mth_i_ukdiv(unsigned long long x, unsigned long long y) * Divide two 64-bit integers to produce a 64-bit * integer quotient. */ -VOID __utl_i_div64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; +VOID __utl_i_div64(arg1, arg2, result) INT64 arg1, arg2, result; { - FLANG_INT64 den; /* denominator used in calculating the + INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -287,7 +287,7 @@ VOID __utl_i_div64(arg1, arg2, result) FLANG_INT64 arg1, arg2, result; * none. */ -static VOID neg64(arg, result) FLANG_INT64 arg, result; +static VOID neg64(arg, result) INT64 arg, result; { int sign; /* sign of the low-order word of arg prior to @@ -304,9 +304,9 @@ static VOID neg64(arg, result) FLANG_INT64 arg, result; * integer quotient. */ VOID -__utl_i_udiv64(FLANG_UINT64 arg1, FLANG_UINT64 arg2, FLANG_UINT64 result) +__utl_i_udiv64(UINT64 arg1, UINT64 arg2, UINT64 result) { - FLANG_INT64 den; /* denominator used in calculating the + INT64 den; /* denominator used in calculating the * quotient */ int i; /* for loop control variable */ int temp_result[4]; /* temporary result used in @@ -358,7 +358,7 @@ long long __mth_i_kicshft(op1, op2, count, direct) UINT op1, op2; /* really INT */ INT count, direct; { - FLANG_INT64 result; + INT64 result; if (count < 0 || count >= 64) { UTL_I_I64RET(0, 0); } @@ -391,7 +391,7 @@ INT count, direct; long long __mth_i_ukicshft(op1, op2, count, direct) UINT op1, op2; INT count, direct; { - FLANG_INT64 result; + INT64 result; if (count < 0 || count >= 64) { UTL_I_I64RET(0, 0); } @@ -422,19 +422,19 @@ INT count, direct; long long __mth_i_kishft(op1, op2, arg2) INT op1, op2, arg2; { - FLANG_INT64 arg1; - FLANG_INT64 result; + INT64 arg1; + INT64 result; arg1[1] = op1; arg1[0] = op2; shf64(arg1, arg2, result); UTL_I_I64RET(result[0], result[1]); } -static VOID shf64(arg, count, result) FLANG_INT64 arg; +static VOID shf64(arg, count, result) INT64 arg; int count; -FLANG_INT64 result; +INT64 result; { - FLANG_UINT64 u_arg; /* 'copy-in' unsigned value of arg */ + UINT64 u_arg; /* 'copy-in' unsigned value of arg */ if (count >= 64 || count <= -64) { result[0] = 0; @@ -879,10 +879,10 @@ register UFP *u; /* unpacked result */ static VOID i64toufp(i, u) /* 64-bit integer to unpacked float */ - FLANG_INT64 i; + INT64 i; UFP *u; { - FLANG_INT64 tmp; + INT64 tmp; if (i[0] == 0L && i[1] == 0L) { u->fsgn = POS; @@ -999,7 +999,7 @@ IEEE32 *r; /* packed result */ static VOID ufptoi64(u, i) /* unpacked float to 64-bit integer */ UFP *u; -FLANG_INT64 i; +INT64 i; { /* Normalize the unpacked * number first. */ @@ -1043,7 +1043,7 @@ FLANG_INT64 i; VOID __utl_i_dfix64(d, i) /* double precision to 64-bit integer */ double d; /*IEEE64 format and double are LITTLE_ENDIAN */ -FLANG_INT64 i; +INT64 i; { UFP u; @@ -1053,7 +1053,7 @@ FLANG_INT64 i; double __utl_i_dflt64(i) /* 64 -- 64-bit integer to double */ - FLANG_INT64 i; + INT64 i; { UFP u; IEEE64 d; @@ -1063,7 +1063,7 @@ double __utl_i_dflt64(i) return *((double *)d); /*IEEE64 format and double are LITTLE_ENDIAN */ } -VOID __utl_i_fix64(float ff, FLANG_INT64 i) /* use prototype to pass as float */ +VOID __utl_i_fix64(float ff, INT64 i) /* use prototype to pass as float */ /* single float to 64-bit */ { IEEE32 f; @@ -1074,7 +1074,7 @@ VOID __utl_i_fix64(float ff, FLANG_INT64 i) /* use prototype to pass as float */ ufptoi64(&u, i); } -float __utl_i_flt64(FLANG_INT64 i) /* use prototype to return as float */ +float __utl_i_flt64(INT64 i) /* use prototype to return as float */ /* 64-bit integer to single precision */ { UFP u; From 8937577ab40fe50ac9ef84dac8f587f096e1f771 Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 18 Dec 2017 16:34:23 -0600 Subject: [PATCH 103/141] [runtime] redefined INT64 type --- runtime/flang/global.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/flang/global.h b/runtime/flang/global.h index 10b2f6942d5..3c875382584 100644 --- a/runtime/flang/global.h +++ b/runtime/flang/global.h @@ -25,6 +25,11 @@ #define GBL_SIZE_T_FORMAT "zu" +#ifdef WIN32 +#define INT64 __FLANG_INT64 +#define UINT64 __FLANG_UINT64 +#endif + /* declarations needed where integer*8 & logical*8 are supported and * the natural integer is integer*4 (__BIGINT is __INT4). */ From 5540d27afe73c5acbeb1b254c8124664f9ff799b Mon Sep 17 00:00:00 2001 From: xoviat Date: Wed, 20 Dec 2017 11:54:14 -0600 Subject: [PATCH 104/141] Fix floating-point register behavior on win32 --- lib/scutil/host-fp-folding.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/scutil/host-fp-folding.c b/lib/scutil/host-fp-folding.c index cd03bb7b57a..d68ac048e27 100644 --- a/lib/scutil/host-fp-folding.c +++ b/lib/scutil/host-fp-folding.c @@ -34,6 +34,9 @@ #include #include #include +#ifdef _WIN32 +#include +#endif /* * Build-time sanity checks @@ -81,16 +84,28 @@ configure_denormals(bool denorms_are_zeros, bool flush_to_zero) fenv_t fenv; if (fegetenv(&fenv) != 0) fprintf(stderr, "fegetenv() failed: %s\n", strerror(errno)); -#if defined(__x86_64__) && !defined(_WIN32) - fenv.__mxcsr &= ~0x0040; +#ifdef __x86_64__ +#ifdef _WIN32 + unsigned int mxcsr = _mm_getcsr(); +#else + unsigned int mxcsr = fenv.__mxcsr +#endif + mxcsr &= ~0x0040; if (denorms_are_zeros) - fenv.__mxcsr |= 0x0040; - fenv.__mxcsr &= ~0x8000; + mxcsr |= 0x0040; + mxcsr &= ~0x8000; if (flush_to_zero) - fenv.__mxcsr |= 0x8000; + mxcsr |= 0x8000; +#ifdef _WIN32 + _mm_setcsr( mxcsr ); +#else + fenv.__mxcsr = mxcsr; #endif +#endif +#ifndef _WIN32 if (fesetenv(&fenv) != 0) fprintf(stderr, "fesetenv() failed: %s\n", strerror(errno)); +#endif } /* From 7e5baa2f9cf3b9f7917fb70ee0463c1f1009635c Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Fri, 22 Dec 2017 09:30:41 +0530 Subject: [PATCH 105/141] Install conda=4.3 --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 57d24493492..ec149f446b7 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -20,7 +20,7 @@ platform: install: # Add path, activate `conda` and update conda. - cmd: call %CONDA_INSTALL_LOCN%\Scripts\activate.bat - - cmd: conda update --yes --quiet conda + - cmd: conda install --yes --quiet conda=4.3 # Add our channels. - cmd: conda config --add channels defaults - cmd: conda config --add channels conda-forge From bc1761d02d5d0338e906c707772b8845f428cfbd Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 21 Dec 2017 14:03:56 -0600 Subject: [PATCH 106/141] Fix complex matrix multiplication --- runtime/flang/mmcmplx16.c | 142 ++++++++++++++++--------------------- runtime/flang/mmcmplx8.c | 126 +++++++++++++++----------------- runtime/include/mthdecls.h | 24 +++++++ 3 files changed, 146 insertions(+), 146 deletions(-) diff --git a/runtime/flang/mmcmplx16.c b/runtime/flang/mmcmplx16.c index 8874727489c..14529afa932 100644 --- a/runtime/flang/mmcmplx16.c +++ b/runtime/flang/mmcmplx16.c @@ -19,29 +19,19 @@ #include "stdioInterf.h" #include "fioMacros.h" -#include "complex.h" +#include "mthdecls.h" #define SMALL_ROWSA 10 #define SMALL_ROWSB 10 #define SMALL_COLSB 10 -#ifndef _WIN32 -#define FLANG_DCOMPLEX double complex -#define FLANG_IS_ZERO(x) x == 0.0 -#else -#define FLANG_DCOMPLEX _Dcomplex -#define FLANG_IS_ZERO(x) (real(x) == 0.0 && imag(x) == 0.0) -#endif - void ENTF90(MMUL_CMPLX16, mmul_cmplx16)(int ta, int tb, __POINT_T mra, __POINT_T ncb, - __POINT_T kab, FLANG_DCOMPLEX *alpha, - FLANG_DCOMPLEX a[], __POINT_T lda, FLANG_DCOMPLEX b[], - __POINT_T ldb, FLANG_DCOMPLEX *beta, - FLANG_DCOMPLEX c[], __POINT_T ldc) + __POINT_T kab, DOUBLE_COMPLEX_TYPE *alpha, + DOUBLE_COMPLEX_TYPE a[], __POINT_T lda, DOUBLE_COMPLEX_TYPE b[], + __POINT_T ldb, DOUBLE_COMPLEX_TYPE *beta, + DOUBLE_COMPLEX_TYPE c[], __POINT_T ldc) { - -#ifndef _WIN32 /* * Notes on parameters * ta, tb = 0 -> no transpose of matrix @@ -76,13 +66,13 @@ void ENTF90(MMUL_CMPLX16, int bufr, bufc, loc, lor; int small_size = SMALL_ROWSA * SMALL_ROWSB * SMALL_COLSB; int tindex = 0; - FLANG_DCOMPLEX buffera[SMALL_ROWSA * SMALL_ROWSB]; - FLANG_DCOMPLEX bufferb[SMALL_COLSB * SMALL_ROWSB]; - FLANG_DCOMPLEX temp; + DOUBLE_COMPLEX_TYPE buffera[SMALL_ROWSA * SMALL_ROWSB]; + DOUBLE_COMPLEX_TYPE bufferb[SMALL_COLSB * SMALL_ROWSB]; + DOUBLE_COMPLEX_TYPE temp; void ftn_mvmul_cmplx16_(), ftn_vmmul_cmplx16_(); void ftn_mnaxnb_cmplx16_(), ftn_mnaxtb_cmplx16_(); void ftn_mtaxnb_cmplx16_(), ftn_mtaxtb_cmplx16_(); - FLANG_DCOMPLEX calpha, cbeta; + DOUBLE_COMPLEX_TYPE calpha, cbeta; /* * Small matrix multiply variables */ @@ -99,19 +89,13 @@ void ENTF90(MMUL_CMPLX16, colsa = kab; rowsb = kab; colsb = ncb; - if (FLANG_IS_ZERO(calpha)) { - if (FLANG_IS_ZERO(cbeta)) { + if (DOUBLE_COMPLEX_EQ_CC(calpha, DOUBLE_COMPLEX_CREATE(0.0, 0.0))) { + if (DOUBLE_COMPLEX_EQ_CC(cbeta, DOUBLE_COMPLEX_CREATE(0.0, 0.0))) { cndx = 0; indx_strt = ldc; for (j = 0; j < ncb; j++) { - for (i = 0; i < mra; i++) { - #ifndef _WIN32 - c[cndx + i] = 0.0; - #else - real(c[cndx + i]) = 0.0; - imag(c[cndx + i]) = 0.0; - #endif - } + for (i = 0; i < mra; i++) + c[cndx + i] = DOUBLE_COMPLEX_CREATE(0.0, 0.0); cndx = indx_strt; indx_strt += ldc; } @@ -120,7 +104,7 @@ void ENTF90(MMUL_CMPLX16, indx_strt = ldc; for (j = 0; j < ncb; j++) { for (i = 0; i < mra; i++) - c[cndx + i] = cbeta * c[cndx + i]; + c[cndx + i] = DOUBLE_COMPLEX_MUL_CC(cbeta, c[cndx + i]); cndx = indx_strt; indx_strt += ldc; } @@ -153,30 +137,30 @@ void ENTF90(MMUL_CMPLX16, andx = astrt; indx = 0; for (ja = 0; ja < colsa; ja++) { - buffera[indx++] = calpha * a[andx]; + buffera[indx++] = DOUBLE_COMPLEX_MUL_CC(calpha, a[andx]); andx += lda; } astrt++; cndx = cstrt; /* Now use the transposed row on all of b */ - if (cbeta == 0.0) { + if (DOUBLE_COMPLEX_EQ_CC(cbeta, DOUBLE_COMPLEX_CREATE(0.0, 0.0))) { for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; for (k = 0; k < rowsb; k++) - temp += buffera[k] * b[bndx++]; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(buffera[k], b[bndx++])); bstrt += ldb; c[cndx] = temp; cndx += ldc; } } else { for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; for (k = 0; k < rowsb; k++) - temp += buffera[k] * b[bndx++]; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(buffera[k], b[bndx++])); bstrt += ldb; - c[cndx] = temp + cbeta * c[cndx]; + c[cndx] = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(cbeta, c[cndx])); cndx += ldc; } } @@ -206,7 +190,7 @@ void ENTF90(MMUL_CMPLX16, indx = indx_strt; bndx = bstrt; for (i = 0; i < colsb; i++) { - bufferb[indx] = conjf(b[bndx++]); + bufferb[indx] = conj(b[bndx++]); // printf( "( %f, %f )\n", crealf( bufferb[indx] ), // cimagf( bufferb[indx] ) ); indx += rowsb; @@ -218,7 +202,7 @@ void ENTF90(MMUL_CMPLX16, /* Now muliply the transposed b matrix by a */ - if (cbeta == 0.0) { /* beta == 0.0 */ + if (DOUBLE_COMPLEX_EQ_CC(cbeta, DOUBLE_COMPLEX_CREATE(0.0, 0.0))) { /* beta == 0.0 */ astrt = 0; indx = 0; cstrt = 0; @@ -235,10 +219,10 @@ void ENTF90(MMUL_CMPLX16, cndx = cstrt; indx = 0; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); for (k = 0; k < rowsb; k++) - temp += buffera[k] * bufferb[indx++]; - c[cndx] = calpha * temp; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(buffera[k], bufferb[indx++])); + c[cndx] = DOUBLE_COMPLEX_MUL_CC(calpha, temp); cndx += ldc; // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( // c[cndx] ) ); @@ -263,10 +247,10 @@ void ENTF90(MMUL_CMPLX16, cndx = cstrt; indx = 0; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); for (k = 0; k < rowsb; k++) - temp += buffera[k] * bufferb[indx++]; - c[cndx] = cbeta * c[cndx] + calpha * temp; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(buffera[k], bufferb[indx++])); + c[cndx] = DOUBLE_COMPLEX_ADD_CC(DOUBLE_COMPLEX_MUL_CC(cbeta, c[cndx]), DOUBLE_COMPLEX_MUL_CC(calpha, temp)); cndx += ldc; } cstrt++; /* set index for next row of c */ @@ -280,17 +264,17 @@ void ENTF90(MMUL_CMPLX16, if (tb == 0) { astrt = 0; cstrt = 0; - if (cbeta == 0.0) { /* beta == 0 */ + if (DOUBLE_COMPLEX_EQ_CC(cbeta, DOUBLE_COMPLEX_CREATE(0.0, 0.0))) { /* beta == 0 */ for (i = 0; i < rowsa; i++) { cndx = cstrt; bstrt = 0; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; andx = astrt; for (k = 0; k < rowsb; k++) - temp += a[andx++] * b[bndx++]; - c[cndx] = calpha * temp; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(a[andx++], b[bndx++])); + c[cndx] = DOUBLE_COMPLEX_MUL_CC(calpha, temp); // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( // c[cndx] ) ); @@ -309,15 +293,15 @@ void ENTF90(MMUL_CMPLX16, bstrt = 0; ; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; andx = astrt; for (k = 0; k < rowsb; k++) { - temp += a[andx] * b[bndx]; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(a[andx], b[bndx])); andx++; bndx++; } - c[cndx] = cbeta * c[cndx] + calpha * temp; + c[cndx] = DOUBLE_COMPLEX_ADD_CC(DOUBLE_COMPLEX_MUL_CC(cbeta, c[cndx]), DOUBLE_COMPLEX_MUL_CC(calpha, temp)); // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( c[cndx] ) ); bstrt += ldb; cndx += ldc; @@ -334,7 +318,7 @@ void ENTF90(MMUL_CMPLX16, indx = indx_strt; bndx = bstrt; for (i = 0; i < colsb; i++) { - bufferb[indx] = calpha * b[bndx++]; + bufferb[indx] = DOUBLE_COMPLEX_MUL_CC(calpha, b[bndx++]); // printf( "( %f, %f )\n", crealf( bufferb[indx] ), cimagf( // bufferb[indx] ) ); indx += rowsb; @@ -349,7 +333,7 @@ void ENTF90(MMUL_CMPLX16, indx = indx_strt; bndx = bstrt; for (i = 0; i < colsb; i++) { - bufferb[indx] = calpha * conjf(b[bndx++]); + bufferb[indx] = DOUBLE_COMPLEX_MUL_CC(calpha, conj(b[bndx++])); // printf( "( %f, %f )\n", crealf( bufferb[indx] ), // cimagf( bufferb[indx] ) ); indx += rowsb; @@ -361,7 +345,7 @@ void ENTF90(MMUL_CMPLX16, /* Now muliply the transposed b matrix by a, which is transposed */ - if (cbeta == 0.0) { /* beta == 0.0 */ + if (DOUBLE_COMPLEX_EQ_CC(cbeta, DOUBLE_COMPLEX_CREATE(0.0, 0.0))) { /* beta == 0.0 */ astrt = 0; indx = 0; cstrt = 0; @@ -371,10 +355,10 @@ void ENTF90(MMUL_CMPLX16, bufferb */ cndx = cstrt; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); andx = astrt; for (k = 0; k < rowsb; k++) - temp += a[andx++] * bufferb[indx++]; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(a[andx++], bufferb[indx++])); c[cndx] = temp; cndx += ldc; // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( @@ -396,11 +380,11 @@ void ENTF90(MMUL_CMPLX16, cndx = cstrt; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); andx = astrt; for (k = 0; k < rowsb; k++) - temp += a[andx++] * bufferb[indx++]; - c[cndx] = cbeta * c[cndx] + temp; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(a[andx++], bufferb[indx++])); + c[cndx] = DOUBLE_COMPLEX_ADD_CC(DOUBLE_COMPLEX_MUL_CC(cbeta, c[cndx]), temp); cndx += ldc; // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( // c[cndx] ) ); @@ -420,18 +404,18 @@ void ENTF90(MMUL_CMPLX16, andx = astrt; indx = 0; for (ja = 0; ja < colsa; ja++) { - buffera[indx++] = calpha * a[andx]; + buffera[indx++] = DOUBLE_COMPLEX_MUL_CC(calpha, a[andx]); andx += lda; } astrt++; cndx = cstrt; /* Now use the transposed row on all of b */ - if (cbeta == 0.0) { + if (DOUBLE_COMPLEX_EQ_CC(cbeta, DOUBLE_COMPLEX_CREATE(0.0, 0.0))) { for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; for (k = 0; k < rowsb; k++) - temp += buffera[k] * b[bndx++]; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(buffera[k], b[bndx++])); bstrt += ldb; c[cndx] = temp; cndx += ldc; @@ -439,12 +423,12 @@ void ENTF90(MMUL_CMPLX16, cstrt++; /* set index for next row of c */ } else { for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; for (k = 0; k < rowsb; k++) - temp += buffera[k] * b[bndx++]; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(buffera[k], b[bndx++])); bstrt += ldb; - c[cndx] = temp + cbeta * c[cndx]; + c[cndx] = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(cbeta, c[cndx])); cndx += ldc; } cstrt++; /* set index for next row of c */ @@ -458,7 +442,7 @@ void ENTF90(MMUL_CMPLX16, indx = indx_strt; bndx = bstrt; for (i = 0; i < colsb; i++) { - bufferb[indx] = calpha * b[bndx++]; + bufferb[indx] = DOUBLE_COMPLEX_MUL_CC(calpha, b[bndx++]); // printf( "( %f, %f )\n", crealf( // bufferb[indx] ), cimagf( bufferb[indx] ) ); @@ -474,7 +458,7 @@ void ENTF90(MMUL_CMPLX16, indx = indx_strt; bndx = bstrt; for (i = 0; i < colsb; i++) { - bufferb[indx] = calpha * conjf(b[bndx++]); + bufferb[indx] = DOUBLE_COMPLEX_MUL_CC(calpha, conj(b[bndx++])); // printf( "( %f, %f )\n", crealf( bufferb[indx] ), // cimagf( bufferb[indx] ) ); indx += rowsb; @@ -486,7 +470,7 @@ void ENTF90(MMUL_CMPLX16, /* Now muliply the transposed b matrix by a */ - if (cbeta == 0.0) { /* beta == 0.0 */ + if (DOUBLE_COMPLEX_EQ_CC(cbeta, DOUBLE_COMPLEX_CREATE(0.0, 0.0))) { /* beta == 0.0 */ astrt = 0; indx = 0; cstrt = 0; @@ -496,16 +480,16 @@ void ENTF90(MMUL_CMPLX16, indx = 0; /* indx will be used for accessing both buffera and bufferb */ for (ja = 0; ja < colsa; ja++) { - buffera[indx++] = calpha * a[andx]; + buffera[indx++] = DOUBLE_COMPLEX_MUL_CC(calpha, a[andx]); andx += lda; } astrt++; cndx = cstrt; indx = 0; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); for (k = 0; k < rowsb; k++) - temp += buffera[k] * bufferb[indx++]; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(buffera[k], bufferb[indx++])); c[cndx] = temp; cndx += ldc; // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( @@ -524,17 +508,17 @@ void ENTF90(MMUL_CMPLX16, indx = 0; /* indx will be used for accessing both buffera and bufferb */ for (ja = 0; ja < colsa; ja++) { - buffera[indx++] = calpha * a[andx]; + buffera[indx++] = DOUBLE_COMPLEX_MUL_CC(calpha, a[andx]); andx += lda; } astrt++; cndx = cstrt; indx = 0; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = DOUBLE_COMPLEX_CREATE(0.0, 0.0); for (k = 0; k < rowsb; k++) - temp += buffera[k] * bufferb[indx++]; - c[cndx] = cbeta * c[cndx] + temp; + temp = DOUBLE_COMPLEX_ADD_CC(temp, DOUBLE_COMPLEX_MUL_CC(buffera[k], bufferb[indx++])); + c[cndx] = DOUBLE_COMPLEX_ADD_CC(DOUBLE_COMPLEX_MUL_CC(cbeta, c[cndx]), temp); // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( // c[cndx] ) ); cndx += ldc; @@ -571,5 +555,5 @@ void ENTF90(MMUL_CMPLX16, beta, c, &ldc); } } -#endif -} + +} \ No newline at end of file diff --git a/runtime/flang/mmcmplx8.c b/runtime/flang/mmcmplx8.c index 1968d17b5e8..ecfe9fd3245 100644 --- a/runtime/flang/mmcmplx8.c +++ b/runtime/flang/mmcmplx8.c @@ -19,25 +19,18 @@ #include "stdioInterf.h" #include "fioMacros.h" -#include "complex.h" +#include "mthdecls.h" #define SMALL_ROWSA 10 #define SMALL_ROWSB 10 #define SMALL_COLSB 10 -#ifndef _WIN32 -#define FLANG_FCOMPLEX double complex -#else -#define FLANG_FCOMPLEX _Dcomplex -#endif - void ENTF90(MMUL_CMPLX8, mmul_cmplx8)(int ta, int tb, __POINT_T mra, __POINT_T ncb, - __POINT_T kab, FLANG_FCOMPLEX *alpha, FLANG_FCOMPLEX a[], - __POINT_T lda, FLANG_FCOMPLEX b[], __POINT_T ldb, - FLANG_FCOMPLEX *beta, FLANG_FCOMPLEX c[], __POINT_T ldc) + __POINT_T kab, FLOAT_COMPLEX_TYPE *alpha, FLOAT_COMPLEX_TYPE a[], + __POINT_T lda, FLOAT_COMPLEX_TYPE b[], __POINT_T ldb, + FLOAT_COMPLEX_TYPE *beta, FLOAT_COMPLEX_TYPE c[], __POINT_T ldc) { - #ifndef _WIN32 /* * Notes on parameters * ta, tb = 0 -> no transpose of matrix @@ -72,13 +65,13 @@ void ENTF90(MMUL_CMPLX8, int bufr, bufc, loc, lor; int small_size = SMALL_ROWSA * SMALL_ROWSB * SMALL_COLSB; int tindex = 0; - FLANG_FCOMPLEX buffera[SMALL_ROWSA * SMALL_ROWSB]; - FLANG_FCOMPLEX bufferb[SMALL_COLSB * SMALL_ROWSB]; - FLANG_FCOMPLEX temp; + FLOAT_COMPLEX_TYPE buffera[SMALL_ROWSA * SMALL_ROWSB]; + FLOAT_COMPLEX_TYPE bufferb[SMALL_COLSB * SMALL_ROWSB]; + FLOAT_COMPLEX_TYPE temp; void ftn_mvmul_cmplx8_(), ftn_vmmul_cmplx8_(); void ftn_mnaxnb_cmplx8_(), ftn_mnaxtb_cmplx8_(); void ftn_mtaxnb_cmplx8_(), ftn_mtaxtb_cmplx8_(); - FLANG_FCOMPLEX calpha, cbeta; + FLOAT_COMPLEX_TYPE calpha, cbeta; /* * Small matrix multiply variables */ @@ -95,13 +88,13 @@ void ENTF90(MMUL_CMPLX8, colsa = kab; rowsb = kab; colsb = ncb; - if (calpha == 0.0) { - if (cbeta == 0.0) { + if (FLOAT_COMPLEX_EQ_CC(calpha, FLOAT_COMPLEX_CREATE(0.0, 0.0))) { + if (FLOAT_COMPLEX_EQ_CC(cbeta, FLOAT_COMPLEX_CREATE(0.0, 0.0))) { cndx = 0; indx_strt = ldc; for (j = 0; j < ncb; j++) { for (i = 0; i < mra; i++) - c[cndx + i] = 0.0; + c[cndx + i] = FLOAT_COMPLEX_CREATE(0.0, 0.0); cndx = indx_strt; indx_strt += ldc; } @@ -110,7 +103,7 @@ void ENTF90(MMUL_CMPLX8, indx_strt = ldc; for (j = 0; j < ncb; j++) { for (i = 0; i < mra; i++) - c[cndx + i] = cbeta * c[cndx + i]; + c[cndx + i] = FLOAT_COMPLEX_MUL_CC(cbeta, c[cndx + i]); cndx = indx_strt; indx_strt += ldc; } @@ -143,30 +136,30 @@ void ENTF90(MMUL_CMPLX8, andx = astrt; indx = 0; for (ja = 0; ja < colsa; ja++) { - buffera[indx++] = calpha * a[andx]; + buffera[indx++] = FLOAT_COMPLEX_MUL_CC(calpha, a[andx]); andx += lda; } astrt++; cndx = cstrt; /* Now use the transposed row on all of b */ - if (cbeta == 0.0) { + if (FLOAT_COMPLEX_EQ_CC(cbeta, FLOAT_COMPLEX_CREATE(0.0, 0.0))) { for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; for (k = 0; k < rowsb; k++) - temp += buffera[k] * b[bndx++]; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(buffera[k], b[bndx++])); bstrt += ldb; c[cndx] = temp; cndx += ldc; } } else { for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; for (k = 0; k < rowsb; k++) - temp += buffera[k] * b[bndx++]; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(buffera[k], b[bndx++])); bstrt += ldb; - c[cndx] = temp + cbeta * c[cndx]; + c[cndx] = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(cbeta, c[cndx])); cndx += ldc; } } @@ -208,7 +201,7 @@ void ENTF90(MMUL_CMPLX8, /* Now muliply the transposed b matrix by a */ - if (cbeta == 0.0) { /* beta == 0.0 */ + if (FLOAT_COMPLEX_EQ_CC(cbeta, FLOAT_COMPLEX_CREATE(0.0, 0.0))) { /* beta == 0.0 */ astrt = 0; indx = 0; cstrt = 0; @@ -225,10 +218,10 @@ void ENTF90(MMUL_CMPLX8, cndx = cstrt; indx = 0; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); for (k = 0; k < rowsb; k++) - temp += buffera[k] * bufferb[indx++]; - c[cndx] = calpha * temp; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(buffera[k], bufferb[indx++])); + c[cndx] = FLOAT_COMPLEX_MUL_CC(calpha, temp); cndx += ldc; // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( // c[cndx] ) ); @@ -253,10 +246,10 @@ void ENTF90(MMUL_CMPLX8, cndx = cstrt; indx = 0; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); for (k = 0; k < rowsb; k++) - temp += buffera[k] * bufferb[indx++]; - c[cndx] = cbeta * c[cndx] + calpha * temp; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(buffera[k], bufferb[indx++])); + c[cndx] = FLOAT_COMPLEX_ADD_CC(FLOAT_COMPLEX_MUL_CC(cbeta, c[cndx]), FLOAT_COMPLEX_MUL_CC(calpha, temp)); cndx += ldc; } cstrt++; /* set index for next row of c */ @@ -270,17 +263,17 @@ void ENTF90(MMUL_CMPLX8, if (tb == 0) { astrt = 0; cstrt = 0; - if (cbeta == 0.0) { /* beta == 0 */ + if (FLOAT_COMPLEX_EQ_CC(cbeta, FLOAT_COMPLEX_CREATE(0.0, 0.0))) { /* beta == 0 */ for (i = 0; i < rowsa; i++) { cndx = cstrt; bstrt = 0; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; andx = astrt; for (k = 0; k < rowsb; k++) - temp += a[andx++] * b[bndx++]; - c[cndx] = calpha * temp; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(a[andx++], b[bndx++])); + c[cndx] = FLOAT_COMPLEX_ADD_CC(calpha, temp); // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( // c[cndx] ) ); @@ -299,15 +292,15 @@ void ENTF90(MMUL_CMPLX8, bstrt = 0; ; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; andx = astrt; for (k = 0; k < rowsb; k++) { - temp += a[andx] * b[bndx]; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(a[andx], b[bndx])); andx++; bndx++; } - c[cndx] = cbeta * c[cndx] + calpha * temp; + c[cndx] = FLOAT_COMPLEX_ADD_CC(FLOAT_COMPLEX_MUL_CC(cbeta, c[cndx]), FLOAT_COMPLEX_MUL_CC(calpha, temp)); // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( c[cndx] ) ); bstrt += ldb; cndx += ldc; @@ -324,7 +317,7 @@ void ENTF90(MMUL_CMPLX8, indx = indx_strt; bndx = bstrt; for (i = 0; i < colsb; i++) { - bufferb[indx] = calpha * b[bndx++]; + bufferb[indx] = FLOAT_COMPLEX_MUL_CC(calpha, b[bndx++]); // printf( "( %f, %f )\n", crealf( bufferb[indx] ), cimagf( // bufferb[indx] ) ); indx += rowsb; @@ -339,7 +332,7 @@ void ENTF90(MMUL_CMPLX8, indx = indx_strt; bndx = bstrt; for (i = 0; i < colsb; i++) { - bufferb[indx] = calpha * conjf(b[bndx++]); + bufferb[indx] = FLOAT_COMPLEX_MUL_CC(calpha, conjf(b[bndx++])); // printf( "( %f, %f )\n", crealf( bufferb[indx] ), // cimagf( bufferb[indx] ) ); indx += rowsb; @@ -351,7 +344,7 @@ void ENTF90(MMUL_CMPLX8, /* Now muliply the transposed b matrix by a, which is transposed */ - if (cbeta == 0.0) { /* beta == 0.0 */ + if (FLOAT_COMPLEX_EQ_CC(cbeta, FLOAT_COMPLEX_CREATE(0.0, 0.0))) { /* beta == 0.0 */ astrt = 0; indx = 0; cstrt = 0; @@ -361,10 +354,10 @@ void ENTF90(MMUL_CMPLX8, bufferb */ cndx = cstrt; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); andx = astrt; for (k = 0; k < rowsb; k++) - temp += a[andx++] * bufferb[indx++]; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(a[andx++], bufferb[indx++])); c[cndx] = temp; cndx += ldc; // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( @@ -386,11 +379,11 @@ void ENTF90(MMUL_CMPLX8, cndx = cstrt; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); andx = astrt; for (k = 0; k < rowsb; k++) - temp += a[andx++] * bufferb[indx++]; - c[cndx] = cbeta * c[cndx] + temp; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(a[andx++], bufferb[indx++])); + c[cndx] = FLOAT_COMPLEX_ADD_CC(FLOAT_COMPLEX_MUL_CC(cbeta, c[cndx]), temp); cndx += ldc; // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( // c[cndx] ) ); @@ -410,18 +403,18 @@ void ENTF90(MMUL_CMPLX8, andx = astrt; indx = 0; for (ja = 0; ja < colsa; ja++) { - buffera[indx++] = calpha * a[andx]; + buffera[indx++] = FLOAT_COMPLEX_MUL_CC(calpha, a[andx]); andx += lda; } astrt++; cndx = cstrt; /* Now use the transposed row on all of b */ - if (cbeta == 0.0) { + if (FLOAT_COMPLEX_EQ_CC(cbeta, FLOAT_COMPLEX_CREATE(0.0, 0.0))) { for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; for (k = 0; k < rowsb; k++) - temp += buffera[k] * b[bndx++]; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(buffera[k], b[bndx++])); bstrt += ldb; c[cndx] = temp; cndx += ldc; @@ -429,12 +422,12 @@ void ENTF90(MMUL_CMPLX8, cstrt++; /* set index for next row of c */ } else { for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); bndx = bstrt; for (k = 0; k < rowsb; k++) - temp += buffera[k] * b[bndx++]; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(buffera[k], b[bndx++])); bstrt += ldb; - c[cndx] = temp + cbeta * c[cndx]; + c[cndx] = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(cbeta, c[cndx])); cndx += ldc; } cstrt++; /* set index for next row of c */ @@ -448,7 +441,7 @@ void ENTF90(MMUL_CMPLX8, indx = indx_strt; bndx = bstrt; for (i = 0; i < colsb; i++) { - bufferb[indx] = calpha * b[bndx++]; + bufferb[indx] = FLOAT_COMPLEX_MUL_CC(calpha, b[bndx++]); // printf( "( %f, %f )\n", crealf( // bufferb[indx] ), cimagf( bufferb[indx] ) ); @@ -464,7 +457,7 @@ void ENTF90(MMUL_CMPLX8, indx = indx_strt; bndx = bstrt; for (i = 0; i < colsb; i++) { - bufferb[indx] = calpha * conjf(b[bndx++]); + bufferb[indx] = FLOAT_COMPLEX_MUL_CC(calpha, conjf(b[bndx++])); // printf( "( %f, %f )\n", crealf( bufferb[indx] ), // cimagf( bufferb[indx] ) ); indx += rowsb; @@ -476,7 +469,7 @@ void ENTF90(MMUL_CMPLX8, /* Now muliply the transposed b matrix by a */ - if (cbeta == 0.0) { /* beta == 0.0 */ + if (FLOAT_COMPLEX_EQ_CC(cbeta, FLOAT_COMPLEX_CREATE(0.0, 0.0))) { /* beta == 0.0 */ astrt = 0; indx = 0; cstrt = 0; @@ -486,16 +479,16 @@ void ENTF90(MMUL_CMPLX8, indx = 0; /* indx will be used for accessing both buffera and bufferb */ for (ja = 0; ja < colsa; ja++) { - buffera[indx++] = calpha * a[andx]; + buffera[indx++] = FLOAT_COMPLEX_MUL_CC(calpha, a[andx]); andx += lda; } astrt++; cndx = cstrt; indx = 0; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); for (k = 0; k < rowsb; k++) - temp += buffera[k] * bufferb[indx++]; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(buffera[k], bufferb[indx++])); c[cndx] = temp; cndx += ldc; // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( @@ -514,17 +507,17 @@ void ENTF90(MMUL_CMPLX8, indx = 0; /* indx will be used for accessing both buffera and bufferb */ for (ja = 0; ja < colsa; ja++) { - buffera[indx++] = calpha * a[andx]; + buffera[indx++] = FLOAT_COMPLEX_MUL_CC(calpha, a[andx]); andx += lda; } astrt++; cndx = cstrt; indx = 0; for (j = 0; j < colsb; j++) { - temp = 0.0; + temp = FLOAT_COMPLEX_CREATE(0.0, 0.0); for (k = 0; k < rowsb; k++) - temp += buffera[k] * bufferb[indx++]; - c[cndx] = cbeta * c[cndx] + temp; + temp = FLOAT_COMPLEX_ADD_CC(temp, FLOAT_COMPLEX_MUL_CC(buffera[k], bufferb[indx++])); + c[cndx] = FLOAT_COMPLEX_ADD_CC(FLOAT_COMPLEX_MUL_CC(cbeta, c[cndx]), temp); // printf( "( %f, %f )\n", crealf( c[cndx] ), cimagf( // c[cndx] ) ); cndx += ldc; @@ -561,6 +554,5 @@ void ENTF90(MMUL_CMPLX8, beta, c, &ldc); } } -#endif -} +} diff --git a/runtime/include/mthdecls.h b/runtime/include/mthdecls.h index ddec42510f0..6913895e0c8 100644 --- a/runtime/include/mthdecls.h +++ b/runtime/include/mthdecls.h @@ -46,6 +46,30 @@ typedef unsigned long _ULONGLONG_T; #include #endif +#if !defined(HOST_WIN) && !defined(WINNT) && !defined(WIN64) && !defined(WIN32) && !defined(HOST_MINGW) +#define FLOAT_COMPLEX_TYPE complex float +#define FLOAT_COMPLEX_CREATE(real, imag) (real + imag * I) +#define FLOAT_COMPLEX_MUL_CC(a, b) a * b +#define FLOAT_COMPLEX_ADD_CC(a, b) a + b +#define FLOAT_COMPLEX_EQ_CC(a, b) a == b +#define DOUBLE_COMPLEX_TYPE complex double +#define DOUBLE_COMPLEX_CREATE(real, imag) (real + imag * I) +#define DOUBLE_COMPLEX_MUL_CC(a, b) a * b +#define DOUBLE_COMPLEX_ADD_CC(a, b) a + b +#define DOUBLE_COMPLEX_EQ_CC(a, b) a == b +#else +#define FLOAT_COMPLEX_TYPE _Fcomplex +#define FLOAT_COMPLEX_CREATE(real, imag) _FCbuild(real, imag) +#define FLOAT_COMPLEX_MUL_CC(a, b) _FCmulcc(a, b) +#define FLOAT_COMPLEX_ADD_CC(a, b) _FCbuild(crealf(a) + crealf(b), cimagf(a) + cimagf(b)) +#define FLOAT_COMPLEX_EQ_CC(a, b) (crealf(a) == crealf(b) && cimagf(a) == cimagf(b)) +#define DOUBLE_COMPLEX_TYPE _Dcomplex +#define DOUBLE_COMPLEX_CREATE(real, imag) _Cbuild(real, imag) +#define DOUBLE_COMPLEX_MUL_CC(a, b) _Cmulcc(a, b) +#define DOUBLE_COMPLEX_ADD_CC(a, b) _Cbuild(creal(a) + creal(b), cimag(a) + cimag(b)) +#define DOUBLE_COMPLEX_EQ_CC(a, b) (creal(a) == creal(b) && cimag(a) == cimag(b)) +#endif + typedef struct { float real; float imag; From f70c7b779e6363acbfcbfce7a4731ea2316ae986 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 28 Dec 2017 09:14:30 -0600 Subject: [PATCH 107/141] Register boolean "es" argument. This allows preprocessor-only mode to run. --- tools/flang1/flang1exe/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/flang1/flang1exe/main.c b/tools/flang1/flang1exe/main.c index 7c2272d45ed..0f3ab1165bb 100644 --- a/tools/flang1/flang1exe/main.c +++ b/tools/flang1/flang1exe/main.c @@ -798,6 +798,7 @@ init(int argc, char *argv[]) register_integer_arg(arg_parser, "vect", &(vect_val), 0); register_boolean_arg(arg_parser, "standard", (bool *)&(flg.standard), false); register_boolean_arg(arg_parser, "save", (bool *)&(flg.save), false); + register_boolean_arg(arg_parser, "es", (bool *)&(flg.es), false); register_boolean_arg(arg_parser, "extend", &arg_extend, false); register_boolean_arg(arg_parser, "recursive", (bool *)&(flg.recursive), false); From c45ea619fe67a7cf76e46ae5fbb46dcc1a6d1ec6 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 28 Dec 2017 09:14:48 -0600 Subject: [PATCH 108/141] Remove dependency that confused ninja-build. --- runtime/flang/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index a5134e4ae96..eb9ce8359fe 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -557,7 +557,7 @@ set_source_files_properties( ieee_arithmetic.F95 ieee_exceptions.F95 PROPERTIES - OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod + #OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod ) set_target_properties(flang_static flang_shared From 6315df57e8150d07c5a78b766346f96568139bc1 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 28 Dec 2017 11:23:08 -0600 Subject: [PATCH 109/141] Set preprocessor filename to output filename --- tools/flang1/flang1exe/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/flang1/flang1exe/main.c b/tools/flang1/flang1exe/main.c index 0f3ab1165bb..de93a9c0afa 100644 --- a/tools/flang1/flang1exe/main.c +++ b/tools/flang1/flang1exe/main.c @@ -1122,9 +1122,9 @@ init(int argc, char *argv[]) if (!ipa_import_mode) { if (fpp_) { if (flg.es) { - if (cppfile == NULL) + if (outfile_name == NULL) gbl.cppfil = stdout; - else if ((gbl.cppfil = fopen(cppfile, "w")) == NULL) + else if ((gbl.cppfil = fopen(outfile_name, "w")) == NULL) errfatal(5); } else { if ((gbl.cppfil = tmpf("a")) == NULL) From 1bc7adbd341c3fab88c8d414e9ee42ff69b2b5ee Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 29 Dec 2017 15:36:37 -0600 Subject: [PATCH 110/141] Fix regression in host-fp-folding --- lib/scutil/host-fp-folding.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/scutil/host-fp-folding.c b/lib/scutil/host-fp-folding.c index d68ac048e27..e40b4491609 100644 --- a/lib/scutil/host-fp-folding.c +++ b/lib/scutil/host-fp-folding.c @@ -88,7 +88,7 @@ configure_denormals(bool denorms_are_zeros, bool flush_to_zero) #ifdef _WIN32 unsigned int mxcsr = _mm_getcsr(); #else - unsigned int mxcsr = fenv.__mxcsr + unsigned int mxcsr = fenv.__mxcsr; #endif mxcsr &= ~0x0040; if (denorms_are_zeros) From f7ca01890a97ba2d7317c18684ba40a12c8f6c75 Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 29 Dec 2017 15:45:17 -0600 Subject: [PATCH 111/141] Fix CMake regression --- runtime/flang/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index eb9ce8359fe..a5134e4ae96 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -557,7 +557,7 @@ set_source_files_properties( ieee_arithmetic.F95 ieee_exceptions.F95 PROPERTIES - #OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod + OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod ) set_target_properties(flang_static flang_shared From 281cc422a0c5d900dbc4ba9794bf16d3ce5565a5 Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 29 Dec 2017 16:20:21 -0600 Subject: [PATCH 112/141] CMake: do depdencies correctly --- runtime/flang/CMakeLists.txt | 42 ++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index a5134e4ae96..e65a98550c9 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -335,12 +335,9 @@ SET(FTN_SUPPORT descIntrins.c descFioUtil.c descRW.c - ieee_arithmetic.F95 - ieee_exceptions.F95 ieee_features.F95 initpar.c inquire.c - iso_c_bind.F95 iso_fortran_env.f90 ldread.c ldwrite.c @@ -477,6 +474,15 @@ SET(FTN_SUPPORT xfer_rpm1.c ) +add_library(iso_c_bind + iso_c_bind.F95 +) + +add_library(ieee_arithmetic + ieee_arithmetic.F95 + ieee_exceptions.F95 +) + add_flang_library(flang_static ${FTN_INTRINSICS} ${FTN_SUPPORT} @@ -484,9 +490,9 @@ add_flang_library(flang_static ) if (MSVC) -set_property(TARGET flang_static PROPERTY OUTPUT_NAME libflang) + set_property(TARGET flang_static PROPERTY OUTPUT_NAME libflang) else() -set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang) + set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang) endif() set(SHARED_LIBRARY TRUE) @@ -545,20 +551,6 @@ set_property( ## CMake does not handle module dependencies between Fortran files, ## we need to help it -# State the module that the source is producing -set_source_files_properties( - iso_c_bind.F95 - PROPERTIES - OBJECT_OUTPUTS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod - ) - -# State a dependency on the module -set_source_files_properties( - ieee_arithmetic.F95 - ieee_exceptions.F95 - PROPERTIES - OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod - ) set_target_properties(flang_static flang_shared PROPERTIES @@ -589,6 +581,18 @@ add_dependencies(flang_shared flang2 ) +add_dependencies(iso_c_bind + flang1 + flang2 +) + +add_dependencies(ieee_arithmetic + iso_c_bind +) + +target_link_libraries(flang_static iso_c_bind ieee_arithmetic) +target_link_libraries(flang_shared iso_c_bind ieee_arithmetic) + if (NOT MSVC) target_compile_options(flang_static PRIVATE -fPIC) target_compile_options(flang_shared PRIVATE -fPIC) From a9daa897844af79e18099cdd504be3671b506233 Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 29 Dec 2017 16:41:27 -0600 Subject: [PATCH 113/141] one two three three four five seven six nine ten --- .appveyor.yml | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index ec149f446b7..1c2daf8379c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,56 +4,51 @@ branches: - windows - windows-rebased -cache: - - '%APPVEYOR_BUILD_FOLDER%\build' - environment: global: - MSYS2_ROOT: C:\msys64 CONDA_INSTALL_LOCN: C:\\Miniconda36-x64 - PYTHON2_LOCN: C:\\Python27-x64 APPVEYOR_SAVE_CACHE_ON_FAILURE: true +os: Visual Studio 2017 + platform: - x64 install: # Add path, activate `conda` and update conda. - cmd: call %CONDA_INSTALL_LOCN%\Scripts\activate.bat - - cmd: conda install --yes --quiet conda=4.3 # Add our channels. - cmd: conda config --add channels defaults - cmd: conda config --add channels conda-forge - - cmd: conda install --yes --quiet flang-meta llvmdev clangdev openmp cmake - - cmd: set "PATH=%PYTHON2_LOCN%\Scripts;%PYTHON2_LOCN%;%PATH%" - - cmd: appveyor DownloadFile "https://raw.githubusercontent.com/isuruf/flang/utils/llvm_utils_for_flang.zip" -FileName "utils.zip" - - cmd: 7z x -oC:\llvm_src utils.zip + - cmd: conda install --yes --quiet llvmdev clangdev flang cmake + - cmd: conda install --yes -c isuruf kitware-ninja + build_script: - - ps: mkdir build; $LastExitCode = 0 + - ps: mkdir build + - cd build - set "PATH=%cd%\bin;%PATH%" - - call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 + - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 + - ps: | - cmake -G "NMake Makefiles" -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=ON -DLLVM_MAIN_SRC_DIR=C:\llvm_src .. + cmake -G "Ninja" -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=ON -DLLVM_MAIN_SRC_DIR=C:\llvm_src .. Push-AppveyorArtifact .\CMakeFiles\CMakeOutput.log Push-AppveyorArtifact .\CMakeFiles\CMakeError.log + - ps: | cmake --build . 2>&1 | Out-File build_output.txt if($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode ) } Push-AppveyorArtifact .\build_output.txt Get-Content .\build_output.txt -Tail 500 + - ps: Compress-Archive -Path C:\projects\flang\build\bin -DestinationPath C:\Projects\flang\bin.zip - ps: Push-AppveyorArtifact C:\Projects\flang\bin.zip - ps: Compress-Archive -Path C:\projects\flang\build\lib -DestinationPath C:\Projects\flang\lib.zip - ps: Push-AppveyorArtifact C:\Projects\flang\lib.zip test_script: - - cmd: set "PATH=%MSYS2_ROOT%\usr\bin\;%PATH%" - cmd: copy lib\flangmain.lib %CONDA_INSTALL_LOCN%\Library\lib - cmd: copy lib\flangrti.lib %CONDA_INSTALL_LOCN%\Library\lib - cmd: copy lib\flang.lib %CONDA_INSTALL_LOCN%\Library\lib - cmd: copy lib\ompstub.lib %CONDA_INSTALL_LOCN%\Library\lib - - cmd: nmake FileCheck - - cmd: copy bin\FileCheck.exe binFileCheck.exe - #- cmd: nmake check-flang From 31950cc355c3ebb1972a9f9dd65a1756e8580819 Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 29 Dec 2017 20:17:26 -0600 Subject: [PATCH 114/141] CMake: Fix missing symbols introduced in gh-90 The third time may be a charm --- runtime/flang/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index e65a98550c9..a676821751c 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -335,9 +335,12 @@ SET(FTN_SUPPORT descIntrins.c descFioUtil.c descRW.c + ieee_arithmetic.F95 + ieee_exceptions.F95 ieee_features.F95 initpar.c inquire.c + iso_c_bind.F95 iso_fortran_env.f90 ldread.c ldwrite.c @@ -573,12 +576,14 @@ target_include_directories(flang_shared add_dependencies(flang_static flang1 flang2 + ieee_arithmetic ) # Make sure the compiler is built before we bootstrap add_dependencies(flang_shared flang1 flang2 + ieee_arithmetic ) add_dependencies(iso_c_bind @@ -590,9 +595,6 @@ add_dependencies(ieee_arithmetic iso_c_bind ) -target_link_libraries(flang_static iso_c_bind ieee_arithmetic) -target_link_libraries(flang_shared iso_c_bind ieee_arithmetic) - if (NOT MSVC) target_compile_options(flang_static PRIVATE -fPIC) target_compile_options(flang_shared PRIVATE -fPIC) From f94b2c5f45887998b0d3bf61a0cfdbe1fd4f0832 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 30 Dec 2017 09:50:34 +0530 Subject: [PATCH 115/141] Fix CMake Warning --- CMakeLists.txt | 19 ++++--------------- runtime/flangrti/CMakeLists.txt | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 322616b573c..4514b5df535 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -359,25 +359,14 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include ) -if (MSVC) # Direct module files to build include directory set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/runtime/flang) # Install Fortran module files -# TODO: this creates empty directories. Figure out a workaround or -# better would be to figure out why CMAKE_Fortran_MODULE_DIRECTORY is different -install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ - DESTINATION include FILES_MATCHING PATTERN *.mod - ) -else() -# Direct module files to build include directory -set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include) - -# Install Fortran module files -install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ - DESTINATION include - ) -endif() +install( + CODE "file(GLOB FLANG_MOD_FILES \"${CMAKE_Fortran_MODULE_DIRECTORY}/*.mod\")" + CODE "file(INSTALL \${FLANG_MOD_FILES} DESTINATION \"${CMAKE_INSTALL_PREFIX}/include\")" +) # Install Fortran OpenMP include file # Copy omp_lib.h file, not the symlink diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index acf57ca2712..547ead089f4 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -201,7 +201,7 @@ add_flang_library(flangrti_shared # Resolve symbols against libm if (NOT MSVC) -target_link_libraries(flangrti_shared m) +target_link_libraries(flangrti_shared PUBLIC m) endif() # Import OpenMP From 0cc7ab54531da16649c3e16d80ab8fe674a6b84f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 30 Dec 2017 09:51:47 +0530 Subject: [PATCH 116/141] Run make install in travis.yml --- .travis.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 29d267eefb5..6fa55855036 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,12 +30,9 @@ install: script: - mkdir -p build - cd build - - cmake -DFLANG_INCLUDE_TESTS=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_Fortran_COMPILER=flang .. + - cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DFLANG_INCLUDE_TESTS=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_Fortran_COMPILER=flang .. - make -j4 - - - cp lib/* $HOME/miniconda/envs/test-environment/lib - - cp bin/* $HOME/miniconda/envs/test-environment/bin - + - make install -j4 - make check-flang notifications: From 78d15891f89ffeb7b0eb4b5ccff142bcd01fa7dc Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 30 Dec 2017 09:34:33 +0530 Subject: [PATCH 117/141] Don't check fortran ABI --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4514b5df535..80378e145fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,9 +21,8 @@ cmake_minimum_required(VERSION 2.8) # In order to bootstrap the runtime library we need to skip # CMake's Fortran tests SET(CMAKE_Fortran_COMPILER_WORKS 1) - - -set(CMAKE_Fortran_PREPROCESS_SOURCE +SET(CMAKE_Fortran_ABI_COMPILED 0) +SET(CMAKE_Fortran_PREPROCESS_SOURCE " -cpp -E -o ") # If we are not building as a part of LLVM, build Flang as an From 683d410f5f6def6b77c42b39719744e80d801c20 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 30 Dec 2017 09:36:03 +0530 Subject: [PATCH 118/141] Update .appveyor.yml --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 1c2daf8379c..83025cb2e00 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -20,7 +20,7 @@ install: # Add our channels. - cmd: conda config --add channels defaults - cmd: conda config --add channels conda-forge - - cmd: conda install --yes --quiet llvmdev clangdev flang cmake + - cmd: conda install --yes --quiet llvmdev clangdev flang-meta cmake - cmd: conda install --yes -c isuruf kitware-ninja From b59487852d9c236d3eb157c049c8129c8c67aea6 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 30 Dec 2017 09:42:10 +0530 Subject: [PATCH 119/141] Flang support F90 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 80378e145fa..ea605b2a4e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ cmake_minimum_required(VERSION 2.8) # CMake's Fortran tests SET(CMAKE_Fortran_COMPILER_WORKS 1) SET(CMAKE_Fortran_ABI_COMPILED 0) +SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1) SET(CMAKE_Fortran_PREPROCESS_SOURCE " -cpp -E -o ") From 48077b4060863e93baffbdfac51672d9b9237971 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 30 Dec 2017 10:26:59 +0530 Subject: [PATCH 120/141] Make iso_c_bind OBJECT libraries so that no linking is done --- runtime/flang/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index a676821751c..4f5685fedb0 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -477,11 +477,11 @@ SET(FTN_SUPPORT xfer_rpm1.c ) -add_library(iso_c_bind +add_library(iso_c_bind OBJECT iso_c_bind.F95 ) -add_library(ieee_arithmetic +add_library(ieee_arithmetic OBJECT ieee_arithmetic.F95 ieee_exceptions.F95 ) From d6323154a2c05eab63142ad9009ac260e56898f8 Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 29 Dec 2017 23:09:01 -0600 Subject: [PATCH 121/141] Travis: disable testing --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6fa55855036..6ed46ba68cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ install: - conda info -a # For testing - - pip install lit + #- pip install lit script: - mkdir -p build @@ -33,7 +33,7 @@ script: - cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DFLANG_INCLUDE_TESTS=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_Fortran_COMPILER=flang .. - make -j4 - make install -j4 - - make check-flang + #- make check-flang notifications: email: false From a1009b9fbc4d83c7e20a13ef20b76ba5999512e3 Mon Sep 17 00:00:00 2001 From: xoviat Date: Fri, 29 Dec 2017 23:13:42 -0600 Subject: [PATCH 122/141] Travis: set branches --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6ed46ba68cb..35aa87fa181 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,11 @@ cache: - $HOME/.conda/pkgs - $HOME/miniconda/pkgs +branches: + only: + - master + - windows + install: - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh; - bash miniconda.sh -u -b -p $HOME/miniconda From 550cdb8a981a30456ea343e35a71b92f6a72e320 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 31 Dec 2017 08:22:17 +0530 Subject: [PATCH 123/141] Test install in appveyor --- .appveyor.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 83025cb2e00..03495543551 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -32,7 +32,7 @@ build_script: - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 - ps: | - cmake -G "Ninja" -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=ON -DLLVM_MAIN_SRC_DIR=C:\llvm_src .. + cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX=$Env:CONDA_PREFIX -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=ON -DLLVM_MAIN_SRC_DIR=C:\llvm_src .. Push-AppveyorArtifact .\CMakeFiles\CMakeOutput.log Push-AppveyorArtifact .\CMakeFiles\CMakeError.log @@ -48,7 +48,4 @@ build_script: - ps: Push-AppveyorArtifact C:\Projects\flang\lib.zip test_script: - - cmd: copy lib\flangmain.lib %CONDA_INSTALL_LOCN%\Library\lib - - cmd: copy lib\flangrti.lib %CONDA_INSTALL_LOCN%\Library\lib - - cmd: copy lib\flang.lib %CONDA_INSTALL_LOCN%\Library\lib - - cmd: copy lib\ompstub.lib %CONDA_INSTALL_LOCN%\Library\lib + - cmd: cmake --build . --target install From 1ab1d9bcbf23162bb034907430a0b276f881867e Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 31 Dec 2017 09:02:42 +0530 Subject: [PATCH 124/141] Fix install --- .appveyor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 03495543551..f3b5424e037 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -30,9 +30,8 @@ build_script: - cd build - set "PATH=%cd%\bin;%PATH%" - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 - + - cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX% -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=ON -DLLVM_MAIN_SRC_DIR=C:\llvm_src .. - ps: | - cmake -G "Ninja" -DCMAKE_INSTALL_PREFIX=$Env:CONDA_PREFIX -DFLANG_INCLUDE_TESTS=ON -DFLANG_TEST_VERBOSE_MODE=ON -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=ON -DLLVM_MAIN_SRC_DIR=C:\llvm_src .. Push-AppveyorArtifact .\CMakeFiles\CMakeOutput.log Push-AppveyorArtifact .\CMakeFiles\CMakeError.log From a0160d7ba47757a3cbe0109aceb736acc31aa0f1 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 31 Dec 2017 09:54:36 +0530 Subject: [PATCH 125/141] Fix Fortran compiler identification --- CMakeLists.txt | 10 +++++----- runtime/flang/CMakeLists.txt | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea605b2a4e9..965bbc5891b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ SET(CMAKE_Fortran_ABI_COMPILED 0) SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1) SET(CMAKE_Fortran_PREPROCESS_SOURCE " -cpp -E -o ") +set(CMAKE_Fortran_MODDIR_FLAG "-module ") # If we are not building as a part of LLVM, build Flang as an # standalone project, using LLVM as an external library: @@ -360,13 +361,12 @@ include_directories(BEFORE ) # Direct module files to build include directory -set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/runtime/flang) +set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include) # Install Fortran module files -install( - CODE "file(GLOB FLANG_MOD_FILES \"${CMAKE_Fortran_MODULE_DIRECTORY}/*.mod\")" - CODE "file(INSTALL \${FLANG_MOD_FILES} DESTINATION \"${CMAKE_INSTALL_PREFIX}/include\")" -) +install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ + DESTINATION include + ) # Install Fortran OpenMP include file # Copy omp_lib.h file, not the symlink diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 4f5685fedb0..cfbd1002589 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -25,7 +25,10 @@ endif() # We are using Fortran driver to build this library with fresh compiler # components, so point its binary directory to the build directory to pick up # flang* executables -SET(CMAKE_Fortran_FLAGS "-B ${LLVM_RUNTIME_OUTPUT_INTDIR} ${CMAKE_Fortran_FLAGS} -no-flang-libs") +SET(CMAKE_Fortran_FLAGS "-B ${LLVM_RUNTIME_OUTPUT_INTDIR} ${CMAKE_Fortran_FLAGS}") + +# flang runtime libraries are being built here. Don't link them +SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -no-flang-libs") SET(FTN_INTRINSICS abort3f.c @@ -508,7 +511,7 @@ set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang) target_link_libraries(flang_shared flangrti_shared) # Resolve symbols against libm and librt if (NOT MSVC) -target_link_libraries(flang_shared rt m) + target_link_libraries(flang_shared rt m) else() set_target_properties(flang_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) endif() From 4ca7af69ec85389d8386ead3e5835cf14e8062d6 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 31 Dec 2017 11:45:01 +0530 Subject: [PATCH 126/141] Fix parallel build failures This was because the static and shared libraries were both producing .mod files at the same location and a parallel build was confusing the compiler with the timestamps --- CMakeLists.txt | 7 ++- runtime/flang/CMakeLists.txt | 95 +++++++++++++++++++++++++++--------- 2 files changed, 76 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 965bbc5891b..68a451f1f4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ SET(CMAKE_Fortran_ABI_COMPILED 0) SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1) SET(CMAKE_Fortran_PREPROCESS_SOURCE " -cpp -E -o ") -set(CMAKE_Fortran_MODDIR_FLAG "-module ") +SET(CMAKE_Fortran_MODDIR_FLAG "-module ") # If we are not building as a part of LLVM, build Flang as an # standalone project, using LLVM as an external library: @@ -361,7 +361,10 @@ include_directories(BEFORE ) # Direct module files to build include directory -set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include) +set(FLANG_MODULE_DIRECTORY_SHARED ${CMAKE_CURRENT_BINARY_DIR}/include) +# mod files in the following differs only by the timestamp. This is needed to +# ensure that flang can be built parallelly. It is discarded after flang is built +set(FLANG_MODULE_DIRECTORY_STATIC ${CMAKE_CURRENT_BINARY_DIR}/include-static) # Install Fortran module files install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index cfbd1002589..3ab849ddaad 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -206,7 +206,6 @@ SET(FTN_INTRINSICS mod.c mvbits3f.c nargs3f.c - omp_lib.F95 outstr3f.c packtimeqq3f.c perror3f.c @@ -273,7 +272,7 @@ SET(FTN_INTRINSICS wait3f.c ) -SET(FTN_SUPPORT +SET(FTN_SUPPORT_COMMON bcopy.c bcopys.c buffer.c @@ -338,13 +337,8 @@ SET(FTN_SUPPORT descIntrins.c descFioUtil.c descRW.c - ieee_arithmetic.F95 - ieee_exceptions.F95 - ieee_features.F95 initpar.c inquire.c - iso_c_bind.F95 - iso_fortran_env.f90 ldread.c ldwrite.c linux_dummy.c @@ -480,18 +474,46 @@ SET(FTN_SUPPORT xfer_rpm1.c ) -add_library(iso_c_bind OBJECT - iso_c_bind.F95 -) +foreach(FTN_FILE ieee_arithmetic ieee_exceptions ieee_features iso_c_bind omp_lib) + configure_file(${FTN_FILE}.F95 ${FTN_FILE}_static.F95 COPYONLY) +endforeach() +configure_file(iso_fortran_env.f90 iso_fortran_env_static.f90 COPYONLY) -add_library(ieee_arithmetic OBJECT +SET(FTN_SUPPORT_SHARED ieee_arithmetic.F95 ieee_exceptions.F95 + iso_c_bind.F95 + ieee_features.F95 + iso_fortran_env.f90 +) + +SET(FTN_SUPPORT_STATIC + ieee_arithmetic_static.F95 + ieee_exceptions_static.F95 + iso_c_bind_static.F95 + ieee_features_static.F95 + iso_fortran_env_static.f90 +) + +SET(FTN_SUPPORT + ${FTN_SUPPORT_STATIC} + ${FTN_SUPPORT_SHARED} + ${FTN_SUPPORT_COMMON} +) + +SET(FTN_INTRINSICS_STATIC + omp_lib_static.F95 +) + +SET(FTN_INTRINSICS_SHARED + omp_lib_static.F95 ) add_flang_library(flang_static ${FTN_INTRINSICS} - ${FTN_SUPPORT} + ${FTN_INTRINSICS_STATIC} + ${FTN_SUPPORT_COMMON} + ${FTN_SUPPORT_STATIC} ${SHARED_SOURCES} ) @@ -501,10 +523,30 @@ else() set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang) endif() +set_target_properties(flang_static PROPERTIES Fortran_MODULE_DIRECTORY ${FLANG_MODULE_DIRECTORY_STATIC}) + +# State the module that the source is producing +set_source_files_properties( + iso_c_bind_static.F95 + PROPERTIES + OBJECT_OUTPUTS ${FLANG_MODULE_DIRECTORY_STATIC}/iso_c_binding.mod + ) + +# State a dependency on the module +set_source_files_properties( + ieee_arithmetic_static.F95 + ieee_exceptions_static.F95 + PROPERTIES + OBJECT_DEPENDS ${FLANG_MODULE_DIRECTORY_STATIC}/iso_c_binding.mod + ) + set(SHARED_LIBRARY TRUE) + add_flang_library(flang_shared ${FTN_INTRINSICS} - ${FTN_SUPPORT} + ${FTN_INTRINSICS_SHARED} + ${FTN_SUPPORT_COMMON} + ${FTN_SUPPORT_SHARED} ${SHARED_SOURCES} ) set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang) @@ -515,6 +557,22 @@ if (NOT MSVC) else() set_target_properties(flang_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) endif() +set_target_properties(flang_shared PROPERTIES Fortran_MODULE_DIRECTORY ${FLANG_MODULE_DIRECTORY_SHARED}) + +# State the module that the source is producing +set_source_files_properties( + iso_c_bind.F95 + PROPERTIES + OBJECT_OUTPUTS ${FLANG_MODULE_DIRECTORY_SHARED}/iso_c_binding.mod + ) + +# State a dependency on the module +set_source_files_properties( + ieee_arithmetic.F95 + ieee_exceptions.F95 + PROPERTIES + OBJECT_DEPENDS ${FLANG_MODULE_DIRECTORY_SHARED}/iso_c_binding.mod + ) set(SHARED_LIBRARY FALSE) @@ -579,25 +637,14 @@ target_include_directories(flang_shared add_dependencies(flang_static flang1 flang2 - ieee_arithmetic ) # Make sure the compiler is built before we bootstrap add_dependencies(flang_shared flang1 flang2 - ieee_arithmetic ) -add_dependencies(iso_c_bind - flang1 - flang2 -) - -add_dependencies(ieee_arithmetic - iso_c_bind -) - if (NOT MSVC) target_compile_options(flang_static PRIVATE -fPIC) target_compile_options(flang_shared PRIVATE -fPIC) From 50ed86e0c9e66ae385ff916a420c7f5dd70ae7a9 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 31 Dec 2017 12:04:20 +0530 Subject: [PATCH 127/141] reduce diff --- runtime/flang/CMakeLists.txt | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 3ab849ddaad..d58460ea0b5 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -206,6 +206,7 @@ SET(FTN_INTRINSICS mod.c mvbits3f.c nargs3f.c + omp_lib.F95 outstr3f.c packtimeqq3f.c perror3f.c @@ -337,8 +338,10 @@ SET(FTN_SUPPORT_COMMON descIntrins.c descFioUtil.c descRW.c + ieee_features.F95 initpar.c inquire.c + iso_fortran_env.f90 ldread.c ldwrite.c linux_dummy.c @@ -474,25 +477,20 @@ SET(FTN_SUPPORT_COMMON xfer_rpm1.c ) -foreach(FTN_FILE ieee_arithmetic ieee_exceptions ieee_features iso_c_bind omp_lib) +foreach(FTN_FILE ieee_arithmetic ieee_exceptions iso_c_bind) configure_file(${FTN_FILE}.F95 ${FTN_FILE}_static.F95 COPYONLY) endforeach() -configure_file(iso_fortran_env.f90 iso_fortran_env_static.f90 COPYONLY) SET(FTN_SUPPORT_SHARED ieee_arithmetic.F95 ieee_exceptions.F95 iso_c_bind.F95 - ieee_features.F95 - iso_fortran_env.f90 ) SET(FTN_SUPPORT_STATIC ieee_arithmetic_static.F95 ieee_exceptions_static.F95 iso_c_bind_static.F95 - ieee_features_static.F95 - iso_fortran_env_static.f90 ) SET(FTN_SUPPORT @@ -501,17 +499,8 @@ SET(FTN_SUPPORT ${FTN_SUPPORT_COMMON} ) -SET(FTN_INTRINSICS_STATIC - omp_lib_static.F95 -) - -SET(FTN_INTRINSICS_SHARED - omp_lib_static.F95 -) - add_flang_library(flang_static ${FTN_INTRINSICS} - ${FTN_INTRINSICS_STATIC} ${FTN_SUPPORT_COMMON} ${FTN_SUPPORT_STATIC} ${SHARED_SOURCES} @@ -544,7 +533,6 @@ set(SHARED_LIBRARY TRUE) add_flang_library(flang_shared ${FTN_INTRINSICS} - ${FTN_INTRINSICS_SHARED} ${FTN_SUPPORT_COMMON} ${FTN_SUPPORT_SHARED} ${SHARED_SOURCES} From 521a5b57eb9d6725ebf9cb4c1f7814548c6a2bd7 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 31 Dec 2017 12:09:03 +0530 Subject: [PATCH 128/141] Fix install failure --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68a451f1f4b..7a172a436c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -367,7 +367,7 @@ set(FLANG_MODULE_DIRECTORY_SHARED ${CMAKE_CURRENT_BINARY_DIR}/include) set(FLANG_MODULE_DIRECTORY_STATIC ${CMAKE_CURRENT_BINARY_DIR}/include-static) # Install Fortran module files -install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ +install(DIRECTORY ${FLANG_MODULE_DIRECTORY_SHARED}/ DESTINATION include ) From 90c64707f9c5f18f5c549dd37dae926323a4e896 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 31 Dec 2017 12:20:23 +0530 Subject: [PATCH 129/141] Add workaround for ninja --- runtime/flang/CMakeLists.txt | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index d58460ea0b5..a743fa860b7 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -514,6 +514,7 @@ endif() set_target_properties(flang_static PROPERTIES Fortran_MODULE_DIRECTORY ${FLANG_MODULE_DIRECTORY_STATIC}) +if (NOT "${CMAKE_GENERATOR}" STREQUAL "Ninja") # State the module that the source is producing set_source_files_properties( iso_c_bind_static.F95 @@ -528,6 +529,25 @@ set_source_files_properties( PROPERTIES OBJECT_DEPENDS ${FLANG_MODULE_DIRECTORY_STATIC}/iso_c_binding.mod ) +else() +add_library(iso_c_bind OBJECT + iso_c_bind.F95 +) +add_library(ieee_arithmetic OBJECT + ieee_arithmetic.F95 + ieee_exceptions.F95 +) +add_dependencies(iso_c_bind + flang1 + flang2 +) +add_dependencies(ieee_arithmetic + iso_c_bind +) +add_dependencies(flang_static + ieee_arithmetic +) +endif() set(SHARED_LIBRARY TRUE) @@ -547,6 +567,7 @@ else() endif() set_target_properties(flang_shared PROPERTIES Fortran_MODULE_DIRECTORY ${FLANG_MODULE_DIRECTORY_SHARED}) +if (NOT "${CMAKE_GENERATOR}" STREQUAL "Ninja") # State the module that the source is producing set_source_files_properties( iso_c_bind.F95 @@ -561,7 +582,11 @@ set_source_files_properties( PROPERTIES OBJECT_DEPENDS ${FLANG_MODULE_DIRECTORY_SHARED}/iso_c_binding.mod ) - +else() +add_dependencies(flang_shared + ieee_arithmetic +) +endif() set(SHARED_LIBRARY FALSE) set_property( From 12859cfed759b7d5021da9246f67a17693c6f2e4 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 31 Dec 2017 12:33:56 -0600 Subject: [PATCH 130/141] Fix incorrect rounding behavior --- runtime/flangrti/around.c | 5 ++--- runtime/flangrti/dround.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/runtime/flangrti/around.c b/runtime/flangrti/around.c index 9d9e419aacd..39c08862476 100644 --- a/runtime/flangrti/around.c +++ b/runtime/flangrti/around.c @@ -16,11 +16,10 @@ */ #include "mthdecls.h" - -extern float roundf(float); +#include float __mth_i_around(float x) { - return roundf(x); + return rintf(x); } diff --git a/runtime/flangrti/dround.c b/runtime/flangrti/dround.c index 57745f16f95..46172c6dcfb 100644 --- a/runtime/flangrti/dround.c +++ b/runtime/flangrti/dround.c @@ -16,11 +16,10 @@ */ #include "mthdecls.h" - -extern double round(double); +#include double __mth_i_dround(double x) { - return round(x); + return rint(x); } From 1070803581f5c207716992b3158caa087697ace9 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 31 Dec 2017 12:37:29 -0600 Subject: [PATCH 131/141] Remove unnedded functions --- runtime/flangrti/fltmanip.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/runtime/flangrti/fltmanip.c b/runtime/flangrti/fltmanip.c index 94319e0bac0..2bbb9340ae7 100644 --- a/runtime/flangrti/fltmanip.c +++ b/runtime/flangrti/fltmanip.c @@ -359,16 +359,6 @@ nearbyintf(float x) return __nearbyintf(x); } double -rint(double x) -{ - return __nearbyint(x); -} -float -rintf(float x) -{ - return __nearbyintf(x); -} -double remainder(double x, double y) { return __remainder(x, y); From 09072d999497996f1e1078d2934747f530a01a43 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 31 Dec 2017 16:26:01 -0600 Subject: [PATCH 132/141] Revert "Revert "CMake: Cleanup depedency issues"" --- CMakeLists.txt | 7 +-- runtime/flang/CMakeLists.txt | 93 +++++++----------------------------- 2 files changed, 19 insertions(+), 81 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a172a436c2..964e54a2fbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -361,13 +361,10 @@ include_directories(BEFORE ) # Direct module files to build include directory -set(FLANG_MODULE_DIRECTORY_SHARED ${CMAKE_CURRENT_BINARY_DIR}/include) -# mod files in the following differs only by the timestamp. This is needed to -# ensure that flang can be built parallelly. It is discarded after flang is built -set(FLANG_MODULE_DIRECTORY_STATIC ${CMAKE_CURRENT_BINARY_DIR}/include-static) +set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include) # Install Fortran module files -install(DIRECTORY ${FLANG_MODULE_DIRECTORY_SHARED}/ +install(DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}/ DESTINATION include ) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index a743fa860b7..373f376f91d 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -273,7 +273,7 @@ SET(FTN_INTRINSICS wait3f.c ) -SET(FTN_SUPPORT_COMMON +SET(FTN_SUPPORT bcopy.c bcopys.c buffer.c @@ -475,34 +475,14 @@ SET(FTN_SUPPORT_COMMON xfer.c init.c xfer_rpm1.c - ) - -foreach(FTN_FILE ieee_arithmetic ieee_exceptions iso_c_bind) - configure_file(${FTN_FILE}.F95 ${FTN_FILE}_static.F95 COPYONLY) -endforeach() - -SET(FTN_SUPPORT_SHARED ieee_arithmetic.F95 ieee_exceptions.F95 iso_c_bind.F95 -) - -SET(FTN_SUPPORT_STATIC - ieee_arithmetic_static.F95 - ieee_exceptions_static.F95 - iso_c_bind_static.F95 -) - -SET(FTN_SUPPORT - ${FTN_SUPPORT_STATIC} - ${FTN_SUPPORT_SHARED} - ${FTN_SUPPORT_COMMON} -) + ) add_flang_library(flang_static ${FTN_INTRINSICS} - ${FTN_SUPPORT_COMMON} - ${FTN_SUPPORT_STATIC} + ${FTN_SUPPORT} ${SHARED_SOURCES} ) @@ -512,81 +492,33 @@ else() set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang) endif() -set_target_properties(flang_static PROPERTIES Fortran_MODULE_DIRECTORY ${FLANG_MODULE_DIRECTORY_STATIC}) - -if (NOT "${CMAKE_GENERATOR}" STREQUAL "Ninja") -# State the module that the source is producing -set_source_files_properties( - iso_c_bind_static.F95 - PROPERTIES - OBJECT_OUTPUTS ${FLANG_MODULE_DIRECTORY_STATIC}/iso_c_binding.mod - ) - -# State a dependency on the module -set_source_files_properties( - ieee_arithmetic_static.F95 - ieee_exceptions_static.F95 - PROPERTIES - OBJECT_DEPENDS ${FLANG_MODULE_DIRECTORY_STATIC}/iso_c_binding.mod - ) -else() add_library(iso_c_bind OBJECT iso_c_bind.F95 ) + add_library(ieee_arithmetic OBJECT ieee_arithmetic.F95 ieee_exceptions.F95 ) -add_dependencies(iso_c_bind - flang1 - flang2 -) -add_dependencies(ieee_arithmetic - iso_c_bind -) -add_dependencies(flang_static - ieee_arithmetic -) -endif() set(SHARED_LIBRARY TRUE) add_flang_library(flang_shared ${FTN_INTRINSICS} - ${FTN_SUPPORT_COMMON} - ${FTN_SUPPORT_SHARED} + ${FTN_SUPPORT} ${SHARED_SOURCES} ) + set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang) target_link_libraries(flang_shared flangrti_shared) + # Resolve symbols against libm and librt if (NOT MSVC) target_link_libraries(flang_shared rt m) else() set_target_properties(flang_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) endif() -set_target_properties(flang_shared PROPERTIES Fortran_MODULE_DIRECTORY ${FLANG_MODULE_DIRECTORY_SHARED}) -if (NOT "${CMAKE_GENERATOR}" STREQUAL "Ninja") -# State the module that the source is producing -set_source_files_properties( - iso_c_bind.F95 - PROPERTIES - OBJECT_OUTPUTS ${FLANG_MODULE_DIRECTORY_SHARED}/iso_c_binding.mod - ) - -# State a dependency on the module -set_source_files_properties( - ieee_arithmetic.F95 - ieee_exceptions.F95 - PROPERTIES - OBJECT_DEPENDS ${FLANG_MODULE_DIRECTORY_SHARED}/iso_c_binding.mod - ) -else() -add_dependencies(flang_shared - ieee_arithmetic -) -endif() set(SHARED_LIBRARY FALSE) set_property( @@ -650,13 +582,22 @@ target_include_directories(flang_shared add_dependencies(flang_static flang1 flang2 + ieee_arithmetic ) # Make sure the compiler is built before we bootstrap add_dependencies(flang_shared + flang_static + ) + +add_dependencies(iso_c_bind flang1 flang2 - ) +) + +add_dependencies(ieee_arithmetic + iso_c_bind +) if (NOT MSVC) target_compile_options(flang_static PRIVATE -fPIC) From 3595879d3ab0538fe9f1508f784c27cb693aefd1 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 31 Dec 2017 16:29:17 -0600 Subject: [PATCH 133/141] CMake: set fortran module directory for static --- runtime/flang/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 373f376f91d..faac74c63f0 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -486,6 +486,11 @@ add_flang_library(flang_static ${SHARED_SOURCES} ) +set_target_properties(flang_static + PROPERTIES + Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include-static +) + if (MSVC) set_property(TARGET flang_static PROPERTY OUTPUT_NAME libflang) else() From 3d45b53ba37519e518addd71b09ef84553dbe202 Mon Sep 17 00:00:00 2001 From: xoviat Date: Sun, 31 Dec 2017 16:30:53 -0600 Subject: [PATCH 134/141] CMake: remove library dependency --- runtime/flang/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index faac74c63f0..302e8b128bd 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -592,7 +592,9 @@ add_dependencies(flang_static # Make sure the compiler is built before we bootstrap add_dependencies(flang_shared - flang_static + flang1 + flang2 + ieee_arithmetic ) add_dependencies(iso_c_bind From 05134c845966cce47bf5c988ede2b583ce0ce9c5 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Mon, 1 Jan 2018 11:11:19 +0530 Subject: [PATCH 135/141] Fix warnings --- runtime/flang/global.h | 6 +----- runtime/flang/rename3f.c | 1 - runtime/flangrti/round.c | 3 +-- runtime/include/stdioInterf.h | 5 ----- 4 files changed, 2 insertions(+), 13 deletions(-) diff --git a/runtime/flang/global.h b/runtime/flang/global.h index 3c875382584..3ca2a545dad 100644 --- a/runtime/flang/global.h +++ b/runtime/flang/global.h @@ -19,6 +19,7 @@ * \brief Global definitions and declarations for Fortran I/O library */ +#include "stdio.h" #include "fioMacros.h" #include "stdioInterf.h" /* stubbed version of stdio.h */ #include "cnfg.h" /* declarations for configuration items */ @@ -51,11 +52,6 @@ typedef unsigned short WCHAR; #define VOID void -WIN_MSVCRT_IMP char *WIN_CDECL getenv(const char *); -WIN_MSVCRT_IMP long WIN_CDECL strtol(const char *, char **, int); -WIN_MSVCRT_IMP char *WIN_CDECL strerror(int); -WIN_MSVCRT_IMP char *WIN_CDECL strstr(const char *, const char *); - typedef __INT_T INT; /* native integer at least 32 bits */ typedef unsigned int UINT; /* unsigned 32 bit native integer */ #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') diff --git a/runtime/flang/rename3f.c b/runtime/flang/rename3f.c index dbedff0c429..9cd0cc460c3 100644 --- a/runtime/flang/rename3f.c +++ b/runtime/flang/rename3f.c @@ -23,7 +23,6 @@ #include "io3f.h" #include "ent3f.h" -extern int rename(); extern char *__fstr2cstr(); extern void __cstr_free(); diff --git a/runtime/flangrti/round.c b/runtime/flangrti/round.c index 23f9021c0b1..8a590ce0ff7 100644 --- a/runtime/flangrti/round.c +++ b/runtime/flangrti/round.c @@ -16,8 +16,7 @@ */ #include "mthdecls.h" - -extern float roundf(float); +#include "math.h" float __mth_i_round(float x) diff --git a/runtime/include/stdioInterf.h b/runtime/include/stdioInterf.h index ab7226ad6ae..fffba15c6fd 100644 --- a/runtime/include/stdioInterf.h +++ b/runtime/include/stdioInterf.h @@ -114,11 +114,6 @@ int __io_feof(FILE *); int __io_ferror(FILE *); size_t __io_fwrite(const void *, size_t, size_t, FILE *); int __io_timezone(void *); -int fclose(FILE *); -int fflush(FILE *); -int __io_fputc(int, FILE *); -FILE *tmpfile(void); -char *tmpnam(char *); char *__io_tempnam(const char *, const char *); extern void *__aligned_malloc(size_t, size_t); /* pgmemalign.c */ From e31520707af53e605a4b95fff6b4f9845738ffb8 Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 1 Jan 2018 00:29:58 -0600 Subject: [PATCH 136/141] CMake: fix build race condition --- runtime/flang/CMakeLists.txt | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 302e8b128bd..0f20486d856 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -475,15 +475,23 @@ SET(FTN_SUPPORT xfer.c init.c xfer_rpm1.c + ) + +add_library(iso_c_bind OBJECT + iso_c_bind.F95 +) + +add_library(ieee_arithmetic OBJECT ieee_arithmetic.F95 ieee_exceptions.F95 - iso_c_bind.F95 - ) +) add_flang_library(flang_static ${FTN_INTRINSICS} ${FTN_SUPPORT} ${SHARED_SOURCES} + $ + $ ) set_target_properties(flang_static @@ -497,21 +505,14 @@ else() set_property(TARGET flang_static PROPERTY OUTPUT_NAME flang) endif() -add_library(iso_c_bind OBJECT - iso_c_bind.F95 -) - -add_library(ieee_arithmetic OBJECT - ieee_arithmetic.F95 - ieee_exceptions.F95 -) - set(SHARED_LIBRARY TRUE) add_flang_library(flang_shared ${FTN_INTRINSICS} ${FTN_SUPPORT} ${SHARED_SOURCES} + $ + $ ) set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang) @@ -587,14 +588,12 @@ target_include_directories(flang_shared add_dependencies(flang_static flang1 flang2 - ieee_arithmetic ) # Make sure the compiler is built before we bootstrap add_dependencies(flang_shared flang1 flang2 - ieee_arithmetic ) add_dependencies(iso_c_bind From 371f751df83ac2439f3a41ea4dea943b2ce7ac5b Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 1 Jan 2018 11:05:19 -0600 Subject: [PATCH 137/141] CMake: fix race conditions --- runtime/flang/CMakeLists.txt | 41 +++++++++++++++++------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 0f20486d856..e145e49aa5a 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -338,9 +338,12 @@ SET(FTN_SUPPORT descIntrins.c descFioUtil.c descRW.c + ieee_arithmetic.F95 + ieee_exceptions.F95 ieee_features.F95 initpar.c inquire.c + iso_c_bind.F95 iso_fortran_env.f90 ldread.c ldwrite.c @@ -477,21 +480,10 @@ SET(FTN_SUPPORT xfer_rpm1.c ) -add_library(iso_c_bind OBJECT - iso_c_bind.F95 -) - -add_library(ieee_arithmetic OBJECT - ieee_arithmetic.F95 - ieee_exceptions.F95 -) - add_flang_library(flang_static ${FTN_INTRINSICS} ${FTN_SUPPORT} ${SHARED_SOURCES} - $ - $ ) set_target_properties(flang_static @@ -511,8 +503,6 @@ add_flang_library(flang_shared ${FTN_INTRINSICS} ${FTN_SUPPORT} ${SHARED_SOURCES} - $ - $ ) set_property(TARGET flang_shared PROPERTY OUTPUT_NAME flang) @@ -566,6 +556,22 @@ set_property( ## CMake does not handle module dependencies between Fortran files, ## we need to help it +if( NOT ${CMAKE_GENERATOR} STREQUAL "Ninja") + # State the module that the source is producing + set_source_files_properties( + iso_c_bind.F95 + PROPERTIES + OBJECT_OUTPUTS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod + ) + + # State a dependency on the module + set_source_files_properties( + ieee_arithmetic.F95 + ieee_exceptions.F95 + PROPERTIES + OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod + ) +endif() set_target_properties(flang_static flang_shared PROPERTIES @@ -596,15 +602,6 @@ add_dependencies(flang_shared flang2 ) -add_dependencies(iso_c_bind - flang1 - flang2 -) - -add_dependencies(ieee_arithmetic - iso_c_bind -) - if (NOT MSVC) target_compile_options(flang_static PRIVATE -fPIC) target_compile_options(flang_shared PRIVATE -fPIC) From 0073abeeacf84963dd71281bf8912f3bc833a737 Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 1 Jan 2018 12:28:16 -0600 Subject: [PATCH 138/141] Add "use" statements to require modules The CMake Ninja generator requires the "use" statement to declare dependnecies rather than the "use, instrinsic" statement. Since we're bootsrapping, the "intrinsic" makes no functional difference and leads to race conditions. --- runtime/flang/ieee_arithmetic.F95 | 2 +- runtime/flang/ieee_exceptions.F95 | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/flang/ieee_arithmetic.F95 b/runtime/flang/ieee_arithmetic.F95 index 1518b5be7e1..38f690fda3d 100644 --- a/runtime/flang/ieee_arithmetic.F95 +++ b/runtime/flang/ieee_arithmetic.F95 @@ -23,7 +23,7 @@ module IEEE_ARITHMETIC use ieee_exceptions - use, intrinsic :: iso_c_binding + use iso_c_binding #ifdef PGDLL !DEC$ ATTRIBUTES DLLEXPORT :: IEEE_ARITHMETIC #endif diff --git a/runtime/flang/ieee_exceptions.F95 b/runtime/flang/ieee_exceptions.F95 index 827aa0b1e87..5240a564694 100644 --- a/runtime/flang/ieee_exceptions.F95 +++ b/runtime/flang/ieee_exceptions.F95 @@ -21,6 +21,8 @@ #endif module IEEE_EXCEPTIONS + + use iso_c_binding #ifdef PGDLL !DEC$ ATTRIBUTES DLLEXPORT :: IEEE_EXCEPTIONS #endif From a5cac1fa89212d71dfde7d3aa1d88b4873aa6971 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 11 Jan 2018 19:28:03 -0600 Subject: [PATCH 139/141] CMake handles module dependencies now that flang -E works --- runtime/flang/CMakeLists.txt | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index 7332c045c2d..e7ffd43b487 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -552,26 +552,6 @@ set_property( PG_PIC ) -## CMake does not handle module dependencies between Fortran files, -## we need to help it - -if( NOT ${CMAKE_GENERATOR} STREQUAL "Ninja") - # State the module that the source is producing - set_source_files_properties( - iso_c_bind.F95 - PROPERTIES - OBJECT_OUTPUTS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod - ) - - # State a dependency on the module - set_source_files_properties( - ieee_arithmetic.F95 - ieee_exceptions.F95 - PROPERTIES - OBJECT_DEPENDS ${CMAKE_Fortran_MODULE_DIRECTORY}/iso_c_binding.mod - ) -endif() - set_target_properties(flang_static flang_shared PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${FLANG_RTE_LIB_DIR} From d2ba3c4fc6e167e4b79a6e643c61f18fcc4363a2 Mon Sep 17 00:00:00 2001 From: xoviat Date: Tue, 30 Jan 2018 16:37:49 -0600 Subject: [PATCH 140/141] Appveyor: cache packages --- .appveyor.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index f3b5424e037..fd2cde105b5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -9,6 +9,9 @@ environment: CONDA_INSTALL_LOCN: C:\\Miniconda36-x64 APPVEYOR_SAVE_CACHE_ON_FAILURE: true +cache: + - '%CONDA_INSTALL_LOCN%\pkgs' + os: Visual Studio 2017 platform: @@ -20,7 +23,7 @@ install: # Add our channels. - cmd: conda config --add channels defaults - cmd: conda config --add channels conda-forge - - cmd: conda install --yes --quiet llvmdev clangdev flang-meta cmake + - cmd: conda install --yes llvmdev clangdev flang-meta cmake - cmd: conda install --yes -c isuruf kitware-ninja From ccc150277be86141955cc299e6c3b491b962bdc9 Mon Sep 17 00:00:00 2001 From: xoviat Date: Tue, 30 Jan 2018 16:53:31 -0600 Subject: [PATCH 141/141] Trigger build --- LICENSE.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/LICENSE.txt b/LICENSE.txt index 5b03bfcdb16..b0b14418012 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -12,3 +12,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. +