Issue |
130688
|
Summary |
Assertion failure in SCEV - "Your comparator is not a valid strict-weak ordering"
|
Labels |
llvm:SCEV,
hardening
|
Assignees |
sanjoy
|
Reporter |
alexfh
|
While debugging another issue, we found this assertion failure arising from this `stable_sort` invocation: https://github.com/llvm/llvm-project/blame/main/llvm/lib/Analysis/ScalarEvolution.cpp#L795, which is using this comparator: https://github.com/llvm/llvm-project/blame/main/llvm/lib/Analysis/ScalarEvolution.cpp#L781.
This only happens when clang is compiled with the corresponding libc++ hardening enabled (`-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG`).
A reduced test case:
```
$ cat reduced.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define ptr @_f1(ptr %this, ptr %__first) {
entry:
%call = call i64 @_f2(ptr %this, ptr %__first)
%call3 = call ptr @_f3(ptr %this, i64 %call)
ret ptr null
}
define void @_f4(ptr %__from_s, ptr %__to) {
entry:
%0 = load ptr, ptr %__from_s, align 8
%sub.ptr.lhs.cast = ptrtoint ptr %0 to i64
%sub.ptr.rhs.cast = ptrtoint ptr %__to to i64
%sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
%add.ptr = getelementptr i8, ptr %__from_s, i64 %sub.ptr.sub
br label %for.cond
for.cond: ; preds = %for.cond, %entry
%__i.0 = phi ptr [ %add.ptr, %entry ], [ %incdec.ptr, %for.cond ]
store volatile ptr %__i.0, ptr null, align 8
%incdec.ptr = getelementptr i8, ptr %__i.0, i64 1
br label %for.cond
}
define ptr @_f3(ptr %this, i64 %__n) {
entry:
%0 = load ptr, ptr %this, align 8
%call3 = load volatile i64, ptr null, align 8
%add.ptr = getelementptr i8, ptr %0, i64 %call3
%add.ptr16 = getelementptr i8, ptr %add.ptr, i64 %__n
call void @_f4(ptr %add.ptr, ptr %add.ptr16)
ret ptr null
}
define i64 @_f2(ptr %__first, ptr %__last) {
entry:
%call = call i64 @_f5(ptr %__first, ptr %__last)
ret i64 %call
}
define i64 @_f5(ptr %__first, ptr %__last) {
entry:
%sub.ptr.lhs.cast = ptrtoint ptr %__last to i64
%sub.ptr.rhs.cast = ptrtoint ptr %__first to i64
%sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
ret i64 %sub.ptr.sub
}
$ ./clang-bad -O1 -c reduced.ll -o -
libcxx/include/__debug_utils/strict_weak_ordering_check.h:59: assertion __comp(*(__first + __a), *(__first + __b)) failed: Your comparator is not a valid strict-weak ordering
...
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs