@@ -748,7 +748,8 @@ bool Compiler<Emitter>::VisitFloatingLiteral(const FloatingLiteral *E) {
748
748
if (DiscardResult)
749
749
return true ;
750
750
751
- return this ->emitConstFloat (E->getValue (), E);
751
+ APFloat F = E->getValue ();
752
+ return this ->emitFloat (F, E);
752
753
}
753
754
754
755
template <class Emitter >
@@ -4185,13 +4186,14 @@ bool Compiler<Emitter>::visitZeroInitializer(PrimType T, QualType QT,
4185
4186
nullptr , E);
4186
4187
case PT_MemberPtr:
4187
4188
return this ->emitNullMemberPtr (0 , nullptr , E);
4188
- case PT_Float:
4189
- return this ->emitConstFloat (APFloat::getZero (Ctx.getFloatSemantics (QT)), E);
4189
+ case PT_Float: {
4190
+ APFloat F = APFloat::getZero (Ctx.getFloatSemantics (QT));
4191
+ return this ->emitFloat (F, E);
4192
+ }
4190
4193
case PT_FixedPoint: {
4191
4194
auto Sem = Ctx.getASTContext ().getFixedPointSemantics (E->getType ());
4192
4195
return this ->emitConstFixedPoint (FixedPoint::zero (Sem), E);
4193
4196
}
4194
- llvm_unreachable (" Implement" );
4195
4197
}
4196
4198
llvm_unreachable (" unknown primitive type" );
4197
4199
}
@@ -4674,10 +4676,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD,
4674
4676
if (!visitInitializer (Init))
4675
4677
return false ;
4676
4678
4677
- if (!this ->emitFinishInit (Init))
4678
- return false ;
4679
-
4680
- return this ->emitPopPtr (Init);
4679
+ return this ->emitFinishInitGlobal (Init);
4681
4680
};
4682
4681
4683
4682
DeclScope<Emitter> LocalScope (this , VD);
@@ -4698,51 +4697,45 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD,
4698
4697
return false ;
4699
4698
4700
4699
return !Init || (checkDecl () && initGlobal (*GlobalIndex));
4701
- } else {
4702
- InitLinkScope<Emitter> ILS (this , InitLink::Decl (VD));
4703
-
4704
- if (VarT) {
4705
- unsigned Offset = this ->allocateLocalPrimitive (
4706
- VD, *VarT, VD->getType ().isConstQualified (), nullptr ,
4707
- ScopeKind::Block, IsConstexprUnknown);
4708
- if (Init) {
4709
- // If this is a toplevel declaration, create a scope for the
4710
- // initializer.
4711
- if (Toplevel) {
4712
- LocalScope<Emitter> Scope (this );
4713
- if (!this ->visit (Init))
4714
- return false ;
4715
- return this ->emitSetLocal (*VarT, Offset, VD) && Scope.destroyLocals ();
4716
- } else {
4717
- if (!this ->visit (Init))
4718
- return false ;
4719
- return this ->emitSetLocal (*VarT, Offset, VD);
4720
- }
4721
- }
4722
- } else {
4723
- if (std::optional<unsigned > Offset =
4724
- this ->allocateLocal (VD, VD->getType (), nullptr , ScopeKind::Block,
4725
- IsConstexprUnknown)) {
4726
- if (!Init)
4727
- return true ;
4700
+ }
4701
+ // Local variables.
4702
+ InitLinkScope<Emitter> ILS (this , InitLink::Decl (VD));
4728
4703
4729
- if (!this ->emitGetPtrLocal (*Offset, Init))
4704
+ if (VarT) {
4705
+ unsigned Offset = this ->allocateLocalPrimitive (
4706
+ VD, *VarT, VD->getType ().isConstQualified (), nullptr , ScopeKind::Block,
4707
+ IsConstexprUnknown);
4708
+ if (Init) {
4709
+ // If this is a toplevel declaration, create a scope for the
4710
+ // initializer.
4711
+ if (Toplevel) {
4712
+ LocalScope<Emitter> Scope (this );
4713
+ if (!this ->visit (Init))
4730
4714
return false ;
4731
-
4732
- if (!visitInitializer (Init))
4715
+ return this ->emitSetLocal (*VarT, Offset, VD) && Scope.destroyLocals ();
4716
+ } else {
4717
+ if (!this ->visit (Init))
4733
4718
return false ;
4719
+ return this ->emitSetLocal (*VarT, Offset, VD);
4720
+ }
4721
+ }
4722
+ } else {
4723
+ if (std::optional<unsigned > Offset = this ->allocateLocal (
4724
+ VD, VD->getType (), nullptr , ScopeKind::Block, IsConstexprUnknown)) {
4725
+ if (!Init)
4726
+ return true ;
4734
4727
4735
- if (!this ->emitFinishInit ( Init))
4736
- return false ;
4728
+ if (!this ->emitGetPtrLocal (*Offset, Init))
4729
+ return false ;
4737
4730
4738
- return this ->emitPopPtr (Init);
4739
- }
4740
- return false ;
4731
+ if (!visitInitializer (Init))
4732
+ return false ;
4733
+
4734
+ return this ->emitFinishInitPop (Init);
4741
4735
}
4742
- return true ;
4736
+ return false ;
4743
4737
}
4744
-
4745
- return false ;
4738
+ return true ;
4746
4739
}
4747
4740
4748
4741
template <class Emitter >
@@ -4751,8 +4744,10 @@ bool Compiler<Emitter>::visitAPValue(const APValue &Val, PrimType ValType,
4751
4744
assert (!DiscardResult);
4752
4745
if (Val.isInt ())
4753
4746
return this ->emitConst (Val.getInt (), ValType, E);
4754
- else if (Val.isFloat ())
4755
- return this ->emitConstFloat (Val.getFloat (), E);
4747
+ else if (Val.isFloat ()) {
4748
+ APFloat F = Val.getFloat ();
4749
+ return this ->emitFloat (F, E);
4750
+ }
4756
4751
4757
4752
if (Val.isLValue ()) {
4758
4753
if (Val.isNullPointer ())
@@ -6133,8 +6128,10 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
6133
6128
const auto &TargetSemantics = Ctx.getFloatSemantics (E->getType ());
6134
6129
if (!this ->emitLoadFloat (E))
6135
6130
return false ;
6136
- if (!this ->emitConstFloat (llvm::APFloat (TargetSemantics, 1 ), E))
6131
+ APFloat F (TargetSemantics, 1 );
6132
+ if (!this ->emitFloat (F, E))
6137
6133
return false ;
6134
+
6138
6135
if (!this ->emitAddf (getFPOptions (E), E))
6139
6136
return false ;
6140
6137
if (!this ->emitStoreFloat (E))
@@ -6176,8 +6173,10 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
6176
6173
const auto &TargetSemantics = Ctx.getFloatSemantics (E->getType ());
6177
6174
if (!this ->emitLoadFloat (E))
6178
6175
return false ;
6179
- if (!this ->emitConstFloat (llvm::APFloat (TargetSemantics, 1 ), E))
6176
+ APFloat F (TargetSemantics, 1 );
6177
+ if (!this ->emitFloat (F, E))
6180
6178
return false ;
6179
+
6181
6180
if (!this ->emitSubf (getFPOptions (E), E))
6182
6181
return false ;
6183
6182
if (!this ->emitStoreFloat (E))
@@ -6953,6 +6952,20 @@ bool Compiler<Emitter>::emitDummyPtr(const DeclTy &D, const Expr *E) {
6953
6952
return true ;
6954
6953
}
6955
6954
6955
+ template <class Emitter >
6956
+ bool Compiler<Emitter>::emitFloat(const APFloat &F, const Expr *E) {
6957
+ assert (!DiscardResult && " Should've been checked before" );
6958
+
6959
+ if (Floating::singleWord (F.getSemantics ()))
6960
+ return this ->emitConstFloat (Floating (F), E);
6961
+
6962
+ APInt I = F.bitcastToAPInt ();
6963
+ return this ->emitConstFloat (
6964
+ Floating (const_cast <uint64_t *>(I.getRawData ()),
6965
+ llvm::APFloatBase::SemanticsToEnum (F.getSemantics ())),
6966
+ E);
6967
+ }
6968
+
6956
6969
// This function is constexpr if and only if To, From, and the types of
6957
6970
// all subobjects of To and From are types T such that...
6958
6971
// (3.1) - is_union_v<T> is false;
0 commit comments