Browse Source

Fixed parser to work with recent Clang changes.

Basically we need to lock in the MS inheritance model in a record when it appears as part of a member pointer type else we get some fun Clang code gen internals assert.
pull/155/merge
Joao Matos 12 years ago
parent
commit
9e14383e10
  1. 19
      src/CppParser/Parser.cpp
  2. 19
      src/Parser/Parser.cpp

19
src/CppParser/Parser.cpp

@ -1712,7 +1712,7 @@ static const clang::CodeGen::CGFunctionInfo& GetCodeGenFuntionInfo( @@ -1712,7 +1712,7 @@ static const clang::CodeGen::CGFunctionInfo& GetCodeGenFuntionInfo(
return CodeGenTypes->arrangeFunctionDeclaration(FD);
}
static bool CanCheckCodeGenInfo(const clang::Type* Ty)
static bool CanCheckCodeGenInfo(const clang::Type* Ty, bool IsMicrosoftABI)
{
bool CheckCodeGenInfo = true;
@ -1722,6 +1722,16 @@ static bool CanCheckCodeGenInfo(const clang::Type* Ty) @@ -1722,6 +1722,16 @@ static bool CanCheckCodeGenInfo(const clang::Type* Ty)
if (auto RD = Ty->getAsCXXRecordDecl())
CheckCodeGenInfo &= RD->hasDefinition();
// Lock in the MS inheritance model if we have a member pointer to a class,
// else we get an assertion error inside Clang's codegen machinery.
if (IsMicrosoftABI)
{
if (auto MPT = Ty->getAs<clang::MemberPointerType>())
if (auto RT = MPT->getClass())
if (auto RD = RT->getAsCXXRecordDecl())
RD->setMSInheritanceModel();
}
return CheckCodeGenInfo;
}
@ -1830,10 +1840,13 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F, @@ -1830,10 +1840,13 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, Function* F,
ParamStartLoc = VD->getLocEnd();
}
bool IsMicrosoftABI = C->getASTContext().getTargetInfo().getCXXABI().isMicrosoft();
bool CheckCodeGenInfo = !FD->isDependentContext() && !FD->isInvalidDecl();
CheckCodeGenInfo &= CanCheckCodeGenInfo(FD->getReturnType().getTypePtr());
CheckCodeGenInfo &= CanCheckCodeGenInfo(FD->getReturnType().getTypePtr(),
IsMicrosoftABI);
for (auto I = FD->param_begin(), E = FD->param_end(); I != E; ++I)
CheckCodeGenInfo &= CanCheckCodeGenInfo((*I)->getType().getTypePtr());
CheckCodeGenInfo &= CanCheckCodeGenInfo((*I)->getType().getTypePtr(),
IsMicrosoftABI);
if (CheckCodeGenInfo)
{

19
src/Parser/Parser.cpp

@ -1732,7 +1732,7 @@ static const clang::CodeGen::CGFunctionInfo& GetCodeGenFuntionInfo( @@ -1732,7 +1732,7 @@ static const clang::CodeGen::CGFunctionInfo& GetCodeGenFuntionInfo(
return CodeGenTypes->arrangeFunctionDeclaration(FD);
}
static bool CanCheckCodeGenInfo(const clang::Type* Ty)
static bool CanCheckCodeGenInfo(const clang::Type* Ty, bool IsMicrosoftABI)
{
bool CheckCodeGenInfo = true;
@ -1742,6 +1742,16 @@ static bool CanCheckCodeGenInfo(const clang::Type* Ty) @@ -1742,6 +1742,16 @@ static bool CanCheckCodeGenInfo(const clang::Type* Ty)
if (auto RD = Ty->getAsCXXRecordDecl())
CheckCodeGenInfo &= RD->hasDefinition();
// Lock in the MS inheritance model if we have a member pointer to a class,
// else we get an assertion error inside Clang's codegen machinery.
if (IsMicrosoftABI)
{
if (auto MPT = Ty->getAs<clang::MemberPointerType>())
if (auto RT = MPT->getClass())
if (auto RD = RT->getAsCXXRecordDecl())
RD->setMSInheritanceModel();
}
return CheckCodeGenInfo;
}
@ -1851,10 +1861,13 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F, @@ -1851,10 +1861,13 @@ void Parser::WalkFunction(clang::FunctionDecl* FD, CppSharp::AST::Function^ F,
ParamStartLoc = VD->getLocEnd();
}
bool IsMicrosoftABI = C->getASTContext().getTargetInfo().getCXXABI().isMicrosoft();
bool CheckCodeGenInfo = !FD->isDependentContext() && !FD->isInvalidDecl();
CheckCodeGenInfo &= CanCheckCodeGenInfo(FD->getReturnType().getTypePtr());
CheckCodeGenInfo &= CanCheckCodeGenInfo(FD->getReturnType().getTypePtr(),
IsMicrosoftABI);
for (auto I = FD->param_begin(), E = FD->param_end(); I != E; ++I)
CheckCodeGenInfo &= CanCheckCodeGenInfo((*I)->getType().getTypePtr());
CheckCodeGenInfo &= CanCheckCodeGenInfo((*I)->getType().getTypePtr(),
IsMicrosoftABI);
if (CheckCodeGenInfo)
{

Loading…
Cancel
Save