[cfe-commits] [Review] Partial fix for PR 11645: put destructor calls before a return statement.

Xu Zhongxing xu_zhong_xing at 163.com
Wed Jan 18 22:11:39 PST 2012



于 2012/1/17 22:36, Erik Verbruggen 写道:
> I agree that leaving it as it is would make code generation easier for 
> most cases. However, I think we have the return-value-slot problem 
> anyway:
>
> class A {
> public:
> A();
> ~A();
> };
>
> A test() {
> A a;
> return a;
> }
>
> Generates:
>
> [B3 (ENTRY)]
> Succs (1): B2
>
> [B1]
> 1: [B2.2].~A() (Implicit destructor)
> Succs (1): B0
>
> [B2]
> 1: (CXXConstructExpr, class A)
> 2: A a;
> 3: a
> 4: [B2.3] (ImplicitCastExpr, NoOp, const class A)
> 5: [B2.4] (CXXConstructExpr, class A)
> 6: return [B2.5];
> 7: [B2.2].~A() (Implicit destructor)
> Preds (1): B3
> Succs (1): B0
>
> [B0 (EXIT)]
> Preds (2): B1 B2
>
> So to find out that we need to construct A in the return value slot in 
> B2.5, we need to look ahead to B2.6.
For static analysis, we could first construct A in a temporary object, 
then copy it into return value slot when we see B2.6.
>
> Also, I think that Ted pointed to another test-case which is then 
> incorrect:
>
> class A {
> public:
> A();
> ~A();
> };
>
> A test() {
> return A();
> }
>
> Generates:
>
> [B2 (ENTRY)]
> Succs (1): B1
>
> [B1]
> 1: A() (CXXConstructExpr, class A)
> 2: [B1.1] (BindTemporary)
> 3: [B1.2] (ImplicitCastExpr, NoOp, const class A)
> 4: [B1.3]
> 5: [B1.4] (CXXConstructExpr, class A)
> 6: ~A() (Temporary object destructor)

Yeah, for this case A() is destructed before we see 'return ...'. This 
is a problem for AST evaluation.

> 7: return [B1.5];
> Preds (1): B2
> Succs (1): B0
>
> [B0 (EXIT)]
> Preds (1): B1
>
> In the mean time I'll see if I can find out where the extra joint 
> points get generated.
>
> -- Erik.
>
>>
>




More information about the cfe-commits mailing list