From 9143de5c0185332e852f3d3167a7d6c8ae0b2514 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Wed, 5 Jan 2005 15:27:26 +0000 Subject: [PATCH] c-parse.in (asm_string): New. * c-parse.in (asm_string): New. Don't allow wide strings in 'asm'. (simple_asm_expr, asm_argument, asm_operand, asm_clobbers): Use asm_string instead of STRING. testsuite: * gcc.dg/asm-wide-1.c: New test. From-SVN: r92952 --- gcc/ChangeLog | 7 +++++++ gcc/c-parse.in | 37 +++++++++++++++++++++++++------------ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/asm-wide-1.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/asm-wide-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 428d578..1863509 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,12 @@ 2005-01-05 Joseph S. Myers + * c-parse.in (asm_string): New. Don't allow wide strings in + 'asm'. + (simple_asm_expr, asm_argument, asm_operand, asm_clobbers): Use + asm_string instead of STRING. + +2005-01-05 Joseph S. Myers + * c-typeck.c (constructor_no_implicit): Remove. (set_designator, process_init_element): Don't check constructor_no_implicit. diff --git a/gcc/c-parse.in b/gcc/c-parse.in index 94df4bb..413593e 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -1,6 +1,6 @@ /* YACC parser for C syntax and for Objective C. -*-c-*- - Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, - 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, + 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GCC. @@ -209,7 +209,7 @@ do { \ %type scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_volatile %type initdecls notype_initdecls initdcl notype_initdcl %type init -%type simple_asm_expr maybeasm asm_stmt asm_argument +%type simple_asm_expr maybeasm asm_stmt asm_argument asm_string %type asm_operands nonnull_asm_operands asm_operand asm_clobbers %type maybe_attribute attributes attribute attribute_list attrib %type any_word @@ -2330,7 +2330,7 @@ label: CASE expr_no_commas ':' expression with inputs and outputs does not make sense. */ simple_asm_expr: ASM_KEYWORD stop_string_translation - '(' STRING ')' start_string_translation + '(' asm_string ')' start_string_translation { $$ = $4; } ; @@ -2359,16 +2359,16 @@ asm_stmt: asm_argument: /* no operands */ - STRING + asm_string { $$ = build_asm_expr ($1, 0, 0, 0, true); } /* output operands */ - | STRING ':' asm_operands + | asm_string ':' asm_operands { $$ = build_asm_expr ($1, $3, 0, 0, false); } /* output and input operands */ - | STRING ':' asm_operands ':' asm_operands + | asm_string ':' asm_operands ':' asm_operands { $$ = build_asm_expr ($1, $3, $5, 0, false); } /* output and input operands and clobbers */ - | STRING ':' asm_operands ':' asm_operands ':' asm_clobbers + | asm_string ':' asm_operands ':' asm_operands ':' asm_clobbers { $$ = build_asm_expr ($1, $3, $5, $7, false); } ; @@ -2402,10 +2402,11 @@ nonnull_asm_operands: ; asm_operand: - STRING start_string_translation '(' expr ')' stop_string_translation + asm_string start_string_translation '(' expr ')' + stop_string_translation { $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $4.value); } - | '[' identifier ']' STRING start_string_translation + | '[' identifier ']' asm_string start_string_translation '(' expr ')' stop_string_translation { $2 = build_string (IDENTIFIER_LENGTH ($2), IDENTIFIER_POINTER ($2)); @@ -2413,12 +2414,24 @@ asm_operand: ; asm_clobbers: - STRING + asm_string { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); } - | asm_clobbers ',' STRING + | asm_clobbers ',' asm_string { $$ = tree_cons (NULL_TREE, $3, $1); } ; +/* Strings in 'asm' must be narrow strings. */ +asm_string: + STRING + { if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE ($1))) + != char_type_node) + { + error ("wide string literal in %"); + $$ = build_string (1, ""); + } + else + $$ = $1; } + stop_string_translation: { c_lex_string_translate = 0; } ; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d9dc42b..dfc3aa5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-01-05 Joseph S. Myers + + * gcc.dg/asm-wide-1.c: New test. + 2005-01-05 Nathan Sidwell PR c++/19030 diff --git a/gcc/testsuite/gcc.dg/asm-wide-1.c b/gcc/testsuite/gcc.dg/asm-wide-1.c new file mode 100644 index 0000000..82cf368 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-wide-1.c @@ -0,0 +1,35 @@ +/* Wide string literals should not be allowed in asm. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int foo asm (L"bar"); /* { dg-error "error: wide string literal in 'asm'" } */ + +asm (L"foo"); /* { dg-error "error: wide string literal in 'asm'" } */ + +void +f (void) +{ + int x = 1; + asm (L"foo"); /* { dg-error "error: wide string literal in 'asm'" } */ + asm ("foo" : + L"=g" (x)); /* { dg-error "error: wide string literal in 'asm'" } */ + asm ("foo" : [x] + L"=g" (x)); /* { dg-error "error: wide string literal in 'asm'" } */ + asm ("foo" : [x] "=g" (x), + L"=g" (x)); /* { dg-error "error: wide string literal in 'asm'" } */ + asm ("foo" : : + L"g" (x)); /* { dg-error "error: wide string literal in 'asm'" } */ + asm ("foo" : : : + L"memory"); /* { dg-error "error: wide string literal in 'asm'" } */ + asm ("foo" : : : "memory", + L"memory"); /* { dg-error "error: wide string literal in 'asm'" } */ +} + +/* Extra errors from the substitution of "" for wide strings: */ +/* { dg-error "output" "output" { target *-*-* } 16 } */ +/* { dg-error "output" "output" { target *-*-* } 18 } */ +/* { dg-error "output" "output" { target *-*-* } 20 } */ +/* { dg-warning "match" "match" { target *-*-* } 21 } */ +/* { dg-error "register" "register" { target *-*-* } 23 } */ +/* { dg-error "register" "register" { target *-*-* } 25 } */ -- 2.7.4