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

            Bug ID: 66046
           Summary: UBSan output pattern tests fail on target ARM board.
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: testsuite
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chefmax at gcc dot gnu.org
                CC: tetra2005 at gmail dot com
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: arm-linux-gnueabi

I see lots of output pattern test failures in UBSan testsuite running it on
target ARM board:

FAIL: c-c++-common/ubsan/object-size-1.c  -O2  output pattern test
FAIL: c-c++-common/ubsan/object-size-10.c  -O2  output pattern test
FAIL: c-c++-common/ubsan/object-size-4.c  -O2  output pattern test
FAIL: c-c++-common/ubsan/object-size-5.c  -O2  output pattern test
FAIL: c-c++-common/ubsan/overflow-negate-3.c  -O2  output pattern test
FAIL: c-c++-common/ubsan/overflow-sub-4.c  -O0  output pattern test
.................

Looking to the failing tests, I've noticed, that they all try to match the last
(\n|\r\n|\r), for example overflow-negate-3.c:

/* { dg-do run } */
/* { dg-options "-fsanitize=signed-integer-overflow" } */

#define INT_MIN (-__INT_MAX__ - 1)

int
main ()
{
  int x = INT_MIN;
  int y;
  asm ("" : "+g" (x));
  y = -(-x);
  asm ("" : "+g" (y));
  y = -(-INT_MIN);
  asm ("" : "+g" (y));
}

/* { dg-output "negation of -2147483648 cannot be represented in type
'int'\[^\n\r]*; cast to an unsigned type to negate this value to
itself\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in type
'int'\[^\n\r]*; cast to an unsigned type to negate this value to
itself\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in type
'int'\[^\n\r]*; cast to an unsigned type to negate this value to
itself\[^\n\r]*(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*negation of -2147483648 cannot be represented in type
'int'\[^\n\r]*; cast to an unsigned type to negate this value to
itself\[^\n\r]*(\n|\r\n|\r)" } */ <-- matches (\n|\r\n|\r)

But for some reasons, Dejagnu eats the last \n when running tests through ssh,
consider:

$ cat /usr/share/dejagnu/rsh.exp

proc rsh_exec { boardname program pargs inp outp } {
    global timeout
...............
     # Delete one trailing \n because that is what `exec' will do and we want
    # to behave identical to it.
    regsub "\n$" $output "" output                  <-- delete last \n here
    return [list [expr {$status != 0}] $output]
}

Although the easiest way to fix this is just deleting 'regsub "\n$" $output ""
output' line from rsh_exec, I'm not sure that modifying Dejagnu is a good idea.
Another option is to postprocess tests output in
gcc/testsuite/lib/ubsan-dg.exp, just like we do it in
gcc/testsuite/lib/asan-dg.exp:

+# Replace ${tool}_load with a wrapper so that we can symbolize the output.
+if { [info procs ${tool}_load] != [list] \
+      && [info procs saved_ubsan_${tool}_load] == [list] } {
+    rename ${tool}_load saved_ubsan_${tool}_load
+
+    proc ${tool}_load { program args } {
+       global tool
+       set result [eval [list saved_ubsan_${tool}_load $program] $args]
+       set output [lindex $result 1]
+       set result [list [lindex $result 0] "${output}\n"]
+       return $result
+    }
+}
+
#
# ubsan_finish -- called at the end of each subdir of tests
#

Reply via email to