Skip to content

Commit

Permalink
[clang][Interp] Fix ImplicitValueInitExprs for pointer types
Browse files Browse the repository at this point in the history
This previously ran into an "unknown type" assertion when trying to emit
a 'Zero' op for a pointer type. Emit a NullPtr op instead.

Differential Revision: https://reviews.llvm.org/D137235
  • Loading branch information
tbaederr committed Jan 25, 2023
1 parent d7cf7ab commit 2725e2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Expand Up @@ -279,10 +279,15 @@ bool ByteCodeExprGen<Emitter>::VisitPointerArithBinOp(const BinaryOperator *E) {

template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
if (std::optional<PrimType> T = classify(E))
return this->emitZero(*T, E);
std::optional<PrimType> T = classify(E);

return false;
if (!T)
return false;

if (E->getType()->isPointerType())
return this->emitNullPtr(E);

return this->emitZero(*T, E);
}

template <class Emitter>
Expand Down
5 changes: 4 additions & 1 deletion clang/test/AST/Interp/literals.cpp
Expand Up @@ -49,7 +49,10 @@ namespace IntegralCasts {
static_assert(!nu, "");
};


constexpr int UninitI; // expected-error {{must be initialized by a constant expression}} \
// ref-error {{must be initialized by a constant expression}}
constexpr int *UninitPtr; // expected-error {{must be initialized by a constant expression}} \
// ref-error {{must be initialized by a constant expression}}

constexpr bool getTrue() { return true; }
constexpr bool getFalse() { return false; }
Expand Down

0 comments on commit 2725e2c

Please sign in to comment.