tbaeder created this revision. tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik. Herald added a project: All. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This previously ran into an "unknown type" assertion when trying to emit a 'Zero' op for a pointer type. Emit a NullPtr op instead. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D137235 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/literals.cpp Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -49,7 +49,10 @@ 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; } Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -359,10 +359,15 @@ template <class Emitter> bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) { - if (Optional<PrimType> T = classify(E)) - return this->emitZero(*T, E); + 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>
Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -49,7 +49,10 @@ 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; } Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -359,10 +359,15 @@ template <class Emitter> bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) { - if (Optional<PrimType> T = classify(E)) - return this->emitZero(*T, E); + 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>
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits