[llvm-branch-commits] [cfe-branch] r196878 - Merging r196771:
Bill Wendling
isanbard at gmail.com
Mon Dec 9 21:29:38 PST 2013
Author: void
Date: Mon Dec 9 23:29:38 2013
New Revision: 196878
URL: http://llvm.org/viewvc/llvm-project?rev=196878&view=rev
Log:
Merging r196771:
------------------------------------------------------------------------
r196771 | majnemer | 2013-12-09 02:44:32 -0800 (Mon, 09 Dec 2013) | 17 lines
[-cxx-abi microsoft] Mangle large integral constants correctly
Testing has revealed that large integral constants (i.e. > INT64_MAX)
are always mangled as-if they are negative, even in places where it
would not make sense for them to be negative (like non-type template
parameters of type unsigned long long).
To address this, we change the way we model number mangling: always
mangle as-if our number is an int64_t. This should result in correct
results when we have large unsigned numbers.
N.B. Bizarrely, things that are 32-bit displacements like vbptr offsets
are mangled as-if they are unsigned 32-bit numbers. This is a pretty
egregious waste of space, it would be a 4x savings if we could mangle it
like a signed 32-bit number. Instead, we explicitly cast these
displacements to uint32_t and let the mangler proceed.
------------------------------------------------------------------------
Modified:
cfe/branches/release_34/ (props changed)
cfe/branches/release_34/include/clang/AST/Mangle.h
cfe/branches/release_34/lib/AST/MicrosoftMangle.cpp
cfe/branches/release_34/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/branches/release_34/test/CodeGenCXX/mangle-ms-templates.cpp
Propchange: cfe/branches/release_34/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Dec 9 23:29:38 2013
@@ -1,4 +1,4 @@
/cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:195126,195128,195135-195136,195146,195149,195154,195158,195163,195168,195174,195249,195268,195283,195303,195326,195329,195367,195384,195409,195420,195422,195495,195501,195547,195556,195558,195587,195620,195635,195669,195687,195693,195710,195713,195716,195756,195760,195768,195777,195789,195792,195804,195827,195843-195844,195877,195887-195888,195897,195903,195905-195906,195932,195936-195943,195970,195983,196045,196048,196050,196058,196114-196115,196143,196145,196153,196189-196192,196198-196199,196206,196208-196209,196211,196215,196359-196362,196370,196387,196423,196454,196456,196459,196488,196532-196533,196535,196538,196588,196593,196599,196612,196630,196658,196712,196720,196724
+/cfe/trunk:195126,195128,195135-195136,195146,195149,195154,195158,195163,195168,195174,195249,195268,195283,195303,195326,195329,195367,195384,195409,195420,195422,195495,195501,195547,195556,195558,195587,195620,195635,195669,195687,195693,195710,195713,195716,195756,195760,195768,195777,195789,195792,195804,195827,195843-195844,195877,195887-195888,195897,195903,195905-195906,195932,195936-195943,195970,195983,196045,196048,196050,196058,196114-196115,196143,196145,196153,196189-196192,196198-196199,196206,196208-196209,196211,196215,196359-196362,196370,196387,196423,196454,196456,196459,196488,196532-196533,196535,196538,196588,196593,196599,196612,196630,196658,196712,196720,196724,196771
/cfe/trunk/test:170344
/cfe/trunk/test/SemaTemplate:126920
Modified: cfe/branches/release_34/include/clang/AST/Mangle.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/include/clang/AST/Mangle.h?rev=196878&r1=196877&r2=196878&view=diff
==============================================================================
--- cfe/branches/release_34/include/clang/AST/Mangle.h (original)
+++ cfe/branches/release_34/include/clang/AST/Mangle.h Mon Dec 9 23:29:38 2013
@@ -200,7 +200,8 @@ public:
raw_ostream &Out) = 0;
virtual void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD,
- int OffsetInVFTable, raw_ostream &) = 0;
+ uint64_t OffsetInVFTable,
+ raw_ostream &) = 0;
static bool classof(const MangleContext *C) {
return C->getKind() == MK_Microsoft;
Modified: cfe/branches/release_34/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/AST/MicrosoftMangle.cpp?rev=196878&r1=196877&r2=196878&view=diff
==============================================================================
--- cfe/branches/release_34/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/branches/release_34/lib/AST/MicrosoftMangle.cpp Mon Dec 9 23:29:38 2013
@@ -121,8 +121,7 @@ public:
void mangleDeclaration(const NamedDecl *ND);
void mangleFunctionEncoding(const FunctionDecl *FD);
void mangleVariableEncoding(const VarDecl *VD);
- void mangleNumber(uint32_t Number);
- void mangleNumber(const llvm::APSInt &Value);
+ void mangleNumber(int64_t Number);
void mangleType(QualType T, SourceRange Range,
QualifierMangleMode QMM = QMM_Mangle);
void mangleFunctionType(const FunctionType *T, const FunctionDecl *D = 0,
@@ -182,7 +181,8 @@ public:
virtual bool shouldMangleCXXName(const NamedDecl *D);
virtual void mangleCXXName(const NamedDecl *D, raw_ostream &Out);
virtual void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD,
- int OffsetInVFTable, raw_ostream &);
+ uint64_t OffsetInVFTable,
+ raw_ostream &);
virtual void mangleThunk(const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
raw_ostream &);
@@ -390,40 +390,33 @@ void MicrosoftCXXNameMangler::mangleName
Out << '@';
}
-void MicrosoftCXXNameMangler::mangleNumber(uint32_t Number) {
- llvm::APSInt APSNumber(/*BitWidth=*/32, /*isUnsigned=*/true);
- APSNumber = Number;
- mangleNumber(APSNumber);
-}
+void MicrosoftCXXNameMangler::mangleNumber(int64_t Number) {
+ // <non-negative integer> ::= A@ # when Number == 0
+ // ::= <decimal digit> # when 1 <= Number <= 10
+ // ::= <hex digit>+ @ # when Number >= 10
+ //
+ // <number> ::= [?] <non-negative integer>
-void MicrosoftCXXNameMangler::mangleNumber(const llvm::APSInt &Value) {
- // <number> ::= [?] <decimal digit> # 1 <= Number <= 10
- // ::= [?] <hex digit>+ @ # 0 or > 9; A = 0, B = 1, etc...
- // ::= [?] @ # 0 (alternate mangling, not emitted by VC)
- if (Value.isSigned() && Value.isNegative()) {
+ uint64_t Value = static_cast<uint64_t>(Number);
+ if (Number < 0) {
+ Value = -Value;
Out << '?';
- mangleNumber(llvm::APSInt(Value.abs()));
- return;
}
- llvm::APSInt Temp(Value);
- // There's a special shorter mangling for 0, but Microsoft
- // chose not to use it. Instead, 0 gets mangled as "A@". Oh well...
- if (Value.uge(1) && Value.ule(10)) {
- --Temp;
- Temp.print(Out, false);
- } else {
- // We have to build up the encoding in reverse order, so it will come
- // out right when we write it out.
- char Encoding[64];
- char *EndPtr = Encoding+sizeof(Encoding);
- char *CurPtr = EndPtr;
- llvm::APSInt NibbleMask(Value.getBitWidth(), Value.isUnsigned());
- NibbleMask = 0xf;
- do {
- *--CurPtr = 'A' + Temp.And(NibbleMask).getLimitedValue(0xf);
- Temp = Temp.lshr(4);
- } while (Temp != 0);
- Out.write(CurPtr, EndPtr-CurPtr);
+
+ if (Value == 0)
+ Out << "A@";
+ else if (Value >= 1 && Value <= 10)
+ Out << (Value - 1);
+ else {
+ // Numbers that are not encoded as decimal digits are represented as nibbles
+ // in the range of ASCII characters 'A' to 'P'.
+ // The number 0x123450 would be encoded as 'BCDEFA'
+ char EncodedNumberBuffer[sizeof(uint64_t) * 2];
+ llvm::MutableArrayRef<char> BufferRef(EncodedNumberBuffer);
+ llvm::MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
+ for (; Value != 0; Value >>= 4)
+ *I++ = 'A' + (Value & 0xf);
+ Out.write(I.base(), I - BufferRef.rbegin());
Out << '@';
}
}
@@ -885,7 +878,7 @@ MicrosoftCXXNameMangler::mangleIntegerLi
if (IsBoolean && Value.getBoolValue())
mangleNumber(1);
else
- mangleNumber(Value);
+ mangleNumber(Value.getSExtValue());
}
void
@@ -1887,14 +1880,18 @@ static void mangleThunkThisAdjustment(co
}
if (Adjustment.Virtual.Microsoft.VBPtrOffset) {
Out << 'R' << AccessSpec;
- Mangler.mangleNumber(Adjustment.Virtual.Microsoft.VBPtrOffset);
- Mangler.mangleNumber(Adjustment.Virtual.Microsoft.VBOffsetOffset);
- Mangler.mangleNumber(Adjustment.Virtual.Microsoft.VtordispOffset);
- Mangler.mangleNumber(Adjustment.NonVirtual);
+ Mangler.mangleNumber(
+ static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VBPtrOffset));
+ Mangler.mangleNumber(
+ static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VBOffsetOffset));
+ Mangler.mangleNumber(
+ static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VtordispOffset));
+ Mangler.mangleNumber(static_cast<uint32_t>(Adjustment.NonVirtual));
} else {
Out << AccessSpec;
- Mangler.mangleNumber(Adjustment.Virtual.Microsoft.VtordispOffset);
- Mangler.mangleNumber(-Adjustment.NonVirtual);
+ Mangler.mangleNumber(
+ static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VtordispOffset));
+ Mangler.mangleNumber(-static_cast<uint32_t>(Adjustment.NonVirtual));
}
} else if (Adjustment.NonVirtual != 0) {
switch (MD->getAccess()) {
@@ -1909,7 +1906,7 @@ static void mangleThunkThisAdjustment(co
case AS_public:
Out << 'W';
}
- Mangler.mangleNumber(-Adjustment.NonVirtual);
+ Mangler.mangleNumber(-static_cast<uint32_t>(Adjustment.NonVirtual));
} else {
switch (MD->getAccess()) {
case AS_none:
@@ -1927,7 +1924,7 @@ static void mangleThunkThisAdjustment(co
}
void MicrosoftMangleContextImpl::mangleVirtualMemPtrThunk(
- const CXXMethodDecl *MD, int OffsetInVFTable, raw_ostream &Out) {
+ const CXXMethodDecl *MD, uint64_t OffsetInVFTable, raw_ostream &Out) {
bool Is64Bit = getASTContext().getTargetInfo().getPointerWidth(0) == 64;
MicrosoftCXXNameMangler Mangler(*this, Out);
Modified: cfe/branches/release_34/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/CodeGen/MicrosoftCXXABI.cpp?rev=196878&r1=196877&r2=196878&view=diff
==============================================================================
--- cfe/branches/release_34/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/branches/release_34/lib/CodeGen/MicrosoftCXXABI.cpp Mon Dec 9 23:29:38 2013
@@ -1443,9 +1443,9 @@ MicrosoftCXXABI::BuildMemberPointer(cons
FirstField = llvm::Constant::getNullValue(CGM.VoidPtrTy);
} else {
SmallString<256> ThunkName;
- int OffsetInVFTable =
- ML.Index *
- getContext().getTypeSizeInChars(getContext().VoidPtrTy).getQuantity();
+ CharUnits PointerWidth = getContext().toCharUnitsFromBits(
+ getContext().getTargetInfo().getPointerWidth(0));
+ uint64_t OffsetInVFTable = ML.Index * PointerWidth.getQuantity();
llvm::raw_svector_ostream Out(ThunkName);
getMangleContext().mangleVirtualMemPtrThunk(MD, OffsetInVFTable, Out);
Out.flush();
Modified: cfe/branches/release_34/test/CodeGenCXX/mangle-ms-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/test/CodeGenCXX/mangle-ms-templates.cpp?rev=196878&r1=196877&r2=196878&view=diff
==============================================================================
--- cfe/branches/release_34/test/CodeGenCXX/mangle-ms-templates.cpp (original)
+++ cfe/branches/release_34/test/CodeGenCXX/mangle-ms-templates.cpp Mon Dec 9 23:29:38 2013
@@ -24,6 +24,18 @@ class IntTemplate {
IntTemplate() {}
};
+template<long long param>
+class LongLongTemplate {
+ public:
+ LongLongTemplate() {}
+};
+
+template<unsigned long long param>
+class UnsignedLongLongTemplate {
+ public:
+ UnsignedLongLongTemplate() {}
+};
+
template<>
class BoolTemplate<true> {
public:
@@ -108,6 +120,32 @@ void template_mangling() {
IntTemplate<65535> ffff;
// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0PPPP@@@QAE at XZ"
// X64: call {{.*}} @"\01??0?$IntTemplate@$0PPPP@@@QEAA at XZ"
+
+ IntTemplate<-1> neg_1;
+// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?0@@QAE at XZ"
+// X64: call {{.*}} @"\01??0?$IntTemplate@$0?0@@QEAA at XZ"
+ IntTemplate<-9> neg_9;
+// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?8@@QAE at XZ"
+// X64: call {{.*}} @"\01??0?$IntTemplate@$0?8@@QEAA at XZ"
+ IntTemplate<-10> neg_10;
+// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?9@@QAE at XZ"
+// X64: call {{.*}} @"\01??0?$IntTemplate@$0?9@@QEAA at XZ"
+ IntTemplate<-11> neg_11;
+// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?L@@@QAE at XZ"
+// X64: call {{.*}} @"\01??0?$IntTemplate@$0?L@@@QEAA at XZ"
+
+ LongLongTemplate<-9223372036854775807LL-1LL> int64_min;
+// CHECK: call {{.*}} @"\01??0?$LongLongTemplate@$0?IAAAAAAAAAAAAAAA@@@QAE at XZ"
+// X64: call {{.*}} @"\01??0?$LongLongTemplate@$0?IAAAAAAAAAAAAAAA@@@QEAA at XZ"
+ LongLongTemplate<9223372036854775807LL> int64_max;
+// CHECK: call {{.*}} @"\01??0?$LongLongTemplate@$0HPPPPPPPPPPPPPPP@@@QAE at XZ"
+// X64: call {{.*}} @"\01??0?$LongLongTemplate@$0HPPPPPPPPPPPPPPP@@@QEAA at XZ"
+ UnsignedLongLongTemplate<18446744073709551615ULL> uint64_max;
+// CHECK: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QAE at XZ"
+// X64: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QEAA at XZ"
+ UnsignedLongLongTemplate<(unsigned long long)-1> uint64_neg_1;
+// CHECK: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QAE at XZ"
+// X64: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QEAA at XZ"
}
namespace space {
More information about the llvm-branch-commits
mailing list