Assert with getZExtValue()?

Was hoping it might get some help or a better explanation of this:

/ADT/APInt.h:1217: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && “Too many bits for uint64_t”’ failed.

Program received signal SIGABRT, Aborted.
0x00007ffff6eb4d05 in raise (sig=6) at …/nptl/sysdeps/unix/sysv/linux/raise.c:64
64 …/nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
in …/nptl/sysdeps/unix/sysv/linux/raise.c
(gdb) bt
#0 0x00007ffff6eb4d05 in raise (sig=6) at …/nptl/sysdeps/unix/sysv/linux/raise.c:64
#1 0x00007ffff6eb8ab6 in abort () at abort.c:92
#2 0x00007ffff6ead7c5 in __assert_fail (
assertion=0x7ffff6c7c907 “getActiveBits() <= 64 && “Too many bits for uint64_t””,
file=, line=1217, function=) at assert.c:81
#3 0x00007ffff6c6c5cf in getZExtValue (this=)
at /home/ryan/llvm/llvm_core/trunk/include/llvm/ADT/APInt.h:1217
#4 getZExtValue (this=)
at /home/ryan/llvm/llvm_core/trunk/include/llvm/Constants.h:117
#5 cdfgPassClass::storeInstr (this=) at a2c_pass.cpp:2125
#6 0x00007ffff6c73dc1 in (anonymous namespace)::CDFGPass::runOnModule (this=0x16c2fa0,
M=) at a2c_pass.cpp:2949
#7 0x0000000000f4cd4e in llvm::MPPassManager::runOnModule(llvm::Module&) ()
#8 0x0000000000f4d813 in llvm::PassManagerImpl::run(llvm::Module&) ()
#9 0x0000000000f4d94a in llvm::PassManager::run(llvm::Module&) ()
#10 0x0000000000525509 in main ()

Also, why does it give , when I print the value I clearly get one, unless this is some result of const prop?

Thanks.

Was hoping it might get some help or a better explanation of this:

/ADT/APInt.h:1217: uint64_t llvm::APInt::getZExtValue() const: Assertion
`getActiveBits() <= 64 && "Too many bits for uint64_t"' failed.

The error message is exactly what it says: you're trying to call
getZExtValue() on an APInt whose value doesn't fit into a uint64_t.

Program received signal SIGABRT, Aborted.
0x00007ffff6eb4d05 in raise (sig=6) at
../nptl/sysdeps/unix/sysv/linux/raise.c:64
64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
    in ../nptl/sysdeps/unix/sysv/linux/raise.c
(gdb) bt
#0 0x00007ffff6eb4d05 in raise (sig=6) at
../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1 0x00007ffff6eb8ab6 in abort () at abort.c:92
#2 0x00007ffff6ead7c5 in __assert_fail (
    assertion=0x7ffff6c7c907 "getActiveBits() <= 64 && \"Too many bits for
uint64_t\"",
    file=<value optimized out>, line=1217, function=<value optimized out>)
at assert.c:81
#3 0x00007ffff6c6c5cf in getZExtValue (this=<value optimized out>)
    at /home/ryan/llvm/llvm_core/trunk/include/llvm/ADT/APInt.h:1217
#4 getZExtValue (this=<value optimized out>)
    at /home/ryan/llvm/llvm_core/trunk/include/llvm/Constants.h:117
#5 cdfgPassClass::storeInstr (this=<value optimized out>) at
a2c_pass.cpp:2125
#6 0x00007ffff6c73dc1 in (anonymous namespace)::CDFGPass::runOnModule
(this=0x16c2fa0,
    M=<value optimized out>) at a2c_pass.cpp:2949
#7 0x0000000000f4cd4e in llvm::MPPassManager::runOnModule(llvm::Module&) ()
#8 0x0000000000f4d813 in llvm::PassManagerImpl::run(llvm::Module&) ()
#9 0x0000000000f4d94a in llvm::PassManager::run(llvm::Module&) ()
#10 0x0000000000525509 in main ()

Also, why does it give <value optimized out>, when I print the value I
clearly get one, unless this is some result of const prop?

No clue how gdb decides these things. If you file a bug with a
reduced testcase, someone might find the answer.

-Eli

My apologies, here is the corresponding code:

if (const Constant *CV = dyn_cast(V)) {
if (CV && !isa(CV)) {
if (const ConstantInt *CI = dyn_cast(CV)) {
APInt constIntAP = CI->getValue();
char constCharSign = (constIntAP.isNegative()) ? ‘n’ : ‘p’;
//int constValue = abs(CI->getSExtValue());

Thanks.

Eli,

Thanks for responding. Yes, I read the error message but it seems odd that it would be trying to use more than 64 bits. It compiles and executes in gcc on 32 bit arch just fine. I’ll probably take your suggestion and file a bug with a reduced testcase.

Thanks again,

Ryan

So the problem here was trying to return MIN_VALUE zero extended, if I return sign extended than this issue is resolved; however, I still get an error with getSExtValue when trying to get the value of the const from Instruction: %mask166 = and i128 %lvar_ins176, -18446462598732840961

You have the value in an APInt. There is no primitive type that can hold it.

-Krzysztof

So is there a way to return the value as a string instead?

There are several ways:

include/llvm/ADT/APInt.h

   /// toString - Converts an APInt to a string and append it to Str. Str is
   /// commonly a SmallString.
   void toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed,
                 bool formatAsCLiteral = false) const;

   /// Considers the APInt to be unsigned and converts it into a string in the
   /// radix given. The radix can be 2, 8, 10 16, or 36.
   void toStringUnsigned(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
     toString(Str, Radix, false, false);
   }

   /// Considers the APInt to be signed and converts it into a string in the
   /// radix given. The radix can be 2, 8, 10, 16, or 36.
   void toStringSigned(SmallVectorImpl<char> &Str, unsigned Radix = 10) const {
     toString(Str, Radix, true, false);
   }

   /// toString - This returns the APInt as a std::string. Note that this is an
   /// inefficient method. It is better to pass in a SmallVector/SmallString
   /// to the methods above to avoid thrashing the heap for the string.
   std::string toString(unsigned Radix, bool Signed) const;

-Krzysztof