From 685e31ce0c7cfc691d5ac07e9a84aa34762d944d Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Wed, 26 Feb 2020 19:01:18 +0100 Subject: [PATCH] Merge v2.091.0-beta.1 --- dmd/cli.d | 4 +- dmd/dtoh.d | 128 +++++++++++++++++++---------------------- dmd/globals.h | 2 +- dmd/hdrgen.h | 1 + dmd/iasmgcc.d | 55 ++++++++++++------ runtime/druntime | 2 +- runtime/phobos | 2 +- tests/d2/dmd-testsuite | 2 +- 8 files changed, 104 insertions(+), 92 deletions(-) diff --git a/dmd/cli.d b/dmd/cli.d index f049a2c4588..10ff4151d36 100644 --- a/dmd/cli.d +++ b/dmd/cli.d @@ -750,9 +750,9 @@ dmd -cov -unittest myprog.d Feature("dip1000", "vsafe", "implement https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md (Scoped Pointers)"), Feature("dip1008", "ehnogc", - "implement https://github.com/dlang/DIPs/blob/master/DIPs/DIP1008.md (@nogc Throwable)"), + "implement https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1008.md (@nogc Throwable)"), Feature("dip1021", "useDIP1021", - "implement https://github.com/dlang/DIPs/blob/master/DIPs/DIP1021.md (Mutable function arguments)"), + "implement https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md (Mutable function arguments)"), Feature("fieldwise", "fieldwise", "use fieldwise comparisons for struct equality"), Feature("markdown", "markdown", "enable Markdown replacements in Ddoc"), Feature("fixAliasThis", "fixAliasThis", diff --git a/dmd/dtoh.d b/dmd/dtoh.d index 86914221143..331f47149d8 100644 --- a/dmd/dtoh.d +++ b/dmd/dtoh.d @@ -22,12 +22,7 @@ import dmd.astcodegen; import dmd.arraytypes; import dmd.globals; import dmd.identifier; -import dmd.json; -import dmd.mars; -import dmd.root.array; -import dmd.root.file; import dmd.root.filename; -import dmd.root.rmem; import dmd.visitor; import dmd.tokens; @@ -44,6 +39,7 @@ private struct DMDType __gshared Identifier c_longlong; __gshared Identifier c_ulonglong; __gshared Identifier c_long_double; + __gshared Identifier c_wchar_t; __gshared Identifier AssocArray; __gshared Identifier Array; @@ -54,6 +50,7 @@ private struct DMDType c_longlong = Identifier.idPool("__c_longlong"); c_ulonglong = Identifier.idPool("__c_ulonglong"); c_long_double = Identifier.idPool("__c_long_double"); + c_wchar_t = Identifier.idPool("__c_wchar_t"); if (isBuildingCompiler) { @@ -176,6 +173,33 @@ private bool isFrontendModule(ASTCodegen.Module m) (m.parent.parent.ident == DMDModule.dmd && !m.parent.parent.parent)); } +private string translateBasicType(ubyte ty) +{ + import AST = dmd.mtype; + switch (ty) + { + case AST.Tvoid: return "void"; + case AST.Tbool: return "bool"; + case AST.Tchar: return "char"; + case AST.Twchar: return "char16_t"; + case AST.Tdchar: return "char32_t"; + case AST.Tint8: return "int8_t"; + case AST.Tuns8: return "uint8_t"; + case AST.Tint16: return "int16_t"; + case AST.Tuns16: return "uint16_t"; + case AST.Tint32: return "int32_t"; + case AST.Tuns32: return "uint32_t"; + case AST.Tint64: return "int64_t"; + case AST.Tuns64: return "uint64_t"; + case AST.Tfloat32: return "float"; + case AST.Tfloat64: return "double"; + case AST.Tfloat80: return "_d_real"; + default: + //t.print(); + assert(0); + } +} + private void initialize() { __gshared bool initialized; @@ -193,47 +217,24 @@ private void initialize() } } -void genCppHdrFiles(ref Modules ms) +extern(C++) void genCppHdrFiles(ref Modules ms) { initialize(); OutBuffer buf; - buf.writestring("#pragma once\n"); + buf.printf("// Automatically generated by %s Compiler v%d\n", global.vendor.ptr, global.versionNumber()); buf.writeByte('\n'); - buf.printf("// Automatically generated by dmd -HC\n"); + buf.writestring("#pragma once\n"); buf.writeByte('\n'); buf.writestring("#include \n"); buf.writestring("#include \n"); + buf.writestring("#include \n"); buf.writestring("#include \n"); buf.writestring("#include \n"); buf.writeByte('\n'); - buf.writestring("#define _d_void void\n"); - buf.writestring("#define _d_bool bool\n"); - buf.writestring("#define _d_byte signed char\n"); - buf.writestring("#define _d_ubyte unsigned char\n"); - buf.writestring("#define _d_short short\n"); - buf.writestring("#define _d_ushort unsigned short\n"); - buf.writestring("#define _d_int int\n"); - buf.writestring("#define _d_uint unsigned\n"); - if (global.params.isLP64) - { - buf.writestring("#define _d_long long\n"); - buf.writestring("#define _d_ulong unsigned long\n"); - } - else - { - buf.writestring("#define _d_long long long\n"); - buf.writestring("#define _d_ulong unsigned long long\n"); - } - buf.writestring("#define _d_float float\n"); - buf.writestring("#define _d_double double\n"); - buf.writestring("#define _d_real long double\n"); - buf.writestring("#define _d_char char\n"); - buf.writestring("#define _d_wchar wchar_t\n"); - buf.writestring("#define _d_dchar unsigned\n"); - buf.writestring("typedef _d_long d_int64;\n"); - buf.writestring("\n"); - buf.writestring("#define _d_null NULL\n"); + buf.writestring("#if !defined(_d_real)\n"); + buf.writestring("# define _d_real long double\n"); + buf.writestring("#endif\n"); buf.writestring("\n\n"); OutBuffer check; @@ -1005,8 +1006,8 @@ public: else { //printf("Using cpp 98\n"); - buf.writestring("typedef _d_"); - buf.writestring(ed.memtype.kind); + buf.writestring("typedef "); + buf.writestring(translateBasicType(ed.memtype.ty)); buf.writeByte(' '); buf.writestring(ident); buf.writestring(";\n"); @@ -1114,22 +1115,7 @@ public: } if (!cdparent && t.isConst()) buf.writestring("const "); - switch (t.ty) - { - case AST.Tbool, AST.Tvoid: - case AST.Tchar, AST.Twchar, AST.Tdchar: - case AST.Tint8, AST.Tuns8: - case AST.Tint16, AST.Tuns16: - case AST.Tint32, AST.Tuns32: - case AST.Tint64, AST.Tuns64: - case AST.Tfloat32, AST.Tfloat64, AST.Tfloat80: - buf.writestring("_d_"); - buf.writestring(t.dstring); - break; - default: - //t.print(); - assert(0); - } + buf.writestring(translateBasicType(t.ty)); } override void visit(AST.TypePointer t) @@ -1212,25 +1198,27 @@ public: } if (ed.isSpecial()) { - buf.writestring(ed.toChars()); + if (ed.ident == DMDType.c_long) + buf.writestring("long"); + else if (ed.ident == DMDType.c_ulong) + buf.writestring("unsigned long"); + else if (ed.ident == DMDType.c_longlong) + buf.writestring("long long"); + else if (ed.ident == DMDType.c_ulonglong) + buf.writestring("unsigned long long"); + else if (ed.ident == DMDType.c_long_double) + buf.writestring("long double"); + else if (ed.ident == DMDType.c_wchar_t) + buf.writestring("wchar_t"); + else + { + //ed.print(); + assert(0); + } return; } - if (ed.ident == DMDType.c_long) - buf.writestring("long"); - else if (ed.ident == DMDType.c_ulong) - buf.writestring("unsigned long"); - else if (ed.ident == DMDType.c_longlong) - buf.writestring("long long"); - else if (ed.ident == DMDType.c_ulonglong) - buf.writestring("unsigned long long"); - else if (ed.ident == DMDType.c_long_double) - buf.writestring("long double"); - else - { - //ed.print(); - assert(0); - } + buf.writestring(ed.toChars()); } override void visit(AST.TypeEnum t) @@ -1548,7 +1536,7 @@ public: printf("[AST.NullExp enter] %s\n", e.toChars()); scope(exit) printf("[AST.NullExp exit] %s\n", e.toChars()); } - buf.writestring("_d_null"); + buf.writestring("nullptr"); } override void visit(AST.ArrayLiteralExp e) diff --git a/dmd/globals.h b/dmd/globals.h index 510dd81eb70..cd40c854366 100644 --- a/dmd/globals.h +++ b/dmd/globals.h @@ -140,7 +140,7 @@ struct Param bool useInline; // inline expand functions bool useDIP25; // implement http://wiki.dlang.org/DIP25 bool noDIP25; // revert to pre-DIP25 behavior - bool useDIP1021; // implement https://github.com/dlang/DIPs/blob/master/DIPs/DIP1021.md + bool useDIP1021; // implement https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md bool release; // build release version bool preservePaths; // true means don't strip path from source file Diagnostic warnings; diff --git a/dmd/hdrgen.h b/dmd/hdrgen.h index 2478a656368..a945c77b4a7 100644 --- a/dmd/hdrgen.h +++ b/dmd/hdrgen.h @@ -16,5 +16,6 @@ class Module; void genhdrfile(Module *m); +void genCppHdrFiles(Modules &ms); void moduleToBuffer(OutBuffer *buf, Module *m); const char *parametersTypeToChars(ParameterList pl); diff --git a/dmd/iasmgcc.d b/dmd/iasmgcc.d index e568ab5238d..1ec228ca98d 100644 --- a/dmd/iasmgcc.d +++ b/dmd/iasmgcc.d @@ -67,7 +67,9 @@ int parseExtAsmOperands(Parser)(Parser p, GccAsmStatement s) case TOK.leftBracket: if (p.peekNext() == TOK.identifier) { + // Skip over opening `[` p.nextToken(); + // Store the symbolic name name = p.token.ident; p.nextToken(); } @@ -76,8 +78,13 @@ int parseExtAsmOperands(Parser)(Parser p, GccAsmStatement s) p.error(s.loc, "expected identifier after `[`"); goto Lerror; } + // Look for closing `]` p.check(TOK.rightBracket); - goto case; + // Look for the string literal and fall through + if (p.token.value == TOK.string_) + goto case; + else + goto default; case TOK.string_: constraint = p.parsePrimaryExp(); @@ -285,8 +292,7 @@ extern(C++) // IN_LLVM public Statement gccAsmSemantic(GccAsmStatement s, Scope *sc) { //printf("GccAsmStatement.semantic()\n"); - scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated); - scope p = new Parser!ASTCodegen(sc._module, ";", false, diagnosticReporter); + scope p = new Parser!ASTCodegen(sc._module, ";", false); // Make a safe copy of the token list before parsing. Token *toklist = null; @@ -303,8 +309,9 @@ public Statement gccAsmSemantic(GccAsmStatement s, Scope *sc) p.scanloc = s.loc; // Parse the gcc asm statement. + const errors = global.errors; s = p.parseGccAsm(s); - if (p.errors) + if (errors != global.errors) return null; s.stc = sc.stc; @@ -366,25 +373,41 @@ public Statement gccAsmSemantic(GccAsmStatement s, Scope *sc) unittest { + import dmd.mtype : TypeBasic; + uint errors = global.startGagging(); + scope(exit) global.endGagging(errors); + + // If this check fails, then Type._init() was called before reaching here, + // and the entire chunk of code that follows can be removed. + assert(ASTCodegen.Type.tint32 is null); + // Minimally initialize the cached types in ASTCodegen.Type, as they are + // dependencies for some fail asm tests to succeed. + ASTCodegen.Type.stringtable._init(); + scope(exit) + { + ASTCodegen.Type.deinitialize(); + ASTCodegen.Type.tint32 = null; + } + scope tint32 = new TypeBasic(ASTCodegen.Tint32); + ASTCodegen.Type.tint32 = tint32; - // Immitates asmSemantic if version = IN_GCC. + // Imitates asmSemantic if version = IN_GCC. static int semanticAsm(Token* tokens) { + const errors = global.errors; scope gas = new GccAsmStatement(Loc.initial, tokens); - scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated); - scope p = new Parser!ASTCodegen(null, ";", false, diagnosticReporter); + scope p = new Parser!ASTCodegen(null, ";", false); p.token = *tokens; p.parseGccAsm(gas); - return p.errors; + return global.errors - errors; } - // Immitates parseStatement for asm statements. + // Imitates parseStatement for asm statements. static void parseAsm(string input, bool expectError) { // Generate tokens from input test. - scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated); - scope p = new Parser!ASTCodegen(null, input, false, diagnosticReporter); + scope p = new Parser!ASTCodegen(null, input, false); p.nextToken(); Token* toklist = null; @@ -404,7 +427,8 @@ unittest p.check(TOK.rightCurly); auto res = semanticAsm(toklist); - assert(res == 0 || expectError); + // Checks for both unexpected passes and failures. + assert((res == 0) != expectError); } /// Assembly Tests, all should pass. @@ -455,7 +479,9 @@ unittest q{ asm { ""h; } }, - /+ Need a way to test without depending on Type._init() + // https://issues.dlang.org/show_bug.cgi?id=20592 + q{ asm { "nop" : [name] string (expr); } }, + // Expression expected, not ';' q{ asm { ""[; } }, @@ -465,7 +491,6 @@ unittest : : "g" a ? b : : c; } }, - +/ ]; foreach (test; passAsmTests) @@ -473,6 +498,4 @@ unittest foreach (test; failAsmTests) parseAsm(test, true); - - global.endGagging(errors); } diff --git a/runtime/druntime b/runtime/druntime index 6661c041b5f..474abc51b35 160000 --- a/runtime/druntime +++ b/runtime/druntime @@ -1 +1 @@ -Subproject commit 6661c041b5f4077035f392680f44722cb5d04d1b +Subproject commit 474abc51b35abba55f41f84638f7347ce7785b1f diff --git a/runtime/phobos b/runtime/phobos index dfe506e1f9b..8fc84b1adad 160000 --- a/runtime/phobos +++ b/runtime/phobos @@ -1 +1 @@ -Subproject commit dfe506e1f9b1b0fc7367c49d3861c777d6dfbd45 +Subproject commit 8fc84b1adad7ad06186cc1603a06ae278cf7e145 diff --git a/tests/d2/dmd-testsuite b/tests/d2/dmd-testsuite index c49f04021b3..8a05aef625a 160000 --- a/tests/d2/dmd-testsuite +++ b/tests/d2/dmd-testsuite @@ -1 +1 @@ -Subproject commit c49f04021b37ccaac7b709fca88a62b7a9f3ee94 +Subproject commit 8a05aef625ac4f39254c04c4c85e81253bdcd22c