[LLVMdev] Type inconsistency in LLVM 3.1: CGDebugInfo.cpp
Gaster, Benedict
Benedict.Gaster at amd.com
Thu Aug 9 20:08:09 PDT 2012
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
----------------------------
Benedict R. Gaster
Advanced Micro Devices
Fancy a trip to Berlin? Consider submitting a paper to MULTIPROG 2013: http://multiprog.ac.upc.edu/
-----Original Message-----
From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Gaster, Benedict
Sent: Thursday, August 09, 2012 11:12 AM
To: Benjamin Kramer
Cc: llvmdev at cs.uiuc.edu
Subject: Re: [LLVMdev] Type inconsistency in LLVM 3.1: CGDebugInfo.cpp
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/
> -----Original Message-----
> From: Benjamin Kramer [mailto:benny.kra at gmail.com]
> Sent: Thursday, August 09, 2012 10:55 AM
> To: Gaster, Benedict
> Cc: llvmdev at cs.uiuc.edu
> Subject: Re: [LLVMdev] Type inconsistency in LLVM 3.1: CGDebugInfo.cpp
>
>
> On 09.08.2012, at 19:43, "Gaster, Benedict" <Benedict.Gaster at amd.com>
> wrote:
>
> > 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
> >
> > Regards,
> >
> > Ben
> >
> > - Benedict R. Gaster
> > Enjoy Berlin and submit a paper to Multiprog 2013:
> http://multiprog.ac.upc.edu/
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
_______________________________________________
LLVM Developers mailing list
LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list