[PATCH] D146788: [clang][Interp] Fix zero-initializing of floating types
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 24 00:35:49 PDT 2023
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.
After the discussion in https://reviews.llvm.org/D141472, this fixes zero-initializing members of floating type
Repository:
rG LLVM Github Monorepo
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
@@ -1073,8 +1073,12 @@
return this->emitNullPtr(E);
case PT_FnPtr:
return this->emitNullFnPtr(E);
- case PT_Float:
- assert(false);
+ case PT_Float: {
+ const auto &Sem = Ctx.getASTContext().getFloatTypeSemantics(E->getType());
+
+ APFloat Val(Sem);
+ return this->emitConstFloat(Val, E);
+ }
}
llvm_unreachable("unknown primitive type");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146788.507981.patch
Type: text/x-patch
Size: 1062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230324/1d8a723d/attachment.bin>
More information about the cfe-commits
mailing list