False positive in Pointer Checker with atomic pointers

False positive in Pointer Checker with atomic pointers

I would like to report a false positive in the Intel Pointer Checker.

When using atomic pointers, the bounds metadata is not updated atomically with the pointer itself causing a race and a false report in the Checker. My conclusion: Intel Pointer Checker (or future MPX-based tools) can not be used with atomic pointers. Am I wrong? Please comment.

Using composer_xe_2013.5.192 on Linux. 

% cat cxx11_ptr_check.cc

#include <atomic>
#include <thread>
#include <iostream>
#include <assert.h>
std::atomic<int *> p;
int A, B;
void Thread1() { for (int i = 0; i < 100000; i++) p = &A; }
void Thread2() { for (int i = 0; i < 100000; i++) p = &B; }
void Thread3() { for (int i = 0; i < 100000; i++) assert(*p == 0); }
int main() {
 std::cout << "A=" << &A << " B=" << &B << std::endl;
 std::thread t1(Thread1);
 std::thread t2(Thread2);
 std::thread t3(Thread3);
 t1.join();
 t2.join();
 t3.join();
}

% icpc -g -O2 -std=c++0x -check-pointers=rw cxx11_ptr_check.cc -lpthread; ./a.out
A=0x61bc48 B=0x61bc4c
CHKP: Bounds check error
lb: 0x61bc48
ub: 0x61bc4b
addr: 0x61bc4c
end: 0x61bc4f
size: 4
Traceback:
at address 0x405289 in function _Z7Thread3v

in file /tmp/cxx11_ptr_check.cc line 9

2 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

add "p = &A;" between lines 10 and 11 for correctness, otherwise p may be zero when accessed. 

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi