Skip to content

Commit 2dc6c9d

Browse files
authored
Merge pull request #11091 from kinke/valist
[stable] Prevent redundant type semantic for va_list merged-on-behalf-of: Iain Buclaw <ibuclaw@gdcproject.org>
2 parents e37e1be + f845d50 commit 2dc6c9d

File tree

7 files changed

+25
-17
lines changed

7 files changed

+25
-17
lines changed

Diff for: src/dmd/astbase.d

+1-3
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,6 @@ struct ASTBase
26862686
extern (C++) __gshared Type tstring; // immutable(char)[]
26872687
extern (C++) __gshared Type twstring; // immutable(wchar)[]
26882688
extern (C++) __gshared Type tdstring; // immutable(dchar)[]
2689-
extern (C++) __gshared Type tvalist; // va_list alias
26902689
extern (C++) __gshared Type terror; // for error recovery
26912690
extern (C++) __gshared Type tnull; // for null type
26922691

@@ -2847,7 +2846,6 @@ struct ASTBase
28472846
tstring = tchar.immutableOf().arrayOf();
28482847
twstring = twchar.immutableOf().arrayOf();
28492848
tdstring = tdchar.immutableOf().arrayOf();
2850-
tvalist = Target.va_listType();
28512849

28522850
const isLP64 = global.params.isLP64;
28532851

@@ -6518,7 +6516,7 @@ struct ASTBase
65186516
{
65196517
extern (C++) __gshared int ptrsize;
65206518

6521-
extern (C++) static Type va_listType()
6519+
extern (C++) static Type va_listType(const ref Loc loc, Scope* sc)
65226520
{
65236521
if (global.params.isWindows)
65246522
{

Diff for: src/dmd/dsymbolsem.d

+1-2
Original file line numberDiff line numberDiff line change
@@ -3498,8 +3498,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
34983498

34993499
bool isVa_list(Parameter p)
35003500
{
3501-
Type.tvalist = Type.tvalist.typeSemantic(funcdecl.loc, sc);
3502-
return p.type.equals(Type.tvalist);
3501+
return p.type.equals(target.va_listType(funcdecl.loc, sc));
35033502
}
35043503

35053504
const nparams = f.parameterList.length;

Diff for: src/dmd/mtype.d

-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ extern (C++) abstract class Type : ASTNode
440440
extern (C++) __gshared Type tstring; // immutable(char)[]
441441
extern (C++) __gshared Type twstring; // immutable(wchar)[]
442442
extern (C++) __gshared Type tdstring; // immutable(dchar)[]
443-
extern (C++) __gshared Type tvalist; // va_list alias
444443
extern (C++) __gshared Type terror; // for error recovery
445444
extern (C++) __gshared Type tnull; // for null type
446445

@@ -891,7 +890,6 @@ extern (C++) abstract class Type : ASTNode
891890
tstring = tchar.immutableOf().arrayOf();
892891
twstring = twchar.immutableOf().arrayOf();
893892
tdstring = tdchar.immutableOf().arrayOf();
894-
tvalist = target.va_listType();
895893

896894
const isLP64 = global.params.isLP64;
897895

Diff for: src/dmd/mtype.h

-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ class Type : public ASTNode
189189
static Type *tstring; // immutable(char)[]
190190
static Type *twstring; // immutable(wchar)[]
191191
static Type *tdstring; // immutable(dchar)[]
192-
static Type *tvalist; // va_list alias
193192
static Type *terror; // for error recovery
194193
static Type *tnull; // for null type
195194

Diff for: src/dmd/semantic3.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
401401
if (f.linkage == LINK.d || f.parameterList.length)
402402
{
403403
// Declare _argptr
404-
Type t = Type.tvalist;
404+
Type t = target.va_listType(funcdecl.loc, sc);
405405
// Init is handled in FuncDeclaration_toObjFile
406406
funcdecl.v_argptr = new VarDeclaration(funcdecl.loc, t, Id._argptr, new VoidInitializer(funcdecl.loc));
407407
funcdecl.v_argptr.storage_class |= STC.temp;

Diff for: src/dmd/target.d

+17-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import dmd.cppmangle;
3131
import dmd.cppmanglewin;
3232
import dmd.dclass;
3333
import dmd.declaration;
34+
import dmd.dscope;
3435
import dmd.dstruct;
3536
import dmd.dsymbol;
3637
import dmd.expression;
@@ -106,6 +107,8 @@ extern (C++) struct Target
106107
FPTypeProperties!double DoubleProperties; ///
107108
FPTypeProperties!real_t RealProperties; ///
108109

110+
private Type va_list; // cached lazy result of va_listType()
111+
109112
/**
110113
* Initialize the Target
111114
*/
@@ -250,34 +253,41 @@ extern (C++) struct Target
250253
}
251254

252255
/**
253-
* Type for the `va_list` type for the target.
256+
* Type for the `va_list` type for the target; e.g., required for `_argptr`
257+
* declarations.
254258
* NOTE: For Posix/x86_64 this returns the type which will really
255259
* be used for passing an argument of type va_list.
256260
* Returns:
257261
* `Type` that represents `va_list`.
258262
*/
259-
extern (C++) Type va_listType()
263+
extern (C++) Type va_listType(const ref Loc loc, Scope* sc)
260264
{
265+
if (va_list)
266+
return va_list;
267+
261268
if (global.params.isWindows)
262269
{
263-
return Type.tchar.pointerTo();
270+
va_list = Type.tchar.pointerTo();
264271
}
265-
else if (global.params.isLinux || global.params.isFreeBSD || global.params.isOpenBSD || global.params.isDragonFlyBSD ||
266-
global.params.isSolaris || global.params.isOSX)
272+
else if (global.params.isLinux || global.params.isFreeBSD || global.params.isOpenBSD ||
273+
global.params.isDragonFlyBSD || global.params.isSolaris || global.params.isOSX)
267274
{
268275
if (global.params.is64bit)
269276
{
270-
return (new TypeIdentifier(Loc.initial, Identifier.idPool("__va_list_tag"))).pointerTo();
277+
va_list = new TypeIdentifier(Loc.initial, Identifier.idPool("__va_list_tag")).pointerTo();
278+
va_list = typeSemantic(va_list, loc, sc);
271279
}
272280
else
273281
{
274-
return Type.tchar.pointerTo();
282+
va_list = Type.tchar.pointerTo();
275283
}
276284
}
277285
else
278286
{
279287
assert(0);
280288
}
289+
290+
return va_list;
281291
}
282292

283293
/**

Diff for: src/dmd/target.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,16 @@ struct Target
8989
FPTypeProperties<double> DoubleProperties;
9090
FPTypeProperties<real_t> RealProperties;
9191

92+
private:
93+
Type *va_list;
94+
95+
public:
9296
void _init(const Param& params);
9397
// Type sizes and support.
9498
unsigned alignsize(Type *type);
9599
unsigned fieldalign(Type *type);
96100
unsigned critsecsize();
97-
Type *va_listType(); // get type of va_list
101+
Type *va_listType(const Loc &loc, Scope *sc); // get type of va_list
98102
int isVectorTypeSupported(int sz, Type *type);
99103
bool isVectorOpSupported(Type *type, TOK op, Type *t2 = NULL);
100104
// ABI and backend.

0 commit comments

Comments
 (0)