[LLVMdev] A question about CBackend.cpp

Zhou Sheng zhousheng00 at gmail.com
Wed Jun 4 20:52:19 PDT 2008


Hi,

I'm reading the code in CBackend.cpp and found some wired chunk in
void CWriter::printConstant(Constant *CPV)

938 if (ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
939 const Type* Ty = CI->getType();
940 if (Ty == Type::Int1Ty)
941 Out << (CI->getZExtValue() ? '1' : '0');
942 else if (Ty == Type::Int32Ty)
943 Out << CI->getZExtValue() << 'u';
944 else if (Ty->getPrimitiveSizeInBits() > 32)
945 Out << CI->getZExtValue() << "ull";
946 else {
947 Out << "((";
948 printSimpleType(Out, Ty, false) << ')';
949 if (CI->isMinValue(true))
950 Out << CI->getZExtValue() << 'u';
951 else
952 Out << CI->getSExtValue();
953 Out << ')';
954 }
955 return;
956 }


In line 946 to line 954, the "else" branch is for bitwidth from 2 to 31,
the question is why only for CI is MinValue(true), it is zexted, otherwise
sexted.
I'm confused by that logic.  Is there some special reason?



Thanks,
Sheng.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080605/17d384b6/attachment.html>


More information about the llvm-dev mailing list