From 385b91f2f49169442067ff6406b370618d11a776 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 3 Oct 2012 13:39:49 +0000 Subject: [PATCH] When mangling an APSInt with the ms abi, make sure to look at all nibbles. Currently, it's ignored if the number of set bits isn't divisible by 4. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165116 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/MicrosoftMangle.cpp | 2 +- test/CodeGenCXX/mangle-ms-templates.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index 072ad06999..d456e822ae 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -350,7 +350,7 @@ void MicrosoftCXXNameMangler::mangleNumber(const llvm::APSInt &Value) { char *CurPtr = EndPtr; llvm::APSInt NibbleMask(Value.getBitWidth(), Value.isUnsigned()); NibbleMask = 0xf; - for (int i = 0, e = Value.getActiveBits() / 4; i != e; ++i) { + for (int i = 0, e = (Value.getActiveBits() + 3) / 4; i != e; ++i) { *--CurPtr = 'A' + Temp.And(NibbleMask).getLimitedValue(0xf); Temp = Temp.lshr(4); } diff --git a/test/CodeGenCXX/mangle-ms-templates.cpp b/test/CodeGenCXX/mangle-ms-templates.cpp index 977ef353da..efe9565d33 100644 --- a/test/CodeGenCXX/mangle-ms-templates.cpp +++ b/test/CodeGenCXX/mangle-ms-templates.cpp @@ -54,6 +54,15 @@ void template_mangling() { IntTemplate<11> eleven; // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0L@@@QAE@XZ" + IntTemplate<256> _256; +// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0BAA@@@QAE@XZ" + + IntTemplate<513> _513; +// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0CAB@@@QAE@XZ" + + IntTemplate<1026> _1026; +// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0EAC@@@QAE@XZ" + IntTemplate<65535> ffff; // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0PPPP@@@QAE@XZ" } -- 2.40.0