diff --git a/CHANGELOG.md b/CHANGELOG.md index 13415a011a7..633bc6eca50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ #### Big news - Frontend, druntime and Phobos are at version [2.108.0+](https://dlang.org/changelog/2.108.0.html). (#4591, #4615, #4619) -- Support for [LLVM 18](https://releases.llvm.org/18.1.0/docs/ReleaseNotes.html). The prebuilt packages use v18.1.3 (except for Android and macOS arm64). (#4599, #4605, #4607, #4604) +- Support for [LLVM 18](https://releases.llvm.org/18.1.0/docs/ReleaseNotes.html). The prebuilt packages use v18.1.3 (except for Android and macOS arm64). (#4599, #4605, #4607, #4604, #4622) #### Platform support - Supports LLVM 11 - 18. diff --git a/dmd/cparse.d b/dmd/cparse.d index d5bf8f9eda8..1d978aeab50 100644 --- a/dmd/cparse.d +++ b/dmd/cparse.d @@ -5873,13 +5873,15 @@ final class CParser(AST) : Parser!AST const(char)* endp = &slice[length - 7]; + AST.Dsymbols newSymbols; + size_t[void*] defineTab; // hash table of #define's turned into Symbol's - // indexed by Identifier, returns index into symbols[] + // indexed by Identifier, returns index into newSymbols[] // The memory for this is leaked - void addVar(AST.Dsymbol s) + void addSym(AST.Dsymbol s) { - //printf("addVar() %s\n", s.toChars()); + //printf("addSym() %s\n", s.toChars()); if (auto v = s.isVarDeclaration()) v.isCmacro(true); // mark it as coming from a C #define /* If it's already defined, replace the earlier @@ -5887,13 +5889,22 @@ final class CParser(AST) : Parser!AST */ if (size_t* pd = cast(void*)s.ident in defineTab) { - //printf("replacing %s\n", v.toChars()); - (*symbols)[*pd] = s; + //printf("replacing %s\n", s.toChars()); + newSymbols[*pd] = s; return; } - assert(symbols, "symbols is null"); - defineTab[cast(void*)s.ident] = symbols.length; - symbols.push(s); + defineTab[cast(void*)s.ident] = newSymbols.length; + newSymbols.push(s); + } + + void removeSym(Identifier ident) + { + //printf("removeSym() %s\n", ident.toChars()); + if (size_t* pd = cast(void*)ident in defineTab) + { + //printf("removing %s\n", ident.toChars()); + newSymbols[*pd] = null; + } } while (p < endp) @@ -5937,7 +5948,7 @@ final class CParser(AST) : Parser!AST */ AST.Expression e = new AST.IntegerExp(scanloc, intvalue, t); auto v = new AST.VarDeclaration(scanloc, t, id, new AST.ExpInitializer(scanloc, e), STC.manifest); - addVar(v); + addSym(v); ++p; continue; } @@ -5960,7 +5971,7 @@ final class CParser(AST) : Parser!AST */ AST.Expression e = new AST.RealExp(scanloc, floatvalue, t); auto v = new AST.VarDeclaration(scanloc, t, id, new AST.ExpInitializer(scanloc, e), STC.manifest); - addVar(v); + addSym(v); ++p; continue; } @@ -5978,7 +5989,7 @@ final class CParser(AST) : Parser!AST */ AST.Expression e = new AST.StringExp(scanloc, str[0 .. len], len, 1, postfix); auto v = new AST.VarDeclaration(scanloc, null, id, new AST.ExpInitializer(scanloc, e), STC.manifest); - addVar(v); + addSym(v); ++p; continue; } @@ -6014,7 +6025,7 @@ final class CParser(AST) : Parser!AST AST.TemplateParameters* tpl = new AST.TemplateParameters(); AST.Expression constraint = null; auto tempdecl = new AST.TemplateDeclaration(exp.loc, id, tpl, constraint, decldefs, false); - addVar(tempdecl); + addSym(tempdecl); ++p; continue; } @@ -6105,7 +6116,7 @@ final class CParser(AST) : Parser!AST AST.Dsymbols* decldefs = new AST.Dsymbols(); decldefs.push(fd); auto tempdecl = new AST.TemplateDeclaration(exp.loc, id, tpl, null, decldefs, false); - addVar(tempdecl); + addSym(tempdecl); ++p; continue; @@ -6116,6 +6127,14 @@ final class CParser(AST) : Parser!AST } } } + else if (p[0 .. 6] == "#undef") + { + p += 6; + nextToken(); + //printf("undef %s\n", token.toChars()); + if (token.value == TOK.identifier) + removeSym(token.ident); + } // scan to end of line while (*p) ++p; @@ -6123,6 +6142,16 @@ final class CParser(AST) : Parser!AST scanloc.linnum = scanloc.linnum + 1; } + if (newSymbols.length) + { + assert(symbols, "symbols is null"); + symbols.reserve(newSymbols.length); + + foreach (sym; newSymbols) + if (sym) // undefined entries are null + symbols.push(sym); + } + scanloc = scanlocSave; eSink = save; defines = buf; diff --git a/dmd/traits.d b/dmd/traits.d index ec89ef5efb2..b3b6b386564 100644 --- a/dmd/traits.d +++ b/dmd/traits.d @@ -1245,7 +1245,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc) // @@@DEPRECATION 2.100.2 if (auto td = s.isTemplateDeclaration()) { - if (td.overnext || td.overroot) + if (td.overnext) { deprecation(e.loc, "`__traits(getAttributes)` may only be used for individual functions, not the overload set `%s`", td.ident.toChars()); deprecationSupplemental(e.loc, "the result of `__traits(getOverloads)` may be used to select the desired function to extract attributes from"); diff --git a/packaging/reggae_version b/packaging/reggae_version index 1f9498885c1..bf35f0316be 100644 --- a/packaging/reggae_version +++ b/packaging/reggae_version @@ -1 +1 @@ -5260790492c465eedde921080952ea34bb14c524 \ No newline at end of file +9a67d1a1f863c676f30b06ac606b34a792abebdd \ No newline at end of file diff --git a/tests/dmd/compilable/test24479.d b/tests/dmd/compilable/test24479.d new file mode 100644 index 00000000000..7865c1b6074 --- /dev/null +++ b/tests/dmd/compilable/test24479.d @@ -0,0 +1,35 @@ +// https://issues.dlang.org/show_bug.cgi?id=24479 + +/* +TEST_OUTPUT: +--- +1 +2 +--- +*/ + +struct S +{ + @1 + S opBinary(string op: "-")(S rhs) const pure nothrow @nogc + { + return rhs; + } + @2 + S opBinary(string op: "*")(S dur) const pure nothrow @nogc + { + return dur; + } +} + +private enum hasExternalUDA(alias A) = is(A == External) || is(typeof(A) == External); + +void foo() +{ + static foreach (t; __traits(getOverloads, S, "opBinary", true)) + static foreach(attr; __traits(getAttributes, t)) + pragma(msg, attr); + + static assert(__traits(getOverloads, S, "opBinary", true).length == 2); + alias A = __traits(getAttributes, __traits(getOverloads, S, "opBinary", true)[1]); +} diff --git a/tests/dmd/compilable/test24505.c b/tests/dmd/compilable/test24505.c new file mode 100644 index 00000000000..9ba16106a81 --- /dev/null +++ b/tests/dmd/compilable/test24505.c @@ -0,0 +1,15 @@ +// https://issues.dlang.org/show_bug.cgi?id=24505 + +// PERMUTE_ARGS: + +struct stat { int x; }; + +void __stat(int x, int y); +#define stat(x, y) __stat(x, y) + +// reversed order: +#define stat2(x, y) __stat(x, y) +struct stat2 { int x; }; + +#undef stat +#undef stat2