Type inconsistency in LLVM 3.1: CGDebugInfo.cpp

I’m probably missing something simple here but in:

CGDebugInfo.h:

std::vector<std::pair<void *, llvm::WeakVH> >ReplaceMap;

but then in

CGDebugInfo.cpp:

llvm::DIType TC = getTypeOrNull(Ty);

void * v = Ty.getAsOpaquePtr();

std::pair<void *, llvm::WeakVH> tmp = std::make_pair(v, TC);

if (TC.Verify() && TC.isForwardDecl())

ReplaceMap.push_back(Ty.getTypeOrNull(), TC);

Note that TC is of type llvm:DIType and not WeakVH.

What am I missing, as this does not compile under Visual Studio 2012 RC?

Regards,

Ben

  • Benedict R. Gaster

Enjoy Berlin and submit a paper to Multiprog 2013: http://multiprog.ac.upc.edu/

Sorry the code had some left over debug code, should have been:

CGDebugInfo.cpp:

llvm::DIType TC = getTypeOrNull(Ty);

if (TC.Verify() && TC.isForwardDecl())

ReplaceMap.push_back(Ty.getTypeOrNull(), TC);

Regards,

Ben

I’m probably missing something simple here but in:

CGDebugInfo.h:

   std::vector<std::pair<void *, llvm::WeakVH> >ReplaceMap;

but then in

CGDebugInfo.cpp:

  llvm::DIType TC = getTypeOrNull(Ty);

  void * v = Ty.getAsOpaquePtr();
  std::pair<void *, llvm::WeakVH> tmp = std::make_pair(v, TC);

  if (TC.Verify() && TC.isForwardDecl())
    ReplaceMap.push_back(Ty.getTypeOrNull(), TC);

Note that TC is of type llvm:DIType and not WeakVH.

What am I missing, as this does not compile under Visual Studio 2012 RC?

Tricky code, DIType (or rather its superclass DIDescriptor) implicitly converts to MDNode* via a operator overload. MDNode is a subclass of Value, and WeakVH is constructible from Value*.

Wouldn't surprise me if MSVC has problems eating that, lots of magic involved here.

- Ben

Hi Ben,

Thanks that helped a lot.

The problem seems to be that with the move to C++11 we now have:

void std::vector<_Ty>::push_back(std::pair<_Ty1,_Ty2> &&)'

and there no conversion operator that can be applied to convert:

'std::pair<_Ty1,_Ty2>' to 'std::pair<_Ty3,_Ty4> &&

Where:

      [
              _Ty1=void *,
             _Ty2=llvm::DIType
       ]
       and
       [
              _Ty3=void *,
              _Ty4=llvm::WeakVH
        ]

The reason it gives is std::pair<_Ty1,_Ty2>' to 'std::pair<_Ty3,_Ty4>, but as you point out there is indeed a conversion operator for DITYPE to WeakVH. Putting the explicit cast to give:

if (T.Verify() && T.isForwardDecl())
    ReplaceMap.push_back(std::make_pair(Ty.getAsOpaquePtr(), (llvm::MDNode *)T));

and all it well again. This does indeed seem to be a bug in VS, unless there is some C++11 changes that stops implicit conversion under std::pair.

Regards,

Ben

- Benedict R. Gaster
Enjoy Berlin and submit a paper to Multiprog 2013: http://multiprog.ac.upc.edu/

I tracked this issue down and it turns out that Visual Studio is correct and this is a bug in the LLVM code with respect to C++11. (Note: it is valid C++ 2003, it is just that VS 2012 RC is closer to C++11 now, at least in this regard.)

The C++11 specification has change from C++ 2003 and is described in the ISO spec:

"template<class U, class V> pair(const pair<U, V>& p);
Remark: This constructor shall not participate in overload resolution unless const U& is implicitly convertible to first_type and const V& is implicitly convertible to second_type."

This is does not hold for the code example and so an explicit cast is required:

if (T.Verify() && T.isForwardDecl())
    ReplaceMap.push_back(std::make_pair(Ty.getAsOpaquePtr(),static_cast<llvm::Value*>(T)));

With this small change the code is both valid C++ 2003 and valid C++11.

I checked out the top of tree Clang and discovered that this change has already been made, which is great.

Regards,

Ben