Fixes C++ mangling for substituted basic types that are target-specific.
Introduces a new method that currently does nothing, but could in future
make use of flag_abi_version as extern(C++) integration improves in
latter versions of the D front-end.
Reviewed-on: https://github.com/dlang/dmd/pull/9439
gcc/d/ChangeLog:
2019-03-12 Iain Buclaw <ibuclaw@gdcproject.org>
* d-lang.cc (d_init_options): Set global.params.cplusplus to C++14.
* d-target.cc (Target::cppFundamentalType): New method.
From-SVN: r269611
+2019-03-12 Iain Buclaw <ibuclaw@gdcproject.org>
+
+ * d-lang.cc (d_init_options): Set global.params.cplusplus to C++14.
+ * d-target.cc (Target::cppFundamentalType): New method.
+
2019-03-09 Iain Buclaw <ibuclaw@gdcproject.org>
PR d/89041
global.params.betterC = false;
global.params.allInst = false;
+ /* Default extern(C++) mangling to C++14. */
+ global.params.cplusplus = CppStdRevisionCpp14;
+
global.params.linkswitches = new Strings ();
global.params.libfiles = new Strings ();
global.params.objfiles = new Strings ();
return t;
}
+/* Checks whether TYPE is a vendor-specific fundamental type. Stores the result
+ in IS_FUNDAMENTAL and returns true if the parameter was set. */
+
+bool
+Target::cppFundamentalType (const Type *, bool &)
+{
+ return false;
+}
+
/* Return the default system linkage for the target. */
LINK
-fcc235e8e25f7758266f7874edd5abefb9943e0b
+7423993c996ed9f73d6ba6d58f625ad3c778ca1d
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
!getQualifier(s)); // at global level
}
+ /************************
+ * Determine if type is a C++ fundamental type.
+ * Params:
+ * t = type to check
+ * Returns:
+ * true if it is a fundamental type
+ */
+ static bool isFundamentalType(Type *t)
+ {
+ // First check the target whether some specific ABI is being followed.
+ bool isFundamental;
+ if (Target::cppFundamentalType(t, isFundamental))
+ return isFundamental;
+ if (t->ty == Tenum)
+ {
+ // Peel off enum type from special types.
+ TypeEnum *te = (TypeEnum *)t;
+ if (te->sym->isSpecial())
+ t = te->sym->getMemtype(Loc());
+ }
+
+ // Fundamental arithmetic types:
+ // 1. integral types: bool, char, int, ...
+ // 2. floating point types: float, double, real
+ // 3. void
+ // 4. null pointer: std::nullptr_t (since C++11)
+ if (t->ty == Tvoid || t->ty == Tbool)
+ return true;
+ else if (t->ty == Tnull && global.params.cplusplus >= CppStdRevisionCpp11)
+ return true;
+ else
+ return t->isTypeBasic() && (t->isintegral() || t->isreal());
+ }
+
/******************************
* Write the mangled representation of the template arguments.
* Params:
*/
void writeBasicType(Type *t, char p, char c)
{
- if (p || t->isConst())
+ // Only do substitutions for non-fundamental types.
+ if (!isFundamentalType(t) || t->isConst())
{
if (substitute(t))
return;
if (t->isImmutable() || t->isShared())
return error(t);
+ // Handle any target-specific basic types.
+ if (const char *tm = Target::cppTypeMangle(t))
+ {
+ // Only do substitutions for non-fundamental types.
+ if (!isFundamentalType(t) || t->isConst())
+ {
+ if (substitute(t))
+ return;
+ else
+ append(t);
+ }
+ CV_qualifiers(t);
+ buf->writestring(tm);
+ return;
+ }
+
/* <builtin-type>:
* v void
* w wchar_t
case Tcomplex80: p = 'C'; c = 'e'; break;
default:
- // Handle any target-specific basic types.
- if (const char *tm = Target::cppTypeMangle(t))
- {
- if (substitute(t))
- return;
- else
- append(t);
- CV_qualifiers(t);
- buf->writestring(tm);
- return;
- }
return error(t);
}
writeBasicType(t, p, c);
native // the machine the compiler is being run on
};
+enum CppStdRevision
+{
+ CppStdRevisionCpp98 = 199711,
+ CppStdRevisionCpp11 = 201103,
+ CppStdRevisionCpp14 = 201402,
+ CppStdRevisionCpp17 = 201703
+};
+
// Put command line switches in here
struct Param
{
bool check10378; // check for issues transitioning to 10738
bool bug10378; // use pre-bugzilla 10378 search strategy
bool vsafe; // use enhanced @safe checking
+ unsigned cplusplus; // version of C++ name mangling to support
bool showGaggedErrors; // print gagged errors anyway
CPU cpu; // CPU instruction set to target
static const char *cppTypeInfoMangle(ClassDeclaration *cd);
static const char *cppTypeMangle(Type *t);
static Type *cppParameterType(Parameter *p);
+ static bool cppFundamentalType(const Type *t, bool& isFundamental);
static LINK systemLinkage();
};
alias c_long_double myld;
extern (C++) myld testld(myld);
+extern (C++) myld testldld(myld, myld);
void test15()
myld ld = 5.0;
ld = testld(ld);
assert(ld == 6.0);
+
+ myld ld2 = 5.0;
+ ld2 = testldld(ld2, ld2);
+ assert(ld2 == 6.0);
}
/****************************************/
return ld + 1;
}
+long double testldld(long double ld1, long double ld2)
+{
+ assert(ld1 == 5);
+ return ld2 + 1;
+}
+
long testl(long lng)
{
assert(lng == 5);