Skip to content

Commit f35bd75

Browse files
committed
Improved robustness when parsing C++ ABI kind.
Fixes #1202.
1 parent 1521425 commit f35bd75

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/CppParser/Parser.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ LayoutField Parser::WalkVTablePointer(Class* Class,
8585
return LayoutField;
8686
}
8787

88+
static CppAbi GetClassLayoutAbi(clang::TargetCXXABI::Kind abi)
89+
{
90+
switch (abi)
91+
{
92+
case clang::TargetCXXABI::Microsoft:
93+
return CppAbi::Microsoft;
94+
case clang::TargetCXXABI::GenericItanium:
95+
return CppAbi::Itanium;
96+
case clang::TargetCXXABI::GenericARM:
97+
return CppAbi::ARM;
98+
case clang::TargetCXXABI::iOS:
99+
return CppAbi::iOS;
100+
case clang::TargetCXXABI::iOS64:
101+
return CppAbi::iOS64;
102+
default:
103+
llvm_unreachable("Unsupported C++ ABI kind");
104+
}
105+
}
106+
88107
void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD,
89108
clang::CharUnits Offset, bool IncludeVirtualBases)
90109
{
@@ -695,12 +714,13 @@ void Parser::WalkVTable(const clang::CXXRecordDecl* RD, Class* C)
695714
if (!C->layout)
696715
C->layout = new ClassLayout();
697716

717+
C->layout->ABI = GetClassLayoutAbi(targetABI);
718+
698719
auto& AST = c->getASTContext();
699720
switch(targetABI)
700721
{
701722
case TargetCXXABI::Microsoft:
702723
{
703-
C->layout->ABI = CppAbi::Microsoft;
704724
MicrosoftVTableContext VTContext(AST);
705725

706726
const auto& VFPtrs = VTContext.getVFPtrOffsets(RD);
@@ -719,7 +739,6 @@ void Parser::WalkVTable(const clang::CXXRecordDecl* RD, Class* C)
719739
}
720740
case TargetCXXABI::GenericItanium:
721741
{
722-
C->layout->ABI = CppAbi::Itanium;
723742
ItaniumVTableContext VTContext(AST);
724743

725744
auto& VTLayout = VTContext.getVTableLayout(RD);
@@ -954,6 +973,7 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC)
954973
const auto& Layout = c->getASTContext().getASTRecordLayout(Record);
955974
if (!RC->layout)
956975
RC->layout = new ClassLayout();
976+
RC->layout->ABI = GetClassLayoutAbi(targetABI);
957977
RC->layout->alignment = (int)Layout.getAlignment().getQuantity();
958978
RC->layout->size = (int)Layout.getSize().getQuantity();
959979
RC->layout->dataSize = (int)Layout.getDataSize().getQuantity();

0 commit comments

Comments
 (0)