[llvm-bugs] [Bug 51113] New: Declaring an array of struct without explicit constructor causes excessive memory consumption
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jul 16 03:41:23 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51113
Bug ID: 51113
Summary: Declaring an array of struct without explicit
constructor causes excessive memory consumption
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: mivik at qq.com
CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
richard-llvm at metafoo.co.uk
Declaring an array of struct without explicit constructor can cause abnormally
excessive memory consumption.
Here's the code I compiled:
struct data {
int a, b, c, d;
} arr[10000000];
int main() {}
This array should take only (4 bytes * 4) * 10000000 = 152MB, but clang used
around 3GB to compile it. Here's the log:
$ /usr/bin/time -v clang++ sample.cpp -std=c++11
Command being timed: "clang++ sample.cpp -std=c++11"
User time (seconds): 3.11
System time (seconds): 1.00
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:04.12
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 3730012
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 930464
Voluntary context switches: 7
Involuntary context switches: 28
Swaps: 0
File system inputs: 0
File system outputs: 40
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
The abnormal memory consumption can be observed at "Maximum resident set size".
However, adding a constructor to the struct will let the problem disappear.
Also, I noticed that the problem occurs only when c++11 or higher standards are
specified, and when I use "-std=c++98" this problem does not produce. So I
guess this might has something to do with constexpr analyzing.
Clang Version:
Ubuntu clang version 12.0.0-3ubuntu1~20.04.3
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64
--
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/20210716/9b820155/attachment-0001.html>
More information about the llvm-bugs
mailing list