Skip to content

Commit 4ab9ad7

Browse files
committed
Merging r310905 and r310994:
------------------------------------------------------------------------ r310905 | rnk | 2017-08-14 18:17:47 -0700 (Mon, 14 Aug 2017) | 11 lines Avoid PointerIntPair of constexpr EvalInfo structs 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 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r310994 | chandlerc | 2017-08-16 00:22:49 -0700 (Wed, 16 Aug 2017) | 6 lines Fix a UBSan failure where this boolean was copied when uninitialized. When r310905 moved the pointer and bool out of a PointerIntPair, it made them end up uninitialized and caused UBSan failures when copying the uninitialized boolean. However, making the pointer be null should avoid the reference to the boolean entirely. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_50@318225 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d8199c9 commit 4ab9ad7

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lib/AST/ExprConstant.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ namespace {
537537
/// rules. For example, the RHS of (0 && foo()) is not evaluated. We can
538538
/// evaluate the expression regardless of what the RHS is, but C only allows
539539
/// certain things in certain situations.
540-
struct LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) EvalInfo {
540+
struct EvalInfo {
541541
ASTContext &Ctx;
542542

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

985984
void moveFromAndCancel(SpeculativeEvaluationRAII &&Other) {
986-
InfoAndOldSpecEval = Other.InfoAndOldSpecEval;
987-
Old = Other.Old;
988-
Other.InfoAndOldSpecEval.setPointer(nullptr);
985+
Info = Other.Info;
986+
OldStatus = Other.OldStatus;
987+
Other.Info = nullptr;
989988
}
990989

991990
void maybeRestoreState() {
992-
EvalInfo *Info = InfoAndOldSpecEval.getPointer();
993991
if (!Info)
994992
return;
995993

996-
Info->EvalStatus = Old;
997-
Info->IsSpeculativelyEvaluating = InfoAndOldSpecEval.getInt();
994+
Info->EvalStatus = OldStatus;
995+
Info->IsSpeculativelyEvaluating = OldIsSpeculativelyEvaluating;
998996
}
999997

1000998
public:
1001999
SpeculativeEvaluationRAII() = default;
10021000

10031001
SpeculativeEvaluationRAII(
10041002
EvalInfo &Info, SmallVectorImpl<PartialDiagnosticAt> *NewDiag = nullptr)
1005-
: InfoAndOldSpecEval(&Info, Info.IsSpeculativelyEvaluating),
1006-
Old(Info.EvalStatus) {
1003+
: Info(&Info), OldStatus(Info.EvalStatus),
1004+
OldIsSpeculativelyEvaluating(Info.IsSpeculativelyEvaluating) {
10071005
Info.EvalStatus.Diag = NewDiag;
10081006
Info.IsSpeculativelyEvaluating = true;
10091007
}

0 commit comments

Comments
 (0)