[cfe-commits] r158151 - in /cfe/trunk: include/clang/AST/TemplateBase.h lib/AST/TemplateBase.cpp
Benjamin Kramer
benny.kra at googlemail.com
Thu Jun 7 08:54:03 PDT 2012
Author: d0k
Date: Thu Jun 7 10:54:03 2012
New Revision: 158151
URL: http://llvm.org/viewvc/llvm-project?rev=158151&view=rev
Log:
Reuse APInt's getNumWords, which gets rounding right (my ad-hoc solution missed it).
Modified:
cfe/trunk/include/clang/AST/TemplateBase.h
cfe/trunk/lib/AST/TemplateBase.cpp
Modified: cfe/trunk/include/clang/AST/TemplateBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TemplateBase.h?rev=158151&r1=158150&r2=158151&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TemplateBase.h (original)
+++ cfe/trunk/include/clang/AST/TemplateBase.h Thu Jun 7 10:54:03 2012
@@ -244,12 +244,13 @@
/// \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)),
- Integer.IsUnsigned);
+ 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);
}
/// \brief Retrieve the type of the integral value.
Modified: cfe/trunk/lib/AST/TemplateBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TemplateBase.cpp?rev=158151&r1=158150&r2=158151&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TemplateBase.cpp (original)
+++ cfe/trunk/lib/AST/TemplateBase.cpp Thu Jun 7 10:54:03 2012
@@ -61,9 +61,10 @@
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();
More information about the cfe-commits
mailing list