llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.55k stars 11.8k forks source link

llvm-diff claims file is different from itself in 15, segfaults in 16 and 17 #60993

Open rptb1 opened 1 year ago

rptb1 commented 1 year ago

The llvm-diff tool produces a false positive result when comparing some files with themselves. That is, llvm-diff X X outputs differences and exits with code 1.

I have observed this in both version 14 and 15.

Here is a quick repro and example, including detailed version info.

rb@plover:~/tmp$ llvm-diff-15 --version
Ubuntu LLVM version 15.0.6
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: znver1
rb@plover:~/tmp$ clang-15 --version
Ubuntu clang version 15.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
rb@plover:~/tmp$ uname -a
Linux plover 5.15.0-60-generic #66-Ubuntu SMP Fri Jan 20 14:29:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
rb@plover:~/tmp$ clang-15 -dumpmachine
x86_64-pc-linux-gnu
rb@plover:~/tmp$ git clone --depth=1 https://github.com/Ravenbrook/mps.git
rb@plover:~/tmp$ cd mps/code
rb@plover:~/tmp/mps/code$ git log --oneline -n 1
142999b (grafted, HEAD -> master, origin/master, origin/HEAD) Merging branch/2023-02-16/manual-xrefs for GitHub pull request #159 <https://github.com/Ravenbrook/mps/pull/159>.
rb@plover:~/tmp/mps/code$ clang-15 -S -emit-llvm trace.c
rb@plover:~/tmp/mps/code$ llvm-diff-15 trace.ll trace.ll
in function ScanStateCheck:
  in block %14 / %14:
    >   %15 = phi i1 [ false, %6 ], [ %13, %9 ]
    >   %16 = zext i1 %15 to i32
    >   %17 = icmp ne i32 %16, 0
    >   %18 = zext i1 %17 to i32
    >   %19 = sext i32 %18 to i64
    >   %20 = icmp ne i64 %19, 0
    >   br i1 %20, label %21, label %24
    <   %15 = phi i1 [ false, %6 ], [ %13, %9 ]
    <   %16 = zext i1 %15 to i32
    <   %17 = icmp ne i32 %16, 0
    <   %18 = zext i1 %17 to i32
    <   %19 = sext i32 %18 to i64
    <   %20 = icmp ne i64 %19, 0
    <   br i1 %20, label %21, label %24

in function TraceCheck:
  in block %11 / %11:
    >   %12 = phi i1 [ false, %3 ], [ %10, %6 ]
    >   %13 = zext i1 %12 to i32
    >   %14 = icmp ne i32 %13, 0
    >   %15 = zext i1 %14 to i32
    >   %16 = sext i32 %15 to i64
    >   %17 = icmp ne i64 %16, 0
    >   br i1 %17, label %18, label %21
    <   %12 = phi i1 [ false, %3 ], [ %10, %6 ]
    <   %13 = zext i1 %12 to i32
    <   %14 = icmp ne i32 %13, 0
    <   %15 = zext i1 %14 to i32
    <   %16 = sext i32 %15 to i64
    <   %17 = icmp ne i64 %16, 0
    <   br i1 %17, label %18, label %21

in function TraceAddWhite:
  in block %174 / %174:
    >   %175 = phi i1 [ false, %161 ], [ false, %158 ], [ %173, %166 ]
    >   %176 = zext i1 %175 to i32
    >   %177 = icmp ne i32 %176, 0
    >   %178 = zext i1 %177 to i32
    >   %179 = sext i32 %178 to i64
    >   %180 = icmp ne i64 %179, 0
    >   br i1 %180, label %182, label %181
    <   %175 = phi i1 [ false, %161 ], [ false, %158 ], [ %173, %166 ]
    <   %176 = zext i1 %175 to i32
    <   %177 = icmp ne i32 %176, 0
    <   %178 = zext i1 %177 to i32
    <   %179 = sext i32 %178 to i64
    <   %180 = icmp ne i64 %179, 0
    <   br i1 %180, label %182, label %181
  in block %227 / %227:
    >   %228 = phi i1 [ false, %182 ], [ false, %151 ], [ %226, %215 ]
    >   %229 = zext i1 %228 to i32
    >   %230 = icmp ne i32 %229, 0
    >   %231 = zext i1 %230 to i32
    >   %232 = sext i32 %231 to i64
    >   %233 = icmp ne i64 %232, 0
    >   br i1 %233, label %235, label %234
    <   %228 = phi i1 [ false, %182 ], [ false, %151 ], [ %226, %215 ]
    <   %229 = zext i1 %228 to i32
    <   %230 = icmp ne i32 %229, 0
    <   %231 = zext i1 %230 to i32
    <   %232 = sext i32 %231 to i64
    <   %233 = icmp ne i64 %232, 0
    <   br i1 %233, label %235, label %234

in function TraceRankForAccess:
  in block %49 / %49:
    >   %50 = phi i1 [ false, %40 ], [ %48, %43 ]
    >   %51 = zext i1 %50 to i32
    >   %52 = icmp ne i32 %51, 0
    >   %53 = zext i1 %52 to i32
    >   %54 = sext i32 %53 to i64
    >   %55 = icmp ne i64 %54, 0
    >   br i1 %55, label %56, label %59
    <   %50 = phi i1 [ false, %40 ], [ %48, %43 ]
    <   %51 = zext i1 %50 to i32
    <   %52 = icmp ne i32 %51, 0
    <   %53 = zext i1 %52 to i32
    <   %54 = sext i32 %53 to i64
    <   %55 = icmp ne i64 %54, 0
    <   br i1 %55, label %56, label %59

in function TraceSegAccess:
  in block %84 / %84:
    >   %85 = phi i1 [ true, %70 ], [ %83, %73 ]
    >   %86 = zext i1 %85 to i32
    >   %87 = icmp ne i32 %86, 0
    >   %88 = zext i1 %87 to i32
    >   %89 = sext i32 %88 to i64
    >   %90 = icmp ne i64 %89, 0
    >   br i1 %90, label %91, label %94
    <   %85 = phi i1 [ true, %70 ], [ %83, %73 ]
    <   %86 = zext i1 %85 to i32
    <   %87 = icmp ne i32 %86, 0
    <   %88 = zext i1 %87 to i32
    <   %89 = sext i32 %88 to i64
    <   %90 = icmp ne i64 %89, 0
    <   br i1 %90, label %91, label %94

in function TraceStart:
  in block %201 / %201:
    >   %202 = phi i1 [ false, %180 ], [ false, %173 ], [ %200, %189 ]
    >   %203 = zext i1 %202 to i32
    >   %204 = icmp ne i32 %203, 0
    >   %205 = zext i1 %204 to i32
    >   %206 = sext i32 %205 to i64
    >   %207 = icmp ne i64 %206, 0
    >   br i1 %207, label %209, label %208
    <   %202 = phi i1 [ false, %180 ], [ false, %173 ], [ %200, %189 ]
    <   %203 = zext i1 %202 to i32
    <   %204 = icmp ne i32 %203, 0
    <   %205 = zext i1 %204 to i32
    <   %206 = sext i32 %205 to i64
    <   %207 = icmp ne i64 %206, 0
    <   br i1 %207, label %209, label %208

in function TracePoll:
  in block %97 / %97:
    >   %98 = phi i1 [ false, %82 ], [ %96, %87 ]
    >   br i1 %98, label %80, label %99, !llvm.loop !6
    <   %98 = phi i1 [ false, %82 ], [ %96, %87 ]
    <   br i1 %98, label %80, label %99, !llvm.loop !6
EugeneZelenko commented 1 year ago

Could you please try 16 or main branch?

rptb1 commented 1 year ago

Could you please try 16 or main branch?

Good news and bad news.

No false positives from the same test case in a fresh LXD Ubuntu container with LLVM 16 installed according to https://apt.llvm.org/ :

root@llvm-16:~/mps/code# llvm-diff-16 --version
llvm-diff-16 --version
Ubuntu LLVM version 16.0.0
  Optimized build.
root@llvm-16:~/mps/code# clang-16 -S -emit-llvm trace.c
root@llvm-16:~/mps/code# llvm-diff-16 trace.ll trace.ll
root@llvm-16:~/mps/code# echo $?
0

However, I thought I'd try compiling every source file as a test:

root@llvm-16:~/mps/code# for f in *.c; do clang-16 -S -emit-llvm $f; done
[various unimportant errors from sources intended for other platforms]
root@llvm-16:~/mps/code# for f in *.ll; do llvm-diff-16 $f $f || echo $f; done
Segmentation fault (core dumped)
djbench.ll
Segmentation fault (core dumped)
gcbench.ll
Segmentation fault (core dumped)
mps.ll
Segmentation fault (core dumped)
protocol.ll
rptb1 commented 1 year ago

I ran llvm.sh 17 to install that too. Same results.

root@llvm-16:~/mps/code# for f in *.c; do clang-17 -S -emit-llvm $f; done
...
root@llvm-16:~/mps/code# for f in *.ll; do llvm-diff-17 $f $f || echo $f; done
Segmentation fault (core dumped)
djbench.ll
Segmentation fault (core dumped)
gcbench.ll
Segmentation fault (core dumped)
mps.ll
Segmentation fault (core dumped)
protocol.ll
root@llvm-16:~/mps/code# llvm-diff-17 --version
Ubuntu LLVM version 17.0.0
  Optimized build.