forked from OSchip/llvm-project
Reuse APInt's getNumWords, which gets rounding right (my ad-hoc solution missed it).
llvm-svn: 158151
This commit is contained in:
parent
6003ad5848
commit
5d4cff72b4
|
@ -244,11 +244,12 @@ public:
|
|||
/// \brief Retrieve the template argument as an integral value.
|
||||
// FIXME: Provide a way to read the integral data without copying the value.
|
||||
llvm::APSInt getAsIntegral() const {
|
||||
using namespace llvm;
|
||||
if (Integer.BitWidth <= 64)
|
||||
return llvm::APSInt(llvm::APInt(Integer.BitWidth, Integer.VAL),
|
||||
Integer.IsUnsigned);
|
||||
return llvm::APSInt(llvm::APInt(Integer.BitWidth,
|
||||
llvm::makeArrayRef(Integer.pVal, Integer.BitWidth / 8)),
|
||||
return APSInt(APInt(Integer.BitWidth, Integer.VAL), Integer.IsUnsigned);
|
||||
|
||||
unsigned NumWords = APInt::getNumWords(Integer.BitWidth);
|
||||
return APSInt(APInt(Integer.BitWidth, makeArrayRef(Integer.pVal, NumWords)),
|
||||
Integer.IsUnsigned);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,9 +61,10 @@ TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value,
|
|||
Integer.BitWidth = Value.getBitWidth();
|
||||
Integer.IsUnsigned = Value.isUnsigned();
|
||||
// If the value is large, we have to get additional memory from the ASTContext
|
||||
if (Integer.BitWidth > 64) {
|
||||
void *Mem = Ctx.Allocate(Integer.BitWidth / 8);
|
||||
std::memcpy(Mem, Value.getRawData(), Integer.BitWidth / 8);
|
||||
unsigned NumWords = Value.getNumWords();
|
||||
if (NumWords > 1) {
|
||||
void *Mem = Ctx.Allocate(NumWords * sizeof(uint64_t));
|
||||
std::memcpy(Mem, Value.getRawData(), NumWords * sizeof(uint64_t));
|
||||
Integer.pVal = static_cast<uint64_t *>(Mem);
|
||||
} else {
|
||||
Integer.VAL = Value.getZExtValue();
|
||||
|
|
Loading…
Reference in New Issue