d: Merge upstream dmd 5cc71ff83, druntime 1134b710

D front-end changes:

 - Fix ICEs that occurred when using opaque enums.

 - Update `pragma(printf)' checking code to work on 16-bit targets.

Phobos change:

 - Don't compile in argTypes code on AArch64

Reviewed-on: https://github.com/dlang/dmd/pull/12378
	     https://github.com/dlang/druntime/pull/3431

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd 5cc71ff83.

libphobos/ChangeLog:

	* libdruntime/MERGE: Merge upstream druntime 1134b710.
This commit is contained in:
Iain Buclaw
2021-04-05 14:05:28 +02:00
parent 406f58e1e3
commit dddf3bb0c3
13 changed files with 292 additions and 90 deletions

View File

@@ -1,4 +1,4 @@
3b808e838bb00f527eb4ed5281cd985756237b8f
5cc71ff830fcfba218152360014298550be9180e
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.

View File

@@ -610,7 +610,7 @@ bool checkPrintfFormat(const Loc &loc, const char *format, Expressions &args, bo
Type *t = e->type->toBasetype();
Type *tnext = t->nextOf();
const unsigned c_longsize = target.c.longsize;
const bool is64bit = global.params.is64bit;
const unsigned ptrsize = target.ptrsize;
// Types which are promoted to int are allowed.
// Spec: C99 6.5.2.2.7
@@ -619,46 +619,56 @@ bool checkPrintfFormat(const Loc &loc, const char *format, Expressions &args, bo
case Format_u: // unsigned int
case Format_d: // int
if (t->ty != Tint32 && t->ty != Tuns32)
errorPrintfFormat(NULL, slice, e, "int", t);
errorPrintfFormat(NULL, slice, e, fmt == Format_u ? "uint" : "int", t);
break;
case Format_hhu: // unsigned char
case Format_hhd: // signed char
if (t->ty != Tint32 && t->ty != Tuns32 && t->ty != Tint8 && t->ty != Tuns8)
errorPrintfFormat(NULL, slice, e, "byte", t);
errorPrintfFormat(NULL, slice, e, fmt == Format_hhu ? "ubyte" : "byte", t);
break;
case Format_hu: // unsigned short int
case Format_hd: // short int
if (t->ty != Tint32 && t->ty != Tuns32 && t->ty != Tint16 && t->ty != Tuns16)
errorPrintfFormat(NULL, slice, e, "short", t);
errorPrintfFormat(NULL, slice, e, fmt == Format_hu ? "ushort" : "short", t);
break;
case Format_lu: // unsigned long int
case Format_ld: // long int
if (!(t->isintegral() && t->size() == c_longsize))
errorPrintfFormat(NULL, slice, e, (c_longsize == 4 ? "int" : "long"), t);
{
if (fmt == Format_lu)
errorPrintfFormat(NULL, slice, e, (c_longsize == 4 ? "uint" : "ulong"), t);
else
errorPrintfFormat(NULL, slice, e, (c_longsize == 4 ? "int" : "long"), t);
}
break;
case Format_llu: // unsigned long long int
case Format_lld: // long long int
if (t->ty != Tint64 && t->ty != Tuns64)
errorPrintfFormat(NULL, slice, e, "long", t);
errorPrintfFormat(NULL, slice, e, fmt == Format_llu ? "ulong" : "long", t);
break;
case Format_ju: // uintmax_t
case Format_jd: // intmax_t
if (t->ty != Tint64 && t->ty != Tuns64)
errorPrintfFormat(NULL, slice, e, "core.stdc.stdint.intmax_t", t);
{
if (fmt == Format_ju)
errorPrintfFormat(NULL, slice, e, "core.stdc.stdint.uintmax_t", t);
else
errorPrintfFormat(NULL, slice, e, "core.stdc.stdint.intmax_t", t);
}
break;
case Format_zd: // size_t
if (!(t->isintegral() && t->size() == (is64bit ? 8 : 4)))
if (!(t->isintegral() && t->size() == ptrsize))
errorPrintfFormat(NULL, slice, e, "size_t", t);
break;
case Format_td: // ptrdiff_t
if (!(t->isintegral() && t->size() == (is64bit ? 8 : 4)))
if (!(t->isintegral() && t->size() == ptrsize))
errorPrintfFormat(NULL, slice, e, "ptrdiff_t", t);
break;
@@ -685,7 +695,7 @@ bool checkPrintfFormat(const Loc &loc, const char *format, Expressions &args, bo
break;
case Format_ln: // pointer to long int
if (!(t->ty == Tpointer && tnext->isintegral() && tnext->size() == c_longsize))
if (!(t->ty == Tpointer && tnext->isintegral() && !tnext->isunsigned() && tnext->size() == c_longsize))
errorPrintfFormat(NULL, slice, e, (c_longsize == 4 ? "int*" : "long*"), t);
break;
@@ -710,12 +720,12 @@ bool checkPrintfFormat(const Loc &loc, const char *format, Expressions &args, bo
break;
case Format_zn: // pointer to size_t
if (!(t->ty == Tpointer && tnext->ty == (is64bit ? Tuns64 : Tuns32)))
if (!(t->ty == Tpointer && tnext->isintegral() && tnext->isunsigned() && tnext->size() == ptrsize))
errorPrintfFormat(NULL, slice, e, "size_t*", t);
break;
case Format_tn: // pointer to ptrdiff_t
if (!(t->ty == Tpointer && tnext->ty == (is64bit ? Tint64 : Tint32)))
if (!(t->ty == Tpointer && tnext->isintegral() && !tnext->isunsigned() && tnext->size() == ptrsize))
errorPrintfFormat(NULL, slice, e, "ptrdiff_t*", t);
break;
@@ -845,7 +855,7 @@ bool checkScanfFormat(const Loc &loc, const char *format, Expressions &args, boo
Type *t = e->type->toBasetype();
Type *tnext = t->nextOf();
const unsigned c_longsize = target.c.longsize;
const bool is64bit = global.params.is64bit;
const unsigned ptrsize = target.ptrsize;
switch (fmt)
{
@@ -887,13 +897,13 @@ bool checkScanfFormat(const Loc &loc, const char *format, Expressions &args, boo
case Format_zn:
case Format_zd: // pointer to size_t
if (!(t->ty == Tpointer && tnext->ty == (is64bit ? Tuns64 : Tuns32)))
if (!(t->ty == Tpointer && tnext->isintegral() && tnext->isunsigned() && tnext->size() == ptrsize))
errorScanfFormat(NULL, slice, e, "size_t*", t);
break;
case Format_tn:
case Format_td: // pointer to ptrdiff_t
if (!(t->ty == Tpointer && tnext->ty == (is64bit ? Tint64 : Tint32)))
if (!(t->ty == Tpointer && tnext->isintegral() && !tnext->isunsigned() && tnext->size() == ptrsize))
errorScanfFormat(NULL, slice, e, "ptrdiff_t*", t);
break;
@@ -913,7 +923,7 @@ bool checkScanfFormat(const Loc &loc, const char *format, Expressions &args, boo
break;
case Format_lu: // pointer to unsigned long int
if (!(t->ty == Tpointer && tnext->ty == (is64bit ? Tuns64 : Tuns32)))
if (!(t->ty == Tpointer && tnext->isintegral() && tnext->isunsigned() && tnext->size() == c_longsize))
errorScanfFormat(NULL, slice, e, (c_longsize == 4 ? "uint*" : "ulong*"), t);
break;
@@ -923,7 +933,7 @@ bool checkScanfFormat(const Loc &loc, const char *format, Expressions &args, boo
break;
case Format_ju: // pointer to uintmax_t
if (!(t->ty == Tpointer && tnext->ty == (is64bit ? Tuns64 : Tuns32)))
if (!(t->ty == Tpointer && tnext->ty == Tuns64))
errorScanfFormat(NULL, slice, e, "ulong*", t);
break;

View File

@@ -122,7 +122,7 @@ Expression *EnumDeclaration::getMaxMinValue(Loc loc, Identifier *id)
dsymbolSemantic(this, _scope);
if (errors)
goto Lerrors;
if (semanticRun == PASSinit || !members)
if (!members)
{
if (isSpecial())
{
@@ -131,7 +131,7 @@ Expression *EnumDeclaration::getMaxMinValue(Loc loc, Identifier *id)
return memtype->getProperty(loc, id, 0);
}
error("is forward referenced looking for .%s", id->toChars());
error(loc, "is opaque and has no `.%s`", id->toChars());
goto Lerrors;
}
if (!(memtype && memtype->isintegral()))
@@ -148,12 +148,21 @@ Expression *EnumDeclaration::getMaxMinValue(Loc loc, Identifier *id)
if (!em)
continue;
if (em->errors)
goto Lerrors;
{
errors = true;
continue;
}
if (em->semanticRun < PASSsemanticdone)
{
em->error("is forward referenced looking for `.%s`", id->toChars());
errors = true;
continue;
}
Expression *e = em->value();
if (first)
{
*pval = e;
*pval = em->value();
first = false;
}
else
@@ -168,15 +177,23 @@ Expression *EnumDeclaration::getMaxMinValue(Loc loc, Identifier *id)
* if (e > maxval)
* maxval = e;
*/
Expression *e = em->value();
Expression *ec = new CmpExp(id == Id::max ? TOKgt : TOKlt, em->loc, e, *pval);
inuse++;
ec = expressionSemantic(ec, em->_scope);
inuse--;
ec = ec->ctfeInterpret();
if (ec->op == TOKerror)
{
errors = true;
continue;
}
if (ec->toInteger())
*pval = e;
}
}
if (errors)
goto Lerrors;
Ldone:
{
Expression *e = *pval;
@@ -213,16 +230,17 @@ Expression *EnumDeclaration::getDefaultValue(Loc loc)
dsymbolSemantic(this, _scope);
if (errors)
goto Lerrors;
if (semanticRun == PASSinit || !members)
if (!members)
{
if (isSpecial())
{
/* Allow these special enums to not need a member list
*/
return memtype->defaultInit(loc);
defaultval = memtype->defaultInit(loc);
return defaultval;
}
error(loc, "forward reference of %s.init", toChars());
error(loc, "is opaque and has no default initializer");
goto Lerrors;
}
@@ -231,6 +249,12 @@ Expression *EnumDeclaration::getDefaultValue(Loc loc)
EnumMember *em = (*members)[i]->isEnumMember();
if (em)
{
if (em->semanticRun < PASSsemanticdone)
{
error(loc, "forward reference of `%s.init`", toChars());
goto Lerrors;
}
defaultval = em->value();
return defaultval;
}
@@ -252,15 +276,10 @@ Type *EnumDeclaration::getMemtype(Loc loc)
*/
if (memtype)
memtype = typeSemantic(memtype, loc, _scope);
else
{
if (!isAnonymous() && members)
memtype = Type::tint32;
}
}
if (!memtype)
{
if (!isAnonymous() && members)
if (!isAnonymous() && (members || semanticRun >= PASSsemanticdone))
memtype = Type::tint32;
else
{
@@ -307,13 +326,6 @@ Dsymbol *EnumDeclaration::search(const Loc &loc, Identifier *ident, int flags)
dsymbolSemantic(this, _scope);
}
if (!members || !symtab || _scope)
{
error("is forward referenced when looking for `%s`", ident->toChars());
//*(char*)0=0;
return NULL;
}
Dsymbol *s = ScopeDsymbol::search(loc, ident, flags);
return s;
}

View File

@@ -415,7 +415,19 @@ public:
TypeStruct *ts = (TypeStruct *)tb;
if (!ts->sym->members)
{
dsym->error("no definition of struct %s", ts->toChars());
dsym->error("no definition of struct `%s`", ts->toChars());
// Explain why the definition is required when it's part of another type
if (!dsym->type->isTypeStruct())
{
// Prefer Loc of the dependant type
Dsymbol *s = dsym->type->toDsymbol(sc);
Loc loc = s ? s->loc : dsym->loc;
errorSupplemental(loc, "required by type `%s`", dsym->type->toChars());
}
// Flag variable as error to avoid invalid error messages due to unknown size
dsym->type = Type::terror;
}
}
if ((dsym->storage_class & STCauto) && !inferred)
@@ -1737,6 +1749,9 @@ public:
ed->semanticRun = PASSinit;
return;
}
else
// Ensure that semantic is run to detect. e.g. invalid forward references
dsymbolSemantic(sym, sc);
}
if (ed->memtype->ty == Tvoid)
{

View File

@@ -6806,23 +6806,6 @@ Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident, int fl
if (sym->semanticRun < PASSsemanticdone)
dsymbolSemantic(sym, NULL);
if (!sym->members)
{
if (sym->isSpecial())
{
/* Special enums forward to the base type
*/
e = sym->memtype->dotExp(sc, e, ident, flag);
}
else if (!(flag & 1))
{
sym->error("is forward referenced when looking for `%s`", ident->toChars());
e = new ErrorExp();
}
else
e = NULL;
return e;
}
Dsymbol *s = sym->search(e->loc, ident);
if (!s)

View File

@@ -0,0 +1,5 @@
enum E1 : int;
static assert(is(E1 e == enum) && is(e == int));
enum E2;
static assert(is(E2 e == enum));

View File

@@ -36,7 +36,7 @@ fail_compilation/chkformat.d(214): Deprecation: argument `0` for format specific
fail_compilation/chkformat.d(215): Deprecation: argument `0` for format specification `"%hhu"` must be `ubyte*`, not `int`
fail_compilation/chkformat.d(216): Deprecation: argument `0` for format specification `"%hu"` must be `ushort*`, not `int`
fail_compilation/chkformat.d(218): Deprecation: argument `0` for format specification `"%llu"` must be `ulong*`, not `int`
fail_compilation/chkformat.d(219): Deprecation: argument `0` for format specification `"%ju"` must be `ulong*`, not `int`
fail_compilation/chkformat.d(219): Deprecation: argument `0` for format specification `"%ju"` must be `core.stdc.stdint.uintmax_t*`, not `int`
fail_compilation/chkformat.d(220): Deprecation: argument `0` for format specification `"%zu"` must be `size_t*`, not `int`
fail_compilation/chkformat.d(221): Deprecation: argument `0` for format specification `"%tu"` must be `ptrdiff_t*`, not `int`
fail_compilation/chkformat.d(222): Deprecation: argument `8.0L` for format specification `"%g"` must be `float*`, not `real`
@@ -137,3 +137,35 @@ void test302() { va_list vargs; vscanf("%Q", vargs); }
//void test() { vscanf(); }
//void test() { vfscanf(); }
//void test() { vsscanf(); }
/* TEST_OUTPUT:
---
fail_compilation/chkformat.d(401): Deprecation: argument `p` for format specification `"%u"` must be `uint`, not `char*`
fail_compilation/chkformat.d(402): Deprecation: argument `p` for format specification `"%d"` must be `int`, not `char*`
fail_compilation/chkformat.d(403): Deprecation: argument `p` for format specification `"%hhu"` must be `ubyte`, not `char*`
fail_compilation/chkformat.d(404): Deprecation: argument `p` for format specification `"%hhd"` must be `byte`, not `char*`
fail_compilation/chkformat.d(405): Deprecation: argument `p` for format specification `"%hu"` must be `ushort`, not `char*`
fail_compilation/chkformat.d(406): Deprecation: argument `p` for format specification `"%hd"` must be `short`, not `char*`
fail_compilation/chkformat.d(407): Deprecation: argument `p` for format specification `"%lu"` must be `$?:windows=uint|32=uint|64=ulong$`, not `char*`
fail_compilation/chkformat.d(408): Deprecation: argument `p` for format specification `"%ld"` must be `$?:windows=int|32=int|64=long$`, not `char*`
fail_compilation/chkformat.d(409): Deprecation: argument `p` for format specification `"%llu"` must be `ulong`, not `char*`
fail_compilation/chkformat.d(410): Deprecation: argument `p` for format specification `"%lld"` must be `long`, not `char*`
fail_compilation/chkformat.d(411): Deprecation: argument `p` for format specification `"%ju"` must be `core.stdc.stdint.uintmax_t`, not `char*`
fail_compilation/chkformat.d(412): Deprecation: argument `p` for format specification `"%jd"` must be `core.stdc.stdint.intmax_t`, not `char*`
---
*/
#line 400
void test401() { char* p; printf("%u", p); }
void test402() { char* p; printf("%d", p); }
void test403() { char* p; printf("%hhu", p); }
void test404() { char* p; printf("%hhd", p); }
void test405() { char* p; printf("%hu", p); }
void test406() { char* p; printf("%hd", p); }
void test407() { char* p; printf("%lu", p); }
void test408() { char* p; printf("%ld", p); }
void test409() { char* p; printf("%llu", p); }
void test410() { char* p; printf("%lld", p); }
void test411() { char* p; printf("%ju", p); }
void test412() { char* p; printf("%jd", p); }

View File

@@ -0,0 +1,171 @@
/*
https://issues.dlang.org/show_bug.cgi?id=8511
TEST_OUTPUT:
---
fail_compilation/enum_init.d(5): Error: type `SQRTMAX` has no value
---
*/
#line 1
real hypot()
{
enum SQRTMAX;
SQRTMAX/2;
}
/*
https://issues.dlang.org/show_bug.cgi?id=21785
TEST_OUTPUT:
---
fail_compilation/enum_init.d(106): Error: enum `enum_init.NoBase` is opaque and has no default initializer
---
*/
#line 100
enum NoBase;
void fooNB()
{
NoBase nbv = void;
NoBase nb;
}
/*
https://issues.dlang.org/show_bug.cgi?id=21785
TEST_OUTPUT:
---
fail_compilation/enum_init.d(206): Error: enum `enum_init.Xobj` is opaque and has no default initializer
---
*/
#line 200
enum Xobj : void*;
void main()
{
Xobj vv = void;
Xobj var;
}
/*
https://issues.dlang.org/show_bug.cgi?id=21785
TEST_OUTPUT:
---
fail_compilation/enum_init.d(306): Error: variable `enum_init.fooOB.ob` no definition of struct `S`
fail_compilation/enum_init.d(302): required by type `OpaqueBase`
---
*/
#line 300
struct S;
enum OpaqueBase : S;
void fooOB()
{
OpaqueBase ob;
}
/*
TEST_OUTPUT:
---
fail_compilation/enum_init.d(405): Error: enum `enum_init.forwardRef.Foo` forward reference of `Foo.init`
---
*/
#line 400
void forwardRef()
{
enum Foo
{
a = Foo.init
}
}
/*
https://issues.dlang.org/show_bug.cgi?id=21792
TEST_OUTPUT:
---
fail_compilation/enum_init.d(503): Error: circular reference to enum base type `Bar`
---
*/
#line 500
void forwardRef2()
{
enum Bar : Bar
{
a
}
}
/*
TEST_OUTPUT:
---
fail_compilation/enum_init.d(606): Error: enum member `enum_init.forwardRef3.Foo.b` is forward referenced looking for `.min`
fail_compilation/enum_init.d(607): Error: enum member `enum_init.forwardRef3.Foo.c` is forward referenced looking for `.min`
---
*/
#line 600
void forwardRef3()
{
enum Foo
{
a,
b = Foo.min,
c
}
}
/*
TEST_OUTPUT:
---
fail_compilation/enum_init.d(711): Error: circular reference to enum base type `int[Bar.sizeof]`
---
*/
#line 700
void forwardRef4()
{
enum Foo
{
a = Foo.sizeof,
c
}
// pragma(msg, typeof(Foo.sizeof));
// static assert(is(Foo Base == enum) && is(Base == int));
enum Bar : int[Bar.sizeof]
{
a
}
}
/*
TEST_OUTPUT:
---
fail_compilation/enum_init.d(809): Error: enum `enum_init.opaqueProperties.Foo` is opaque and has no default initializer
fail_compilation/enum_init.d(810): Error: enum `enum_init.opaqueProperties.Foo` is opaque and has no `.min`
fail_compilation/enum_init.d(811): Error: enum `enum_init.opaqueProperties.Foo` is opaque and has no `.max`
---
*/
#line 800
void opaqueProperties()
{
enum Foo;
// Valid
enum size = Foo.sizeof;
enum s = Foo.mangleof;
Foo f = Foo.init;
int min = Foo.min;
int max = Foo.max;
}

View File

@@ -53,10 +53,10 @@ enum B
/* Bugzilla 11849
TEST_OUTPUT:
---
fail_compilation/fail109.d(72): Error: enum fail109.RegValueType1a recursive definition of `.max` property
fail_compilation/fail109.d(79): Error: enum fail109.RegValueType1b recursive definition of `.max` property
fail_compilation/fail109.d(84): Error: enum fail109.RegValueType2a recursive definition of `.min` property
fail_compilation/fail109.d(91): Error: enum fail109.RegValueType2b recursive definition of `.min` property
fail_compilation/fail109.d(72): Error: enum member `fail109.RegValueType1a.Unknown` is forward referenced looking for `.max`
fail_compilation/fail109.d(79): Error: enum member `fail109.RegValueType1b.Unknown` is forward referenced looking for `.max`
fail_compilation/fail109.d(84): Error: enum member `fail109.RegValueType2a.Unknown` is forward referenced looking for `.min`
fail_compilation/fail109.d(91): Error: enum member `fail109.RegValueType2b.Unknown` is forward referenced looking for `.min`
---
*/

View File

@@ -1,13 +0,0 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice10770.d(13): Error: enum ice10770.E2 is forward referenced looking for base type
fail_compilation/ice10770.d(13): while evaluating: `static assert(is(E2 e == enum))`
---
*/
enum E1 : int;
static assert(is(E1 e == enum) && is(e == int));
enum E2;
static assert(is(E2 e == enum));

View File

@@ -1,13 +0,0 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice8511.d(11): Error: enum ice8511.hypot.SQRTMAX is forward referenced looking for base type
fail_compilation/ice8511.d(12): Error: incompatible types for ((SQRTMAX) / (2)): cannot use '/' with types
---
*/
real hypot()
{
enum SQRTMAX;
SQRTMAX/2;
}

View File

@@ -1,4 +1,4 @@
483bc12977af3c1288fd52e7b4fa14b716896c5a
1134b71039881464e9bf021836d82796b3a1fcfc
The first line of this file holds the git revision number of the last
merge done from the dlang/druntime repository.

View File

@@ -42,7 +42,7 @@ else version (X86_64)
else version (Windows) { /* no need for Win64 ABI */ }
else version = WithArgTypes;
}
version (AArch64)
else version (AArch64)
{
// Apple uses a trivial varargs implementation
version (OSX) {}