|
50 | 50 | #include "clang/AST/StmtVisitor.h" |
51 | 51 | #include "clang/AST/TypeLoc.h" |
52 | 52 | #include "clang/Basic/Builtins.h" |
| 53 | +#include "clang/Basic/DiagnosticSema.h" |
53 | 54 | #include "clang/Basic/TargetInfo.h" |
54 | 55 | #include "llvm/ADT/APFixedPoint.h" |
55 | 56 | #include "llvm/ADT/SmallBitVector.h" |
@@ -1995,7 +1996,8 @@ static bool IsGlobalLValue(APValue::LValueBase B) { |
1995 | 1996 |
|
1996 | 1997 | // ... a null pointer value, or a prvalue core constant expression of type |
1997 | 1998 | // std::nullptr_t. |
1998 | | - if (!B) return true; |
| 1999 | + if (!B) |
| 2000 | + return true; |
1999 | 2001 |
|
2000 | 2002 | if (const ValueDecl *D = B.dyn_cast<const ValueDecl*>()) { |
2001 | 2003 | // ... the address of an object with static storage duration, |
@@ -2126,6 +2128,7 @@ static void NoteLValueLocation(EvalInfo &Info, APValue::LValueBase Base) { |
2126 | 2128 | Info.Note((*Alloc)->AllocExpr->getExprLoc(), |
2127 | 2129 | diag::note_constexpr_dynamic_alloc_here); |
2128 | 2130 | } |
| 2131 | + |
2129 | 2132 | // We have no information to show for a typeid(T) object. |
2130 | 2133 | } |
2131 | 2134 |
|
@@ -16379,6 +16382,45 @@ static bool EvaluateBuiltinStrLen(const Expr *E, uint64_t &Result, |
16379 | 16382 | } |
16380 | 16383 | } |
16381 | 16384 |
|
| 16385 | +bool Expr::EvaluateCharRangeAsString(std::string &Result, |
| 16386 | + const Expr *SizeExpression, |
| 16387 | + const Expr *PtrExpression, ASTContext &Ctx, |
| 16388 | + EvalResult &Status) const { |
| 16389 | + LValue String; |
| 16390 | + EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantExpression); |
| 16391 | + Info.InConstantContext = true; |
| 16392 | + |
| 16393 | + FullExpressionRAII Scope(Info); |
| 16394 | + APSInt SizeValue; |
| 16395 | + if (!::EvaluateInteger(SizeExpression, SizeValue, Info)) |
| 16396 | + return false; |
| 16397 | + |
| 16398 | + int64_t Size = SizeValue.getExtValue(); |
| 16399 | + |
| 16400 | + if (!::EvaluatePointer(PtrExpression, String, Info)) |
| 16401 | + return false; |
| 16402 | + |
| 16403 | + QualType CharTy = PtrExpression->getType()->getPointeeType(); |
| 16404 | + for (int64_t I = 0; I < Size; ++I) { |
| 16405 | + APValue Char; |
| 16406 | + if (!handleLValueToRValueConversion(Info, PtrExpression, CharTy, String, |
| 16407 | + Char)) |
| 16408 | + return false; |
| 16409 | + |
| 16410 | + APSInt C = Char.getInt(); |
| 16411 | + Result.push_back(static_cast<char>(C.getExtValue())); |
| 16412 | + if (!HandleLValueArrayAdjustment(Info, PtrExpression, String, CharTy, 1)) |
| 16413 | + return false; |
| 16414 | + } |
| 16415 | + if (!Scope.destroy()) |
| 16416 | + return false; |
| 16417 | + |
| 16418 | + if (!CheckMemoryLeaks(Info)) |
| 16419 | + return false; |
| 16420 | + |
| 16421 | + return true; |
| 16422 | +} |
| 16423 | + |
16382 | 16424 | bool Expr::tryEvaluateStrLen(uint64_t &Result, ASTContext &Ctx) const { |
16383 | 16425 | Expr::EvalStatus Status; |
16384 | 16426 | EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantFold); |
|
0 commit comments