From 69b5279e977593d656906288316ee03a8bf79c6a Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 1 Jul 2019 13:36:05 +0000 Subject: [PATCH] gimple-parser.c (c_parser_gimple_postfix_expression): Handle _Literal (char *) &"foo" for address literals pointing to STRING_CSTs. 2019-07-01 Richard Biener c/ * gimple-parser.c (c_parser_gimple_postfix_expression): Handle _Literal (char *) &"foo" for address literals pointing to STRING_CSTs. * gcc.dg/gimplefe-42.c: New testcase. From-SVN: r272872 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/gimple-parser.c | 9 +++++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/gimplefe-42.c | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gimplefe-42.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 83f3eaaa022..271ed4ba3e9 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2019-07-01 Richard Biener + + * gimple-parser.c (c_parser_gimple_postfix_expression): Handle + _Literal (char *) &"foo" for address literals pointing to + STRING_CSTs. + 2019-06-24 Martin Sebor * c-typeck.c (build_binary_op): Hyphenate floating-point. diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index 275ad911d08..b2b364cc41a 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -1596,17 +1596,22 @@ c_parser_gimple_postfix_expression (gimple_parser &parser) } else { - bool neg_p; + bool neg_p, addr_p; if ((neg_p = c_parser_next_token_is (parser, CPP_MINUS))) c_parser_consume_token (parser); + if ((addr_p = c_parser_next_token_is (parser, CPP_AND))) + c_parser_consume_token (parser); tree val = c_parser_gimple_postfix_expression (parser).value; if (! val || val == error_mark_node - || ! CONSTANT_CLASS_P (val)) + || ! CONSTANT_CLASS_P (val) + || (addr_p && TREE_CODE (val) != STRING_CST)) { c_parser_error (parser, "invalid _Literal"); return expr; } + if (addr_p) + val = build1 (ADDR_EXPR, type, val); if (neg_p) { val = const_unop (NEGATE_EXPR, TREE_TYPE (val), val); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7e5f38c9113..ef255f5a312 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-01 Richard Biener + + * gcc.dg/gimplefe-42.c: New testcase. + 2019-07-01 Hristian Kirtchev * gnat.dg/sets1.adb: Update. diff --git a/gcc/testsuite/gcc.dg/gimplefe-42.c b/gcc/testsuite/gcc.dg/gimplefe-42.c new file mode 100644 index 00000000000..b79033934d2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-42.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +typedef char ref_all_char __attribute__((may_alias)); +char a[7]; +__GIMPLE void f() +{ + int _1; + /* string literals inside __MEM need their address taken. */ + __MEM ((ref_all_char *)&a) + = __MEM (_Literal (char *) &"654321"); + /* but plain assignment also works. */ + __MEM ((ref_all_char *)&a) = "654321"; + /* also punning with int. */ + _1 = __MEM (_Literal (char *) &"654321"); + __MEM ((ref_all_char *)&a) = _1; + return; +} -- 2.30.2