[clang] 015ffba - [clang][Interp] Fix converting function pointers to bool
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 1 06:37:09 PDT 2023
Author: Timm Bäder
Date: 2023-08-01T15:36:34+02:00
New Revision: 015ffba811c49ee4d98cc68125b03bd5e1c2a2b6
URL: https://github.com/llvm/llvm-project/commit/015ffba811c49ee4d98cc68125b03bd5e1c2a2b6
DIFF: https://github.com/llvm/llvm-project/commit/015ffba811c49ee4d98cc68125b03bd5e1c2a2b6.diff
LOG: [clang][Interp] Fix converting function pointers to bool
Differential Revision: https://reviews.llvm.org/D156786
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index b727865427054b..8a756e4fc2db42 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -167,14 +167,16 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
}
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:
diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp
index 3540791917fab1..e1dd73b6958688 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -176,6 +176,13 @@ namespace FunctionReturnType {
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(!op2, "");
}
namespace Comparison {
More information about the cfe-commits
mailing list