diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-15 02:18:13 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-15 02:18:13 +0000 |
commit | b228a86fcfd165b06919e43d28b8f1d0713c9802 (patch) | |
tree | c78028d3e040c7d57ee17c0f821f0059a84645c0 /clang/lib/AST/APValue.cpp | |
parent | d1ff1cbe231b58e8a9fd91a30e4568fbce7528aa (diff) | |
download | bcm5719-llvm-b228a86fcfd165b06919e43d28b8f1d0713c9802.tar.gz bcm5719-llvm-b228a86fcfd165b06919e43d28b8f1d0713c9802.zip |
Implement DR1454. This allows all intermediate results in constant expressions
to be core constant expressions (including pointers and references to
temporaries), and makes constexpr calculations Turing-complete. A Turing machine
simulator is included as a testcase.
This opens up the possibilty of removing CCValue entirely, and removing some
copies from the constant evaluator in the process, but that cleanup is not part
of this change.
llvm-svn: 150557
Diffstat (limited to 'clang/lib/AST/APValue.cpp')
-rw-r--r-- | clang/lib/AST/APValue.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp index b8942c33101..4e17d3b69eb 100644 --- a/clang/lib/AST/APValue.cpp +++ b/clang/lib/AST/APValue.cpp @@ -28,6 +28,7 @@ namespace { llvm::PointerIntPair<APValue::LValueBase, 1, bool> BaseAndIsOnePastTheEnd; CharUnits Offset; unsigned PathLength; + unsigned CallIndex; }; } @@ -166,9 +167,10 @@ const APValue &APValue::operator=(const APValue &RHS) { else if (isLValue()) { if (RHS.hasLValuePath()) setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), RHS.getLValuePath(), - RHS.isLValueOnePastTheEnd()); + RHS.isLValueOnePastTheEnd(), RHS.getLValueCallIndex()); else - setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), NoLValuePath()); + setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), NoLValuePath(), + RHS.getLValueCallIndex()); } else if (isArray()) { for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; ++I) getArrayInitializedElt(I) = RHS.getArrayInitializedElt(I); @@ -525,22 +527,31 @@ ArrayRef<APValue::LValuePathEntry> APValue::getLValuePath() const { return ArrayRef<LValuePathEntry>(LVal.getPath(), LVal.PathLength); } -void APValue::setLValue(LValueBase B, const CharUnits &O, NoLValuePath) { +unsigned APValue::getLValueCallIndex() const { + assert(isLValue() && "Invalid accessor"); + return ((const LV*)(const char*)Data)->CallIndex; +} + +void APValue::setLValue(LValueBase B, const CharUnits &O, NoLValuePath, + unsigned CallIndex) { assert(isLValue() && "Invalid accessor"); LV &LVal = *((LV*)(char*)Data); LVal.BaseAndIsOnePastTheEnd.setPointer(B); LVal.BaseAndIsOnePastTheEnd.setInt(false); LVal.Offset = O; + LVal.CallIndex = CallIndex; LVal.resizePath((unsigned)-1); } void APValue::setLValue(LValueBase B, const CharUnits &O, - ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd) { + ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd, + unsigned CallIndex) { assert(isLValue() && "Invalid accessor"); LV &LVal = *((LV*)(char*)Data); LVal.BaseAndIsOnePastTheEnd.setPointer(B); LVal.BaseAndIsOnePastTheEnd.setInt(IsOnePastTheEnd); LVal.Offset = O; + LVal.CallIndex = CallIndex; LVal.resizePath(Path.size()); memcpy(LVal.getPath(), Path.data(), Path.size() * sizeof(LValuePathEntry)); } |