d/dmd: Merge upstream dmd b061bd744
authorIain Buclaw <ibuclaw@gdcproject.org>
Mon, 16 Mar 2020 08:48:54 +0000 (09:48 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Mon, 16 Mar 2020 09:38:55 +0000 (10:38 +0100)
Fixes an ICE in the parser, and deprecates a previously allowed style of
syntax that deviated from GNU-style extended asm.

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

gcc/testsuite/ChangeLog:

2020-03-16  Iain Buclaw  <ibuclaw@gdcproject.org>

* gdc.dg/asm1.d: Add new test for ICE in asm parser.
* gdc.dg/asm5.d: New test.

gcc/d/dmd/MERGE
gcc/d/dmd/iasmgcc.c
gcc/testsuite/ChangeLog
gcc/testsuite/gdc.dg/asm1.d
gcc/testsuite/gdc.dg/asm5.d [new file with mode: 0644]

index b017c037d74c4c715f05f6c8877ed292518890bd..6cbc4e37819921ffb7277183ffb7254861cebbc6 100644 (file)
@@ -1,4 +1,4 @@
-e9420cfbf5cd0cf9e6e398603e009ccc8e14d324
+b061bd744cb4eb94a7118581387d988d4ec25e97
 
 The first line of this file holds the git revision number of the last
 merge done from the dlang/dmd repository.
index cecbdefe41a0abda6cd8520ed1fe588c9f35cc62..548453321db87bf57ea81545a352ee2886585d41 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "scope.h"
 #include "declaration.h"
+#include "errors.h"
 #include "parse.h"
 #include "statement.h"
 
@@ -23,8 +24,8 @@ Statement *semantic(Statement *s, Scope *sc);
  * Parse list of extended asm input or output operands.
  * Grammar:
  *      | Operands:
- *      |     SymbolicName(opt) StringLiteral AssignExpression
- *      |     SymbolicName(opt) StringLiteral AssignExpression , Operands
+ *      |     SymbolicName(opt) StringLiteral ( AssignExpression )
+ *      |     SymbolicName(opt) StringLiteral ( AssignExpression ), Operands
  *      |
  *      | SymbolicName:
  *      |     [ Identifier ]
@@ -54,7 +55,9 @@ static int parseExtAsmOperands(Parser *p, GccAsmStatement *s)
             case TOKlbracket:
                 if (p->peekNext() == TOKidentifier)
                 {
+                    // Skip over openings `[`
                     p->nextToken();
+                    // Store the symbolic name
                     name = p->token.ident;
                     p->nextToken();
                 }
@@ -63,12 +66,32 @@ static int parseExtAsmOperands(Parser *p, GccAsmStatement *s)
                     p->error(s->loc, "expected identifier after `[`");
                     goto Lerror;
                 }
+                // Look for closing `]`
                 p->check(TOKrbracket);
+                // Look for the string literal and fall through
+                if (p->token.value != TOKstring)
+                    goto Ldefault;
                 // fall through
 
             case TOKstring:
                 constraint = p->parsePrimaryExp();
-                arg = p->parseAssignExp();
+                // @@@DEPRECATED@@@
+                // Old parser allowed omitting parentheses around the expression.
+                // Deprecated in 2.091. Can be made permanent error after 2.100
+                if (p->token.value != TOKlparen)
+                {
+                    arg = p->parseAssignExp();
+                    deprecation(arg->loc, "`%s` must be surrounded by parentheses", arg->toChars());
+                }
+                else
+                {
+                    // Look for the opening `(`
+                    p->check(TOKlparen);
+                    // Parse the assign expression
+                    arg = p->parseAssignExp();
+                    // Look for the closing `)`
+                    p->check(TOKrparen);
+                }
 
                 if (!s->args)
                 {
@@ -86,6 +109,7 @@ static int parseExtAsmOperands(Parser *p, GccAsmStatement *s)
                 break;
 
             default:
+            Ldefault:
                 p->error("expected constant string constraint for operand, not `%s`",
                         p->token.toChars());
                 goto Lerror;
index 1297954f5df0928d724ff1cb84cd761de79569c3..0f87a04d10017fdf740207a0ed79a30f66b5d460 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-16  Iain Buclaw  <ibuclaw@gdcproject.org>
+
+       * gdc.dg/asm1.d: Add new test for ICE in asm parser.
+       * gdc.dg/asm5.d: New test.
+
 2020-03-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/94167
index 7b00e4d54ec89a0fb8d2776b508c763df0b125c3..3fcfd6a58c11c8a06445682f76ba5d1eec3a9e4b 100644 (file)
@@ -29,6 +29,15 @@ void parse3()
     // { dg-error "found 'EOF' when expecting ';'" "" { target *-*-* } .-4 }
 }
 
+void parse4()
+{
+    int expr;
+    asm
+    {
+        "%name" : [name] string (expr); // { dg-error "expected constant string constraint for operand, not 'string'" }
+    }
+}
+
 void semantic1()
 {
     {
diff --git a/gcc/testsuite/gdc.dg/asm5.d b/gcc/testsuite/gdc.dg/asm5.d
new file mode 100644 (file)
index 0000000..b525a21
--- /dev/null
@@ -0,0 +1,12 @@
+// https://issues.dlang.org/show_bug.cgi?id=20593
+// { dg-do compile }
+// { dg-options "-Wall -Wdeprecated -Werror" }
+module asm5;
+
+void test(int a)
+{
+    asm
+    {
+        "cpuid" : : "a" a;  // { dg-error "'a' must be surrounded by parentheses" }
+    }
+}