[PATCH] D146788: [clang][Interp] Fix zero-initializing of floating types

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 6 01:52:16 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG70e5a2a94354: [clang][Interp] Fix zero-initializing of floating types (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146788

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/floats.cpp


Index: clang/test/AST/Interp/floats.cpp
===================================================================
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -78,3 +78,17 @@
   }
   static_assert(f2() == __FLT_MAX__, "");
 }
+
+namespace ZeroInit {
+  template<typename FloatT>
+  struct A {
+    int a;
+    FloatT f;
+  };
+
+  constexpr A<float> a{12};
+  static_assert(a.f == 0.0f);
+
+  constexpr A<double> b{12};
+  static_assert(a.f == 0.0);
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -953,8 +953,10 @@
     return this->emitNullPtr(E);
   case PT_FnPtr:
     return this->emitNullFnPtr(E);
-  case PT_Float:
-    assert(false);
+  case PT_Float: {
+    return this->emitConstFloat(
+        APFloat::getZero(Ctx.getFloatSemantics(E->getType())), E);
+  }
   }
   llvm_unreachable("unknown primitive type");
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146788.511324.patch
Type: text/x-patch
Size: 1015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230406/b224cc02/attachment-0001.bin>


More information about the cfe-commits mailing list