https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116370

            Bug ID: 116370
           Summary: UBSAN issue in fortran/trans-expr.cc in
                    arrayfunc_assign_needs_temporary - enum value out of
                    range
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jamborm at gcc dot gnu.org
                CC: pault at gcc dot gnu.org
            Blocks: 63426
  Target Milestone: ---
              Host: x86_64-linux
            Target: x86_64-linux

With a compiler built with UBSAN instrumentation, compiling testcase
gfortran.dg/class_transformational_1.f90 fails with error:

/home/worker/buildworker/tiber-gcc-ubsan/build/gcc/fortran/trans-expr.cc:11157:33:
runtime error: load of value 1818451807, which is not a valid value for type
'expr_t'

This can be reproduced without UBSAN by just adding an assert like he following
 to function arrayfunc_assign_needs_temporary that the loaded enum value is in
range and then running the test:

--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -11153,6 +11153,8 @@ arrayfunc_assign_needs_temporary (gfc_expr * expr1,
gfc_expr * expr2)
      character lengths are the same.  */
   if (expr2->ts.type == BT_CHARACTER && expr2->rank > 0)
     {
+      gcc_assert (expr1->ts.u.cl->length == NULL
+                 || (((unsigned) expr1->ts.u.cl->length->expr_type) <=
(unsigned) EXPR_PPC));
       if (expr1->ts.u.cl->length == NULL
            || expr1->ts.u.cl->length->expr_type != EXPR_CONSTANT)
        return true;


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63426
[Bug 63426] [meta-bug] Issues found with -fsanitize=undefined

Reply via email to