Skip to content

Commit

Permalink
Merge tag 'dmd-rewrite-v2.105.2' into merge-2.105.2
Browse files Browse the repository at this point in the history
v2.105.2
  • Loading branch information
kinke committed Sep 22, 2023
2 parents 04e1064 + 0ba78f4 commit c2e29d9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
8 changes: 5 additions & 3 deletions dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -11029,7 +11029,9 @@ version (IN_LLVM)
(exp.e2.isStringExp() && (exp.e1.isIntegerExp() || exp.e1.isStringExp())))
return exp;

Identifier hook = global.params.tracegc ? Id._d_arraycatnTXTrace : Id._d_arraycatnTX;
bool useTraceGCHook = global.params.tracegc && sc.needsCodegen();

Identifier hook = useTraceGCHook ? Id._d_arraycatnTXTrace : Id._d_arraycatnTX;
if (!verifyHookExist(exp.loc, *sc, hook, "concatenating arrays"))
{
setError();
Expand Down Expand Up @@ -11058,7 +11060,7 @@ version (IN_LLVM)
}

auto arguments = new Expressions();
if (global.params.tracegc)
if (useTraceGCHook)
{
auto funcname = (sc.callsc && sc.callsc.func) ?
sc.callsc.func.toPrettyChars() : sc.func.toPrettyChars();
Expand All @@ -11085,7 +11087,7 @@ version (IN_LLVM)
/* `_d_arraycatnTX` canot be used with `-betterC`, but `CatExp`s may be
* used with `-betterC`, but only during CTFE.
*/
if (global.params.betterC || !sc.needsCodegen())
if (global.params.betterC)
return;

if (auto ce = exp.isCatExp())
Expand Down
10 changes: 5 additions & 5 deletions dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ struct Loc final
{
private:
uint32_t _linnum;
uint16_t _charnum;
uint16_t fileIndex;
uint32_t _charnum;
uint32_t fileIndex;
public:
static bool showColumns;
static MessageStyle messageStyle;
Expand Down Expand Up @@ -7019,9 +7019,9 @@ struct UnionExp final
private:
union __AnonStruct__u
{
char exp[25LLU];
char exp[29LLU];
char integerexp[40LLU];
char errorexp[25LLU];
char errorexp[29LLU];
char realexp[48LLU];
char complexexp[64LLU];
char symoffexp[64LLU];
Expand All @@ -7030,7 +7030,7 @@ struct UnionExp final
char assocarrayliteralexp[48LLU];
char structliteralexp[76LLU];
char compoundliteralexp[40LLU];
char nullexp[25LLU];
char nullexp[29LLU];
char dotvarexp[49LLU];
char addrexp[40LLU];
char indexexp[74LLU];
Expand Down
4 changes: 2 additions & 2 deletions dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ struct Loc
{
private:
unsigned _linnum;
unsigned short _charnum;
unsigned short fileIndex;
unsigned _charnum;
unsigned fileIndex;
public:
static void set(bool showColumns, MessageStyle messageStyle);

Expand Down
20 changes: 14 additions & 6 deletions dmd/location.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ debug info etc.
struct Loc
{
private uint _linnum;
private ushort _charnum;
private ushort fileIndex; // index into filenames[], starting from 1 (0 means no filename)
private uint _charnum;
private uint fileIndex; // index into filenames[], starting from 1 (0 means no filename)
version (LocOffset)
uint fileOffset; /// utf8 code unit index relative to start of file, starting from 0

Expand Down Expand Up @@ -67,7 +67,7 @@ nothrow:
extern (D) this(const(char)* filename, uint linnum, uint charnum)
{
this._linnum = linnum;
this._charnum = cast(ushort) charnum;
this._charnum = charnum;
this.filename = filename;
}

Expand All @@ -80,7 +80,7 @@ nothrow:
/// ditto
extern (C++) uint charnum(uint num) @nogc @safe
{
return _charnum = cast(ushort) num;
return _charnum = num;
}

/// line number, starting from 1
Expand Down Expand Up @@ -114,8 +114,16 @@ nothrow:
{
//printf("setting %s\n", name);
filenames.push(name);
fileIndex = cast(ushort)filenames.length;
assert(fileIndex); // no overflow
fileIndex = cast(uint)filenames.length;
if (!fileIndex)
{
import dmd.globals : global;
import dmd.errors : error, fatal;

global.gag = 0; // ensure error message gets printed
error(Loc.initial, "internal compiler error: file name index overflow!");
fatal();
}
}
else
fileIndex = 0;
Expand Down
15 changes: 15 additions & 0 deletions tests/dmd/compilable/test24118.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// https://issues.dlang.org/show_bug.cgi?id=24118

void map(alias fun, T)(T[] arr)
{
fun(arr);
}


void foo()
{
if( __ctfe )
{
["a", "b", "c"].map!( a => " " ~ a[0] );
}
}

0 comments on commit c2e29d9

Please sign in to comment.