View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001723 | OpenFOAM | Bug | public | 2015-05-30 19:42 | 2015-05-30 21:06 |
Reporter | Assigned To | henry | |||
Priority | normal | Severity | crash | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Platform | Any | OS | Any | OS Version | Any |
Summary | 0001723: Use of null references is incompatible with Clang/LLVM 3.5+ -- causes segfaults | ||||
Description | This problem was first reported here: http://www.openfoam.org/mantisbt/view.php?id=427 And the bug was closed because it was not currently causing a demonstrable problem. Now it is. As of Clang/LLVM 3.5, the optimizer will remove checks that the address of a reference is null. The underlying problem is that a function like this: bool foo(int &x) { return &x; } will always return true when optimizations are enabled. Running, on the above function: clang -O3 -S -emit-llvm -o - will yield: ... define zeroext i1 @_Z3fooRi(i32* nocapture readnone dereferenceable(4) %x) #0 { entry: ret i1 true } ... Clang 3.5 also added a warning for this, as discussed here: http://llvm.org/releases/3.5.0/tools/clang/docs/ReleaseNotes.html#major-new-features on the above function, you'll see: warning: reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true [-Wundefined-bool-conversion] This warning now is triggered in many places when compiling OpenFOAM (I'm specifically testing using the 2.3.x dev branch). | ||||
Steps To Reproduce | When compiling OpenFOAM with Clang/LLVM 3.5+ (including trunk), using, for example, bgclang build r238097-20150523 on the IBM BG/Q supercomputer, this can cause reconstructPar to crash. More details can certainly be provided if necessary. There are plenty of places in OpenFOAM that have statements like this: if (&iF && iF.size()) { .. } that now crash because the first check is removed by the optimizer. For example, in finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C we have the above code in one of the Foam::fvPatchField<Type>::fvPatchField constructors. | ||||
Tags | No tags attached. | ||||