c-family: Initialize ridpointers for __int128 etc. [PR105186]
authorJakub Jelinek <jakub@redhat.com>
Mon, 11 Apr 2022 08:41:07 +0000 (10:41 +0200)
committerJakub Jelinek <jakub@redhat.com>
Mon, 11 Apr 2022 08:41:07 +0000 (10:41 +0200)
The following testcase ICEs with C++ and is incorrectly rejected with C.
The reason is that both FEs use ridpointers identifiers for CPP_KEYWORD
and value or u.value for CPP_NAME e.g. when parsing attributes or OpenMP
directives etc., like:
         /* Save away the identifier that indicates which attribute
            this is.  */
         identifier = (token->type == CPP_KEYWORD)
           /* For keywords, use the canonical spelling, not the
              parsed identifier.  */
           ? ridpointers[(int) token->keyword]
           : id_token->u.value;

         identifier = canonicalize_attr_name (identifier);
I've tried to change those to use ridpointers only if non-NULL and otherwise
use the value/u.value even for CPP_KEYWORDS, but that was a large 10 hunks
patch.

The following patch instead just initializes ridpointers for the __intNN
keywords.  It can't be done earlier before we record_builtin_type as there
are 2 different spellings and if we initialize those ridpointers early, the
second record_builtin_type fails miserably.

2022-04-11  Jakub Jelinek  <jakub@redhat.com>

PR c++/105186
* c-common.cc (c_common_nodes_and_builtins): After registering __int%d
and __int%d__ builtin types, initialize corresponding ridpointers
entry.

* c-c++-common/pr105186.c: New test.

gcc/c-family/c-common.cc
gcc/testsuite/c-c++-common/pr105186.c [new file with mode: 0644]

index d034837..70f55f3 100644 (file)
@@ -4278,6 +4278,8 @@ c_common_nodes_and_builtins (void)
       sprintf (name, "__int%d__", int_n_data[i].bitsize);
       record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
                           int_n_trees[i].signed_type);
+      ridpointers[RID_FIRST_INT_N + i]
+       = DECL_NAME (TYPE_NAME (int_n_trees[i].signed_type));
 
       sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
       record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
diff --git a/gcc/testsuite/c-c++-common/pr105186.c b/gcc/testsuite/c-c++-common/pr105186.c
new file mode 100644 (file)
index 0000000..ea687ea
--- /dev/null
@@ -0,0 +1,5 @@
+/* PR c++/105186 */
+/* { dg-do compile } */
+
+__attribute__((__int128)) int i;       /* { dg-warning "'__int128' attribute directive ignored" } */
+__attribute__((__int128__)) int j;     /* { dg-warning "'__int128' attribute directive ignored" } */