[llvm-bugs] [Bug 40226] New: Passing struct by value instead of const& results in linear stack bloat

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 4 06:42:01 PST 2019


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: unassignedclangbugs at nondot.org
          Reporter: glider at google.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190104/a0b53206/attachment.html>


More information about the llvm-bugs mailing list