Re: [Patch][LTO] Set proper DECL_ALIGN in offload_handle_link_vars (PR94233)

2020-03-21 Thread Richard Biener
On March 20, 2020 10:10:54 PM GMT+01:00, Tobias Burnus 
 wrote:
>When compiling the existing libgomp.c/target-link-1.c with -O3, the
>test case was ICEing as DECL_ALIGN was 1 (alias "1U << 0").
>
>The reason is that "make_node (VAR_DECL)" calls "SET_DECL_ALIGN (t, 1)"
>and unless one overrides this, it stays like that. Here, it later
>failed by violating the assert that "align % BITS_PER_UNIT == 0" as
>1 % 8 != 0
>
>I don't know why this only fails with -O3. (For Nvidia, this
>test case is disabled. I don't know why or whether it work(s/ed)
>with Intel MIC or HSA.)
>
>I am not sure what to do about the testcase; it is currently is
>run with -O2 – which did not trigger this ICE. I could add
>'{ dg-do run }', but this does not make a difference. I could add
>'{ dg-additional-options "-O3" }' – if that makes sense.
>Better ideas?
>
>OK for the trunk?

It should be TYPE_ALIGN (type). OK with that change. Note this fails to honor 
target bits so it might be better to lay out the decl properly? 

>Tobias
>
>Side notes:
>
>* The modified code is protected by "#ifdef ACCEL_COMPILER".
>* The function was added 2015-12-15; I assume that nothing but
>GCN uses it (as Nvidia PTX does not work); hence, I do not see a
>reason for backporting.
>
>* Independent of that patch, it still fails at run time with
>   "libgomp: Cannot map target variables (size mismatch)"
>   My feeling is that the following bit flip of omp-offload.c's
>   add_decls_addresses_to_decl_constructor
>   is not handled in libgomp/target.c:
>   if (!is_link_var)
>   else
>   isize |= 1ULL << (int_size_in_bytes (const_ptr_type_node)
>
>-
>Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München /
>Germany
>Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung,
>Alexander Walter



[commited][PATCH] Fix comma at end of enumerator list seen with -std=c++98.

2020-03-21 Thread Martin Liška

Hi.

The following patch fixes many warnings seen with -std=c++98:

include/plugin-api.h:144:16: warning: comma at end of enumerator list 
[-Wpedantic]

Installed as obvious.

Martin

include/ChangeLog:

2020-03-21  Martin Liska  

* plugin-api.h (enum ld_plugin_symbol_type): Remove
comma after last value of an enum.
---
 include/plugin-api.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/include/plugin-api.h b/include/plugin-api.h
index f0f9667bf3b..673f136ce68 100644
--- a/include/plugin-api.h
+++ b/include/plugin-api.h
@@ -141,7 +141,7 @@ enum ld_plugin_symbol_type
 {
   LDST_UNKNOWN,
   LDST_FUNCTION,
-  LDST_VARIABLE,
+  LDST_VARIABLE
 };
 
 enum ld_plugin_symbol_section_kind



[PATCH] c: Fix up cfun->function_end_locus on invalid function bodies [PR94239]

2020-03-21 Thread Jakub Jelinek via Gcc-patches
Hi!

On Thu, Mar 19, 2020 at 09:38:30PM +, Joseph Myers wrote:
> The second patch is OK.

Unfortunately the patch broke
+FAIL: gcc.dg/pr20245-1.c (internal compiler error)
+FAIL: gcc.dg/pr20245-1.c (test for excess errors)
+FAIL: gcc.dg/pr28419.c (internal compiler error)
+FAIL: gcc.dg/pr28419.c (test for excess errors)
on some targets (and under valgrind on the rest of them).

Those functions don't have the opening { and so c_parser_compound_statement
returned error_mark_node before initializing *endlocp.
So, either we can initialize it in that case too:
--- gcc/c/c-parser.c2020-03-20 22:09:39.659411721 +0100
+++ gcc/c/c-parser.c2020-03-21 09:36:44.455705261 +0100
@@ -5611,6 +5611,8 @@ c_parser_compound_statement (c_parser *p
 if we have just prepared to enter a function body.  */
   stmt = c_begin_compound_stmt (true);
   c_end_compound_stmt (brace_loc, stmt, true);
+  if (endlocp)
+   *endlocp = brace_loc;
   return error_mark_node;
 }
   stmt = c_begin_compound_stmt (true);
or perhaps simpler initialize it to the function_start_locus at the
beginning and have those functions without { have function_start_locus ==
function_end_locus like the __GIMPLE functions (where propagating the
closing } seemed too difficult).

The following patch has been successfully bootstrapped/regtested on
x86_64-linux and i686-linux and tested on the testcases under valgrind,
ok for trunk (or do you prefer the above hunk instead)?

2020-03-21  Jakub Jelinek  

PR gcov-profile/94029
PR c/94239
* c-parser.c (c_parser_declaration_or_fndef): Initialize endloc to
the function_start_locus location.  Don't do that afterwards for the
__GIMPLE body parsing.

--- gcc/c/c-parser.c.jj 2020-03-19 22:55:49.694691865 +0100
+++ gcc/c/c-parser.c2020-03-20 22:09:39.659411721 +0100
@@ -2469,9 +2469,10 @@ c_parser_declaration_or_fndef (c_parser
   omp_declare_simd_clauses);
   if (oacc_routine_data)
c_finish_oacc_routine (oacc_routine_data, current_function_decl, true);
+  location_t startloc = c_parser_peek_token (parser)->location;
   DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
-   = c_parser_peek_token (parser)->location;
-  location_t endloc;
+   = startloc;
+  location_t endloc = startloc;
 
   /* If the definition was marked with __RTL, use the RTL parser now,
 consuming the function body.  */
@@ -2499,8 +2500,6 @@ c_parser_declaration_or_fndef (c_parser
  specs->declspec_il,
  specs->entry_bb_count);
  in_late_binary_op = saved;
- struct function *fun = DECL_STRUCT_FUNCTION (current_function_decl);
- endloc = fun->function_start_locus;
}
   else
fnbody = c_parser_compound_statement (parser, &endloc);


Jakub



[PATCH] Darwin: Fix i686 bootstrap when the assembler supports GOTOFF in data.

2020-03-21 Thread Iain Sandoe
Hi,

When we use an assembler that supports " .long XX@GOTOFF", the current
combination of configuration parameters and conditional compilation
(when building an i686-darwin compiler with mdynamic-no-pic) assume that
it's OK to put jump tables in the .const section.

However, when we encounter a weak function with a jump table, this
produces relocations that directly access the weak symbol section from
the .const section - which is deemed illegal by the linker (since that
would mean that the weak symbol could not be replaced).

Arguably, this is a limitation (maybe even a bug) in the linker - but
it seems that we'd have to change the ABI to fix it - since it would
require some annotation (maybe just using a special section for the
jump tables) to tell the linker that this specific circumstance is OK
because the direct access to the weak symbol can only occur from that
symbol itself.

The fix is to force jump tables into the text section for all X86 Darwin
versions (PIC code already had this change).

===

The change to i386.h is just a  tidy up, and I can apply the darwin.h portion
independently of that to fix the problem if you’d prefer no changes at this
stage.

OK for master (for the  i386.h part of the change)?
backports to open branches (for the  i386.h part of the change)?

thanks
Iain.

gcc/ChangeLog:

2020-03-21  Iain Sandoe  

* config/i386/darwin.h (JUMP_TABLES_IN_TEXT_SECTION): Remove
references to Darwin.
* config/i386/i386.h (JUMP_TABLES_IN_TEXT_SECTION): Define this
unconditionally and comment on why.

diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
index 1b94cb88c98..5faa1f40089 100644
--- a/gcc/config/i386/darwin.h
+++ b/gcc/config/i386/darwin.h
@@ -239,6 +239,16 @@ along with GCC; see the file COPYING3.  If not see
 #undef TARGET_ASM_OUTPUT_IDENT
 #define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive
 
+/* We always want jump tables in the text section:
+   * for PIC code, we need the subtracted symbol to be defined at
+ assembly-time.
+   * for mdynamic-no-pic, we cannot support jump tables in the .const
+ section for weak functions, this looks to ld64 like direct access
+ to the weak symbol from an anonymous atom.  */
+
+#undef JUMP_TABLES_IN_TEXT_SECTION
+#define JUMP_TABLES_IN_TEXT_SECTION 1
+
 /* Darwin profiling -- call mcount.
If we need a stub, then we unconditionally mark it as used.  */
 #undef FUNCTION_PROFILER
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 98235f75a9e..d4255f0d678 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2285,11 +2285,10 @@ extern int const 
svr4_dbx_register_map[FIRST_PSEUDO_REGISTER];
 
 /* Under some conditions we need jump tables in the text section,
because the assembler cannot handle label differences between
-   sections.  This is the case for x86_64 on Mach-O for example.  */
+   sections.  */
 
 #define JUMP_TABLES_IN_TEXT_SECTION \
-  (flag_pic && ((TARGET_MACHO && TARGET_64BIT) \
-   || (!TARGET_64BIT && !HAVE_AS_GOTOFF_IN_DATA)))
+  (flag_pic && (!TARGET_64BIT && !HAVE_AS_GOTOFF_IN_DATA))
 
 /* Switch to init or fini section via SECTION_OP, emit a call to FUNC,
and switch back.  For x86 we do this only to save a few bytes that



Re: [PATCH] Darwin: Fix i686 bootstrap when the assembler supports GOTOFF in data.

2020-03-21 Thread Uros Bizjak via Gcc-patches
On Sat, Mar 21, 2020 at 3:21 PM Iain Sandoe  wrote:
>
> Hi,
>
> When we use an assembler that supports " .long XX@GOTOFF", the current
> combination of configuration parameters and conditional compilation
> (when building an i686-darwin compiler with mdynamic-no-pic) assume that
> it's OK to put jump tables in the .const section.
>
> However, when we encounter a weak function with a jump table, this
> produces relocations that directly access the weak symbol section from
> the .const section - which is deemed illegal by the linker (since that
> would mean that the weak symbol could not be replaced).
>
> Arguably, this is a limitation (maybe even a bug) in the linker - but
> it seems that we'd have to change the ABI to fix it - since it would
> require some annotation (maybe just using a special section for the
> jump tables) to tell the linker that this specific circumstance is OK
> because the direct access to the weak symbol can only occur from that
> symbol itself.
>
> The fix is to force jump tables into the text section for all X86 Darwin
> versions (PIC code already had this change).
>
> ===
>
> The change to i386.h is just a  tidy up, and I can apply the darwin.h portion
> independently of that to fix the problem if you’d prefer no changes at this
> stage.
>
> OK for master (for the  i386.h part of the change)?
> backports to open branches (for the  i386.h part of the change)?

OK everywhere, but please rewrite the condition to equivalent:

(flag_pic && !(TARGET_64BIT || HAVE_AS_GOTOFF_IN_DATA))

Thanks,
Uros.

>
> thanks
> Iain.
>
> gcc/ChangeLog:
>
> 2020-03-21  Iain Sandoe  
>
> * config/i386/darwin.h (JUMP_TABLES_IN_TEXT_SECTION): Remove
> references to Darwin.
> * config/i386/i386.h (JUMP_TABLES_IN_TEXT_SECTION): Define this
> unconditionally and comment on why.
>
> diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
> index 1b94cb88c98..5faa1f40089 100644
> --- a/gcc/config/i386/darwin.h
> +++ b/gcc/config/i386/darwin.h
> @@ -239,6 +239,16 @@ along with GCC; see the file COPYING3.  If not see
>  #undef TARGET_ASM_OUTPUT_IDENT
>  #define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive
>
> +/* We always want jump tables in the text section:
> +   * for PIC code, we need the subtracted symbol to be defined at
> + assembly-time.
> +   * for mdynamic-no-pic, we cannot support jump tables in the .const
> + section for weak functions, this looks to ld64 like direct access
> + to the weak symbol from an anonymous atom.  */
> +
> +#undef JUMP_TABLES_IN_TEXT_SECTION
> +#define JUMP_TABLES_IN_TEXT_SECTION 1
> +
>  /* Darwin profiling -- call mcount.
> If we need a stub, then we unconditionally mark it as used.  */
>  #undef FUNCTION_PROFILER
> diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
> index 98235f75a9e..d4255f0d678 100644
> --- a/gcc/config/i386/i386.h
> +++ b/gcc/config/i386/i386.h
> @@ -2285,11 +2285,10 @@ extern int const 
> svr4_dbx_register_map[FIRST_PSEUDO_REGISTER];
>
>  /* Under some conditions we need jump tables in the text section,
> because the assembler cannot handle label differences between
> -   sections.  This is the case for x86_64 on Mach-O for example.  */
> +   sections.  */
>
>  #define JUMP_TABLES_IN_TEXT_SECTION \
> -  (flag_pic && ((TARGET_MACHO && TARGET_64BIT) \
> -   || (!TARGET_64BIT && !HAVE_AS_GOTOFF_IN_DATA)))
> +  (flag_pic && (!TARGET_64BIT && !HAVE_AS_GOTOFF_IN_DATA))
>
>  /* Switch to init or fini section via SECTION_OP, emit a call to FUNC,
> and switch back.  For x86 we do this only to save a few bytes that
>


Re: [Patch][LTO] Set proper DECL_ALIGN in offload_handle_link_vars (PR94233)

2020-03-21 Thread Tobias Burnus

On 3/21/20 8:03 AM, Richard Biener wrote:


OK for the trunk?

It should be TYPE_ALIGN (type). OK with that change.


I am confused. The patch has:
+   SET_DECL_ALIGN (link_ptr_var, TYPE_ALIGN (ptr_type_node));
which looks correct and to uses already TYPE_ALIGN?!?


Note this fails to honor target bits so it might be better to lay out the decl 
properly?


However, that's a good point. Let's do it properly by calling layout_decl
— indirectly, by calling build_decl.

OK?

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander 
Walter
Set proper DECL_ALIGN in offload_handle_link_vars (PR94233)

	gcc/lto/
	PR middle-end/94233
	* lto.c (offload_handle_link_vars): Cleanup; call
	build_decl to ensure alignment is set.

diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index 39bb5f45c95..467b922eedf 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -561,18 +561,14 @@ offload_handle_link_vars (void)
 			  DECL_ATTRIBUTES (var->decl)))
   {
 	tree type = build_pointer_type (TREE_TYPE (var->decl));
-	tree link_ptr_var = make_node (VAR_DECL);
-	TREE_TYPE (link_ptr_var) = type;
-	TREE_USED (link_ptr_var) = 1;
-	TREE_STATIC (link_ptr_var) = 1;
-	SET_DECL_MODE (link_ptr_var, TYPE_MODE (type));
-	DECL_SIZE (link_ptr_var) = TYPE_SIZE (type);
-	DECL_SIZE_UNIT (link_ptr_var) = TYPE_SIZE_UNIT (type);
-	DECL_ARTIFICIAL (link_ptr_var) = 1;
 	tree var_name = DECL_ASSEMBLER_NAME (var->decl);
 	char *new_name
 	  = ACONCAT ((IDENTIFIER_POINTER (var_name), "_linkptr", NULL));
-	DECL_NAME (link_ptr_var) = get_identifier (new_name);
+	tree link_ptr_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+	get_identifier (new_name), type);
+	TREE_USED (link_ptr_var) = 1;
+	TREE_STATIC (link_ptr_var) = 1;
+	DECL_ARTIFICIAL (link_ptr_var) = 1;
 	SET_DECL_ASSEMBLER_NAME (link_ptr_var, DECL_NAME (link_ptr_var));
 	SET_DECL_VALUE_EXPR (var->decl, build_simple_mem_ref (link_ptr_var));
 	DECL_HAS_VALUE_EXPR_P (var->decl) = 1;


[PATCH d] Committed fix for ICE in add_symbol_to_partition_1 at lto/lto-partition.c:215 (PR94920)

2020-03-21 Thread Iain Buclaw via Gcc-patches
Hi,

This patch addresses two problems with TypeInfo initializer generation.

1. D array fields pointing to compiler generated data are referencing
public symbols with no unique prefix, which can lead to duplicate
definition errors in some hard to reduce cases.  To avoid name clashes,
all symbols that are generated for TypeInfo initializers now use the
assembler name of the TypeInfo decl as a prefix.

2. An ICE would occur during LTO pass because these same decls are
considered to be part of the same comdat group as the TypeInfo decl that
it's referred by, despite itself being neither marked public nor comdat.
This resulted in decls being added to the LTRANS partition out of order,
triggering an assert when add_symbol_to_partition_1 attempted to add
them again.  To remedy, TREE_PUBLIC and DECL_COMDAT are now set on all
generated symbols.

Jakub, I'll also want to backport this to the gcc-9 branch if there's no
problem with that.

Bootstrapped and tested on x86_64-linux-gnu, and committed to trunk.

Regards,
Iain.

---
gcc/d/ChangeLog:

2020-03-21  Iain Buclaw  

PR d/94290
* typeinfo.cc (class TypeInfoVisitor): Replace type_ field with decl_.
(TypeInfoVisitor::TypeInfoVisitor): Set decl_.
(TypeInfoVisitor::result): Update.
(TypeInfoVisitor::internal_reference): New function.
(TypeInfoVisitor::layout_string): Use internal_reference.
(TypeInfoVisitor::visit (TypeInfoTupleDeclaration *)): Likewise.
(layout_typeinfo): Construct TypeInfoVisitor with typeinfo decl.
(layout_classinfo): Likewise.

---
 gcc/d/typeinfo.cc | 47 ---
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index d4f777159af..07011deaf6f 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -341,9 +341,29 @@ class TypeInfoVisitor : public Visitor
 {
   using Visitor::visit;
 
-  tree type_;
+  tree decl_;
   vec *init_;
 
+  /* Build an internal comdat symbol for the manifest constant VALUE, so that
+ its address can be taken.  */
+
+  tree internal_reference (tree value)
+  {
+/* Use the typeinfo decl name as a prefix for the internal symbol.  */
+const char *prefix = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME 
(this->decl_));
+tree decl = build_artificial_decl (TREE_TYPE (value), value, prefix);
+
+/* The internal pointer reference should be public, but not visible outside
+   the compilation unit.  */
+DECL_EXTERNAL (decl) = 0;
+TREE_PUBLIC (decl) = 1;
+DECL_VISIBILITY (decl) = VISIBILITY_INTERNAL;
+DECL_COMDAT (decl) = 1;
+d_pushdecl (decl);
+
+return decl;
+  }
+
   /* Add VALUE to the constructor values list.  */
 
   void layout_field (tree value)
@@ -364,10 +384,8 @@ class TypeInfoVisitor : public Visitor
 TREE_STATIC (value) = 1;
 
 /* Taking the address, so assign the literal to a static var.  */
-tree decl = build_artificial_decl (TREE_TYPE (value), value);
+tree decl = this->internal_reference (value);
 TREE_READONLY (decl) = 1;
-DECL_EXTERNAL (decl) = 0;
-d_pushdecl (decl);
 
 value = d_array_value (build_ctype (Type::tchar->arrayOf ()),
   size_int (len), build_address (decl));
@@ -500,9 +518,9 @@ class TypeInfoVisitor : public Visitor
 
 
 public:
-  TypeInfoVisitor (tree type)
+  TypeInfoVisitor (tree decl)
   {
-this->type_ = type;
+this->decl_ = decl;
 this->init_ = NULL;
   }
 
@@ -510,7 +528,7 @@ public:
 
   tree result (void)
   {
-return build_struct_literal (this->type_, this->init_);
+return build_struct_literal (TREE_TYPE (this->decl_), this->init_);
   }
 
   /* Layout of TypeInfo is:
@@ -1125,19 +1143,12 @@ public:
build_typeinfo (d->loc, arg->type));
   }
 tree ctor = build_constructor (build_ctype (satype), elms);
-tree decl = build_artificial_decl (TREE_TYPE (ctor), ctor);
-
-/* The internal pointer reference should be public, but not visible outside
-   the compilation unit, as it's referencing COMDAT decls.  */
-TREE_PUBLIC (decl) = 1;
-DECL_VISIBILITY (decl) = VISIBILITY_INTERNAL;
-DECL_COMDAT (decl) = 1;
+tree decl = this->internal_reference (ctor);
 
 tree length = size_int (ti->arguments->dim);
 tree ptr = build_address (decl);
 this->layout_field (d_array_value (array_type_node, length, ptr));
 
-d_pushdecl (decl);
 rest_of_decl_compilation (decl, 1, 0);
   }
 };
@@ -1152,8 +1163,7 @@ layout_typeinfo (TypeInfoDeclaration *d)
   if (!Type::dtypeinfo)
 create_frontend_tinfo_types ();
 
-  tree type = TREE_TYPE (get_typeinfo_decl (d));
-  TypeInfoVisitor v = TypeInfoVisitor (type);
+  TypeInfoVisitor v = TypeInfoVisitor (get_typeinfo_decl (d));
   d->accept (&v);
   return v.result ();
 }
@@ -1168,8 +1178,7 @@ layout_classinfo (ClassDeclaration *cd)
 create_frontend_tinfo_types ();
 
   TypeInfoClassDeclaration *d = TypeInfoCl

[committed] Darwin: Address translation comments (PR93694).

2020-03-21 Thread Iain Sandoe
This updates the options descriptions after feedback from a translator.

tested on x86_64-darwin16,
applied to master,
thanks
Iain

gcc/ChangeLog:

2020-03-21  Iain Sandoe  

PR target/93694
* gcc/config/darwin.opt: Amend options descriptions.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e55a8e75ec9..ba619c240d3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-21 Iain Sandoe 
+
+   PR target/93694
+   * gcc/config/darwin.opt: Amend options descriptions.
+
 2020-03-21  Richard Sandiford  
 
PR rtl-optimization/94052
diff --git a/gcc/config/darwin.opt b/gcc/config/darwin.opt
index 15bbdbfafd1..5b75536378d 100644
--- a/gcc/config/darwin.opt
+++ b/gcc/config/darwin.opt
@@ -68,7 +68,7 @@ Generate code for the kernel or loadable kernel extensions.
 ; Init is never used.
 mmacosx-version-min=
 Target RejectNegative Joined Report Var(darwin_macosx_version_min) 
Init(DEF_MIN_OSX_VERSION)
-The earliest MacOS X version on which this program will run.
+The earliest macOS version on which this program will run.
 
 ; Really, only relevant to PowerPC which has a 4 byte bool by default.
 mone-byte-bool
@@ -85,57 +85,57 @@ Target RejectNegative Joined Report Alias(mtarget-linker)
 
 mtarget-linker
 Target RejectNegative Joined Separate Report Var(darwin_target_linker) 
Init(LD64_VERSION)
-The version of ld64 in use for this toolchain.
+-mtarget-linker   Specify that ld64  is the toolchain 
linker for the current invocation.
 
 ; Driver options.
 
 all_load
 Driver RejectNegative Alias(Zall_load)
-Loads all members of archive libraries
+Load all members of archive libraries, rather than only those that satisfy 
undefined symbols.
 
 allowable_client
 Driver RejectNegative Separate Alias(Zallowable_client)
--allowable_clientThe output dylib is private to the client(s) 
named
+-allowable_clientThe output dylib is private to the client 
.
 
 arch
 Driver RejectNegative Separate
--archSpecify that the output file should be generated for 
architecture  \"name\"
+-archGenerate output for architecture .
 
 arch_errors_fatal
 Driver RejectNegative Alias(Zarch_errors_fatal)
-Mismatches between file architecture and the \"-arch\" are errors instead of 
warnings
+Mismatches between file architecture and one specified by \"-arch\" are errors 
instead of warnings.
 
 asm_macosx_version_min=
 Driver RejectNegative Joined
-The earliest MacOS X version on which this program will run (formatted for the 
assembler)
+The earliest macOS version on which this program will run (formatted for the 
assembler).
 
 bind_at_load
 Driver RejectNegative Alias(Zbind_at_load)
-Produce an output file that will bind symbols on load, rather than lazily.
+Generate an output executable that binds symbols on load, rather than lazily.
 
 bundle
 Driver RejectNegative Alias(Zbundle)
-Produce a Mach-O bundle (file type MH_BUNDLE)
+Generate a Mach-O bundle (file type MH_BUNDLE).
 
 bundle_loader
 Driver RejectNegative Separate Alias(Zbundle_loader)
--bundle_loader Treat \"executable\" (that will be loading this 
bundle) as if it was one of the dynamic libraries the bundle is linked against 
for symbol resolution
+-bundle_loader Treat  (that will be loading this 
bundle) as if it was one of the dynamic libraries the bundle is linked against 
for symbol resolution.
 
 client_name
 Driver RejectNegative Separate
--client_name Enable the executable being built to link against a 
private dylib (using allowable_client)
+-client_name Enable the executable being built to link against a 
private dylib (using allowable_client).
 
 compatibility_version
 Driver RejectNegative Separate
--compatibility_version Set the minimum version for the client 
interface.  Clients must record a greater number than this or the binding will 
fail at runtime
+-compatibility_version Set the version for the client 
interface.  Client programs must record a value less than or equal to , 
or the binding will fail at runtime.
 
 current_version
 Driver RejectNegative Separate
--current_version   Set the current version for the library.
+-current_version   Set the current version for the library to 
.
 
 dead_strip
 Driver RejectNegative Alias(Zdead_strip)
-Remove code and data that is unreachable from any exported symbol (including 
the entry point)
+Remove code and data that is unreachable from any exported symbol (including 
the entry point).
 
 dylib_file
 Driver Separate Alias(Zdylib_file)
@@ -154,15 +154,15 @@ The default (and opposite of -static), implied by user 
mode executables, shared
 
 dynamiclib
 Driver RejectNegative Alias(Zdynamiclib)
-Produce a Mach-O shared library (file type MH_DYLIB), synonym for -shared
+Produce a Mach-O shared library (file type MH_DYLIB), synonym for \"-shared\".
 
 exported_symbols_list
 Driver RejectNegative Separate Alias(Zexported_symbols_list)
--exported_symbols_list   Global symbols in \"filename\" will be 
exp

[committed] Darwin: Handle NULL DECL_SIZE_TYPE in machopic_select_section (PR94237).

2020-03-21 Thread Iain Sandoe
Hi,

A recent change in the LTO streaming arrangement means that it is
now possible for machopic_select_section () to be called with a NULL
value for DECL_SIZE_TYPE - corresponding to an incomplete or not-yet-
laid out type.

When section anchors are present, and we are generating assembler, we
normally need to know the object size when choosing the section, since
zero-sized objects must be placed in sections that forbid section
anchors.

In the current circumstance, the objective of the earlier streaming of
this data is to allow nm to determine BSS c.f. Data symbols (when used
with the LTO plugin).

We now detect when the size is unknown and return the 'generic' section
for the DECL kind, which will still be correct in determining the BSS 
c.f. Data case.

Since Darwin does not yet make use of the LTO plugin this is a bit of
future-proofing (but needed to fix the PR too). 

tested across the darwin range,
applied to master,
thanks
Iain

gcc/ChangeLog:

2020-03-21  Iain Sandoe  

PR lto/94237
* config/darwin.c (darwin_mergeable_constant_section): Collect
section anchor checks into the caller.
(machopic_select_section): Collect section anchor checks into
the determination of 'effective zero-size' objects.  When the
size is unknown, assume it is non-zero, and thus return the
'generic' section for the DECL.

diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 8131361715b..d3c0af8a4b6 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -1354,9 +1354,7 @@ darwin_mergeable_constant_section (tree exp,
   machine_mode mode = DECL_MODE (exp);
   unsigned int modesize = GET_MODE_BITSIZE (mode);
 
-  if (DARWIN_SECTION_ANCHORS
-  && flag_section_anchors
-  && zsize)
+  if (zsize)
 return darwin_sections[zobj_const_section];
 
   if (flag_merge_constants
@@ -1586,8 +1584,23 @@ machopic_select_section (tree decl,
  && DECL_WEAK (decl)
  && !lookup_attribute ("weak_import", DECL_ATTRIBUTES (decl)));
 
-  zsize = (DECL_P (decl)
+  /* Darwin pads zero-sized objects with at least one byte, so that the ld64
+ atom model is preserved (objects must have distinct regions starting with
+ a unique linker-visible symbol).
+ In order to support section anchors, we need to move objects with zero
+ size into sections which are marked as "no section anchors"; the padded
+ objects, obviously, have real sizes that differ from their DECL sizes.  */
+  zsize = DARWIN_SECTION_ANCHORS && flag_section_anchors;
+
+  /* In the streaming of LTO symbol data, we might have a situation where the
+ var is incomplete or layout not finished (DECL_SIZE_UNIT is NULL_TREE).
+ We cannot tell if it is zero-sized then, but we can get the section
+ category correct so that nm reports the right kind of section
+ (e.g. BSS c.f. data).  */
+  zsize = (zsize
+  && DECL_P (decl)
   && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL)
+  && DECL_SIZE_UNIT (decl)
   && tree_to_uhwi (DECL_SIZE_UNIT (decl)) == 0);
 
   one = DECL_P (decl)
@@ -1635,15 +1648,11 @@ machopic_select_section (tree decl,
  else
base_section = darwin_sections[data_coal_section];
}
-  else if (DARWIN_SECTION_ANCHORS
-  && flag_section_anchors
-  && zsize)
+  else if (zsize)
{
  /* If we're doing section anchors, then punt zero-sized objects into
 their own sections so that they don't interfere with offset
-computation for the remaining vars.  This does not need to be done
-for stuff in mergeable sections, since these are ineligible for
-anchors.  */
+computation for the remaining vars.  */
  if (ro)
base_section = darwin_sections[zobj_const_data_section];
  else



Re: [PATCH] avoid -Wredundant-tags on a first declaration in use (PR 93824)

2020-03-21 Thread Martin Sebor via Gcc-patches

On 3/20/20 3:53 PM, Jason Merrill wrote:

On 3/19/20 7:55 PM, Martin Sebor wrote:

On 3/18/20 9:07 PM, Jason Merrill wrote:

On 3/12/20 6:38 PM, Martin Sebor wrote:

...
+ declarations of a class from its uses doesn't work for type 
aliases

+ (as in using T = class C;).  */


Good point.  Perhaps we could pass flags to 
cp_parser_declares_only_class_p and have it return false if 
CP_PARSER_FLAGS_TYPENAME_OPTIONAL, since that is set for an alias but 
not for a normal type-specifier.


I wondered if there was a way to identify that we're dealing with
an alias.  CP_PARSER_FLAGS_TYPENAME_OPTIONAL is set not just for
those but also for template declarations (in
cp_parser_single_declaration) but I was able to make it work by
tweaking cp_parser_type_specifier.  It doesn't feel very clean
(it seems like either the bit or all of cp_parser_flags could be
a member of the parser class or some subobject of it) but it does
the job.  Thanks for pointing me in the right direction!


Hmm, true, relying on that flag is probably too fragile.  And now that I 
look closer, I see that we already have is_declaration in 
cp_parser_elaborated_type_specifier, we just need to check that before 
cp_parser_declares_only_class_p like we do earlier in the function.


I changed it to use is_declaration instead.


+  if (!decl_p && !def_p && TREE_CODE (decl) == TEMPLATE_DECL)
 {
+  /* When TYPE is the use of an implicit specialization of a 
previously
+ declared template set TYPE_DECL to the type of the primary 
template
+ for the specialization and look it up in CLASS2LOC below.  For 
uses
+ of explicit or partial specializations TYPE_DECL already 
points to

+ the declaration of the specialization.  */
+  type_decl = specialization_of (type_decl);


Here shouldn't is_use be true?


If it were set to true here we would find the partial specialization
corresponding to its specialization in the use when what we want is
the latter.  As a result, for the following:

   template    struct S;
   template  struct S;

   extern class  S s1;   // expect -Wmismatched-tags
   extern struct S s2;

we'd end up with a warning for s2 pointing to the instantiation of
s1 as the "guiding declaration:"

z.C:5:15: warning: ‘template struct S’ declared with a 
mismatched class-key ‘struct’ [-Wmismatched-tags]

 5 | extern struct S s2;
   |   ^~~
z.C:5:15: note: remove the class-key or replace it with ‘class’
z.C:4:15: note: ‘template struct S’ first declared as 
‘class’ here

 4 | extern class  S s1;   // expect -Wmismatched-tags
   |   ^~~


I found this puzzling and wanted to see why that would be, but I can't 
reproduce it; compiling with -Wmismatched-tags produces only


I'm not sure what you did differently.  With the patch (the last one
or the one in the attachment) we get the expected warning below.



wa2.C:4:17: warning: ‘S’ declared with a mismatched class-key 
‘class’ [-Wmismatched-tags]

     4 |   extern class  S s1;   // expect -Wmismatched-tags
   | ^~~
wa2.C:4:17: note: remove the class-key or replace it with ‘struct’
wa2.C:2:29: note: ‘S’ first declared as ‘struct’ here
     2 |   template  struct S;

So the only difference is whether we talk about S or S.  I 
agree that the latter is probably better, which is what you get without 
my suggested change.  But since specialization_of does nothing if is_use 
is false, how about removing the call here and removing the is_use 
parameter?


Sure.




+  if (tree spec = most_specialized_partial_spec (ret, tf_none))
+    if (spec != error_mark_node)
+  ret = TREE_VALUE (spec);


I think you want to take the TREE_TYPE of the template here, so you 
don't need to do it here:



+  tree pt = specialization_of (TYPE_MAIN_DECL (type), true);
+  if (TREE_CODE (pt) == TEMPLATE_DECL)
+   pt = TREE_TYPE (pt);
+  pt = TYPE_MAIN_DECL (pt);


And also, since it takes a TYPE_DECL, it would be better to return 
another TYPE_DECL rather than a _TYPE, especially since the only caller 
immediately extracts a TYPE_DECL.


Okay.  Attached is an revised patch with these changes.

Martin
PR c++/94078 - bogus and missing -Wmismatched-tags on an instance of a template
PR c++/93824 - bogus -Wredundant-tags on a first declaration in use
PR c++/93810 - missing -Wmismatched-tags and -Wredundant-tags on a typedef of an implicit class template specialization

gcc/cp/ChangeLog:

	PR c++/94078
	PR c++/93824
	PR c++/93810
	* cp-tree.h (most_specialized_partial_spec): Declare.
	* parser.c (cp_parser_elaborated_type_specifier): Distinguish alias
	from declarations.
	(class_decl_loc_t::class_decl_loc_t): Add an argument.
	(class_decl_loc_t::add): Same.
	(class_decl_loc_t::add_or_diag_mismatched_tag): Same.
	(class_decl_loc_t::is_decl): New member function.
	(class_decl_loc_t::class_key_loc_t): Add a new member.
	(specialization_of): New function.
	(cp_parser_check_class_key): Move code...
	(class_decl_loc_t:

[committed] libstdc++: Fix path::generic_string allocator handling (PR 94242)

2020-03-21 Thread Jonathan Wakely via Gcc-patches
It's not possible to construct a path::string_type from an allocator of
a different type. Create the correct specialization of basic_string, and
adjust path::_S_str_convert to use a basic_string_view so that it is
independent of the allocator type.

PR libstdc++/94242
* include/bits/fs_path.h (path::_S_str_convert): Replace first
parameter with basic_string_view so that strings with different
allocators can be accepted.
(path::generic_string()): Use basic_string object that uses the
right allocator type.
* testsuite/27_io/filesystem/path/generic/94242.cc: New test.
* testsuite/27_io/filesystem/path/generic/generic_string.cc: Improve
test coverage.

Tested x86_64-linux, committed to master.

I plan to backport this too.

commit 9fc985118d9f5014afc1caf32a411ee5803fba61
Author: Jonathan Wakely 
Date:   Sat Mar 21 21:51:07 2020 +

libstdc++: Fix path::generic_string allocator handling (PR 94242)

It's not possible to construct a path::string_type from an allocator of
a different type. Create the correct specialization of basic_string, and
adjust path::_S_str_convert to use a basic_string_view so that it is
independent of the allocator type.

PR libstdc++/94242
* include/bits/fs_path.h (path::_S_str_convert): Replace first
parameter with basic_string_view so that strings with different
allocators can be accepted.
(path::generic_string()): Use basic_string object that uses 
the
right allocator type.
* testsuite/27_io/filesystem/path/generic/94242.cc: New test.
* testsuite/27_io/filesystem/path/generic/generic_string.cc: Improve
test coverage.

diff --git a/libstdc++-v3/include/bits/fs_path.h 
b/libstdc++-v3/include/bits/fs_path.h
index bf1f09929c3..fb6e8a5247f 100644
--- a/libstdc++-v3/include/bits/fs_path.h
+++ b/libstdc++-v3/include/bits/fs_path.h
@@ -579,7 +579,7 @@ namespace __detail
 
 template
   static basic_string<_CharT, _Traits, _Allocator>
-  _S_str_convert(const string_type&, const _Allocator& __a);
+  _S_str_convert(basic_string_view, const _Allocator&);
 
 void _M_split_cmpts();
 
@@ -1015,7 +1015,8 @@ namespace __detail
   /// @cond undocumented
   template
 std::basic_string<_CharT, _Traits, _Allocator>
-path::_S_str_convert(const string_type& __str, const _Allocator& __a)
+path::_S_str_convert(basic_string_view __str,
+const _Allocator& __a)
 {
   static_assert(!is_same_v<_CharT, value_type>);
 
@@ -1126,7 +1127,9 @@ namespace __detail
 #else
   const value_type __slash = '/';
 #endif
-  string_type __str(__a);
+  using _Alloc2 = typename allocator_traits<_Allocator>::template
+   rebind_alloc;
+  basic_string, _Alloc2> __str(__a);
 
   if (_M_type() == _Type::_Root_dir)
__str.assign(1, __slash);
@@ -1145,7 +1148,7 @@ namespace __detail
 #endif
  if (__add_slash)
__str += __slash;
- __str += __elem._M_pathname;
+ __str += basic_string_view(__elem._M_pathname);
  __add_slash = __elem._M_type() == _Type::_Filename;
}
}
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/generic/94242.cc 
b/libstdc++-v3/testsuite/27_io/filesystem/path/generic/94242.cc
new file mode 100644
index 000..c917daed94e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/generic/94242.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do run { target c++17 } }
+
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// .
+
+// C++17 30.10.7.4.7 path generic format observers [fs.path.generic.obs]
+
+#include 
+#include 
+
+using std::filesystem::path;
+using __gnu_test::SimpleAllocator;
+
+void
+test01()
+{
+  path p = "//foo//bar//.";
+  using C = path::value_type;
+  auto g = p.generic_string, SimpleAllocator>();
+  VERIFY( g == path("/foo/bar/.").c_str() );
+}
+
+void
+test02()
+{
+  path p = "//foo//bar//.";
+  using C = char16_t;
+  auto g = p.generic_string, SimpleAllocator>();
+  VERIFY( g == u"/foo/bar/." );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+}
diff --git 
a/libstdc++-v3/testsuite/

[committed] libstdc++: Fix experimental::path::generic_string (PR 93245)

2020-03-21 Thread Jonathan Wakely via Gcc-patches
This function was unimplemented, simply returning the native format
string instead.

PR libstdc++/93245
* include/experimental/bits/fs_path.h (path::generic_string()):
* testsuite/experimental/filesystem/path/generic/generic_string.cc:
Improve test coverage.

Tested powerpc64le-linux and x86_64-w64-mingw32, committed to master.

I think this could be safely backported too.

commit a577c0c26931090e7c25e56ef5ffc807627961ec
Author: Jonathan Wakely 
Date:   Sat Mar 21 22:11:44 2020 +

libstdc++: Fix experimental::path::generic_string (PR 93245)

This function was unimplemented, simply returning the native format
string instead.

PR libstdc++/93245
* include/experimental/bits/fs_path.h 
(path::generic_string()):
* testsuite/experimental/filesystem/path/generic/generic_string.cc:
Improve test coverage.

diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h 
b/libstdc++-v3/include/experimental/bits/fs_path.h
index 7b3d9926e60..d7234c08a00 100644
--- a/libstdc++-v3/include/experimental/bits/fs_path.h
+++ b/libstdc++-v3/include/experimental/bits/fs_path.h
@@ -1086,34 +1086,56 @@ namespace __detail
   inline std::u32string
   path::u32string() const { return string(); }
 
-#ifndef _GLIBCXX_FILESYSTEM_IS_WINDOWS
   template
 inline std::basic_string<_CharT, _Traits, _Allocator>
 path::generic_string(const _Allocator& __a) const
-{ return string<_CharT, _Traits, _Allocator>(__a); }
+{
+#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
+  const _CharT __slash = is_same<_CharT, wchar_t>::value
+   ? _CharT(L'/')
+   : _CharT('/'); // Assume value is correct for the encoding.
+#else
+  const _CharT __slash = _CharT('/');
+#endif
+  basic_string<_CharT, _Traits, _Allocator> __str(__a);
+  __str.reserve(_M_pathname.size());
+  bool __add_slash = false;
+  for (auto& __elem : *this)
+   {
+ if (__elem._M_type == _Type::_Root_dir)
+   {
+ __str += __slash;
+ continue;
+   }
+ if (__add_slash)
+   __str += __slash;
+ __str += __elem.string<_CharT, _Traits, _Allocator>(__a);
+ __add_slash = __elem._M_type == _Type::_Filename;
+   }
+  return __str;
+}
 
   inline std::string
-  path::generic_string() const { return string(); }
+  path::generic_string() const { return generic_string(); }
 
 #if _GLIBCXX_USE_WCHAR_T
   inline std::wstring
-  path::generic_wstring() const { return wstring(); }
+  path::generic_wstring() const { return generic_string(); }
 #endif
 
 #ifdef _GLIBCXX_USE_CHAR8_T
   inline std::u8string
-  path::generic_u8string() const { return u8string(); }
+  path::generic_u8string() const { return generic_string(); }
 #else
   inline std::string
-  path::generic_u8string() const { return u8string(); }
+  path::generic_u8string() const { return generic_string(); }
 #endif
 
   inline std::u16string
-  path::generic_u16string() const { return u16string(); }
+  path::generic_u16string() const { return generic_string(); }
 
   inline std::u32string
-  path::generic_u32string() const { return u32string(); }
-#endif
+  path::generic_u32string() const { return generic_string(); }
 
   inline int
   path::compare(const string_type& __s) const { return compare(path(__s)); }
diff --git 
a/libstdc++-v3/testsuite/experimental/filesystem/path/generic/generic_string.cc 
b/libstdc++-v3/testsuite/experimental/filesystem/path/generic/generic_string.cc
index 40b39d22023..aa977847436 100644
--- 
a/libstdc++-v3/testsuite/experimental/filesystem/path/generic/generic_string.cc
+++ 
b/libstdc++-v3/testsuite/experimental/filesystem/path/generic/generic_string.cc
@@ -23,27 +23,55 @@
 
 #include 
 #include 
-#include 
+#include 
 
 using std::experimental::filesystem::path;
 
 void
 test01()
 {
-  for (const path& p : __gnu_test::test_paths)
+  __gnu_test::compare_paths( path("///a//b///").generic_string(), "/a/b/." );
+  __gnu_test::compare_paths( path("///a//b").generic_u16string(), "/a/b" );
+  __gnu_test::compare_paths( path("//a//b").generic_u16string(), "//a/b" );
+}
+
+using __gnu_test::SimpleAllocator;
+
+void
+test02()
+{
+  path p = "//foo//bar//.";
+  using C = char16_t;
+  auto g = p.generic_string, SimpleAllocator>();
+  VERIFY( g == u"//foo/bar/." );
+}
+
+
+void
+test03()
+{
+  for (path p : { "/a///b//c", "///a//b//c", "a:b//c", "a://b///c" })
   {
-path p2(p), p3;
-p2.swap(p3);
-VERIFY( p2 == path() );
-VERIFY( p3 == p );
-p2.swap(p3);
-VERIFY( p2 == p );
-VERIFY( p3 == path() );
+// A path constructed from the generic format string should compare equal
+// to the original, because they represent the same path.
+VERIFY( path(p.generic_string()) == p );
+VERIFY( path(p.generic_wstring()) == p );
+VERIFY( path(p.generic_u8string()) == p );
+VERIFY( path(p.generic_u16string()) == p );
+VERIFY( path(p.generic_u32string()) == p );
 

[PATCH] d: Fix missing dependencies in depfile for imported files (PR93038)

2020-03-21 Thread Iain Buclaw via Gcc-patches
Hi,

A new field for tracking imported files was added to the front-end, this
makes use of it by writing all such files in the make dependency list,
fixing PR 93038.

Bootstrapped and tested on x86_64-linux-gnu, and committed to trunk.

Regards
Iain.

---
gcc/d/ChangeLog:

2020-03-22  Iain Buclaw  

PR d/93038
* d-lang.cc (deps_write): Add content imported files to the make
dependency list.

gcc/testsuite/ChangeLog:

2020-03-22  Iain Buclaw  

PR d/93038
* gdc.dg/fileimports/pr93038.txt: New test.
* gdc.dg/pr93038.d: New test.

---
 gcc/d/d-lang.cc  | 52 
 gcc/testsuite/gdc.dg/fileimports/pr93038.txt |  1 +
 gcc/testsuite/gdc.dg/pr93038.d   |  8 +++
 3 files changed, 41 insertions(+), 20 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/fileimports/pr93038.txt
 create mode 100644 gcc/testsuite/gdc.dg/pr93038.d

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 3f50b5f1104..514799d8e89 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -151,7 +151,8 @@ deps_add_target (const char *target, bool quoted)
 static void
 deps_write (Module *module, OutBuffer *buffer, unsigned colmax = 72)
 {
-  hash_set  dependencies;
+  hash_set  seen_modules;
+  vec  dependencies = vNULL;
 
   Modules modlist;
   modlist.push (module);
@@ -179,38 +180,28 @@ deps_write (Module *module, OutBuffer *buffer, unsigned 
colmax = 72)
   buffer->writestring (":");
   column++;
 
-  /* Write out all make dependencies.  */
+  /* Search all modules for file dependencies.  */
   while (modlist.dim > 0)
 {
   Module *depmod = modlist.pop ();
 
   str = depmod->srcfile->name->str;
-  size = strlen (str);
 
-  /* Skip dependencies that have already been written.  */
-  if (dependencies.add (str))
+  /* Skip modules that have already been looked at.  */
+  if (seen_modules.add (str))
continue;
 
-  column += size;
-
-  if (colmax && column > colmax)
-   {
- buffer->writestring (" \\\n ");
- column = size + 1;
-   }
-  else
-   {
- buffer->writestring (" ");
- column++;
-   }
-
-  buffer->writestring (str);
+  dependencies.safe_push (str);
 
   /* Add to list of phony targets if is not being compile.  */
   if (d_option.deps_phony && !depmod->isRoot ())
phonylist.push (depmod);
 
-  /* Search all imports of the written dependency.  */
+  /* Add imported files to dependency list.  */
+  for (size_t i = 0; i < depmod->contentImportedFiles.dim; i++)
+   dependencies.safe_push (depmod->contentImportedFiles[i]);
+
+  /* Search all imports of the module.  */
   for (size_t i = 0; i < depmod->aimports.dim; i++)
{
  Module *m = depmod->aimports[i];
@@ -244,6 +235,27 @@ deps_write (Module *module, OutBuffer *buffer, unsigned 
colmax = 72)
}
 }
 
+  /* Write out all make dependencies.  */
+  for (size_t i = 0; i < dependencies.length (); i++)
+{
+  str = dependencies[i];
+  size = strlen (str);
+  column += size;
+
+  if (colmax && column > colmax)
+   {
+ buffer->writestring (" \\\n ");
+ column = size + 1;
+   }
+  else
+   {
+ buffer->writestring (" ");
+ column++;
+   }
+
+  buffer->writestring (str);
+}
+
   buffer->writenl ();
 
   /* Write out all phony targets.  */
diff --git a/gcc/testsuite/gdc.dg/fileimports/pr93038.txt 
b/gcc/testsuite/gdc.dg/fileimports/pr93038.txt
new file mode 100644
index 000..9d1dc810c95
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/fileimports/pr93038.txt
@@ -0,0 +1 @@
+v2.091.0
diff --git a/gcc/testsuite/gdc.dg/pr93038.d b/gcc/testsuite/gdc.dg/pr93038.d
new file mode 100644
index 000..4e09690a473
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr93038.d
@@ -0,0 +1,8 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93038
+// { dg-options "-J $srcdir/gdc.dg/fileimports -MMD" }
+// { dg-do compile }
+// { dg-final { scan-file pr93038.deps "pr93038.o: \[^\n\]*/pr93038.d \[ 
\n\]*\[^\n\]*/fileimports/pr93038.txt" } }
+// { dg-final { file delete pr93038.deps } }
+module pr93038;
+
+const VERSION = import("pr93038.txt");
-- 
2.20.1