summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/tools/clang/lib/AST/APValue.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2019-06-23 21:36:31 +0000
committerpatrick <patrick@openbsd.org>2019-06-23 21:36:31 +0000
commit23f101f37937a1bd4a29726cab2f76e0fb038b35 (patch)
treef7da7d6b32c2e07114da399150bfa88d72187012 /gnu/llvm/tools/clang/lib/AST/APValue.cpp
parentsort previous; ok deraadt (diff)
downloadwireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.tar.xz
wireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.zip
Import LLVM 8.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/tools/clang/lib/AST/APValue.cpp')
-rw-r--r--gnu/llvm/tools/clang/lib/AST/APValue.cpp40
1 files changed, 34 insertions, 6 deletions
diff --git a/gnu/llvm/tools/clang/lib/AST/APValue.cpp b/gnu/llvm/tools/clang/lib/AST/APValue.cpp
index c45b52a65a4..0c2ba57f798 100644
--- a/gnu/llvm/tools/clang/lib/AST/APValue.cpp
+++ b/gnu/llvm/tools/clang/lib/AST/APValue.cpp
@@ -416,18 +416,26 @@ void APValue::printPretty(raw_ostream &Out, ASTContext &Ctx, QualType Ty) const{
<< GetApproxValue(getComplexFloatImag()) << "i";
return;
case APValue::LValue: {
- LValueBase Base = getLValueBase();
- if (!Base) {
- Out << "0";
- return;
- }
-
bool IsReference = Ty->isReferenceType();
QualType InnerTy
= IsReference ? Ty.getNonReferenceType() : Ty->getPointeeType();
if (InnerTy.isNull())
InnerTy = Ty;
+ LValueBase Base = getLValueBase();
+ if (!Base) {
+ if (isNullPointer()) {
+ Out << (Ctx.getLangOpts().CPlusPlus11 ? "nullptr" : "0");
+ } else if (IsReference) {
+ Out << "*(" << InnerTy.stream(Ctx.getPrintingPolicy()) << "*)"
+ << getLValueOffset().getQuantity();
+ } else {
+ Out << "(" << Ty.stream(Ctx.getPrintingPolicy()) << ")"
+ << getLValueOffset().getQuantity();
+ }
+ return;
+ }
+
if (!hasLValuePath()) {
// No lvalue path: just print the offset.
CharUnits O = getLValueOffset();
@@ -592,6 +600,26 @@ std::string APValue::getAsString(ASTContext &Ctx, QualType Ty) const {
return Result;
}
+bool APValue::toIntegralConstant(APSInt &Result, QualType SrcTy,
+ const ASTContext &Ctx) const {
+ if (isInt()) {
+ Result = getInt();
+ return true;
+ }
+
+ if (isLValue() && isNullPointer()) {
+ Result = Ctx.MakeIntValue(Ctx.getTargetNullPointerValue(SrcTy), SrcTy);
+ return true;
+ }
+
+ if (isLValue() && !getLValueBase()) {
+ Result = Ctx.MakeIntValue(getLValueOffset().getQuantity(), SrcTy);
+ return true;
+ }
+
+ return false;
+}
+
const APValue::LValueBase APValue::getLValueBase() const {
assert(isLValue() && "Invalid accessor");
return ((const LV*)(const void*)Data.buffer)->Base;