tbaeder created this revision. tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin. Herald added a project: All. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Emit the proper `PT_FnPtr` instructions if we're handling function pointers here. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D156786 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/functions.cpp Index: clang/test/AST/Interp/functions.cpp =================================================================== --- clang/test/AST/Interp/functions.cpp +++ clang/test/AST/Interp/functions.cpp @@ -176,6 +176,13 @@ constexpr S s{ 12 }; static_assert(s.fp == nullptr, ""); // zero-initialized function pointer. + + constexpr int (*op)(int, int) = add; + constexpr bool b = op; + static_assert(op, ""); + static_assert(!!op, ""); + constexpr int (*op2)(int, int) = nullptr; + static_assert(!op, ""); } namespace Comparison { Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -165,14 +165,16 @@ } case CK_PointerToBoolean: { + PrimType PtrT = classifyPrim(SubExpr->getType()); + // Just emit p != nullptr for this. if (!this->visit(SubExpr)) return false; - if (!this->emitNullPtr(CE)) + if (!this->emitNull(PtrT, CE)) return false; - return this->emitNEPtr(CE); + return this->emitNE(PtrT, CE); } case CK_ToVoid:
Index: clang/test/AST/Interp/functions.cpp =================================================================== --- clang/test/AST/Interp/functions.cpp +++ clang/test/AST/Interp/functions.cpp @@ -176,6 +176,13 @@ constexpr S s{ 12 }; static_assert(s.fp == nullptr, ""); // zero-initialized function pointer. + + constexpr int (*op)(int, int) = add; + constexpr bool b = op; + static_assert(op, ""); + static_assert(!!op, ""); + constexpr int (*op2)(int, int) = nullptr; + static_assert(!op, ""); } namespace Comparison { Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -165,14 +165,16 @@ } case CK_PointerToBoolean: { + PrimType PtrT = classifyPrim(SubExpr->getType()); + // Just emit p != nullptr for this. if (!this->visit(SubExpr)) return false; - if (!this->emitNullPtr(CE)) + if (!this->emitNull(PtrT, CE)) return false; - return this->emitNEPtr(CE); + return this->emitNE(PtrT, CE); } case CK_ToVoid:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits