[PATCH] D156786: [clang][Interp] Fix converting function pointers to bool

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 1 06:37:29 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG015ffba811c4: [clang][Interp] Fix converting function pointers to bool (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156786/new/

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(!op2, "");
 }
 
 namespace Comparison {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -167,14 +167,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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156786.546027.patch
Type: text/x-patch
Size: 1145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230801/f68886e3/attachment.bin>


More information about the cfe-commits mailing list