Skip to content

Commit

Permalink
[clang][bytecode] Handle DiscardResult for fixed-point literals (llvm…
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr authored Sep 30, 2024
1 parent 79382eb commit 3c85102
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,9 @@ bool Compiler<Emitter>::VisitFixedPointLiteral(const FixedPointLiteral *E) {
assert(E->getType()->isFixedPointType());
assert(classifyPrim(E) == PT_FixedPoint);

if (DiscardResult)
return true;

auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->getType());
APInt Value = E->getValue();
return this->emitConstFixedPoint(FixedPoint(Value, Sem), E);
Expand Down
2 changes: 2 additions & 0 deletions clang/test/AST/ByteCode/fixed-point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ static_assert(1.0k != 1.0k); // both-error {{failed due to requirement '1.0k !=
static_assert(1.0k != 1); // both-error {{failed due to requirement '1.0k != 1'}}
static_assert(-12.0k == -(-(-12.0k)));

constexpr _Accum acc = (0.5r, 6.9k);

/// Zero-init.
constexpr _Accum A{};
static_assert(A == 0.0k);
Expand Down
1 change: 1 addition & 0 deletions clang/test/Frontend/fixed_point_crash.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -verify -ffixed-point %s
// RUN: %clang_cc1 -verify -ffixed-point %s -fexperimental-new-constant-interpreter

union a {
_Accum x;
Expand Down

0 comments on commit 3c85102

Please sign in to comment.