diff --git a/lib/scutil/int128.c b/lib/scutil/int128.c index 782d6454e5c..4e566614df2 100644 --- a/lib/scutil/int128.c +++ b/lib/scutil/int128.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,11 +85,11 @@ int int128_count_leading_zeros(const int128_t *x) { int128_t v = *x; + int128_t mask = 1; + mask <<= 127; int j; - if (v == 0) - return 128; - for (j = 0; v > 0; ++j) { - v += v; + for(j = 0; j < 128 && 0 == (mask & v); j++) { + mask >>= 1; } return j; } diff --git a/runtime/libpgmath/lib/x86_64/x86id.h b/runtime/libpgmath/lib/x86_64/x86id.h index d21944de9b2..a8dee684b69 100644 --- a/runtime/libpgmath/lib/x86_64/x86id.h +++ b/runtime/libpgmath/lib/x86_64/x86id.h @@ -59,4 +59,8 @@ extern int X86IDFN(is_x86_64)(void); /* return 0 or 1 */ extern int X86IDFN(get_cachesize)(void); extern char *X86IDFN(get_processor_name)(void); +#if !defined(FOR_LIBPGC) +extern int get_cores(void); +#endif + #endif /* X86ID_H_ */ diff --git a/tools/flang1/flang1exe/lowersym.c b/tools/flang1/flang1exe/lowersym.c index 93ebf83a6ca..f4047c01aa7 100644 --- a/tools/flang1/flang1exe/lowersym.c +++ b/tools/flang1/flang1exe/lowersym.c @@ -4677,9 +4677,19 @@ lower_symbols(void) } } } else if (!VISITG(sptr) && CLASSG(sptr) && DESCARRAYG(sptr) && - STYPEG(sptr) == ST_DESCRIPTOR /*&& FINALG(sptr)*/) { - if (PARENTG(sptr)) { - /* FS#21658: Only perform this if PARENT is set */ + STYPEG(sptr) == ST_DESCRIPTOR) { + SPTR scope = SCOPEG(sptr); + bool is_interface = ( (STYPEG(scope) == ST_PROC || + STYPEG(scope) == ST_ENTRY) && + IS_INTERFACEG(scope) ); + if (PARENTG(sptr) && !is_interface) { + /* Only perform this if PARENT is set. Also do not create type + * descriptors for derived types defined inside interfaces. When + * derived types are defined inside interfaces, type descriptors are + * not needed because there is no executable code inside an interface. + * Furthermore, if we generate them, we might get multiple definitions + * of the same type descriptor. + */ lower_put_datatype_stb(DTYPEG(sptr)); VISITP(sptr, 1); lower_symbol_stb(sptr); diff --git a/tools/flang1/flang1exe/semant.c b/tools/flang1/flang1exe/semant.c index d1debe381cf..75764869049 100644 --- a/tools/flang1/flang1exe/semant.c +++ b/tools/flang1/flang1exe/semant.c @@ -2455,7 +2455,7 @@ semant1(int rednum, SST *top) */ INTERNALP(sptr, 0); } - + IS_INTERFACEP(sptr, sem.interface); break; /* ------------------------------------------------------------------ */ @@ -13058,26 +13058,12 @@ process_bind(int sptr) np = stb.n_base + CONVAL1G(bind_attr.altname); if (!*np) return; -#if defined(TARGET_OSX) - /* Win32 and OSX needs altname with underbar for bind only, to - match C routines. Do not depend on processing in - assem.c : we can not tell that this came specifically - from a bind statement - */ - w32_name = (char *)getitem(0, strlen(SYMNAME(bind_attr.altname)) + 1); - w32_name[0] = '_'; - strcpy(&(w32_name[1]), np); - - wsptr = getstring(w32_name, strlen(w32_name)); - ALTNAMEP(sptr, wsptr); -#else ALTNAMEP(sptr, bind_attr.altname); -#endif break; case DA_C: #if defined(TARGET_OSX) - /* add underscore to win32 common block names */ + /* add underscore to OSX common block names */ if (STYPEG(sptr) == ST_CMBLK) need_altname = 1; #endif @@ -13094,22 +13080,8 @@ process_bind(int sptr) } /* end for */ if ((need_altname) && ALTNAMEG(sptr) == 0) { -#if defined(TARGET_OSX) - - /* Win32 needs altname with underbar for bind only, to - match C routines. Do not depend on processing in - assem.c : we can not tell that this came specifically - from a bind statement - */ - w32_name = (char *)getitem(0, strlen(SYMNAME(sptr)) + 1); - w32_name[0] = '_'; - strcpy(&w32_name[1], SYMNAME(sptr)); - wsptr = getstring(w32_name, strlen(w32_name)); - ALTNAMEP(sptr, wsptr); -#else /* set default altname, so that no underbar gets added */ ALTNAMEP(sptr, getstring(SYMNAME(sptr), strlen(SYMNAME(sptr)))); -#endif } } /* process_bind */ diff --git a/tools/flang1/flang1exe/semutil2.c b/tools/flang1/flang1exe/semutil2.c index 5c9bbfc0088..bc5efea72c3 100644 --- a/tools/flang1/flang1exe/semutil2.c +++ b/tools/flang1/flang1exe/semutil2.c @@ -4979,8 +4979,10 @@ make_structkwd_str(DTYPE dtype, int *num_of_member, int *is_extend) NEW(kwd_str, char, size); *kwd_str = '\0'; member_sptr = DTY(dtype + 1); - + ptr_sptr = member_sptr; for (; member_sptr > NOSYM; member_sptr = SYMLKG(member_sptr)) { + if (POINTERG(member_sptr)) + ptr_sptr = member_sptr; if (is_tbp_or_final(member_sptr)) { possible_ext = 0; continue; /* skip tbp */ @@ -5196,9 +5198,8 @@ all_default_init(DTYPE dtype) thissptr = DTY(dtype + 1); for (mem = DTY(dtype + 1); mem > NOSYM; mem = SYMLKG(mem)) { - if (SCG(mem) == SC_BASED) { + if (POINTERG(mem)) thissptr = mem; - } myparent = PARENTG(thissptr); if (myparent && myparent == PARENTG(mem) && possible_ext && DTY(DTYPEG(mem)) == TY_DERIVED) { @@ -5279,6 +5280,7 @@ get_exttype_default(DTYPE dtype, int pos) if (pos >= DTC_DT_CNT) return pos; + ptr_sptr = member_sptr; for (; member_sptr > NOSYM; member_sptr = SYMLKG(member_sptr)) { if (no_data_components(DTYPEG(member_sptr))) { possible_ext = 0; @@ -5288,6 +5290,8 @@ get_exttype_default(DTYPE dtype, int pos) possible_ext = 0; continue; } + if (POINTERG(member_sptr)) + ptr_sptr = member_sptr; if (ptr_sptr && (member_sptr == MIDNUMG(ptr_sptr) || member_sptr == PTROFFG(ptr_sptr) || member_sptr == SDSCG(ptr_sptr) || @@ -5638,6 +5642,7 @@ get_exttype_struct_constructor(ACL *in_aclp, DTYPE dtype, ACL **prev_aclp) #endif member_sptr = DTY(dtype + 1); + ptr_sptr = member_sptr; if (member_sptr == 0) { error(155, 3, gbl.lineno, "Use of derived type name before definition:", SYMNAME(DTY(dtype + 3))); @@ -5654,6 +5659,8 @@ get_exttype_struct_constructor(ACL *in_aclp, DTYPE dtype, ACL **prev_aclp) continue; /* skip tbp */ } + if (POINTERG(member_sptr)) + ptr_sptr = member_sptr; if (ptr_sptr && (member_sptr == MIDNUMG(ptr_sptr) || member_sptr == PTROFFG(ptr_sptr) || member_sptr == SDSCG(ptr_sptr) || @@ -5775,6 +5782,7 @@ chk_struct_constructor(ACL *in_aclp) dtype = aclp->dtype; aclp = aclp->subc; /* go down to member list */ member_sptr = DTY(dtype + 1); + ptr_sptr = member_sptr; if (member_sptr == 0) { error(155, 3, gbl.lineno, "Use of derived type name before definition:", SYMNAME(DTY(dtype + 3))); @@ -5792,6 +5800,8 @@ chk_struct_constructor(ACL *in_aclp) cnt = 0; prev_aclp = NULL; for (; member_sptr != NOSYM; member_sptr = SYMLKG(member_sptr)) { + if (POINTERG(member_sptr)) + ptr_sptr = member_sptr; if (no_data_components(DTYPEG(member_sptr))) continue; if (is_tbp_or_final(member_sptr)) diff --git a/tools/flang1/utils/symtab/sharedefs.h b/tools/flang1/utils/symtab/sharedefs.h index 410a21ec68a..759b28137f6 100644 --- a/tools/flang1/utils/symtab/sharedefs.h +++ b/tools/flang1/utils/symtab/sharedefs.h @@ -28,6 +28,7 @@ * i = STG_NEXT_SIZE(name, size) - return next available index, allocate size * i = STG_NEXT_FREELIST(name) - return index from free list * STG_NEED(name) - test avail vs size, realloc if needed + * STG_RETURN(name) - return lastest added element * STG_ADD_FREELIST(name, i) - add to free list * STG_ALLOC_SIDECAR(basename, name, datatype) * allocate name the same size as basename @@ -98,6 +99,8 @@ int stg_next(STG *stg, int n); /* allocate 'size' elements at stg_avail */ #define STG_NEXT_SIZE(name, size) stg_next((STG *)&name.stg_base, size) +/* + /* check that stg_avail does not overflow stg_size */ void stg_need(STG *stg); #define STG_NEED(name) stg_need((STG *)&name.stg_base) @@ -111,6 +114,11 @@ void stg_set_freelink(STG *stg, int offset); int stg_next_freelist(STG *stg); #define STG_NEXT_FREELIST(name) stg_next_freelist((STG *)&name.stg_base) +/* return latest added field */ +void stg_return(STG *stg); +#define STG_RETURN(name) \ + stg_return((STG *)&name.stg_base) + /* put this element on the free list */ void stg_add_freelist(STG *stg, int r); #define STG_ADD_FREELIST(name, index) \ diff --git a/tools/flang1/utils/symtab/symtab.n b/tools/flang1/utils/symtab/symtab.n index ea0b9045b9f..1828197cfd8 100644 --- a/tools/flang1/utils/symtab/symtab.n +++ b/tools/flang1/utils/symtab/symtab.n @@ -1395,6 +1395,8 @@ name list group. .lp .ul Flags +.FL IS_INTERFACE f89 +Set if the entry symbol is in an interface block. .FL DCLD Set if currently processing a function subprogram and the data type of this entry has been explicitly declared. @@ -1560,6 +1562,8 @@ for this symbol. .lp .ul Flags +.FL IS_INTERFACE +Set if the procedure symbol is in an interface block. .FL IS_PROC_DUMMY f109 This flag is set if this ST_PROC is used as a procedure dummy argument. .FL CLASS f42 diff --git a/tools/flang2/utils/symtab/sharedefs.h b/tools/flang2/utils/symtab/sharedefs.h index 410a21ec68a..759b28137f6 100644 --- a/tools/flang2/utils/symtab/sharedefs.h +++ b/tools/flang2/utils/symtab/sharedefs.h @@ -28,6 +28,7 @@ * i = STG_NEXT_SIZE(name, size) - return next available index, allocate size * i = STG_NEXT_FREELIST(name) - return index from free list * STG_NEED(name) - test avail vs size, realloc if needed + * STG_RETURN(name) - return lastest added element * STG_ADD_FREELIST(name, i) - add to free list * STG_ALLOC_SIDECAR(basename, name, datatype) * allocate name the same size as basename @@ -98,6 +99,8 @@ int stg_next(STG *stg, int n); /* allocate 'size' elements at stg_avail */ #define STG_NEXT_SIZE(name, size) stg_next((STG *)&name.stg_base, size) +/* + /* check that stg_avail does not overflow stg_size */ void stg_need(STG *stg); #define STG_NEED(name) stg_need((STG *)&name.stg_base) @@ -111,6 +114,11 @@ void stg_set_freelink(STG *stg, int offset); int stg_next_freelist(STG *stg); #define STG_NEXT_FREELIST(name) stg_next_freelist((STG *)&name.stg_base) +/* return latest added field */ +void stg_return(STG *stg); +#define STG_RETURN(name) \ + stg_return((STG *)&name.stg_base) + /* put this element on the free list */ void stg_add_freelist(STG *stg, int r); #define STG_ADD_FREELIST(name, index) \ diff --git a/tools/shared/miscutil.c b/tools/shared/miscutil.c index 5e08b4b8b52..cd2a8f0a3a8 100644 --- a/tools/shared/miscutil.c +++ b/tools/shared/miscutil.c @@ -347,7 +347,7 @@ int stg_next(STG *stg, int n) { STG *thisstg; - int r = stg->stg_avail; + unsigned int r = stg->stg_avail; if (n == 0) return 0; if (n < 0) { @@ -422,6 +422,24 @@ stg_next_freelist(STG *stg) return r; } /* stg_next_freelist */ +/* + * return latest entry (from stg_next) + */ +void +stg_return(STG *stg) +{ + STG *thisstg; + unsigned int r = stg->stg_avail - 1; + stg->stg_avail = r; + if (stg->stg_cleared > r) + stg->stg_cleared = r; + for (thisstg = (STG *)stg->stg_sidecar; thisstg; + thisstg = (STG *)thisstg->stg_sidecar) { + thisstg->stg_avail = stg->stg_avail; + thisstg->stg_cleared = stg->stg_cleared; + } +} /* stg_return */ + /* * add element to the free list * store the link to the next free element at 'word 0' diff --git a/tools/shared/sharedefs.h b/tools/shared/sharedefs.h index 410a21ec68a..759b28137f6 100644 --- a/tools/shared/sharedefs.h +++ b/tools/shared/sharedefs.h @@ -28,6 +28,7 @@ * i = STG_NEXT_SIZE(name, size) - return next available index, allocate size * i = STG_NEXT_FREELIST(name) - return index from free list * STG_NEED(name) - test avail vs size, realloc if needed + * STG_RETURN(name) - return lastest added element * STG_ADD_FREELIST(name, i) - add to free list * STG_ALLOC_SIDECAR(basename, name, datatype) * allocate name the same size as basename @@ -98,6 +99,8 @@ int stg_next(STG *stg, int n); /* allocate 'size' elements at stg_avail */ #define STG_NEXT_SIZE(name, size) stg_next((STG *)&name.stg_base, size) +/* + /* check that stg_avail does not overflow stg_size */ void stg_need(STG *stg); #define STG_NEED(name) stg_need((STG *)&name.stg_base) @@ -111,6 +114,11 @@ void stg_set_freelink(STG *stg, int offset); int stg_next_freelist(STG *stg); #define STG_NEXT_FREELIST(name) stg_next_freelist((STG *)&name.stg_base) +/* return latest added field */ +void stg_return(STG *stg); +#define STG_RETURN(name) \ + stg_return((STG *)&name.stg_base) + /* put this element on the free list */ void stg_add_freelist(STG *stg, int r); #define STG_ADD_FREELIST(name, index) \