Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2adf6ff

Browse files
kinkeGeod24
authored andcommittedMay 30, 2021
Initialize Target before Type
As `Type._init()` depends on `target.isLP64`. Don't initialize that field in `reconcileCommands`, but in `Target._init()`.
1 parent ecb4374 commit 2adf6ff

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed
 

Diff for: ‎src/dmd/frontend.d

+3-4
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,17 @@ void initDMD(
140140
}
141141

142142
versionIdentifiers.each!(VersionCondition.addGlobalIdent);
143-
addDefaultVersionIdentifiers(global.params, target);
144143

144+
target.os = defaultTargetOS();
145+
target._init(global.params);
145146
Type._init();
146147
Id.initialize();
147148
Module._init();
148-
target._init(global.params);
149-
target.os = defaultTargetOS();
150149
Expression._init();
151150
Objc._init();
152151
FileCache._init();
153152

154-
addDefaultVersionIdentifiers(global.params,target);
153+
addDefaultVersionIdentifiers(global.params, target);
155154

156155
version (CRuntime_Microsoft)
157156
initFPU();

Diff for: ‎src/dmd/mars.d

+1-5
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params)
293293
setDefaultLibrary();
294294

295295
// Initialization
296+
target._init(params);
296297
Type._init();
297298
Id.initialize();
298299
Module._init();
299-
target._init(params);
300300
Expression._init();
301301
Objc._init();
302302
import dmd.filecache : FileCache;
@@ -2541,10 +2541,6 @@ private void reconcileCommands(ref Param params)
25412541
error(Loc.initial, "`-mscrtlib` can only be used when targetting windows");
25422542
}
25432543

2544-
// Target uses 64bit pointers.
2545-
// FIXME: X32 is 64bit but uses 32 bit pointers
2546-
target.isLP64 = target.is64bit;
2547-
25482544
if (params.boundscheck != CHECKENABLE._default)
25492545
{
25502546
if (params.useArrayBounds == CHECKENABLE._default)

Diff for: ‎src/dmd/target.d

+4
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,16 @@ extern (C++) struct Target
191191
*/
192192
extern (C++) void _init(ref const Param params)
193193
{
194+
// is64bit, mscoff and cpu are initialized in parseCommandLine
195+
194196
this.params = &params;
195197

196198
FloatProperties.initialize();
197199
DoubleProperties.initialize();
198200
RealProperties.initialize();
199201

202+
isLP64 = is64bit;
203+
200204
// These have default values for 32 bit code, they get
201205
// adjusted for 64 bit code.
202206
ptrsize = 4;

Diff for: ‎src/tests/cxxfrontend.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,19 @@ static void frontend_init()
6767
gc_disable();
6868

6969
global._init();
70-
target.os = Target::OS_linux;
7170
global.vendor = "Front-End Tester";
7271
global.params.objname = NULL;
72+
73+
target.os = Target::OS_linux;
74+
target.is64bit = true;
7375
target.cpu = CPU::native;
76+
target._init(global.params);
7477

7578
Type::_init();
7679
Id::initialize();
7780
Module::_init();
7881
Expression::_init();
7982
Objc::_init();
80-
target._init(global.params);
8183
CTFloat::initialize();
8284
}
8385

@@ -525,12 +527,12 @@ void test_cppmangle()
525527
fd = (*cd->members)[0]->isFuncDeclaration();
526528
assert(fd);
527529
mangle = cppThunkMangleItanium(fd, b->offset);
528-
assert(strcmp(mangle, "_ZThn4_N7Derived9MethodCPPEv") == 0);
530+
assert(strcmp(mangle, "_ZThn8_N7Derived9MethodCPPEv") == 0);
529531

530532
fd = (*cd->members)[1]->isFuncDeclaration();
531533
assert(fd);
532534
mangle = cppThunkMangleItanium(fd, b->offset);
533-
assert(strcmp(mangle, "_ZThn4_N7Derived7MethodDEv") == 0);
535+
assert(strcmp(mangle, "_ZThn8_N7Derived7MethodDEv") == 0);
534536

535537
assert(!global.endGagging(errors));
536538
}

Diff for: ‎test/dub_package/frontend_file.d

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
dependency "dmd" path="../.."
44
+/
55
import std.stdio;
6+
import std.string : replace;
67

78
// test frontend
89
void main()
@@ -49,7 +50,7 @@ void main()
4950
import object;
5051
double average(int[] array)
5152
{
52-
immutable immutable(uint) initialLength = array.length;
53+
immutable immutable(SIZE_T) initialLength = array.length;
5354
double accumulator = 0.0;
5455
for (; array.length;)
5556
{
@@ -60,7 +61,7 @@ double average(int[] array)
6061
}
6162
return accumulator / cast(double)initialLength;
6263
}
63-
};
64+
}.replace("SIZE_T", size_t.sizeof == 8 ? "ulong" : "uint");
6465

6566
assert(generated.canFind(expected));
6667
}
@@ -73,6 +74,5 @@ This is required because this file is stored with Unix line endings but the
7374
*/
7475
string toUnixLineEndings(string str)
7576
{
76-
import std.string : replace;
7777
return str.replace("\r\n", "\n");
7878
}

0 commit comments

Comments
 (0)
Please sign in to comment.