https://llvm.org/bugs/show_bug.cgi?id=30317
Bug ID: 30317 Summary: Constructing a vector with an initializer list generates more code than push_back / emplace_back Product: clang Version: unspecified Hardware: PC OS: Windows NT Status: NEW Severity: normal Priority: P Component: LLVM Codegen Assignee: unassignedclangb...@nondot.org Reporter: dch...@google.com CC: llvm-bugs@lists.llvm.org Classification: Unclassified Simple test case: #include <stdio.h> #include <string> #include <vector> void PrintVector(const std::vector<std::string>& strings) { for (const auto& s : strings) { printf("%s\n", s.data()); } } void Foo() { std::vector<std::string> names; names.push_back("abc"); names.push_back("def"); names.push_back("ghi"); PrintVector(names); } void Bar() { std::vector<std::string> names{ "abc", "def", "ghi", }; PrintVector(names); } int main() { Foo(); Bar(); } With -O2, the function sizes are roughly the same. Foo() is 847 bytes, Bar() is 844 bytes. With -O1, Foo() is much smaller at 294 bytes, while Bar() is 396 bytes. -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs