From b0927c5c8c8b9afd53b820ba6a660e06ad767ce3 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Mon, 11 Aug 2025 20:41:15 +0100
Subject: [pushed] D: Adjust the code-gen for a string constant.

Re-tested on x86_64 darwin, pushed to trunk.
Iain

--- 8< ---

In this function, we are generating a string constant but do so with
a mismatch between the actual string length and the length specified
in the type.  This causes Darwin, at least, to place the string in an
unexpected section (since the parameters do not match, it is rejected
as a cstring).

Use build_string_literal() to construct a consistent null-terminated
string.

gcc/d/ChangeLog:

	* d-codegen.cc (build_filename_from_loc): Use
	build_string_literal() to build a null-terminated string for
	the filename.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
---
 gcc/d/d-codegen.cc | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index e35f75af584..f3c3e4ab691 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1939,11 +1939,7 @@ build_filename_from_loc (const Loc &loc)
   if (filename == NULL)
     filename = d_function_chain->module->srcfile.toChars ();
 
-  unsigned length = strlen (filename);
-  tree str = build_string (length, filename);
-  TREE_TYPE (str) = make_array_type (Type::tchar, length + 1);
-
-  return build_address (str);
+  return build_string_literal (filename);
 }
 
 /* Builds a CALL_EXPR at location LOC in the source file to call LIBCALL when
-- 
2.39.2 (Apple Git-143)

