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

            Bug ID: 40776
           Summary: missed optimization with C constructors of sparse
                    structures
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

I stumbled over a file with excessive stack usage in the Linux kernel when
building with clang, but not with gcc, reduced the test case to:

struct i2c_adapter {
  char name[48];
  int a[1000];
} hexium_attach_hexium;
void hexium_attach(void) {
    hexium_attach_hexium = (struct i2c_adapter){"hexium gemini"};
}

$ clang-8 -Werror  -c hexium-gemini.c -Wframe-larger-than=100  -O2
hexium-gemini.c:5:6: error: stack frame size of 4056 bytes in function
'hexium_attach' [-Werror,-Wframe-larger-than=]

Comparing the output shows that clang not only allocates stack space for the
extra copy of the structure, but also fails to optimize the string assignment:

https://godbolt.org/z/7jpy_y

I worked around it in the kernel sources by using an explict memset and
strscpy, but this seems like a generally useful optimization that could be
added.

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

Reply via email to