Make sure that the canonical representation of integral template arguments uses the bitwidth and signedness of the template parameter
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66990 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 3780259..142cc45 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -1283,11 +1283,12 @@
return false;
}
- llvm::APInt CanonicalArg(Context.getTypeSize(IntegerType), 0,
- IntegerType->isSignedIntegerType());
- CanonicalArg = Value;
+ unsigned ExpectedBits = Context.getTypeSize(IntegerType);
+ if (Value.getBitWidth() != ExpectedBits)
+ Value.extOrTrunc(ExpectedBits);
+ Value.setIsSigned(IntegerType->isSignedIntegerType());
- Converted->push_back(TemplateArgument(StartLoc, CanonicalArg,
+ Converted->push_back(TemplateArgument(StartLoc, Value,
Context.getCanonicalType(IntegerType)));
}