File tree Expand file tree Collapse file tree 4 files changed +52
-6
lines changed Expand file tree Collapse file tree 4 files changed +52
-6
lines changed Original file line number Diff line number Diff line change @@ -1700,19 +1700,35 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundLiteralExpr(
1700
1700
}
1701
1701
1702
1702
// Otherwise, use a local variable.
1703
- if (T) {
1703
+ if (T && !E-> isLValue () ) {
1704
1704
// For primitive types, we just visit the initializer.
1705
1705
return this ->delegate (Init);
1706
1706
} else {
1707
- if (std::optional<unsigned > LocalIndex = allocateLocal (Init)) {
1708
- if (!this ->emitGetPtrLocal (*LocalIndex, E))
1707
+ unsigned LocalIndex;
1708
+
1709
+ if (T)
1710
+ LocalIndex = this ->allocateLocalPrimitive (Init, *T, false , false );
1711
+ else if (std::optional<unsigned > MaybeIndex = this ->allocateLocal (Init))
1712
+ LocalIndex = *MaybeIndex;
1713
+ else
1714
+ return false ;
1715
+
1716
+ if (!this ->emitGetPtrLocal (LocalIndex, E))
1717
+ return false ;
1718
+
1719
+ if (T) {
1720
+ if (!this ->visit (Init)) {
1709
1721
return false ;
1722
+ }
1723
+ return this ->emitInit (*T, E);
1724
+ } else {
1710
1725
if (!this ->visitInitializer (Init))
1711
1726
return false ;
1712
- if (DiscardResult)
1713
- return this ->emitPopPtr (E);
1714
- return true ;
1715
1727
}
1728
+
1729
+ if (DiscardResult)
1730
+ return this ->emitPopPtr (E);
1731
+ return true ;
1716
1732
}
1717
1733
1718
1734
return false ;
Original file line number Diff line number Diff line change @@ -1399,6 +1399,19 @@ bool StoreBitFieldPop(InterpState &S, CodePtr OpPC) {
1399
1399
return true ;
1400
1400
}
1401
1401
1402
+ template <PrimType Name, class T = typename PrimConv<Name>::T>
1403
+ bool Init (InterpState &S, CodePtr OpPC) {
1404
+ const T &Value = S.Stk .pop <T>();
1405
+ const Pointer &Ptr = S.Stk .peek <Pointer>();
1406
+ if (!CheckInit (S, OpPC, Ptr)) {
1407
+ assert (false );
1408
+ return false ;
1409
+ }
1410
+ Ptr.initialize ();
1411
+ new (&Ptr.deref <T>()) T (Value);
1412
+ return true ;
1413
+ }
1414
+
1402
1415
template <PrimType Name, class T = typename PrimConv<Name>::T>
1403
1416
bool InitPop (InterpState &S, CodePtr OpPC) {
1404
1417
const T &Value = S.Stk .pop <T>();
Original file line number Diff line number Diff line change @@ -476,6 +476,7 @@ def StoreBitField : StoreBitFieldOpcode {}
476
476
def StoreBitFieldPop : StoreBitFieldOpcode {}
477
477
478
478
// [Pointer, Value] -> []
479
+ def Init : StoreOpcode {}
479
480
def InitPop : StoreOpcode {}
480
481
// [Pointer, Value] -> [Pointer]
481
482
def InitElem : Opcode {
Original file line number Diff line number Diff line change @@ -180,3 +180,19 @@ void test4(void) {
180
180
t1 = sizeof (int );
181
181
}
182
182
183
+ void localCompoundLiteral (void ) {
184
+ struct S { int x , y ; } s = {}; // pedantic-expected-warning {{use of an empty initializer}} \
185
+ // pedantic-ref-warning {{use of an empty initializer}}
186
+ struct T {
187
+ int i ;
188
+ struct S s ;
189
+ } t1 = { 1 , {} }; // pedantic-expected-warning {{use of an empty initializer}} \
190
+ // pedantic-ref-warning {{use of an empty initializer}}
191
+
192
+ struct T t3 = {
193
+ (int ){}, // pedantic-expected-warning {{use of an empty initializer}} \
194
+ // pedantic-ref-warning {{use of an empty initializer}}
195
+ {} // pedantic-expected-warning {{use of an empty initializer}} \
196
+ // pedantic-ref-warning {{use of an empty initializer}}
197
+ };
198
+ }
You can’t perform that action at this time.
0 commit comments