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