Skip to content

Commit c5f20a8

Browse files
committed
Work on unifying the two implementations
1 parent 1591e2c commit c5f20a8

File tree

3 files changed

+79
-204
lines changed

3 files changed

+79
-204
lines changed

clang/lib/AST/Interp/Interp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,11 @@ bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR) {
610610
return false;
611611
}
612612

613-
bool CheckBitcast(InterpState &S, CodePtr OpPC, unsigned IndeterminateBits,
613+
bool CheckBitcast(InterpState &S, CodePtr OpPC, bool HasIndeterminateBits,
614614
bool TargetIsUCharOrByte) {
615615

616616
// This is always fine.
617-
if (IndeterminateBits == 0)
617+
if (!HasIndeterminateBits)
618618
return true;
619619

620620
// Indeterminate bits can only be bitcast to unsigned char or std::byte.

clang/lib/AST/Interp/Interp.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ bool CheckFloatResult(InterpState &S, CodePtr OpPC, const Floating &Result,
187187
/// Checks why the given DeclRefExpr is invalid.
188188
bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR);
189189

190-
bool CheckBitcast(InterpState &S, CodePtr OpPC, unsigned IndeterminateBits,
190+
bool CheckBitcast(InterpState &S, CodePtr OpPC, bool HasIndeterminateBits,
191191
bool TargetIsUCharOrByte);
192192

193193
/// Interpreter entry point.
@@ -205,7 +205,7 @@ bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E,
205205
/// actions of a __builtin_bit_cast expression when the target type
206206
/// is primitive.
207207
bool DoBitCast(InterpState &S, CodePtr OpPC, const Pointer &P, std::byte *Buff,
208-
size_t BuffSize, unsigned &IndeterminateBits);
208+
size_t BuffSize, bool &HasIndeterminateBits);
209209

210210
/// Perform a bitcast of all fields of P into the fields of DestPtr.
211211
/// This performs the actions of a __builtin_bit_cast expression when
@@ -1582,12 +1582,12 @@ bool BitCast(InterpState &S, CodePtr OpPC, bool TargetIsUCharOrByte) {
15821582

15831583
size_t BuffSize = ToT::valueReprBytes(S.getCtx());
15841584
std::vector<std::byte> Buff(BuffSize);
1585-
unsigned IndeterminateBits = 0;
1585+
bool HasIndeterminateBits = false;
15861586

1587-
if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), BuffSize, IndeterminateBits))
1587+
if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), BuffSize, HasIndeterminateBits))
15881588
return false;
15891589

1590-
if (!CheckBitcast(S, OpPC, IndeterminateBits, TargetIsUCharOrByte))
1590+
if (!CheckBitcast(S, OpPC, HasIndeterminateBits, TargetIsUCharOrByte))
15911591
return false;
15921592

15931593
S.Stk.push<ToT>(ToT::bitcastFromMemory(Buff.data()));
@@ -1600,12 +1600,14 @@ inline bool BitCastFP(InterpState &S, CodePtr OpPC,
16001600
const Pointer &FromPtr = S.Stk.pop<Pointer>();
16011601

16021602
std::vector<std::byte> Buff(TargetSize);
1603-
unsigned IndeterminateBits = 0;
1603+
bool HasIndeterminateBits = false;
16041604

1605-
if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), TargetSize, IndeterminateBits))
1605+
if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), TargetSize,
1606+
HasIndeterminateBits))
16061607
return false;
16071608

1608-
if (!CheckBitcast(S, OpPC, IndeterminateBits, /*TargetIsUCharOrByte=*/false))
1609+
if (!CheckBitcast(S, OpPC, HasIndeterminateBits,
1610+
/*TargetIsUCharOrByte=*/false))
16091611
return false;
16101612

16111613
S.Stk.push<Floating>(Floating::bitcastFromMemory(Buff.data(), *Sem));

0 commit comments

Comments
 (0)