r192496 - Use castAs instead of cast in thunk generation

Reid Kleckner reid at kleckner.net
Fri Oct 11 13:46:27 PDT 2013


Author: rnk
Date: Fri Oct 11 15:46:27 2013
New Revision: 192496

URL: http://llvm.org/viewvc/llvm-project?rev=192496&view=rev
Log:
Use castAs instead of cast in thunk generation

Calling convention attributes can add sugar to methods that we have to
look through.  This fixes an assertion failure in the provided test
case.

Modified:
    cfe/trunk/lib/CodeGen/CGVTables.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-thunks.cpp

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=192496&r1=192495&r2=192496&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Fri Oct 11 15:46:27 2013
@@ -481,7 +481,7 @@ void CodeGenVTables::maybeEmitThunkForVT
   // We can't emit thunks for member functions with incomplete types.
   const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
   if (!CGM.getTypes().isFuncTypeConvertible(
-                                cast<FunctionType>(MD->getType().getTypePtr())))
+           MD->getType()->castAs<FunctionType>()))
     return;
 
   emitThunk(GD, Thunk, /*ForVTable=*/true);

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-thunks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-thunks.cpp?rev=192496&r1=192495&r2=192496&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-thunks.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-thunks.cpp Fri Oct 11 15:46:27 2013
@@ -116,3 +116,18 @@ struct H : E {
 H h;
 
 // FIXME: Write vtordisp adjusting thunk tests
+
+namespace CrashOnThunksForAttributedType {
+// We used to crash on this because the type of foo is an AttributedType, not
+// FunctionType, and we had to look through the sugar.
+struct A {
+  virtual void __stdcall foo();
+};
+struct B {
+  virtual void __stdcall foo();
+};
+struct C : A, B {
+  virtual void __stdcall foo();
+};
+C c;
+}





More information about the cfe-commits mailing list