aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorAlexandre Oliva <aoliva@redhat.com>2018-04-16 21:35:34 +0000
committerAlexandre Oliva <aoliva@gcc.gnu.org>2018-04-16 21:35:34 +0000
commit7c5b407fa2f7dee7cfa663f7d5c4521fa4be00c8 (patch)
tree67da6c84e9f4c9931dbc864c087f4b01d201ee64 /gcc/cp
parent34722c3669ee87bd6754d4346e12e822641b0cd7 (diff)
downloadgcc-7c5b407fa2f7dee7cfa663f7d5c4521fa4be00c8.zip
gcc-7c5b407fa2f7dee7cfa663f7d5c4521fa4be00c8.tar.gz
gcc-7c5b407fa2f7dee7cfa663f7d5c4521fa4be00c8.tar.bz2
[PR c++/85039] no type definitions in builtin offsetof
Types defined within a __builtin_offsetof argument don't always get properly recorded as members of their context types, so if they're anonymous, we may fail to assign them an anon type index for mangling and ICE. We shouldn't allow types to be introduced in __builtin_offsetof, I think, and Jason says the std committee agrees, so I've arranged for us to reject them. Even then, we still parse the definitions and attempt to assign mangled names to its member functions, so the ICE remains. Since we've already reported an error, we might as well complete the name assignment with an arbitrary index, thus avoiding the ICE. We used to have a test that expected to be able to define types in __builtin_offsetof; this patch removes that specific test. for gcc/cp/ChangeLog PR c++/85039 * parser.c (cp_parser_builtin_offset): Reject type definitions. * mangle.c (nested_anon_class_index): Avoid crash returning -1 if we've seen errors. for gcc/testsuite/ChangeLog PR c++/85039 * g++.dg/pr85039-1.C: New. * g++.dg/pr85039-2.C: New. * g++.dg/parse/semicolon3.C: Remove test_offsetof. From-SVN: r259423
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/mangle.c3
-rw-r--r--gcc/cp/parser.c8
3 files changed, 17 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 5f29b0c..954127f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2018-04-16 Alexandre Oliva <aoliva@redhat.com>
+
+ PR c++/85039
+ * parser.c (cp_parser_builtin_offset): Reject type definitions.
+ * mangle.c (nested_anon_class_index): Avoid crash returning -1
+ if we've seen errors.
+
2018-04-12 David Malcolm <dmalcolm@redhat.com>
PR c++/85385
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 94c4bed..a7f9d68 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -1623,6 +1623,9 @@ nested_anon_class_index (tree type)
++index;
}
+ if (seen_error ())
+ return -1;
+
gcc_unreachable ();
}
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 8b1b271..bf46165f 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -9823,7 +9823,13 @@ cp_parser_builtin_offsetof (cp_parser *parser)
parens.require_open (parser);
/* Parse the type-id. */
location_t loc = cp_lexer_peek_token (parser->lexer)->location;
- type = cp_parser_type_id (parser);
+ {
+ const char *saved_message = parser->type_definition_forbidden_message;
+ parser->type_definition_forbidden_message
+ = G_("types may not be defined within __builtin_offsetof");
+ type = cp_parser_type_id (parser);
+ parser->type_definition_forbidden_message = saved_message;
+ }
/* Look for the `,'. */
cp_parser_require (parser, CPP_COMMA, RT_COMMA);
token = cp_lexer_peek_token (parser->lexer);