Commit 21526606 by Eric Christopher

target-supports.exp (check-iconv-available): New function.

2004-02-26  Eric Christopher  <echristo@redhat.com>

	* lib/target-supports.exp (check-iconv-available): New function.
	* lib/gcc-dg.exp (dg-require-iconv): New function.
	Use above.
        * gcc.dg/charset: New directory.
        * gcc.dg/charset/charset.exp: New file.
        * gcc.dg/charset/asm1.c: Ditto.
        * gcc.dg/charset/asm2.c: Ditto.
        * gcc.dg/charset/asm3.c: Ditto.
        * gcc.dg/charset/asm4.c: Ditto.
        * gcc.dg/charset/asm5.c: Ditto.
        * gcc.dg/charset/attribute1.c: Ditto.
        * gcc.dg/charset/attribute2.c: Ditto.
        * gcc.dg/charset/string1.c: Ditto.
        * g++.dg/charset: New directory.
        * g++.dg/dg.exp: Add here. Special options.
        * g++.dg/charset/charset.exp: New file.
        * g++.dg/charset/asm1.c: Ditto.
        * g++.dg/charset/asm2.c: Ditto.
        * g++.dg/charset/asm3.c: Ditto.
        * g++.dg/charset/asm4.c: Ditto.
        * g++.dg/charset/attribute1.c: Ditto.
        * g++.dg/charset/attribute2.c: Ditto.
        * g++.dg/charset/extern1.cc: Ditto.
        * g++.dg/charset/extern2.cc: Ditto.
        * g++.dg/charset/string1.c: Ditto.

2004-02-26  Eric Christopher  <echristo@redhat.com>

	* c-lex.c (c_lex_string_translate): New variable.
	(lex_string): Use to determine string translation.
	* c-pragma.h: Prototype.
	* c-parse.in (start_string_translation): New. Set above.
	(stop_string_translation): Ditto.
	(attribute, attribute_list, asm_def, asm_stmt,
	asm_operand): Use above functions.
	* cp/parser.c (cp_parser_declaration): Translate strings
	unless token is RID_EXTERN. Set c_lex_string_translate
	for recursive use.
	(cp_parser_asm_definition): Only translate argument strings
	to asms.
	(cp_parser_asm_operand_list): Ditto.
	(cp_parser_attribute_list): Do not translate attribute strings.

From-SVN: r78548
parent 26d8bbbb
2004-02-26 Eric Christopher <echristo@redhat.com>
* c-lex.c (c_lex_string_translate): New variable.
(lex_string): Use to determine string translation.
* c-pragma.h: Prototype.
* c-parse.in (start_string_translation): New. Set above.
(stop_string_translation): Ditto.
(attribute, attribute_list, asm_def, asm_stmt,
asm_operand): Use above functions.
* cp/parser.c (cp_parser_declaration): Translate strings
unless token is RID_EXTERN. Set c_lex_string_translate
for recursive use.
(cp_parser_asm_definition): Only translate argument strings
to asms.
(cp_parser_asm_operand_list): Ditto.
(cp_parser_attribute_list): Do not translate attribute strings.
2004-02-26 Kazu Hirata <kazu@cs.umass.edu>
* stmt.c (expand_start_case_dummy): Remove.
......
......@@ -54,6 +54,7 @@ static splay_tree file_info_tree;
int pending_lang_change; /* If we need to switch languages - C++ only */
int c_header_level; /* depth in C headers - C++ only */
bool c_lex_string_translate = true; /* If we need to translate characters received. */
static tree interpret_integer (const cpp_token *, unsigned int);
static tree interpret_float (const cpp_token *, unsigned int);
......@@ -693,7 +694,9 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string)
if (count > 1 && !objc_string && warn_traditional && !in_system_header)
warning ("traditional C rejects string constant concatenation");
if (cpp_interpret_string (parse_in, strs, count, &istr, wide))
if ((c_lex_string_translate
? cpp_interpret_string : cpp_interpret_string_notranslate)
(parse_in, strs, count, &istr, wide))
{
value = build_string (istr.len, (char *)istr.text);
free ((void *)istr.text);
......
......@@ -1432,8 +1432,11 @@ attributes:
;
attribute:
ATTRIBUTE '(' '(' attribute_list ')' ')'
{ $$ = $4; }
ATTRIBUTE stop_string_translation
'(' '(' attribute_list ')' ')' start_string_translation
{ $$ = $5; }
| ATTRIBUTE error start_string_translation
{}
;
attribute_list:
......@@ -2480,8 +2483,9 @@ label: CASE expr_no_commas ':'
/* simple_asm_expr is used in restricted contexts, where a full
expression with inputs and outputs does not make sense. */
simple_asm_expr:
ASM_KEYWORD '(' STRING ')'
{ $$ = $3; }
ASM_KEYWORD stop_string_translation
'(' STRING ')' start_string_translation
{ $$ = $4; }
;
/* maybeasm: used for assembly names for declarations */
......@@ -2495,14 +2499,17 @@ maybeasm:
asmdef:
simple_asm_expr ';'
{ assemble_asm ($1); }
| ASM_KEYWORD error start_string_translation ';'
{}
;
/* Full-blown asm statement with inputs, outputs, clobbers, and
volatile tag allowed. */
asm_stmt:
ASM_KEYWORD maybe_volatile '(' asm_argument ')' ';'
ASM_KEYWORD maybe_volatile stop_string_translation
'(' asm_argument ')' start_string_translation ';'
{ stmt_count++;
$$ = build_asm_stmt ($2, $4); }
$$ = build_asm_stmt ($2, $5); }
;
asm_argument:
......@@ -2550,12 +2557,13 @@ nonnull_asm_operands:
;
asm_operand:
STRING '(' expr ')'
{ $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $3); }
| '[' identifier ']' STRING '(' expr ')'
STRING start_string_translation '(' expr ')' stop_string_translation
{ $$ = build_tree_list (build_tree_list (NULL_TREE, $1), $4); }
| '[' identifier ']' STRING start_string_translation
'(' expr ')' stop_string_translation
{ $2 = build_string (IDENTIFIER_LENGTH ($2),
IDENTIFIER_POINTER ($2));
$$ = build_tree_list (build_tree_list ($2, $4), $6); }
$$ = build_tree_list (build_tree_list ($2, $4), $7); }
;
asm_clobbers:
......@@ -2565,6 +2573,15 @@ asm_clobbers:
{ $$ = tree_cons (NULL_TREE, $3, $1); }
;
stop_string_translation:
{ c_lex_string_translate = false; }
;
start_string_translation:
{ c_lex_string_translate = true; }
;
/* This is what appears inside the parens in a function declarator.
Its value is a list of ..._TYPE nodes. Attributes must appear here
to avoid a conflict with their appearance after an open parenthesis
......
......@@ -57,4 +57,8 @@ extern void add_to_renaming_pragma_list (tree, tree);
extern int c_lex (tree *);
extern int c_lex_with_flags (tree *, unsigned char *);
/* If true, then lex strings into the execution character set.
Otherwise, lex strings into the host character set. */
extern bool c_lex_string_translate;
#endif /* GCC_C_PRAGMA_H */
......@@ -6331,6 +6331,10 @@ cp_parser_declaration (cp_parser* parser)
cp_token token2;
int saved_pedantic;
/* Set this here since we can be called after
pushing the linkage specification. */
c_lex_string_translate = true;
/* Check for the `__extension__' keyword. */
if (cp_parser_extension_opt (parser, &saved_pedantic))
{
......@@ -6344,6 +6348,11 @@ cp_parser_declaration (cp_parser* parser)
/* Try to figure out what kind of declaration is present. */
token1 = *cp_lexer_peek_token (parser->lexer);
/* Don't translate the CPP_STRING in extern "C". */
if (token1.keyword == RID_EXTERN)
c_lex_string_translate = false;
if (token1.type != CPP_EOF)
token2 = *cp_lexer_peek_nth_token (parser->lexer, 2);
......@@ -6396,6 +6405,8 @@ cp_parser_declaration (cp_parser* parser)
else
/* Try to parse a block-declaration, or a function-definition. */
cp_parser_block_declaration (parser, /*statement_p=*/false);
c_lex_string_translate = true;
}
/* Parse a block-declaration.
......@@ -9765,9 +9776,10 @@ cp_parser_asm_definition (cp_parser* parser)
/* Look for the opening `('. */
cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
/* Look for the string. */
c_lex_string_translate = false;
token = cp_parser_require (parser, CPP_STRING, "asm body");
if (!token)
return;
goto finish;
string = token->value;
/* If we're allowing GNU extensions, check for the extended assembly
syntax. Unfortunately, the `:' tokens need not be separated by
......@@ -9861,6 +9873,9 @@ cp_parser_asm_definition (cp_parser* parser)
}
else
assemble_asm (string);
finish:
c_lex_string_translate = true;
}
/* Declarators [gram.dcl.decl] */
......@@ -13273,6 +13288,8 @@ cp_parser_asm_operand_list (cp_parser* parser)
tree name;
cp_token *token;
c_lex_string_translate = false;
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_SQUARE))
{
/* Consume the `[' token. */
......@@ -13290,12 +13307,14 @@ cp_parser_asm_operand_list (cp_parser* parser)
/* Look for the string-literal. */
token = cp_parser_require (parser, CPP_STRING, "string-literal");
string_literal = token ? token->value : error_mark_node;
c_lex_string_translate = true;
/* Look for the `('. */
cp_parser_require (parser, CPP_OPEN_PAREN, "`('");
/* Parse the expression. */
expression = cp_parser_expression (parser);
/* Look for the `)'. */
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
c_lex_string_translate = false;
/* Add this operand to the list. */
asm_operands = tree_cons (build_tree_list (name, string_literal),
expression,
......@@ -13421,6 +13440,7 @@ cp_parser_attribute_list (cp_parser* parser)
{
tree attribute_list = NULL_TREE;
c_lex_string_translate = false;
while (true)
{
cp_token *token;
......@@ -13466,6 +13486,7 @@ cp_parser_attribute_list (cp_parser* parser)
/* Consume the comma and keep going. */
cp_lexer_consume_token (parser->lexer);
}
c_lex_string_translate = true;
/* We built up the list in reverse order. */
return nreverse (attribute_list);
......
2004-02-26 Eric Christopher <echristo@redhat.com>
* lib/target-supports.exp (check-iconv-available): New function.
* lib/gcc-dg.exp (dg-require-iconv): New function.
Use above.
* gcc.dg/charset: New directory.
* gcc.dg/charset/charset.exp: New file.
* gcc.dg/charset/asm1.c: Ditto.
* gcc.dg/charset/asm2.c: Ditto.
* gcc.dg/charset/asm3.c: Ditto.
* gcc.dg/charset/asm4.c: Ditto.
* gcc.dg/charset/asm5.c: Ditto.
* gcc.dg/charset/attribute1.c: Ditto.
* gcc.dg/charset/attribute2.c: Ditto.
* gcc.dg/charset/string1.c: Ditto.
* g++.dg/charset: New directory.
* g++.dg/dg.exp: Add here. Special options.
* g++.dg/charset/charset.exp: New file.
* g++.dg/charset/asm1.c: Ditto.
* g++.dg/charset/asm2.c: Ditto.
* g++.dg/charset/asm3.c: Ditto.
* g++.dg/charset/asm4.c: Ditto.
* g++.dg/charset/attribute1.c: Ditto.
* g++.dg/charset/attribute2.c: Ditto.
* g++.dg/charset/extern1.cc: Ditto.
* g++.dg/charset/extern2.cc: Ditto.
* g++.dg/charset/string1.c: Ditto.
2004-02-26 Mark Mitchell <mark@codesourcery.com>
PR c++/14278
......@@ -21063,5 +21091,3 @@ rlsruhe.de>
correspond to c-torture 1.11.
* New file.
/* { dg-do compile { target *-*-* } }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler ".ascii bar" } }
{ dg-final { scan-assembler ".ascii foo" } }
*/
extern int x, y;
asm (".ascii bar");
int foo (void)
{
__asm__ (".ascii foo");
return 0;
}
/* Test for complex asm statements. Make sure it compiles
then test for some of the asm statements not being translated. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler "std" } }
{ dg-final { scan-assembler "cld" } }
{ dg-final { scan-assembler "rep" } }
{ dg-final { scan-assembler "movsb" } } */
#define size_t int
void *
memmove (void *__dest, __const void *__src, size_t __n)
{
register unsigned long int __d0, __d1, __d2;
if (__dest < __src)
__asm__ __volatile__
("cld\n\t"
"rep\n\t"
"movsb"
: "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
: "0" (__n), "1" (__src), "2" (__dest)
: "memory");
else
__asm__ __volatile__
("std\n\t"
"rep\n\t"
"movsb\n\t"
"cld"
: "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
: "0" (__n), "1" (__n - 1 + (const char *) __src),
"2" (__n - 1 + (char *) __dest)
: "memory");
return __dest;
}
/* Simple asm test. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler "foo" } } */
extern int bar;
int main (void)
{
asm ("foo %0" : "=r" (bar));
}
/* Test for string translation. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler-not "translate" } } */
void foo (void)
{
asm ("xx" : : "r"("translate") : "cc");
}
/* Test for attribute non-translation. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler "foo" } } */
int walrus __attribute__ ((section (".foo")));
int main (void)
{
return 0;
}
/* Test to make sure that invalid attributes aren't translated.
If error recovery is ever testable then "foobar" should be
translated. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
*/
int foo __attribute__ ((walrus)); /* { dg-error "walrus" "ignored" } */
char x[] = "foobar";
# Copyright (C) 2004 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# GCC testsuite that uses the 'dg.exp' driver.
# There's a bunch of headers we need.
if [is_remote host] {
foreach header [glob -nocomplain $srcdir/$subdir/*.{h,def} ] {
remote_download host $header
}
}
# Load support procs.
load_lib g++-dg.exp
load_lib target-supports.exp
# If a testcase doesn't have special options, use these.
global DEFAULT_CFLAGS
if ![info exists DEFAULT_CFLAGS] then {
set DEFAULT_CFLAGS "-fexec-charset=IBM-1047"
}
# Initialize `dg'.
dg-init
# Main loop.
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.{c,S} ]] \
"" $DEFAULT_CFLAGS
# All done.
dg-finish
/* Test extern statments not being translated. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
*/
extern "C" {
int testbug (void) {
return 0;
}
} //extern block
/* Check that we push the declaration and then continue translation. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler-not "foobar" } } */
extern "C" { char *foo = "foobar"; }
/* Simple character translation test. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler-not "string foobar" } } */
char *foo = "string foobar";
......@@ -32,6 +32,7 @@ dg-init
# that are handled specially.
set tests [lsort [find $srcdir/$subdir *.C]]
set tests [prune $tests $srcdir/$subdir/bprob/*]
set tests [prune $tests $srcdir/$subdir/charset/*]
set tests [prune $tests $srcdir/$subdir/compat/*]
set tests [prune $tests $srcdir/$subdir/debug/*]
set tests [prune $tests $srcdir/$subdir/gcov/*]
......
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler ".ascii bar" } }
{ dg-final { scan-assembler ".ascii foo" } }
*/
extern int x, y;
asm (".ascii bar");
int foo (void)
{
__asm__ (".ascii foo");
return 0;
}
/* Test for execution character set encoding errors.
If we ever get a good way to test error recovery
the string "foobar" should be translated. */
/* { dg-do compile } */
/* { dg-require-iconv "IBM-1047" } */
asm (not_a_string); /* { dg-error "syntax error before" "not_a_string" } */
char x[] = "foobar";
void foo (void)
{
char *y;
asm (not_a_string2); /* { dg-error "syntax error before" "not_a_string" } */
#define FOO "walrus"
y = FOO;
}
/* Test for complex asm statements. Make sure it compiles
then test for some of the asm statements not being translated. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler "std" } }
{ dg-final { scan-assembler "cld" } }
{ dg-final { scan-assembler "rep" } }
{ dg-final { scan-assembler "movsb" } } */
#define size_t int
void *
memmove (void *__dest, __const void *__src, size_t __n)
{
register unsigned long int __d0, __d1, __d2;
if (__dest < __src)
__asm__ __volatile__
("cld\n\t"
"rep\n\t"
"movsb"
: "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
: "0" (__n), "1" (__src), "2" (__dest)
: "memory");
else
__asm__ __volatile__
("std\n\t"
"rep\n\t"
"movsb\n\t"
"cld"
: "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
: "0" (__n), "1" (__n - 1 + (const char *) __src),
"2" (__n - 1 + (char *) __dest)
: "memory");
return __dest;
}
/* Simple asm test. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler "foo" } } */
extern int bar;
int main (void)
{
asm ("foo %0" : "=r" (bar));
}
/* Test for string translation. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler-not "translate" } } */
void foo (void)
{
asm ("xx" : : "r"("translate") : "cc");
}
/* Test for attribute non-translation. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler "foo" } } */
int walrus __attribute__ ((section (".foo")));
int main (void)
{
return 0;
}
/* Test to make sure that invalid attributes aren't translated.
If error recovery is ever testable then "foobar" should be
translated. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
*/
int foo __attribute__ ((walrus)); /* { dg-error "walrus" "ignored" } */
char x[] = "foobar";
# Copyright (C) 2004 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# GCC testsuite that uses the 'dg.exp' driver.
# There's a bunch of headers we need.
if [is_remote host] {
foreach header [glob -nocomplain $srcdir/$subdir/*.{h,def} ] {
remote_download host $header
}
}
# Load support procs.
load_lib gcc-dg.exp
load_lib target-supports.exp
# If a testcase doesn't have special options, use these.
global DEFAULT_CHARSETCFLAGS
if ![info exists DEFAULT_CHARSETCFLAGS] then {
set DEFAULT_CHARSETCFLAGS "-fexec-charset=IBM-1047"
}
# Initialize `dg'.
dg-init
# Main loop.
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.{c,S} ]] \
"" $DEFAULT_CHARSETCFLAGS
# All done.
dg-finish
/* Simple character translation test. */
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler-not "string foobar" } } */
char *foo = "string foobar";
......@@ -348,6 +348,15 @@ proc dg-require-dll { args } {
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
}
proc dg-require-iconv { args } {
if { ![ check_iconv_available ${args} ] } {
upvar dg-do-what dg-do-what
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
return
}
return
}
# Prune any messages matching ARGS[1] (a regexp) from test output.
proc dg-prune-output { args } {
global additional_prunes
......
......@@ -211,3 +211,34 @@ proc check_profiling_available { test_what } {
return $profiling_available_saved
}
# Return true if iconv is supported on the target. In particular IBM-1047.
proc check_iconv_available { test_what } {
global tool
set result ""
verbose "check_iconv_available compiling testfile" 1
set f [open "tmp.c" "w"]
# Compile a small test program.
puts $f "#include <iconv.h>\n"
puts $f "int main (void)\n {\n iconv_t cd; \n"
puts $f "cd = iconv_open (\"[lindex $test_what 1]\", \"UTF-8\");\n"
puts $f "if (cd == (iconv_t) -1)\n return 1;\n"
puts $f "return 0;\n}"
close $f
set lines [${tool}_target_compile "tmp.c" "tmp.x" executable ""]
set result [${tool}_load "./tmp.x" "" ""]
set status [lindex $result 0];
verbose "status is <$status>"
if { $status == "pass" } then {
return 1
}
return 0
}
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