aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/dmd/cppmangle.d
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@symmetryinvestments.com>2024-12-29 06:40:04 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2025-01-05 13:30:24 +0100
commit332cf038fda109ea0612eeba7a85441293ba6984 (patch)
treeca5c381d189ace8afa4cf40369cd7d2063bc00a4 /gcc/d/dmd/cppmangle.d
parent31f1bec65ba257adc346f952fd79a1ec3165a2e6 (diff)
downloadgcc-332cf038fda109ea0612eeba7a85441293ba6984.zip
gcc-332cf038fda109ea0612eeba7a85441293ba6984.tar.gz
gcc-332cf038fda109ea0612eeba7a85441293ba6984.tar.bz2
d: Merge upstream dmd c11e1d1708, druntime e60bfd11bd, phobos 8729740e3
Synchronizing the compiler with the upstream release of v2.108.1. D front-end changes: - Import dmd v2.108.1. - Add experimental support for language editions, enabled by adding the UDA `@__edition_latest_do_not_use' before module declarations. - [Next Edition] Aliasing a member of a type instance is now an error. - Added `__ctfeWrite' to write messages from CTFE. - `-fdump-c++-spec' generates signatures for `extern(Windows)' and `extern(System)' functions. - `foreach_reverse' on a delegate is now an error. - ImportC has improved Unicode support. D runtime changes: - Mark unsafe unittest @trusted. Phobos changes: - Mark unsafe functions @trusted. gcc/d/ChangeLog: * Make-lang.in (D_FRONTEND_OBJS): Add d/attribsem.o, d/common-charactertables.o, d/common-identifiertables.o. * d-attribs.cc (apply_user_attributes): Update for new front-end interface. * d-builtins.cc (d_init_versions): Predefine CppRuntime_GNU. * d-incpath.cc (add_globalpaths): Update for new front-end interface. (add_filepaths): Likewise. (add_import_paths): Likewise. * d-lang.cc (d_post_options): Likewise. * dmd/MERGE: Merge upstream dmd c11e1d1708. * dmd/VERSION: Bump version to v2.108.1. libphobos/ChangeLog: * libdruntime/MERGE: Merge upstream druntime e60bfd11bd. * src/MERGE: Merge upstream phobos 8729740e3. gcc/testsuite/ChangeLog: * gdc.dg/torture/pr96435.d: Add dg-warning.
Diffstat (limited to 'gcc/d/dmd/cppmangle.d')
-rw-r--r--gcc/d/dmd/cppmangle.d58
1 files changed, 40 insertions, 18 deletions
diff --git a/gcc/d/dmd/cppmangle.d b/gcc/d/dmd/cppmangle.d
index 0116aa3..334088b 100644
--- a/gcc/d/dmd/cppmangle.d
+++ b/gcc/d/dmd/cppmangle.d
@@ -49,19 +49,30 @@ import dmd.typesem;
import dmd.visitor;
-// helper to check if an identifier is a C++ operator
-enum CppOperator { Cast, Assign, Eq, Index, Call, Unary, Binary, OpAssign, Unknown }
-package CppOperator isCppOperator(Identifier id)
+// C++ operators
+enum CppOperator { Unknown, Cast, Assign, Eq, Index, Call, Unary, Binary, OpAssign }
+
+/**************
+ * Check if id is a C++ operator
+ * Params:
+ * id = identifier to be checked
+ * Returns:
+ * CppOperator, or Unknown if not a C++ operator
+ */
+package CppOperator isCppOperator(const scope Identifier id)
{
- __gshared const(Identifier)[] operators = null;
- if (!operators)
- operators = [Id._cast, Id.assign, Id.eq, Id.index, Id.call, Id.opUnary, Id.opBinary, Id.opOpAssign];
- foreach (i, op; operators)
- {
- if (op == id)
- return cast(CppOperator)i;
+ with (Id) with (CppOperator)
+ {
+ return (id == _cast) ? Cast :
+ (id == assign) ? Assign :
+ (id == eq) ? Eq :
+ (id == index) ? Index :
+ (id == call) ? Call :
+ (id == opUnary) ? Unary :
+ (id == opBinary) ? Binary :
+ (id == opOpAssign) ? OpAssign :
+ Unknown ;
}
- return CppOperator.Unknown;
}
///
@@ -71,6 +82,8 @@ const(char)* toCppMangleItanium(Dsymbol s)
OutBuffer buf;
scope CppMangleVisitor v = new CppMangleVisitor(&buf, s.loc);
v.mangleOf(s);
+ if (v.errors)
+ fatal();
return buf.extractChars();
}
@@ -82,6 +95,8 @@ const(char)* cppTypeInfoMangleItanium(Dsymbol s)
buf.writestring("_ZTI"); // "TI" means typeinfo structure
scope CppMangleVisitor v = new CppMangleVisitor(&buf, s.loc);
v.cpp_mangle_name(s, false);
+ if (v.errors)
+ fatal();
return buf.extractChars();
}
@@ -93,6 +108,8 @@ const(char)* cppThunkMangleItanium(FuncDeclaration fd, int offset)
buf.printf("_ZThn%u_", offset); // "Th" means thunk, "n%u" is the call offset
scope CppMangleVisitor v = new CppMangleVisitor(&buf, fd.loc);
v.mangle_function_encoding(fd);
+ if (v.errors)
+ fatal();
return buf.extractChars();
}
@@ -163,6 +180,7 @@ private final class CppMangleVisitor : Visitor
Objects components; /// array of components available for substitution
OutBuffer* buf; /// append the mangling to buf[]
Loc loc; /// location for use in error messages
+ bool errors; /// failed to mangle properly
/**
* Constructor
@@ -484,7 +502,8 @@ private final class CppMangleVisitor : Visitor
else
{
.error(ti.loc, "%s `%s` internal compiler error: C++ `%s` template value parameter is not supported", ti.kind, ti.toPrettyChars, tv.valType.toChars());
- fatal();
+ errors = true;
+ return;
}
}
else if (tp.isTemplateAliasParameter())
@@ -519,13 +538,13 @@ private final class CppMangleVisitor : Visitor
else
{
.error(ti.loc, "%s `%s` internal compiler error: C++ `%s` template alias parameter is not supported", ti.kind, ti.toPrettyChars, o.toChars());
- fatal();
+ errors = true;
}
}
else if (tp.isTemplateThisParameter())
{
.error(ti.loc, "%s `%s` internal compiler error: C++ `%s` template this parameter is not supported", ti.kind, ti.toPrettyChars, o.toChars());
- fatal();
+ errors = true;
}
else
{
@@ -574,7 +593,8 @@ private final class CppMangleVisitor : Visitor
if (t is null)
{
.error(ti.loc, "%s `%s` internal compiler error: C++ `%s` template value parameter is not supported", ti.kind, ti.toPrettyChars, (*ti.tiargs)[j].toChars());
- fatal();
+ errors = true;
+ return false;
}
t.accept(this);
}
@@ -1012,7 +1032,8 @@ private final class CppMangleVisitor : Visitor
if (!(d.storage_class & (STC.extern_ | STC.field | STC.gshared)))
{
.error(d.loc, "%s `%s` internal compiler error: C++ static non-`__gshared` non-`extern` variables not supported", d.kind, d.toPrettyChars);
- fatal();
+ errors = true;
+ return;
}
Dsymbol p = d.toParent();
if (p && !p.isModule()) //for example: char Namespace1::beta[6] should be mangled as "_ZN10Namespace14betaE"
@@ -1348,7 +1369,8 @@ private final class CppMangleVisitor : Visitor
// Static arrays in D are passed by value; no counterpart in C++
.error(loc, "internal compiler error: unable to pass static array `%s` to extern(C++) function, use pointer instead",
t.toChars());
- fatal();
+ errors = true;
+ return;
}
auto prev = this.context.push({
TypeFunction tf;
@@ -1386,7 +1408,7 @@ private final class CppMangleVisitor : Visitor
else
p = "";
.error(loc, "internal compiler error: %stype `%s` cannot be mapped to C++\n", p, t.toChars());
- fatal(); //Fatal, because this error should be handled in frontend
+ errors = true; //Fatal, because this error should be handled in frontend
}
/****************************