r201574 - MS ABI: Refactor extended qualifiers
David Majnemer
david.majnemer at gmail.com
Tue Feb 18 06:20:10 PST 2014
Author: majnemer
Date: Tue Feb 18 08:20:10 2014
New Revision: 201574
URL: http://llvm.org/viewvc/llvm-project?rev=201574&view=rev
Log:
MS ABI: Refactor extended qualifiers
Extended qualifiers can appear in many places, refactor the code so it's
more reusable. Add tests in areas where we've increased compatibility.
Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenCXX/mangle-ms-return-qualifiers.cpp
cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=201574&r1=201573&r2=201574&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Tue Feb 18 08:20:10 2014
@@ -145,7 +145,8 @@ private:
void mangleOperatorName(OverloadedOperatorKind OO, SourceLocation Loc);
void mangleCXXDtorType(CXXDtorType T);
void mangleQualifiers(Qualifiers Quals, bool IsMember);
- void manglePointerQualifiers(Qualifiers Quals, const Type *PointeeType);
+ void manglePointerCVQualifiers(Qualifiers Quals);
+ void manglePointerExtQualifiers(Qualifiers Quals, const Type *PointeeType);
void mangleUnscopedTemplateName(const TemplateDecl *ND);
void mangleTemplateInstantiationName(const TemplateDecl *TD,
@@ -355,8 +356,8 @@ void MicrosoftCXXNameMangler::mangleVari
if (Ty->isPointerType() || Ty->isReferenceType() ||
Ty->isMemberPointerType()) {
mangleType(Ty, TL.getSourceRange(), QMM_Drop);
- if (PointersAre64Bit)
- Out << 'E';
+ manglePointerExtQualifiers(
+ Ty.getDesugaredType(getASTContext()).getLocalQualifiers(), 0);
if (const MemberPointerType *MPT = Ty->getAs<MemberPointerType>()) {
mangleQualifiers(MPT->getPointeeType().getQualifiers(), true);
// Member pointers are suffixed with a back reference to the member
@@ -1213,15 +1214,24 @@ void MicrosoftCXXNameMangler::mangleQual
// FIXME: For now, just drop all extension qualifiers on the floor.
}
-void MicrosoftCXXNameMangler::manglePointerQualifiers(Qualifiers Quals,
- const Type *PointeeType) {
- // <pointer-cvr-qualifiers> ::= P # no qualifiers
- // ::= Q # const
- // ::= R # volatile
- // ::= S # const volatile
+void
+MicrosoftCXXNameMangler::manglePointerExtQualifiers(Qualifiers Quals,
+ const Type *PointeeType) {
+ bool HasRestrict = Quals.hasRestrict();
+ if (PointersAre64Bit && (!PointeeType || !PointeeType->isFunctionType()))
+ Out << 'E';
+
+ if (HasRestrict)
+ Out << 'I';
+}
+
+void MicrosoftCXXNameMangler::manglePointerCVQualifiers(Qualifiers Quals) {
+ // <pointer-cv-qualifiers> ::= P # no qualifiers
+ // ::= Q # const
+ // ::= R # volatile
+ // ::= S # const volatile
bool HasConst = Quals.hasConst(),
- HasVolatile = Quals.hasVolatile(),
- HasRestrict = Quals.hasRestrict();
+ HasVolatile = Quals.hasVolatile();
if (HasConst && HasVolatile) {
Out << 'S';
@@ -1232,12 +1242,6 @@ void MicrosoftCXXNameMangler::manglePoin
} else {
Out << 'P';
}
-
- if (PointersAre64Bit && PointeeType && !PointeeType->isFunctionType())
- Out << 'E';
-
- if (HasRestrict)
- Out << 'I';
}
void MicrosoftCXXNameMangler::mangleArgumentType(QualType T,
@@ -1328,8 +1332,10 @@ void MicrosoftCXXNameMangler::mangleType
}
// We have to mangle these now, while we still have enough information.
- if (IsPointer)
- manglePointerQualifiers(Quals, T->getPointeeType().getTypePtr());
+ if (IsPointer) {
+ manglePointerCVQualifiers(Quals);
+ manglePointerExtQualifiers(Quals, T->getPointeeType().getTypePtr());
+ }
const Type *ty = T.getTypePtr();
switch (ty->getTypeClass()) {
@@ -1469,9 +1475,9 @@ void MicrosoftCXXNameMangler::mangleFunc
// If this is a C++ instance method, mangle the CVR qualifiers for the
// this pointer.
if (IsInstMethod) {
- if (PointersAre64Bit)
- Out << 'E';
- mangleQualifiers(Qualifiers::fromCVRMask(Proto->getTypeQuals()), false);
+ Qualifiers Quals = Qualifiers::fromCVRMask(Proto->getTypeQuals());
+ manglePointerExtQualifiers(Quals, 0);
+ mangleQualifiers(Quals, false);
}
mangleCallingConvention(T);
@@ -1665,7 +1671,7 @@ void MicrosoftCXXNameMangler::mangleType
void MicrosoftCXXNameMangler::mangleDecayedArrayType(const ArrayType *T) {
// This isn't a recursive mangling, so now we have to do it all in this
// one call.
- manglePointerQualifiers(T->getElementType().getQualifiers(), 0);
+ manglePointerCVQualifiers(T->getElementType().getQualifiers());
mangleType(T->getElementType(), SourceRange());
}
void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T,
@@ -1774,8 +1780,7 @@ void MicrosoftCXXNameMangler::mangleType
SourceRange Range) {
// Object pointers never have qualifiers.
Out << 'A';
- if (PointersAre64Bit && !T->getPointeeType()->isFunctionType())
- Out << 'E';
+ manglePointerExtQualifiers(Qualifiers(), T->getPointeeType().getTypePtr());
mangleType(T->getPointeeType(), Range);
}
@@ -1785,8 +1790,7 @@ void MicrosoftCXXNameMangler::mangleType
void MicrosoftCXXNameMangler::mangleType(const LValueReferenceType *T,
SourceRange Range) {
Out << 'A';
- if (PointersAre64Bit && !T->getPointeeType()->isFunctionType())
- Out << 'E';
+ manglePointerExtQualifiers(Qualifiers(), T->getPointeeType().getTypePtr());
mangleType(T->getPointeeType(), Range);
}
@@ -1796,8 +1800,7 @@ void MicrosoftCXXNameMangler::mangleType
void MicrosoftCXXNameMangler::mangleType(const RValueReferenceType *T,
SourceRange Range) {
Out << "$$Q";
- if (PointersAre64Bit && !T->getPointeeType()->isFunctionType())
- Out << 'E';
+ manglePointerExtQualifiers(Qualifiers(), T->getPointeeType().getTypePtr());
mangleType(T->getPointeeType(), Range);
}
Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-return-qualifiers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-return-qualifiers.cpp?rev=201574&r1=201573&r2=201574&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-return-qualifiers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-return-qualifiers.cpp Tue Feb 18 08:20:10 2014
@@ -164,6 +164,12 @@ int S::* f8() { return 0; }
int S::* const f9() { return 0; }
// CHECK: "\01?f9@@YAQQS@@HXZ"
+int S::* __restrict f10() { return 0; }
+// CHECK: "\01?f10@@YAPIQS@@HXZ"
+
+int S::* const __restrict f11() { return 0; }
+// CHECK: "\01?f11@@YAQIQS@@HXZ"
+
typedef int (*function_pointer)(int);
function_pointer g1() { return 0; }
Modified: cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms.cpp?rev=201574&r1=201573&r2=201574&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms.cpp Tue Feb 18 08:20:10 2014
@@ -95,6 +95,9 @@ extern int * const h1 = &a;
// CHECK-DAG: @"\01?h1@@3QAHA"
extern const int * const h2 = &a;
// CHECK-DAG: @"\01?h2@@3QBHB"
+extern int * const __restrict h3 = &a;
+// CHECK-DAG: @"\01?h3@@3QIAHIA"
+// X64-DAG: @"\01?h3@@3QEIAHEIA"
int i[10][20];
// CHECK-DAG: @"\01?i@@3PAY0BE at HA"
More information about the cfe-commits
mailing list