Skip to content

Commit

Permalink
Avoid PointerIntPair of constexpr EvalInfo structs
Browse files Browse the repository at this point in the history
They are stack allocated, so their alignment is not to be trusted.
32-bit MSVC only guarantees 4 byte stack alignment, even though alignof
would tell you otherwise. I tried fixing this with __declspec align, but
that apparently upsets GCC. Hopefully this version will satisfy all
compilers.

See PR32018 for some info about the mingw issues.

Should supercede https://reviews.llvm.org/D34873

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310905 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rnk committed Aug 15, 2017
1 parent 75ea7d1 commit 7890d5a
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ namespace {
/// rules. For example, the RHS of (0 && foo()) is not evaluated. We can
/// evaluate the expression regardless of what the RHS is, but C only allows
/// certain things in certain situations.
struct LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) EvalInfo {
struct EvalInfo {
ASTContext &Ctx;

/// EvalStatus - Contains information about the evaluation.
Expand Down Expand Up @@ -977,33 +977,31 @@ namespace {
/// RAII object used to optionally suppress diagnostics and side-effects from
/// a speculative evaluation.
class SpeculativeEvaluationRAII {
/// Pair of EvalInfo, and a bit that stores whether or not we were
/// speculatively evaluating when we created this RAII.
llvm::PointerIntPair<EvalInfo *, 1, bool> InfoAndOldSpecEval;
Expr::EvalStatus Old;
EvalInfo *Info;
Expr::EvalStatus OldStatus;
bool OldIsSpeculativelyEvaluating;

void moveFromAndCancel(SpeculativeEvaluationRAII &&Other) {
InfoAndOldSpecEval = Other.InfoAndOldSpecEval;
Old = Other.Old;
Other.InfoAndOldSpecEval.setPointer(nullptr);
Info = Other.Info;
OldStatus = Other.OldStatus;
Other.Info = nullptr;
}

void maybeRestoreState() {
EvalInfo *Info = InfoAndOldSpecEval.getPointer();
if (!Info)
return;

Info->EvalStatus = Old;
Info->IsSpeculativelyEvaluating = InfoAndOldSpecEval.getInt();
Info->EvalStatus = OldStatus;
Info->IsSpeculativelyEvaluating = OldIsSpeculativelyEvaluating;
}

public:
SpeculativeEvaluationRAII() = default;

SpeculativeEvaluationRAII(
EvalInfo &Info, SmallVectorImpl<PartialDiagnosticAt> *NewDiag = nullptr)
: InfoAndOldSpecEval(&Info, Info.IsSpeculativelyEvaluating),
Old(Info.EvalStatus) {
: Info(&Info), OldStatus(Info.EvalStatus),
OldIsSpeculativelyEvaluating(Info.IsSpeculativelyEvaluating) {
Info.EvalStatus.Diag = NewDiag;
Info.IsSpeculativelyEvaluating = true;
}
Expand Down

0 comments on commit 7890d5a

Please sign in to comment.