https://bugs.llvm.org/show_bug.cgi?id=40226

            Bug ID: 40226
           Summary: Passing struct by value instead of const& results in
                    linear stack bloat
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

Created attachment 21293
  --> https://bugs.llvm.org/attachment.cgi?id=21293&action=edit
A small repro

Vladislav Kuzkokov has reported the following problem with trunk LLVM (it also
appears to date back to at least LLVM 4.0.1).
When the attached program is compiled with -DBY_VALUE (which results in Struct
being passed by value, as opposed to passing a const reference) Clang allocates
extra stack space for each Struct instance in bar():

$ clang++ byval.cc -c -fno-exceptions -O2 -DBY_VALUE && objdump -Sr byval.o

...
0000000000000000 <_Z3barv>:
   0:   53                      push   %rbx
   1:   48 83 ec 20             sub    $0x20,%rsp
   5:   48 8d 5c 24 18          lea    0x18(%rsp),%rbx
   a:   48 89 df                mov    %rbx,%rdi
...


$ clang++ byval.cc -c -fno-exceptions -O2 -UBY_VALUE && objdump -Sr byval.o

...
0000000000000000 <_Z3barv>:
   0:   53                      push   %rbx
   1:   48 83 ec 10             sub    $0x10,%rsp
   5:   48 8d 5c 24 08          lea    0x8(%rsp),%rbx



Looking at the IR, perhaps the lifetime intrinsics are missing?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to