From 519653d17ed0319e1154a15d34381fb0919793b1 Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 10 Oct 2022 05:19:44 +0200 Subject: [PATCH 1/7] Cache TypeStruct hasXXX methods (#14533) --- compiler/src/dmd/aggregate.h | 2 +- compiler/src/dmd/dstruct.d | 29 ++++++++++++++++++++++++++- compiler/src/dmd/frontend.h | 10 ++++++++- compiler/src/dmd/mtype.d | 39 ++++++------------------------------ 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/compiler/src/dmd/aggregate.h b/compiler/src/dmd/aggregate.h index 5e03c41751..d4432b513c 100644 --- a/compiler/src/dmd/aggregate.h +++ b/compiler/src/dmd/aggregate.h @@ -174,7 +174,7 @@ public: structalign_t alignment; // alignment applied outside of the struct ThreeState ispod; // if struct is POD private: - uint8_t bitFields; + uint16_t bitFields; public: static StructDeclaration *create(const Loc &loc, Identifier *id, bool inObject); StructDeclaration *syntaxCopy(Dsymbol *s) override; diff --git a/compiler/src/dmd/dstruct.d b/compiler/src/dmd/dstruct.d index 4126a8adc6..95f435275d 100644 --- a/compiler/src/dmd/dstruct.d +++ b/compiler/src/dmd/dstruct.d @@ -216,6 +216,10 @@ extern (C++) class StructDeclaration : AggregateDeclaration bool hasIdentityEquals; // true if has identity opEquals bool hasNoFields; // has no fields bool hasCopyCtor; // copy constructor + bool hasPointerField; // members with indirections + bool hasVoidInitPointers; // void-initialized unsafe fields + bool hasFieldWithInvariant; // invariants + bool computedTypeProperties;// the above 3 fields are computed // Even if struct is defined as non-root symbol, some built-in operations // (e.g. TypeidExp, NewExp, ArrayLiteralExp, etc) request its TypeInfo. // For those, today TypeInfo_Struct is generated in COMDAT. @@ -223,7 +227,7 @@ extern (C++) class StructDeclaration : AggregateDeclaration } import dmd.common.bitfields : generateBitFields; - mixin(generateBitFields!(BitFields, ubyte)); + mixin(generateBitFields!(BitFields, ushort)); extern (D) this(const ref Loc loc, Identifier id, bool inObject) { @@ -391,9 +395,32 @@ extern (C++) class StructDeclaration : AggregateDeclaration } } + argTypes = target.toArgTypes(type); } + /// Compute cached type properties for `TypeStruct` + extern(D) final void determineTypeProperties() + { + if (computedTypeProperties) + return; + foreach (vd; fields) + { + if (vd.storage_class & STC.ref_ || vd.hasPointers()) + hasPointerField = true; + + if (vd._init && vd._init.isVoidInitializer() && vd.type.hasPointers()) + hasVoidInitPointers = true; + + if (!vd._init && vd.type.hasVoidInitPointers()) + hasVoidInitPointers = true; + + if (vd.type.hasInvariant()) + hasFieldWithInvariant = true; + } + computedTypeProperties = true; + } + /*************************************** * Determine if struct is POD (Plain Old Data). * diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index 914b860e57..85ac98cece 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -6309,10 +6309,18 @@ public: bool hasNoFields(bool v); bool hasCopyCtor() const; bool hasCopyCtor(bool v); + bool hasPointerField() const; + bool hasPointerField(bool v); + bool hasVoidInitPointers() const; + bool hasVoidInitPointers(bool v); + bool hasFieldWithInvariant() const; + bool hasFieldWithInvariant(bool v); + bool computedTypeProperties() const; + bool computedTypeProperties(bool v); bool requestTypeInfo() const; bool requestTypeInfo(bool v); private: - uint8_t bitFields; + uint16_t bitFields; public: static StructDeclaration* create(const Loc& loc, Identifier* id, bool inObject); StructDeclaration* syntaxCopy(Dsymbol* s) override; diff --git a/compiler/src/dmd/mtype.d b/compiler/src/dmd/mtype.d index 1240f5a8a9..6c65f3ae9b 100644 --- a/compiler/src/dmd/mtype.d +++ b/compiler/src/dmd/mtype.d @@ -5532,52 +5532,25 @@ extern (C++) final class TypeStruct : Type override bool hasPointers() { - // Probably should cache this information in sym rather than recompute - StructDeclaration s = sym; - if (sym.members && !sym.determineFields() && sym.type != Type.terror) error(sym.loc, "no size because of forward references"); - foreach (VarDeclaration v; s.fields) - { - if (v.storage_class & STC.ref_ || v.hasPointers()) - return true; - } - return false; + sym.determineTypeProperties(); + return sym.hasPointerField; } override bool hasVoidInitPointers() { - // Probably should cache this information in sym rather than recompute - StructDeclaration s = sym; - sym.size(Loc.initial); // give error for forward references - foreach (VarDeclaration v; s.fields) - { - if (v._init && v._init.isVoidInitializer() && v.type.hasPointers()) - return true; - if (!v._init && v.type.hasVoidInitPointers()) - return true; - } - return false; + sym.determineTypeProperties(); + return sym.hasVoidInitPointers; } override bool hasInvariant() { - // Probably should cache this information in sym rather than recompute - StructDeclaration s = sym; - sym.size(Loc.initial); // give error for forward references - - if (s.hasInvariant()) - return true; - - foreach (VarDeclaration v; s.fields) - { - if (v.type.hasInvariant()) - return true; - } - return false; + sym.determineTypeProperties(); + return sym.hasInvariant() || sym.hasFieldWithInvariant; } extern (D) MATCH implicitConvToWithoutAliasThis(Type to) From b3dc2e0621f36e714b722f10982a02b5400231d6 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Sun, 9 Oct 2022 20:39:03 -0700 Subject: [PATCH 2/7] dcgcv.d add out of memory checks (#14535) --- compiler/src/dmd/backend/dcgcv.d | 54 ++++++++++---------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/compiler/src/dmd/backend/dcgcv.d b/compiler/src/dmd/backend/dcgcv.d index 26e2159ba0..ed64b93220 100644 --- a/compiler/src/dmd/backend/dcgcv.d +++ b/compiler/src/dmd/backend/dcgcv.d @@ -251,7 +251,9 @@ debtyp_t * debtyp_alloc(uint length) length += pad; } - length < 0x10000 || assert(0); + if (length > ushort.max) + err_nomem(); + const len = debtyp_t.sizeof - (d.data).sizeof + length; debug { @@ -262,6 +264,8 @@ debug else { d = cast(debtyp_t *) malloc(debtyp_t.sizeof - (d.data).sizeof + length); + if (!d) + err_nomem(); } d.length = cast(ushort)length; if (pad) @@ -284,7 +288,7 @@ private void debtyp_free(debtyp_t *d) //fflush(stdout); debug { - assert(d.length < 0x10000); + assert(d.length <= ushort.max); uint len = debtyp_t.sizeof - (d.data).sizeof + d.length; // assert((cast(char*)d)[len] == 0x2E); memset(d, 0x55, len); @@ -325,56 +329,27 @@ void debtyp_check(debtyp_t* d) { } @trusted idx_t cv_debtyp(debtyp_t *d) { - ushort length; uint hashi; assert(d); - length = d.length; + const length = d.length; //printf("length = %3d\n",length); static if (SYMDEB_TDB) { if (config.fulltypes == CVTDB) { - idx_t result; - -static if (1) -{ assert(length); debtyp_check(d); - result = tdb_typidx(&d.length); -} -else -{ - ubyte *buf; + const result = tdb_typidx(&d.length); - // Allocate buffer - buf = malloc(6 + length); - if (!buf) - err_nomem(); // out of memory - - // Fill the buffer - TOLONG(buf,cgcv.signature); - memcpy(buf + 4,cast(char *)d + uint.sizeof,2 + length); - -static if (0) -{ -{int i; - for (i=0;i= uint.sizeof) { // Hash consists of the sum of the first 4 bytes with the last 4 bytes @@ -607,7 +582,8 @@ static if (SYMDEB_TDB) pstate.STtdbtimestamp = tdb_gettimestamp(); size_t len = cv_stringbytes(ftdbname); ubyte *ds = (8 + len <= buf.sizeof) ? buf : cast(ubyte *) malloc(8 + len); - assert(ds); + if (!ds) + err_nomem(); TOWORD(ds,6 + len); TOWORD(ds + 2,S_TDBNAME); TOLONG(ds + 4,pstate.STtdbtimestamp); @@ -2507,7 +2483,8 @@ else // Length of record length = 2 + 2 + 4 * 3 + _tysize[TYint] * 4 + 2 + cgcv.sz_idx + 1; debsym = (length + len <= (buf).sizeof) ? buf.ptr : cast(ubyte *) malloc(length + len); - assert(debsym); + if (!debsym) + err_nomem(); memset(debsym,0,length + len); // Symbol type @@ -2586,7 +2563,8 @@ else } len = cast(uint)strlen(id); debsym = (39 + IDOHD + len <= (buf).sizeof) ? buf.ptr : cast(ubyte *) malloc(39 + IDOHD + len); - assert(debsym); + if (!debsym) + err_nomem(); switch (s.Sclass) { case SC.parameter: From b2db9ad9578136f4d6cdfae2138287c7a1fc7e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ferreira?= Date: Mon, 10 Oct 2022 04:42:01 +0100 Subject: [PATCH 3/7] chore(pre-commit): update pre-commit hooks (#14534) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hook 'sirosen/check-jsonschema' updated from 0.17.1 to 0.18.3. Signed-off-by: Luís Ferreira Signed-off-by: Luís Ferreira --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d9d88dff1..51e5e2f7d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,6 +20,6 @@ repos: - id: no-commit-to-branch args: [--branch, master] - repo: https://github.com/sirosen/check-jsonschema - rev: 0.17.1 + rev: 0.18.3 hooks: - id: check-github-workflows From 5fd7882271c4597c759db4f67ff8570329a4904e Mon Sep 17 00:00:00 2001 From: Razvan Nitu Date: Mon, 10 Oct 2022 08:15:49 +0300 Subject: [PATCH 4/7] Fix Issue 14694 - Functions nested within functions need their body inside the generated .di file (#14529) --- compiler/src/dmd/frontend.h | 5 ++++- compiler/src/dmd/hdrgen.d | 17 +++++++++++++++-- .../test/compilable/extra-files/header1.di | 19 ++++++++++++++++++- .../test/compilable/extra-files/header2.d | 12 ++++++++++++ .../test/compilable/extra-files/header2.di | 15 +++++++++++++++ .../test/compilable/extra-files/header2i.di | 15 +++++++++++++++ 6 files changed, 79 insertions(+), 4 deletions(-) diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index 85ac98cece..6d477da73a 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -3214,6 +3214,7 @@ struct HdrGenState final int32_t tpltMember; int32_t autoMember; int32_t forStmtInit; + int32_t insideFuncBody; bool declstring; EnumDeclaration* inEnumDecl; HdrGenState() : @@ -3224,11 +3225,12 @@ struct HdrGenState final tpltMember(), autoMember(), forStmtInit(), + insideFuncBody(), declstring(), inEnumDecl() { } - HdrGenState(bool hdrgen, bool ddoc = false, bool fullDump = false, bool fullQual = false, int32_t tpltMember = 0, int32_t autoMember = 0, int32_t forStmtInit = 0, bool declstring = false, EnumDeclaration* inEnumDecl = nullptr) : + HdrGenState(bool hdrgen, bool ddoc = false, bool fullDump = false, bool fullQual = false, int32_t tpltMember = 0, int32_t autoMember = 0, int32_t forStmtInit = 0, int32_t insideFuncBody = 0, bool declstring = false, EnumDeclaration* inEnumDecl = nullptr) : hdrgen(hdrgen), ddoc(ddoc), fullDump(fullDump), @@ -3236,6 +3238,7 @@ struct HdrGenState final tpltMember(tpltMember), autoMember(autoMember), forStmtInit(forStmtInit), + insideFuncBody(insideFuncBody), declstring(declstring), inEnumDecl(inEnumDecl) {} diff --git a/compiler/src/dmd/hdrgen.d b/compiler/src/dmd/hdrgen.d index c01e52b7d1..debf01d2a8 100644 --- a/compiler/src/dmd/hdrgen.d +++ b/compiler/src/dmd/hdrgen.d @@ -64,6 +64,7 @@ struct HdrGenState int tpltMember; int autoMember; int forStmtInit; + int insideFuncBody; bool declstring; // set while declaring alias for string,wstring or dstring EnumDeclaration inEnumDecl; @@ -1559,7 +1560,7 @@ public: bodyToBuffer(f); hgs.autoMember--; } - else if (hgs.tpltMember == 0 && global.params.dihdr.fullOutput == false) + else if (hgs.tpltMember == 0 && global.params.dihdr.fullOutput == false && !hgs.insideFuncBody) { if (!f.fbody) { @@ -1644,7 +1645,7 @@ public: void bodyToBuffer(FuncDeclaration f) { - if (!f.fbody || (hgs.hdrgen && global.params.dihdr.fullOutput == false && !hgs.autoMember && !hgs.tpltMember)) + if (!f.fbody || (hgs.hdrgen && global.params.dihdr.fullOutput == false && !hgs.autoMember && !hgs.tpltMember && !hgs.insideFuncBody)) { if (!f.fbody && (f.fensures || f.frequires)) { @@ -1655,6 +1656,18 @@ public: buf.writenl(); return; } + + // there is no way to know if a function is nested + // or not after parsing. We need scope information + // for that, which is avaible during semantic + // analysis. To overcome that, a simple mechanism + // is implemented: everytime we print a function + // body (templated or not) we increment a counter. + // We decredement the counter when we stop + // printing the function body. + ++hgs.insideFuncBody; + scope(exit) { --hgs.insideFuncBody; } + const savetlpt = hgs.tpltMember; const saveauto = hgs.autoMember; hgs.tpltMember = 0; diff --git a/compiler/test/compilable/extra-files/header1.di b/compiler/test/compilable/extra-files/header1.di index f86b9c7df1..fa4eb93771 100644 --- a/compiler/test/compilable/extra-files/header1.di +++ b/compiler/test/compilable/extra-files/header1.di @@ -120,7 +120,24 @@ template Foo(T, int V) B, C, } - void fswitch(Label l); + void fswitch(Label l) + { + final switch (l) + { + case A: + { + break; + } + case B: + { + break; + } + case C: + { + break; + } + } + } loop: while (x) { diff --git a/compiler/test/compilable/extra-files/header2.d b/compiler/test/compilable/extra-files/header2.d index 9836610e33..7c011d2f71 100644 --- a/compiler/test/compilable/extra-files/header2.d +++ b/compiler/test/compilable/extra-files/header2.d @@ -162,6 +162,18 @@ align(2) struct S12200_2 align(1): } +// https://issues.dlang.org/show_bug.cgi?id=14694 +inout(T)[] overlap(T)(inout(T)[] r1, inout(T)[] r2) @trusted pure nothrow +{ + alias U = inout(T); + static U* max(U* a, U* b) nothrow { return a > b ? a : b; } + static U* min(U* a, U* b) nothrow { return a < b ? a : b; } + + auto b = max(r1.ptr, r2.ptr); + auto e = min(r1.ptr + r1.length, r2.ptr + r2.length); + return b < e ? b[0 .. e - b] : null; +} + // https://issues.dlang.org/show_bug.cgi?id=16140 void gun()() { diff --git a/compiler/test/compilable/extra-files/header2.di b/compiler/test/compilable/extra-files/header2.di index 5eb5ec7448..b78abdcc2d 100644 --- a/compiler/test/compilable/extra-files/header2.di +++ b/compiler/test/compilable/extra-files/header2.di @@ -119,6 +119,21 @@ align (2) struct S12200_2 { align (1) {} } +pure nothrow @trusted inout(T)[] overlap(T)(inout(T)[] r1, inout(T)[] r2) +{ + alias U = inout(T); + static nothrow U* max(U* a, U* b) + { + return a > b ? a : b; + } + static nothrow U* min(U* a, U* b) + { + return a < b ? a : b; + } + auto b = max(r1.ptr, r2.ptr); + auto e = min(r1.ptr + r1.length, r2.ptr + r2.length); + return b < e ? b[0..e - b] : null; +} void gun()() { int[] res; diff --git a/compiler/test/compilable/extra-files/header2i.di b/compiler/test/compilable/extra-files/header2i.di index d3ef7cb1f4..3a563958c4 100644 --- a/compiler/test/compilable/extra-files/header2i.di +++ b/compiler/test/compilable/extra-files/header2i.di @@ -221,6 +221,21 @@ align (2) struct S12200_2 { align (1) {} } +pure nothrow @trusted inout(T)[] overlap(T)(inout(T)[] r1, inout(T)[] r2) +{ + alias U = inout(T); + static nothrow U* max(U* a, U* b) + { + return a > b ? a : b; + } + static nothrow U* min(U* a, U* b) + { + return a < b ? a : b; + } + auto b = max(r1.ptr, r2.ptr); + auto e = min(r1.ptr + r1.length, r2.ptr + r2.length); + return b < e ? b[0..e - b] : null; +} void gun()() { int[] res; From 4c1062e80216e49406599718cc7e64af34c6559c Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Mon, 10 Oct 2022 01:17:17 +0200 Subject: [PATCH 5/7] Move druntime changelogs to top-level --- changelog/README.md | 2 +- .../cpuid-add-avx512f.dd | 0 .../drt-oncycle-deprecate.dd | 0 .../posix_gc_signals.dd | 0 druntime/changelog/README.md | 42 ------------------- 5 files changed, 1 insertion(+), 43 deletions(-) rename {druntime/changelog => changelog}/cpuid-add-avx512f.dd (100%) rename {druntime/changelog => changelog}/drt-oncycle-deprecate.dd (100%) rename {druntime/changelog => changelog}/posix_gc_signals.dd (100%) delete mode 100644 druntime/changelog/README.md diff --git a/changelog/README.md b/changelog/README.md index b79acf7e72..874d70fe0f 100644 --- a/changelog/README.md +++ b/changelog/README.md @@ -34,7 +34,7 @@ For more infos, see the [Ddoc spec](https://dlang.org/spec/ddoc.html). Preview changes --------------- -If you have cloned the [tools](https://github.com/dlang/tools) and [dlang.org](https://github.com/dlang/dlang.org) repo), +If you have cloned the [tools](https://github.com/dlang/tools) and [dlang.org](https://github.com/dlang/dlang.org) repo, you can preview the changelog with: ``` diff --git a/druntime/changelog/cpuid-add-avx512f.dd b/changelog/cpuid-add-avx512f.dd similarity index 100% rename from druntime/changelog/cpuid-add-avx512f.dd rename to changelog/cpuid-add-avx512f.dd diff --git a/druntime/changelog/drt-oncycle-deprecate.dd b/changelog/drt-oncycle-deprecate.dd similarity index 100% rename from druntime/changelog/drt-oncycle-deprecate.dd rename to changelog/drt-oncycle-deprecate.dd diff --git a/druntime/changelog/posix_gc_signals.dd b/changelog/posix_gc_signals.dd similarity index 100% rename from druntime/changelog/posix_gc_signals.dd rename to changelog/posix_gc_signals.dd diff --git a/druntime/changelog/README.md b/druntime/changelog/README.md deleted file mode 100644 index 874d70fe0f..0000000000 --- a/druntime/changelog/README.md +++ /dev/null @@ -1,42 +0,0 @@ -This directory will get copied to dlang.org and cleared when master gets -merged into stable prior to a new release. - -How to add a new changelog entry to the pending changelog? -========================================================== - -Create a new file in the `changelog` folder. It should end with `.dd` and look -similar to a git commit message. The first line represents the title of the change. -After an empty line follows the long description: - -``` -My fancy title of the new feature - -A long description of the new feature in `std.range`. -It can be followed by an example: -------- -import std.range : padLeft, padRight; -import std.algorithm.comparison : equal; - -assert([1, 2, 3, 4, 5].padLeft(0, 7).equal([0, 0, 1, 2, 3, 4, 5])); - -assert("Hello World!".padRight('!', 15).equal("Hello World!!!!")); -------- -and links to the documentation, e.g. $(REF drop, std, range) or -$(REF_ALTTEXT a custom name for the function, drop, std, range). - -Links to the spec can look like this $(LINK2 $(ROOT_DIR)spec/module.html, this) -and of course you can link to other $(LINK2 https://forum.dlang.org/, external resources). -``` - -The title can't contain links (it's already one). -For more infos, see the [Ddoc spec](https://dlang.org/spec/ddoc.html). - -Preview changes ---------------- - -If you have cloned the [tools](https://github.com/dlang/tools) and [dlang.org](https://github.com/dlang/dlang.org) repo, -you can preview the changelog with: - -``` -make -C ../dlang.org -f posix.mak pending_changelog -``` From 422351e0c4ad0665fb55d02eb376e4394dd6030d Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Mon, 10 Oct 2022 02:08:49 +0200 Subject: [PATCH 6/7] Prefix changelogs with either dmd. or druntime. --- changelog/{bitfields.dd => dmd.bitfields.dd} | 0 ...lass_instance_alignment.dd => dmd.class_instance_alignment.dd} | 0 ..._constructor_signature.dd => dmd.crt_constructor_signature.dd} | 0 changelog/{d_optimized.dd => dmd.d_optimized.dd} | 0 ...w_contracts.dd => dmd.deprecate_throwing_nothrow_contracts.dd} | 0 .../{deprecate_version_int.dd => dmd.deprecate_version_int.dd} | 0 ...eprecation_warnings.dd => dmd.dip1000_deprecation_warnings.dd} | 0 changelog/{dtoh-improvements.dd => dmd.dtoh-improvements.dd} | 0 changelog/{fix-immutable-conv.dd => dmd.fix-immutable-conv.dd} | 0 changelog/{fix22134.dd => dmd.fix22134.dd} | 0 changelog/{importc_typeof.dd => dmd.importc_typeof.dd} | 0 changelog/{markdown.dd => dmd.markdown.dd} | 0 changelog/{new-aa.dd => dmd.new-aa.dd} | 0 changelog/{previewInLink.dd => dmd.previewInLink.dd} | 0 changelog/{cpuid-add-avx512f.dd => druntime.cpuid-add-avx512f.dd} | 0 ...drt-oncycle-deprecate.dd => druntime.drt-oncycle-deprecate.dd} | 0 changelog/{posix_gc_signals.dd => druntime.posix_gc_signals.dd} | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename changelog/{bitfields.dd => dmd.bitfields.dd} (100%) rename changelog/{class_instance_alignment.dd => dmd.class_instance_alignment.dd} (100%) rename changelog/{crt_constructor_signature.dd => dmd.crt_constructor_signature.dd} (100%) rename changelog/{d_optimized.dd => dmd.d_optimized.dd} (100%) rename changelog/{deprecate_throwing_nothrow_contracts.dd => dmd.deprecate_throwing_nothrow_contracts.dd} (100%) rename changelog/{deprecate_version_int.dd => dmd.deprecate_version_int.dd} (100%) rename changelog/{dip1000_deprecation_warnings.dd => dmd.dip1000_deprecation_warnings.dd} (100%) rename changelog/{dtoh-improvements.dd => dmd.dtoh-improvements.dd} (100%) rename changelog/{fix-immutable-conv.dd => dmd.fix-immutable-conv.dd} (100%) rename changelog/{fix22134.dd => dmd.fix22134.dd} (100%) rename changelog/{importc_typeof.dd => dmd.importc_typeof.dd} (100%) rename changelog/{markdown.dd => dmd.markdown.dd} (100%) rename changelog/{new-aa.dd => dmd.new-aa.dd} (100%) rename changelog/{previewInLink.dd => dmd.previewInLink.dd} (100%) rename changelog/{cpuid-add-avx512f.dd => druntime.cpuid-add-avx512f.dd} (100%) rename changelog/{drt-oncycle-deprecate.dd => druntime.drt-oncycle-deprecate.dd} (100%) rename changelog/{posix_gc_signals.dd => druntime.posix_gc_signals.dd} (100%) diff --git a/changelog/bitfields.dd b/changelog/dmd.bitfields.dd similarity index 100% rename from changelog/bitfields.dd rename to changelog/dmd.bitfields.dd diff --git a/changelog/class_instance_alignment.dd b/changelog/dmd.class_instance_alignment.dd similarity index 100% rename from changelog/class_instance_alignment.dd rename to changelog/dmd.class_instance_alignment.dd diff --git a/changelog/crt_constructor_signature.dd b/changelog/dmd.crt_constructor_signature.dd similarity index 100% rename from changelog/crt_constructor_signature.dd rename to changelog/dmd.crt_constructor_signature.dd diff --git a/changelog/d_optimized.dd b/changelog/dmd.d_optimized.dd similarity index 100% rename from changelog/d_optimized.dd rename to changelog/dmd.d_optimized.dd diff --git a/changelog/deprecate_throwing_nothrow_contracts.dd b/changelog/dmd.deprecate_throwing_nothrow_contracts.dd similarity index 100% rename from changelog/deprecate_throwing_nothrow_contracts.dd rename to changelog/dmd.deprecate_throwing_nothrow_contracts.dd diff --git a/changelog/deprecate_version_int.dd b/changelog/dmd.deprecate_version_int.dd similarity index 100% rename from changelog/deprecate_version_int.dd rename to changelog/dmd.deprecate_version_int.dd diff --git a/changelog/dip1000_deprecation_warnings.dd b/changelog/dmd.dip1000_deprecation_warnings.dd similarity index 100% rename from changelog/dip1000_deprecation_warnings.dd rename to changelog/dmd.dip1000_deprecation_warnings.dd diff --git a/changelog/dtoh-improvements.dd b/changelog/dmd.dtoh-improvements.dd similarity index 100% rename from changelog/dtoh-improvements.dd rename to changelog/dmd.dtoh-improvements.dd diff --git a/changelog/fix-immutable-conv.dd b/changelog/dmd.fix-immutable-conv.dd similarity index 100% rename from changelog/fix-immutable-conv.dd rename to changelog/dmd.fix-immutable-conv.dd diff --git a/changelog/fix22134.dd b/changelog/dmd.fix22134.dd similarity index 100% rename from changelog/fix22134.dd rename to changelog/dmd.fix22134.dd diff --git a/changelog/importc_typeof.dd b/changelog/dmd.importc_typeof.dd similarity index 100% rename from changelog/importc_typeof.dd rename to changelog/dmd.importc_typeof.dd diff --git a/changelog/markdown.dd b/changelog/dmd.markdown.dd similarity index 100% rename from changelog/markdown.dd rename to changelog/dmd.markdown.dd diff --git a/changelog/new-aa.dd b/changelog/dmd.new-aa.dd similarity index 100% rename from changelog/new-aa.dd rename to changelog/dmd.new-aa.dd diff --git a/changelog/previewInLink.dd b/changelog/dmd.previewInLink.dd similarity index 100% rename from changelog/previewInLink.dd rename to changelog/dmd.previewInLink.dd diff --git a/changelog/cpuid-add-avx512f.dd b/changelog/druntime.cpuid-add-avx512f.dd similarity index 100% rename from changelog/cpuid-add-avx512f.dd rename to changelog/druntime.cpuid-add-avx512f.dd diff --git a/changelog/drt-oncycle-deprecate.dd b/changelog/druntime.drt-oncycle-deprecate.dd similarity index 100% rename from changelog/drt-oncycle-deprecate.dd rename to changelog/druntime.drt-oncycle-deprecate.dd diff --git a/changelog/posix_gc_signals.dd b/changelog/druntime.posix_gc_signals.dd similarity index 100% rename from changelog/posix_gc_signals.dd rename to changelog/druntime.posix_gc_signals.dd From aae2fd363f56500ce3c17d6ae98524c724132435 Mon Sep 17 00:00:00 2001 From: Razvan Nitu Date: Mon, 10 Oct 2022 11:56:38 +0300 Subject: [PATCH 7/7] Fix Issue 14905 - duplicate error message: 'Warning: statement is not reachable' (#14543) --- compiler/src/dmd/blockexit.d | 9 ++++++++- compiler/test/fail_compilation/warn14905.d | 23 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 compiler/test/fail_compilation/warn14905.d diff --git a/compiler/src/dmd/blockexit.d b/compiler/src/dmd/blockexit.d index 22c9dde5f7..61f62fa827 100644 --- a/compiler/src/dmd/blockexit.d +++ b/compiler/src/dmd/blockexit.d @@ -162,7 +162,14 @@ int blockExit(Statement s, FuncDeclaration func, bool mustNotThrow) { if (blockExit(s, func, mustNotThrow) != BE.halt && s.hasCode() && s.loc != Loc.initial) // don't emit warning for generated code - s.warning("statement is not reachable"); + { + auto parent1 = func.toParent(); + if (parent1 && parent1.isTemplateInstance()) + s.warning("statement is not reachable in template instance %s", func.toPrettyChars()); + else + s.warning("statement is not reachable"); + } + } else { diff --git a/compiler/test/fail_compilation/warn14905.d b/compiler/test/fail_compilation/warn14905.d new file mode 100644 index 0000000000..55520ba69c --- /dev/null +++ b/compiler/test/fail_compilation/warn14905.d @@ -0,0 +1,23 @@ +// REQUIRED_ARGS: -o- -w + +/* +TEST_OUTPUT: +--- +fail_compilation/warn14905.d(16): Warning: statement is not reachable in template instance warn14905.fun!"a".fun +fail_compilation/warn14905.d(16): Warning: statement is not reachable in template instance warn14905.fun!"b".fun +Error: warnings are treated as errors + Use -wi if you wish to treat warnings only as informational. +--- +*/ + +bool fun(string s)() +{ + return true; + return false; +} + +void main() +{ + cast(void)fun!"a"; + cast(void)fun!"b"; +}