From patchwork Tue Mar 12 13:29:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1055396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-497761-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gdcproject.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="D2NHJKeT"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44JbSM6x2Lz9s6w for ; Wed, 13 Mar 2019 00:30:09 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=E1di14L4QXEjVpcTLlkrpwvovC14cpZ0jDtoJZaA723VyN 2X1dKpx+b8URh6KCjNqksNuzOgnsn7VEJqkvYxLxx0BCPe46vBg5akB+LoTYUZXZ ikKacQSUDvY7i9tZDIc1y5PzdswbvxM/EXHKLIiGYTVd/k5FU2cHbfcUTMGQQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=dixe32zupxrCLxKGoJo0CnFUFcI=; b=D2NHJKeT9VeNnJS/46ON FI2B7H94o+gml0vKS32W5tg4e+Ga7B6nGJu3R9hhcH2gbD3zEs50cjLrJmRnXTR1 edpP1h/kFEnNaRTqvTFnxNqpXKQfSyS5K0+P1vvmp7hmPFT3LI2V61gaxz+QEMBn v3DoGYuy1GY7eONbPKeLd+E= Received: (qmail 54512 invoked by alias); 12 Mar 2019 13:30:01 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 54117 invoked by uid 89); 12 Mar 2019 13:30:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=201703, 2829 X-HELO: mail-qk1-f179.google.com Received: from mail-qk1-f179.google.com (HELO mail-qk1-f179.google.com) (209.85.222.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Mar 2019 13:29:59 +0000 Received: by mail-qk1-f179.google.com with SMTP id z76so1372991qkb.12 for ; Tue, 12 Mar 2019 06:29:59 -0700 (PDT) MIME-Version: 1.0 From: Iain Buclaw Date: Tue, 12 Mar 2019 14:29:46 +0100 Message-ID: Subject: [PATCH, d] Committed merge with upstream dmd To: gcc-patches X-IsSubscribed: yes Hi, This patch merges the D front-end implementation with dmd upstream 7423993c9. Backports a fix for extern(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. Bootstrapped and regression tested on x86_64-linux-gnu. Committed to trunk as r269611. diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc index b53e56e65a2..d97525a590e 100644 --- a/gcc/d/d-lang.cc +++ b/gcc/d/d-lang.cc @@ -282,6 +282,9 @@ d_init_options (unsigned int, cl_decoded_option *decoded_options) 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 (); diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc index de57d9256db..e0cfbafe0b9 100644 --- a/gcc/d/d-target.cc +++ b/gcc/d/d-target.cc @@ -385,6 +385,15 @@ Target::cppParameterType (Parameter *arg) 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 diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index cf5a22f070f..f58b620d844 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -fcc235e8e25f7758266f7874edd5abefb9943e0b +7423993c996ed9f73d6ba6d58f625ad3c778ca1d The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/cppmangle.c b/gcc/d/dmd/cppmangle.c index b991417c35e..9b24fd2c2e4 100644 --- a/gcc/d/dmd/cppmangle.c +++ b/gcc/d/dmd/cppmangle.c @@ -120,6 +120,40 @@ class CppMangleVisitor : public Visitor !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: @@ -741,7 +775,8 @@ public: */ 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; @@ -767,6 +802,22 @@ public: 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; + } + /* : * v void * w wchar_t @@ -832,17 +883,6 @@ public: 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); diff --git a/gcc/d/dmd/globals.h b/gcc/d/dmd/globals.h index 6c37cca3236..e2d42c7b67b 100644 --- a/gcc/d/dmd/globals.h +++ b/gcc/d/dmd/globals.h @@ -55,6 +55,14 @@ enum CPU 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 { @@ -114,6 +122,7 @@ 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 diff --git a/gcc/d/dmd/target.h b/gcc/d/dmd/target.h index 66be2014432..1729bc33ffa 100644 --- a/gcc/d/dmd/target.h +++ b/gcc/d/dmd/target.h @@ -71,5 +71,6 @@ struct 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(); }; diff --git a/gcc/testsuite/gdc.test/runnable/cppa.d b/gcc/testsuite/gdc.test/runnable/cppa.d index 82b93adf1f6..6b2bafbe7bc 100644 --- a/gcc/testsuite/gdc.test/runnable/cppa.d +++ b/gcc/testsuite/gdc.test/runnable/cppa.d @@ -619,6 +619,7 @@ else alias c_long_double myld; extern (C++) myld testld(myld); +extern (C++) myld testldld(myld, myld); void test15() @@ -626,6 +627,10 @@ 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); } /****************************************/ diff --git a/gcc/testsuite/gdc.test/runnable/extra-files/cppb.cpp b/gcc/testsuite/gdc.test/runnable/extra-files/cppb.cpp index 7574c5fba72..587145c61c3 100644 --- a/gcc/testsuite/gdc.test/runnable/extra-files/cppb.cpp +++ b/gcc/testsuite/gdc.test/runnable/extra-files/cppb.cpp @@ -439,6 +439,12 @@ long double testld(long double ld) 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);