Skip to content

Commit

Permalink
Add another test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Oct 16, 2024
1 parent 1cf8a3b commit c1eb8fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3004,6 +3004,9 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool TargetIsUCharOrByte,
uint32_t ResultBitWidth, const llvm::fltSemantics *Sem) {
const Pointer &FromPtr = S.Stk.pop<Pointer>();

if (!CheckLoad(S, OpPC, FromPtr))
return false;

size_t BuffSize = ResultBitWidth / 8;
llvm::SmallVector<std::byte> Buff(BuffSize);
bool HasIndeterminateBits = false;
Expand Down
8 changes: 8 additions & 0 deletions clang/test/AST/ByteCode/builtin-bit-cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ namespace simple {
// ref-note {{indeterminate value can only initialize an object}}
}

namespace Fail {
constexpr int a = 1/0; // both-error {{must be initialized by a constant expression}} \
// both-note {{division by zero}} \
// both-note {{declared here}}
constexpr int b = __builtin_bit_cast(int, a); // both-error {{must be initialized by a constant expression}} \
// both-note {{initializer of 'a' is not a constant expression}}
}

namespace bitint {
constexpr _BitInt(sizeof(int) * 8) BI = ~0;
constexpr unsigned int I = __builtin_bit_cast(unsigned int, BI);
Expand Down

0 comments on commit c1eb8fb

Please sign in to comment.