Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlapping Accesses pointer

I'm trying to run swix in Swift 4. I've solved most of the initial issues that came up but there's one left I don't know enough about to resolve. It's three instances of the same error, see code bellow

var nc = __CLPK_integer(N)
dgetrf_(&nc, &nc, !y, &nc, &ipiv, &info)

Overlapping accesses to 'nc', but modification requires exclusive access; consider copying to a local variable

Any idea on how I can resolve this?

like image 307
Anters Bear Avatar asked Nov 04 '17 19:11

Anters Bear


1 Answers

That is a consequence of SE-0176 Enforce Exclusive Access to Memory, which was implemented in Swift 4: The __m, __n, and __lda arguments of dgetrf_()have the type UnsafeMutablePointer<>, even though the pointed-to variable is not mutated (but the compiler does not know that!) and you pass the address of the same variable nc to all three of them.

There are two possible solutions: Additional variable copies:

var nc1 = nc, nc2 = nc
dgetrf_(&nc, &nc1, &matrix, &nc2, &ipiv, &info)

Or withUnsafeMutablePointer, because unsafe pointers do not use any active enforcement:

withUnsafeMutablePointer(to: &nc) {
    dgetrf_($0, $0, &matrix, $0, &ipiv, &info)
}
like image 160
Martin R Avatar answered Oct 21 '22 05:10

Martin R