]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c/110454 - ICE with bogus TYPE_PRECISION use
authorRichard Biener <rguenther@suse.de>
Thu, 29 Jun 2023 06:55:39 +0000 (08:55 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 29 Jun 2023 08:10:44 +0000 (10:10 +0200)
The following sinks TYPE_PRECISION to properly guarded use places.

PR c/110454
gcc/c/
* c-typeck.cc (convert_argument): Sink formal_prec compute
to where TYPE_PRECISION is valid to use.

gcc/testsuite/
* gcc.dg/Wtraditional-conversion-3.c: New testcase.

gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/Wtraditional-conversion-3.c [new file with mode: 0644]

index 22e240a3c2a55640c1904be56f202b10339b3fa9..7cf411155c60d45bf7d17238055625bfe8b7a039 100644 (file)
@@ -3385,8 +3385,6 @@ convert_argument (location_t ploc, tree function, tree fundecl,
      conversions.  */
   if (warn_traditional_conversion || warn_traditional)
     {
-      unsigned int formal_prec = TYPE_PRECISION (type);
-
       if (INTEGRAL_TYPE_P (type)
          && SCALAR_FLOAT_TYPE_P (valtype))
        warning_at (ploc, OPT_Wtraditional_conversion,
@@ -3429,6 +3427,8 @@ convert_argument (location_t ploc, tree function, tree fundecl,
       else if (SCALAR_FLOAT_TYPE_P (type)
               && SCALAR_FLOAT_TYPE_P (valtype))
        {
+         unsigned int formal_prec = TYPE_PRECISION (type);
+
          /* Warn if any argument is passed as `float',
             since without a prototype it would be `double'.  */
          if (formal_prec == TYPE_PRECISION (float_type_node)
@@ -3472,6 +3472,7 @@ convert_argument (location_t ploc, tree function, tree fundecl,
               && INTEGRAL_TYPE_P (type)
               && INTEGRAL_TYPE_P (valtype))
        {
+         unsigned int formal_prec = TYPE_PRECISION (type);
          tree would_have_been = default_conversion (val);
          tree type1 = TREE_TYPE (would_have_been);
 
diff --git a/gcc/testsuite/gcc.dg/Wtraditional-conversion-3.c b/gcc/testsuite/gcc.dg/Wtraditional-conversion-3.c
new file mode 100644 (file)
index 0000000..796f2eb
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-options "-Wtraditional-conversion -Wno-psabi" } */
+
+typedef int __attribute__((__vector_size__ (4))) V;
+
+void
+foo (V v)
+{
+  foo (v);
+}