diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-09-13 22:47:33 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-09-13 22:47:33 +0000 |
commit | 128719c4fe7c3bc1f4beccb82a8636c375033f5a (patch) | |
tree | 96f1e1cb7261af36a66b840f613882def8912dfe /clang/lib/AST/APValue.cpp | |
parent | 11ca38f4212646e0998ecc10db227df8ce1e6348 (diff) | |
download | bcm5719-llvm-128719c4fe7c3bc1f4beccb82a8636c375033f5a.tar.gz bcm5719-llvm-128719c4fe7c3bc1f4beccb82a8636c375033f5a.zip |
Fix crash on call to __builtin_memcpy with a null pointer to an
incomplete type.
Also improve the diagnostics for similar situations.
llvm-svn: 342192
Diffstat (limited to 'clang/lib/AST/APValue.cpp')
-rw-r--r-- | clang/lib/AST/APValue.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp index c45b52a65a4..c05b160b8e3 100644 --- a/clang/lib/AST/APValue.cpp +++ b/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(); |