Skip to content

Commit

Permalink
[clang][Interp] Handle discarded PointerToIntegral casts
Browse files Browse the repository at this point in the history
Resolve an old TODO comment.
  • Loading branch information
tbaederr committed Feb 13, 2024
1 parent b56b3d7 commit 85e6e71
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
return this->emitNull(classifyPrim(CE->getType()), CE);

case CK_PointerToIntegral: {
// TODO: Discard handling.
if (DiscardResult)
return this->discard(SubExpr);

if (!this->visit(SubExpr))
return false;

Expand Down
1 change: 1 addition & 0 deletions clang/test/AST/Interp/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ _Static_assert(!!1, "");
int a = (1 == 1 ? 5 : 3);
_Static_assert(a == 5, ""); // all-error {{not an integral constant expression}}

const int DiscardedPtrToIntCast = ((intptr_t)((void*)0), 0); // all-warning {{left operand of comma operator has no effect}}

const int b = 3;
_Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant expression}} \
Expand Down

0 comments on commit 85e6e71

Please sign in to comment.