Commit ecbb1530 by Iain Buclaw

d/dmd: Merge upstream dmd ab702e73e

Fixes memory leak in the front-end symbol mangler, and introduces
recognition and rejection of a few more C types and directives.

Reviewed-on: https://github.com/dlang/dmd/pull/9492

From-SVN: r269945
parent 465b8e7f
74ac873be1862090b7ec0e4a876fd1b758520359 ab702e73e56aefb3b77b8f8f42da94bc22143eeb
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository. merge done from the dlang/dmd repository.
...@@ -306,8 +306,9 @@ public: ...@@ -306,8 +306,9 @@ public:
buf2.reserve(32); buf2.reserve(32);
Mangler v(&buf2); Mangler v(&buf2);
v.paramsToDecoBuffer(t->arguments); v.paramsToDecoBuffer(t->arguments);
const char *s = buf2.peekString();
int len = (int)buf2.offset; int len = (int)buf2.offset;
buf->printf("%d%.*s", len, len, buf2.extractData()); buf->printf("%d%.*s", len, len, s);
} }
void visit(TypeNull *t) void visit(TypeNull *t)
......
...@@ -685,14 +685,16 @@ Dsymbol *Scope::search_correct(Identifier *ident) ...@@ -685,14 +685,16 @@ Dsymbol *Scope::search_correct(Identifier *ident)
const char *Scope::search_correct_C(Identifier *ident) const char *Scope::search_correct_C(Identifier *ident)
{ {
TOK tok; TOK tok;
if (ident == Id::_NULL) if (ident == Id::C_NULL)
tok = TOKnull; tok = TOKnull;
else if (ident == Id::_TRUE) else if (ident == Id::C_TRUE)
tok = TOKtrue; tok = TOKtrue;
else if (ident == Id::_FALSE) else if (ident == Id::C_FALSE)
tok = TOKfalse; tok = TOKfalse;
else if (ident == Id::_unsigned) else if (ident == Id::C_unsigned)
tok = TOKuns32; tok = TOKuns32;
else if (ident == Id::C_wchar_t)
tok = global.params.isWindows ? TOKwchar : TOKdchar;
else else
return NULL; return NULL;
return Token::toChars(tok); return Token::toChars(tok);
......
...@@ -374,10 +374,11 @@ Msgtable msgtable[] = ...@@ -374,10 +374,11 @@ Msgtable msgtable[] =
{ "udaSelector", "selector" }, { "udaSelector", "selector" },
// C names, for undefined identifier error messages // C names, for undefined identifier error messages
{ "_NULL", "NULL" }, { "C_NULL", "NULL" },
{ "_TRUE", "TRUE" }, { "C_TRUE", "TRUE" },
{ "_FALSE", "FALSE" }, { "C_FALSE", "FALSE" },
{ "_unsigned", "unsigned" }, { "C_unsigned", "unsigned" },
{ "C_wchar_t", "wchar_t" },
}; };
......
...@@ -901,16 +901,25 @@ void Lexer::scan(Token *t) ...@@ -901,16 +901,25 @@ void Lexer::scan(Token *t)
p++; p++;
Token n; Token n;
scan(&n); scan(&n);
if (n.value == TOKidentifier && n.ident == Id::line) if (n.value == TOKidentifier)
{ {
poundLine(); if (n.ident == Id::line)
continue; {
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; error("C preprocessor directive `#if` is not supported, use `version` or `static if`");
return;
} }
t->value = TOKpound;
return;
} }
default: default:
......
...@@ -3076,7 +3076,23 @@ Type *Parser::parseBasicType(bool dontLookDotIdents) ...@@ -3076,7 +3076,23 @@ Type *Parser::parseBasicType(bool dontLookDotIdents)
case TOKuns16: t = Type::tuns16; goto LabelX; case TOKuns16: t = Type::tuns16; goto LabelX;
case TOKint32: t = Type::tint32; goto LabelX; case TOKint32: t = Type::tint32; goto LabelX;
case TOKuns32: t = Type::tuns32; 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 TOKuns64: t = Type::tuns64; goto LabelX;
case TOKint128: t = Type::tint128; goto LabelX; case TOKint128: t = Type::tint128; goto LabelX;
case TOKuns128: t = Type::tuns128; goto LabelX; case TOKuns128: t = Type::tuns128; goto LabelX;
......
/* 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
/*
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;
}
/*
DISABLED: win32 win64
TEST_OUTPUT:
---
fail_compilation/widechars.d(10): Error: undefined identifier `wchar_t`, did you mean `dchar`?
---
*/
wchar_t x;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment