From patchwork Tue Mar 26 14:40:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1065656 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-498453-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="uMz37B7H"; 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 44TDMc2vwcz9sNj for ; Wed, 27 Mar 2019 01:40:55 +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=SW5GtSb9abIuuZILXP3CMHzezjvTdquzh/FcgRP0/Ff68K uAa5JLtuwe5vOBrKUjnTMy/OZ2eLZpbIZGpqjTIct37cuH1U1p/jqZCW70Qd4TsW EDvQX4vekcM2kv0QGDLQFYfaK0/Ufrcp9XIpXu5FVXSl39kylbBKsFwOKw5lE= 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=KKAHvRVOF2Jvtcv8W8CgXqtmPiM=; b=uMz37B7H0UZ4AQG1WiqU DyQPPfjIN90a0bJ2UMulpVSkOeAjwCQQXkdBm4O1HRTaF2VBs0FOphqLd1JPP075 6B7ZkQBx3gpU8IihSejqtPL9GxjdM67KcboiscKxLuwkoSoe645eLpjF++wd5+ln bdiPby89KIuRFfGg65r33/s= Received: (qmail 46541 invoked by alias); 26 Mar 2019 14:40:44 -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 46375 invoked by uid 89); 26 Mar 2019 14:40:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.9 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=UD:offset, visit X-HELO: mail-qt1-f182.google.com Received: from mail-qt1-f182.google.com (HELO mail-qt1-f182.google.com) (209.85.160.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Mar 2019 14:40:42 +0000 Received: by mail-qt1-f182.google.com with SMTP id v32so14799140qtc.10 for ; Tue, 26 Mar 2019 07:40:42 -0700 (PDT) MIME-Version: 1.0 From: Iain Buclaw Date: Tue, 26 Mar 2019 15:40:29 +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 ab702e73e. Backports memory leak fix in the mangler, and introduces recognition and rejection of more C types and directives. Bootstrapped and regression tested on x86_64-linux-gnu. Committed to trunk as r269945. diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index 3017f0d34af..ffad6cb524d 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -74ac873be1862090b7ec0e4a876fd1b758520359 +ab702e73e56aefb3b77b8f8f42da94bc22143eeb 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/dmangle.c b/gcc/d/dmd/dmangle.c index 7f13947ae2b..44f4f826b41 100644 --- a/gcc/d/dmd/dmangle.c +++ b/gcc/d/dmd/dmangle.c @@ -306,8 +306,9 @@ public: buf2.reserve(32); Mangler v(&buf2); v.paramsToDecoBuffer(t->arguments); + const char *s = buf2.peekString(); int len = (int)buf2.offset; - buf->printf("%d%.*s", len, len, buf2.extractData()); + buf->printf("%d%.*s", len, len, s); } void visit(TypeNull *t) diff --git a/gcc/d/dmd/dscope.c b/gcc/d/dmd/dscope.c index 27c3fd58947..def448a2408 100644 --- a/gcc/d/dmd/dscope.c +++ b/gcc/d/dmd/dscope.c @@ -685,14 +685,16 @@ Dsymbol *Scope::search_correct(Identifier *ident) const char *Scope::search_correct_C(Identifier *ident) { TOK tok; - if (ident == Id::_NULL) + if (ident == Id::C_NULL) tok = TOKnull; - else if (ident == Id::_TRUE) + else if (ident == Id::C_TRUE) tok = TOKtrue; - else if (ident == Id::_FALSE) + else if (ident == Id::C_FALSE) tok = TOKfalse; - else if (ident == Id::_unsigned) + else if (ident == Id::C_unsigned) tok = TOKuns32; + else if (ident == Id::C_wchar_t) + tok = global.params.isWindows ? TOKwchar : TOKdchar; else return NULL; return Token::toChars(tok); diff --git a/gcc/d/dmd/idgen.c b/gcc/d/dmd/idgen.c index ec26b2c7008..e75004893aa 100644 --- a/gcc/d/dmd/idgen.c +++ b/gcc/d/dmd/idgen.c @@ -374,10 +374,11 @@ Msgtable msgtable[] = { "udaSelector", "selector" }, // C names, for undefined identifier error messages - { "_NULL", "NULL" }, - { "_TRUE", "TRUE" }, - { "_FALSE", "FALSE" }, - { "_unsigned", "unsigned" }, + { "C_NULL", "NULL" }, + { "C_TRUE", "TRUE" }, + { "C_FALSE", "FALSE" }, + { "C_unsigned", "unsigned" }, + { "C_wchar_t", "wchar_t" }, }; diff --git a/gcc/d/dmd/lexer.c b/gcc/d/dmd/lexer.c index b466f17e4be..8a2c90f1dfd 100644 --- a/gcc/d/dmd/lexer.c +++ b/gcc/d/dmd/lexer.c @@ -901,16 +901,25 @@ void Lexer::scan(Token *t) p++; Token n; scan(&n); - if (n.value == TOKidentifier && n.ident == Id::line) + if (n.value == TOKidentifier) { - poundLine(); - continue; + if (n.ident == Id::line) + { + poundLine(); + continue; + } + else + { + const Loc locx = loc(); + warning(locx, "C preprocessor directive `#%s` is not supported", n.ident->toChars()); + } } - else + else if (n.value == TOKif) { - t->value = TOKpound; - return; + error("C preprocessor directive `#if` is not supported, use `version` or `static if`"); } + t->value = TOKpound; + return; } default: diff --git a/gcc/d/dmd/parse.c b/gcc/d/dmd/parse.c index e0ee299eb6d..3afdbc257f8 100644 --- a/gcc/d/dmd/parse.c +++ b/gcc/d/dmd/parse.c @@ -3076,7 +3076,23 @@ Type *Parser::parseBasicType(bool dontLookDotIdents) case TOKuns16: t = Type::tuns16; goto LabelX; case TOKint32: t = Type::tint32; goto LabelX; case TOKuns32: t = Type::tuns32; goto LabelX; - case TOKint64: t = Type::tint64; goto LabelX; + case TOKint64: + t = Type::tint64; + nextToken(); + if (token.value == TOKint64) // if `long long` + { + error("use `long` for a 64 bit integer instead of `long long`"); + nextToken(); + } + else if (token.value == TOKfloat64) // if `long double` + { + error("use `real` instead of `long double`"); + t = Type::tfloat80; + nextToken(); + + } + break; + case TOKuns64: t = Type::tuns64; goto LabelX; case TOKint128: t = Type::tint128; goto LabelX; case TOKuns128: t = Type::tuns128; goto LabelX; diff --git a/gcc/testsuite/gdc.test/fail_compilation/cerrors.d b/gcc/testsuite/gdc.test/fail_compilation/cerrors.d new file mode 100644 index 00000000000..3d69d415e2b --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/cerrors.d @@ -0,0 +1,15 @@ +/* REQUIRED_ARGS: -wi +TEST_OUTPUT: +--- +fail_compilation/cerrors.d(11): Error: C preprocessor directive `#if` is not supported, use `version` or `static if` +fail_compilation/cerrors.d(11): Error: declaration expected, not `#` +fail_compilation/cerrors.d(15): Warning: C preprocessor directive `#endif` is not supported +fail_compilation/cerrors.d(15): Error: declaration expected, not `#` +--- +*/ + +#if 1 + +void test(wchar_t u); + +#endif diff --git a/gcc/testsuite/gdc.test/fail_compilation/ctypes.d b/gcc/testsuite/gdc.test/fail_compilation/ctypes.d new file mode 100644 index 00000000000..9f5ff18f751 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/ctypes.d @@ -0,0 +1,13 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/ctypes.d(11): Error: use `real` instead of `long double` +fail_compilation/ctypes.d(12): Error: use `long` for a 64 bit integer instead of `long long` +--- +*/ + +void test() +{ + long double r; + long long ll; +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/widechars.d b/gcc/testsuite/gdc.test/fail_compilation/widechars.d new file mode 100644 index 00000000000..ccfc47aa817 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/widechars.d @@ -0,0 +1,10 @@ + +/* +DISABLED: win32 win64 +TEST_OUTPUT: +--- +fail_compilation/widechars.d(10): Error: undefined identifier `wchar_t`, did you mean `dchar`? +--- +*/ + +wchar_t x;