[-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.
llvm-svn: 196771
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 044e572..6e2f497 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1443,9 +1443,9 @@
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();