r302817 - PR22877: When constructing an array via a constructor with a default argument

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu May 11 14:34:44 PDT 2017


XFAIL'd for hexagon in r302825, filed PR33009 for the miscompile.

Looks like it's only passing empty structs in C++ that is miscompiled, but
that's still pretty serious.

On 11 May 2017 at 14:30, Richard Smith <richard at metafoo.co.uk> wrote:

> Wow, the Hexagon target is just horribly broken. Reduced testcase:
>
> struct A { A(); A(const A&); ~A(); };
> void f(A a);
> void g() { f(A()); }
>
> This completely fails to pass an A object to f. Instrumented version:
>
> #include <stdio.h>
> #define DUMP(ptr) printf("%s %p\\n", __PRETTY_FUNCTION__, ptr)
>
> struct A {
>   A() { DUMP(this); }
>   A(const A&) { DUMP(this); }
>   ~A() { DUMP(this); }
> };
> void f(A a) { DUMP(&a); }
> int main() { f(A()); }
>
> ... prints:
>
> A::A() 0x7ffd54d95658
> void f(A) 0x7ffd54d95638
> A::~A() 0x7ffd54d95658
>
> Also, the hexagon bot appears to be failing to send mail.
>
> On 11 May 2017 at 13:17, Krzysztof Parzyszek via cfe-commits <
> cfe-commits at lists.llvm.org> wrote:
>
>> Hexagon is still broken.  :(
>>
>> http://lab.llvm.org:8011/builders/clang-hexagon-elf/builds/7942
>>
>> -Krzysztof
>>
>>
>> On 5/11/2017 1:58 PM, Richard Smith via cfe-commits wrote:
>>
>>> Author: rsmith
>>> Date: Thu May 11 13:58:24 2017
>>> New Revision: 302817
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=302817&view=rev
>>> Log:
>>> PR22877: When constructing an array via a constructor with a default
>>> argument
>>> in list-initialization, run cleanups for the default argument after each
>>> iteration of the initialization loop.
>>>
>>> We previously only ran the destructor for any temporary once, at the end
>>> of the
>>> complete loop, rather than once per iteration!
>>>
>>> Re-commit of r302750, reverted in r302776.
>>>
>>> Added:
>>>      cfe/trunk/test/CodeGenCXX/array-default-argument.cpp
>>>        - copied, changed from r302775, cfe/trunk/test/CodeGenCXX/arra
>>> y-default-argument.cpp
>>> Modified:
>>>      cfe/trunk/lib/CodeGen/CGExprAgg.cpp
>>>
>>> Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CG
>>> ExprAgg.cpp?rev=302817&r1=302816&r2=302817&view=diff
>>> ============================================================
>>> ==================
>>> --- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
>>> +++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu May 11 13:58:24 2017
>>> @@ -512,12 +512,20 @@ void AggExprEmitter::EmitArrayInit(Addre
>>>       currentElement->addIncoming(element, entryBB);
>>>         // Emit the actual filler expression.
>>> -    LValue elementLV =
>>> -      CGF.MakeAddrLValue(Address(currentElement, elementAlign),
>>> elementType);
>>> -    if (filler)
>>> -      EmitInitializationToLValue(filler, elementLV);
>>> -    else
>>> -      EmitNullInitializationToLValue(elementLV);
>>> +    {
>>> +      // C++1z [class.temporary]p5:
>>> +      //   when a default constructor is called to initialize an
>>> element of
>>> +      //   an array with no corresponding initializer [...] the
>>> destruction of
>>> +      //   every temporary created in a default argument is sequenced
>>> before
>>> +      //   the construction of the next array element, if any
>>> +      CodeGenFunction::RunCleanupsScope CleanupsScope(CGF);
>>> +      LValue elementLV =
>>> +        CGF.MakeAddrLValue(Address(currentElement, elementAlign),
>>> elementType);
>>> +      if (filler)
>>> +        EmitInitializationToLValue(filler, elementLV);
>>> +      else
>>> +        EmitNullInitializationToLValue(elementLV);
>>> +    }
>>>         // Move on to the next element.
>>>       llvm::Value *nextElement =
>>>
>>> Copied: cfe/trunk/test/CodeGenCXX/array-default-argument.cpp (from
>>> r302775, cfe/trunk/test/CodeGenCXX/array-default-argument.cpp)
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCX
>>> X/array-default-argument.cpp?p2=cfe/trunk/test/CodeGenCXX/ar
>>> ray-default-argument.cpp&p1=cfe/trunk/test/CodeGenCXX/array-
>>> default-argument.cpp&r1=302775&r2=302817&rev=302817&view=diff
>>> ============================================================
>>> ==================
>>> --- cfe/trunk/test/CodeGenCXX/array-default-argument.cpp (original)
>>> +++ cfe/trunk/test/CodeGenCXX/array-default-argument.cpp Thu May 11
>>> 13:58:24 2017
>>> @@ -17,11 +17,11 @@ void g() {
>>>     // CHECK: br label %[[LOOP:.*]]
>>>       // [[LOOP]]:
>>> -  // CHECK: {{call|invoke}}[[THISCALL:( x86_thiscallcc)?]] void
>>> @_ZN1AC1Ev([[TEMPORARY:.*]])
>>> +  // CHECK: {{call|invoke}} {{.*}} @_ZN1AC1Ev([[TEMPORARY:.*]])
>>>     // CHECK-EH:  unwind label %[[PARTIAL_ARRAY_LPAD:.*]]
>>> -  // CHECK: {{call|invoke}}[[THISCALL]] void @_ZN1BC1E1A({{.*}},
>>> [[TEMPORARY]])
>>> +  // CHECK: {{call|invoke}} {{.*}} @_ZN1BC1E1A({{.*}}, [[TEMPORARY]])
>>>     // CHECK-EH:  unwind label %[[A_AND_PARTIAL_ARRAY_LPAD:.*]]
>>> -  // CHECK: {{call|invoke}}[[THISCALL]] void @_ZN1AD1Ev([[TEMPORARY]])
>>> +  // CHECK: {{call|invoke}} {{.*}} @_ZN1AD1Ev([[TEMPORARY]])
>>>     // CHECK-EH:  unwind label %[[PARTIAL_ARRAY_LPAD]]
>>>     // CHECK: getelementptr {{.*}}, i{{[0-9]*}} 1
>>>     // CHECK: icmp eq
>>> @@ -32,5 +32,5 @@ void g() {
>>>     f();
>>>       // CHECK-NOT: @_ZN1AD1Ev(
>>> -  // CHECK: {{call|invoke}}[[THISCALL]] void @_ZN1BD1Ev(
>>> +  // CHECK: {{call|invoke}} {{.*}} @_ZN1BD1Ev(
>>>   }
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>>
>> --
>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted
>> by The Linux Foundation
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170511/3feebdda/attachment-0001.html>


More information about the cfe-commits mailing list