[llvm-bugs] [Bug 39508] New: Reuse guard variable for multiple initializations

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 31 06:43:50 PDT 2018


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

            Bug ID: 39508
           Summary: Reuse guard variable for multiple initializations
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: antoshkka at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Consider the following example:

int produce1();
int produce2(int ) noexcept;


auto test() {
    static int val1 = produce1();
    static int val2 = produce2(val1); // noexcept

    return val2 + val2;
}

For the above example two guard variables are generated: for `val1` and `val2`.
However the `val2` initialization always succeeds and may not happen before
`val1` initialization.

So instead of having two variables, `val2` could reuse the guard variable for
`val1`.

Using one variable has advantages: less code is generated and no need in
multiple guard variables checks.

Such optimization will reduce the code size and improve overall performance.

-- 
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/20181031/d1454b78/attachment.html>


More information about the llvm-bugs mailing list