Hi,

The following diff fix a bug in LLVM which it triggered when building lang/rust
1.41.0 (the latest version) on i386 (others archs are fine).

LLVM commit: 
https://github.com/llvm/llvm-project/commit/2153c4b8281c1e5f25887ef9183947198c50a9d2

RedHat has the same problem with rustc on i686 (and I steal the llvm commit 
from them):
- https://bugzilla.redhat.com/show_bug.cgi?id=1797127
- https://github.com/rust-lang/compiler-builtins/issues/338


To reproduce (without rustc, the file is llvm-ir output from rustc):

$ cat load.ll
; ModuleID = 'load.3a1fbbbh-cgu.0'
source_filename = "load.3a1fbbbh-cgu.0"
target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
target triple = "i686-unknown-openbsd"

; Function Attrs: nonlazybind uwtable
define void @unordered_load(i64* %src) unnamed_addr #0 {
start:
  %0 = alloca i64, align 4
  %1 = load atomic i64, i64* %src unordered, align 8
  store i64 %1, i64* %0, align 4
  %2 = load i64, i64* %0, align 4
  br label %bb1

bb1:                                              ; preds = %start
  ret void
}

attributes #0 = { nonlazybind uwtable "no-frame-pointer-elim"="true" 
"probe-stack"="__rust_probestack" "target-cpu"="pentiumpro" }

!llvm.module.flags = !{!0}

!0 = !{i32 2, !"RtLibUseGOT", i32 1}


before (on i386):
$ llc load.ll
cmpxchg instructions must be atomic.
  %1 = cmpxchg i64* %src, i64 0, i64 0 unordered not_atomic
in function unordered_load
LLVM ERROR: Broken function found, compilation aborted!
$

after (on i386):
$ llc load.ll
$   

and load.s is correctly generated and buildable.


I tested the change only on i386.

Comments or OK ?
-- 
Sebastien Marie


diff 9a533cbd26c2f04e3fb1c870b1375d429032de85 
3a1dd56b086ed90c170aec4e116fbf7e017b86f9
blob - 653f411bb1b6feb3a5a9f2e5ed5ab5e4b7f35f01 (mode 644)
blob + aed6bca5abfda531b5e2ebff68215d0210ccd512 (mode 640)
--- devel/llvm/Makefile
+++ devel/llvm/Makefile
@@ -18,7 +18,7 @@ PKGSPEC-main =        llvm-=${LLVM_V}
 PKGNAME-main = llvm-${LLVM_V}
 PKGNAME-python =       py-llvm-${LLVM_V}
 PKGNAME-lldb = lldb-${LLVM_V}
-REVISION-main =        5
+REVISION-main =        6
 REVISION-lldb= 0
 
 CATEGORIES =   devel
blob - /dev/null
blob + 3dcf1e3b1e45f8343e33fc3b841760574c14d83c (mode 640)
--- /dev/null
+++ devel/llvm/patches/patch-lib_CodeGen_AtomicExpandPass_cpp
@@ -0,0 +1,16 @@
+$OpenBSD$
+Fix a crash bug when lowering unordered loads to cmpxchg
+https://github.com/llvm/llvm-project/commit/2153c4b8281c1e5f25887ef9183947198c50a9d2
+
+Index: lib/CodeGen/AtomicExpandPass.cpp
+--- lib/CodeGen/AtomicExpandPass.cpp.orig
++++ lib/CodeGen/AtomicExpandPass.cpp
+@@ -431,6 +431,8 @@ bool AtomicExpand::expandAtomicLoadToLL(LoadInst *LI) 
+ bool AtomicExpand::expandAtomicLoadToCmpXchg(LoadInst *LI) {
+   IRBuilder<> Builder(LI);
+   AtomicOrdering Order = LI->getOrdering();
++  if (Order == AtomicOrdering::Unordered)
++      Order = AtomicOrdering::Monotonic;
+   Value *Addr = LI->getPointerOperand();
+   Type *Ty = cast<PointerType>(Addr->getType())->getElementType();
+   Constant *DummyVal = Constant::getNullValue(Ty);


Reply via email to