aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2020-03-01 17:41:45 -0700
committerMartin Sebor <msebor@redhat.com>2020-03-01 17:41:45 -0700
commita499c2f899961f2c09db2dc33e60b66e8d770092 (patch)
treeb4e1280ce09a78f7b1a84f3e921d48f47aef1ef2 /gcc/c
parent1e9369c5dcf301e090d3a83e2c210cd6b96ac08c (diff)
downloadgcc-a499c2f899961f2c09db2dc33e60b66e8d770092.zip
gcc-a499c2f899961f2c09db2dc33e60b66e8d770092.tar.gz
gcc-a499c2f899961f2c09db2dc33e60b66e8d770092.tar.bz2
PR c/93812 - ICE on redeclaration of an attribute format function without protoype
gcc/c/ChangeLog: PR c/93812 * c-typeck.c (build_functype_attribute_variant): New function. (composite_type): Call it. gcc/testsuite/ChangeLog: PR c/93812 * gcc.dg/format/proto.c: New test.
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-typeck.c27
2 files changed, 30 insertions, 3 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 83bf651..effb71b 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2020-03-01 Martin Sebor <msebor@redhat.com>
+
+ PR c/93812
+ * c-typeck.c (build_functype_attribute_variant): New function.
+ (composite_type): Call it.
+
2020-02-25 Jakub Jelinek <jakub@redhat.com>
PR other/93912
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 8df0849..308fcff 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -353,7 +353,28 @@ c_vla_type_p (const_tree t)
return true;
return false;
}
-
+
+/* If NTYPE is a type of a non-variadic function with a prototype
+ and OTYPE is a type of a function without a prototype and ATTRS
+ contains attribute format, diagnosess and removes it from ATTRS.
+ Returns the result of build_type_attribute_variant of NTYPE and
+ the (possibly) modified ATTRS. */
+
+static tree
+build_functype_attribute_variant (tree ntype, tree otype, tree attrs)
+{
+ if (!prototype_p (otype)
+ && prototype_p (ntype)
+ && lookup_attribute ("format", attrs))
+ {
+ warning_at (input_location, OPT_Wattributes,
+ "%qs attribute cannot be applied to a function that "
+ "does not take variable arguments", "format");
+ attrs = remove_attribute ("format", attrs);
+ }
+ return build_type_attribute_variant (ntype, attrs);
+
+}
/* Return the composite type of two compatible types.
We assume that comptypes has already been done and returned
@@ -504,9 +525,9 @@ composite_type (tree t1, tree t2)
/* Save space: see if the result is identical to one of the args. */
if (valtype == TREE_TYPE (t1) && !TYPE_ARG_TYPES (t2))
- return build_type_attribute_variant (t1, attributes);
+ return build_functype_attribute_variant (t1, t2, attributes);
if (valtype == TREE_TYPE (t2) && !TYPE_ARG_TYPES (t1))
- return build_type_attribute_variant (t2, attributes);
+ return build_functype_attribute_variant (t2, t1, attributes);
/* Simple way if one arg fails to specify argument types. */
if (TYPE_ARG_TYPES (t1) == NULL_TREE)