Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

Window x64 17.0.1 compiler, Visual Studio 2015, and std::list checked iterators issue

$
0
0

I have encountered a number of mysterious crashes on Windows x64 using 17.0.1 in _DEBUG mode only. In _DEBUG mode on Windows, various STL functions are validated using what are called "checked iterators"

 

Here is my sample test program. To reproduce, create a Visual C++ 2015 console project, and run in x64|Debug mode.

#include "stdafx.h"
#include <list>
#include <iostream>
using namespace std;
int main()
{
	std::list<int> a;
	a.clear();
	for(auto & i : a){// we have an iterator loop here, this forces creation of some sticky iterator data structures in the list
		cout << i << endl;// some dummy code
	}
	a.clear();// Intel Compiler and Visual Studio 2015 compiler behave differently on second clear()
    return 0;
}
/// THE FOLLOWING IS PART OF <list>, list::clear() calls _Orphan_ptr(nullptr) in _DEBUG mode
 #if _ITERATOR_DEBUG_LEVEL == 2
	void _Orphan_ptr(_Nodeptr _Ptr)
		{	// orphan iterators with specified node pointers
		_Lockit _Lock(_LOCK_DEBUG);
		const_iterator **_Pnext = (const_iterator **)this->_Getpfirst();
		if (_Pnext != 0)
			while (*_Pnext != 0)
				{	// test an iterator
				if ((*_Pnext)->_Ptr == this->_Myhead()
					|| (_Ptr != nullptr_t{} && (*_Pnext)->_Ptr != _Ptr))
					_Pnext = (const_iterator **)(*_Pnext)->_Getpnext();
				else
					{	// orphan the iterator
					(*_Pnext)->_Clrcont();
					*_Pnext = *(const_iterator **)(*_Pnext)->_Getpnext();
					}
				}
		}
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */

when I step into the function list::_Orphan_ptr  I see different behavior between Visual Studio 2015 native compiled and Intel 17.0.1 compiled in _DEBUG mode, that is with _ITERATOR_DEBUG_LEVEL=2, 

In simple language, if the list is empty, the while() loop should NEVER be entered. 

Visual Studio 2015 -> _Pnext!=0, *_PNext=0 , while loop is skipped ( as expected)

Intel Compiler 17.0.1 -> _Pnext!=0, *_PNext=<some random number>, while loop is entered, often causing an access violation.

This may be a bug in the checked iterator code of MS STL or it may be a bug in the Intel Compiler - I am not sure 100% at the moment.

Zone: 


Viewing all articles
Browse latest Browse all 1175

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>