Anters Bear
Anters Bear

Reputation: 1956

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?

Upvotes: 6

Views: 1460

Answers (1)

Martin R
Martin R

Reputation: 540005

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)
}

Upvotes: 7

Related Questions