[llvm-bugs] [Bug 37786] New: Long compilation time and crash on large cpp file with default constructors

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 13 00:49:32 PDT 2018


            Bug ID: 37786
           Summary: Long compilation time and crash on large cpp file with
                    default constructors
           Product: libraries
           Version: 3.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Core LLVM classes
          Assignee: unassignedbugs at nondot.org
          Reporter: gmail at rolnicki.net
                CC: llvm-bugs at lists.llvm.org

Given the below code (if you want to compile it, copy the designated line ~4000
times), notice the constructor definition for `Drink()`; currently, it has 5
optional arguments. Compiling as is with `clang++ Drink.cpp` will complete in 1
min. If you add 5 more optional arguments (i.e., arg6 - arg10), compilation
time will go to 3.5 minutes. If you trim it down to just 2 arguments, it
compiles in 15 seconds. Also, compiling the version listed below (5 arg
version) with -Oz crashes the compiler.

The below was run on Windows with Ubuntu Linux, but also repros on CentOS. Note
we've seen this code take a whooping ~4 hours to compile on version 3.5 with
-Oz on CentOS, but doesn't cause a compiler crash.

clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

// 2 arg constructor
real    0m17.311s
user    0m16.078s
sys     0m1.219s

// 5 arg constructor
real    1m0.909s
user    0m58.016s
sys     0m2.609s

// 10 arg constructor
real    3m42.512s
user    3m34.453s
sys     0m6.344s

// 5 arg constructor, with -Oz
0  libLLVM-3.8.so.1 0x00007f08d65b8d38
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 56
1  libLLVM-3.8.so.1 0x00007f08d65b6fc6 llvm::sys::RunSignalHandlers() + 54
2  libLLVM-3.8.so.1 0x00007f08d65b7129
3  libc.so.6        0x00007f08d56d54b0
4  libLLVM-3.8.so.1 0x00007f08d6fe47dd
5  libLLVM-3.8.so.1 0x00007f08d6feb32a
6  libLLVM-3.8.so.1 0x00007f08d6fec865
7  libLLVM-3.8.so.1 0x00007f08d6fef397
llvm::LazyValueInfo::getPredicateOnEdge(unsigned int, llvm::Value*,
llvm::Constant*, llvm::BasicBlock*, llvm::BasicBlock*, llvm::Instruction*) +
8  libLLVM-3.8.so.1 0x00007f08d6fef67c
llvm::LazyValueInfo::getPredicateAt(unsigned int, llvm::Value*,
llvm::Constant*, llvm::Instruction*) + 604
9  libLLVM-3.8.so.1 0x00007f08d6d47644
10 libLLVM-3.8.so.1 0x00007f08d66fe2a2
llvm::FPPassManager::runOnFunction(llvm::Function&) + 498
11 libLLVM-3.8.so.1 0x00007f08d6f7320e
12 libLLVM-3.8.so.1 0x00007f08d66fdeef
llvm::legacy::PassManagerImpl::run(llvm::Module&) + 783
13 clang            0x00000000006eb071
clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions
const&, clang::TargetOptions const&, clang::LangOptions const&,
llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::raw_pwrite_stream*)
+ 4305
14 clang            0x0000000000a165a1
15 clang            0x0000000000b36f7a clang::ParseAST(clang::Sema&, bool,
bool) + 938
16 clang            0x000000000099aa0e clang::FrontendAction::Execute() + 302
17 clang            0x0000000000970406
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 278
18 clang            0x0000000000a152b3
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1987
19 clang            0x00000000006b3528 cc1_main(llvm::ArrayRef<char const*>,
char const*, void*) + 2264
20 clang            0x00000000006affbc main + 6252
21 libc.so.6        0x00007f08d56c0830 __libc_start_main + 240
22 clang            0x00000000006b1969 _start + 41
Stack dump:
0.      Program arguments: /usr/lib/llvm-3.8/bin/clang -cc1 -triple
x86_64-pc-linux-gnu -emit-obj -disable-free -disable-llvm-verifier
-main-file-name Drinks.cpp -mrelocation-model static -mthread-model posix
-fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables
-fuse-init-array -target-cpu x86-64 -momit-leaf-frame-pointer
-dwarf-column-info -debugger-tuning=gdb -resource-dir
/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0 -internal-isystem
-internal-isystem /usr/local/include -internal-isystem
/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include
-internal-externc-isystem /usr/include -Oz -fdeprecated-macro
-fdebug-compilation-dir /mnt/c/temp -ferror-limit 19 -fmessage-length 237
-fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -vectorize-slp -o /tmp/Drinks-5b469e.o -x c++ Drinks.cpp
1.      <eof> parser at end of file
2.      Per-module optimization passes
3.      Running pass 'CallGraph Pass Manager' on module 'Drinks.cpp'.
4.      Running pass 'Value Propagation' on function '@_Z10all_drinksB5cxx11v'
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: PLEASE submit a bug report to
http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and
associated run script.
clang: error: unable to execute command: posix_spawn failed: Invalid argument
clang: note: diagnostic msg: Error generating preprocessed source(s).

real    8m4.109s
user    7m14.969s
sys     0m31.109s


#include <string>
#include <list>
#include <map>
#include <iostream>
#include <utility>

using namespace std;

// Declarations
class Ingredient
    string m_name;
    string m_volume;

    Ingredient(string name = "", string volume = "");    
    operator bool() const;

class Drink
    string m_name;
    list<Ingredient> m_ingredients;

    Drink(string name);
        Drink(string name, Ingredient ing1 = Ingredient("", ""), Ingredient
ing2 = Ingredient("", ""), Ingredient ing3 = Ingredient("", ""), Ingredient
ing4 = Ingredient("", ""), Ingredient ing5 = Ingredient("", ""));
    Drink & AddIng(const string & _name, const string & _qty);

// Implementations
Ingredient::Ingredient(string name, string volume)
        m_name = name;
        m_volume = volume;

Ingredient::operator bool() const
        return !m_name.empty();

Drink::Drink(std::string name) 
        m_name = name;

Drink::Drink(string name, Ingredient ing1, Ingredient ing2, Ingredient ing3,
Ingredient ing4, Ingredient ing5)
        m_name = name;
        if (ing1)
        if (ing2)

Drink & Drink::AddIng(const string & _name, const string & _qty)
        m_ingredients.push_back(Ingredient(_name, _qty));
        return *this;

std::map<std::string, const Drink *> & all_drinks()
        static std::map<std::string, const Drink *> g_drinks;
        if (g_drinks.empty())
        g_drinks["Martini"] = new Drink("Martini", Ingredient("Dry Vermouth",
"1/2 oz "), Ingredient("Gin", "3 oz "));
        g_drinks["Martini"] = new Drink("Martini", Ingredient("Dry Vermouth",
"1/2 oz "), Ingredient("Gin", "3 oz "));
        // ... Repeat this line 4000 times
        g_drinks["Martini"] = new Drink("Martini", Ingredient("Dry Vermouth",
"1/2 oz "), Ingredient("Gin", "3 oz "));

        return g_drinks;

int main()
        return 0;

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/20180613/e4b0263f/attachment.html>

More information about the llvm-bugs mailing list