<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - CFGBuilder needs to handle ExprWithCleanups better"
   href="https://llvm.org/bugs/show_bug.cgi?id=29152">29152</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>CFGBuilder needs to handle ExprWithCleanups better
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>pirama@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, srhines@google.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=17054" name="attach_17054" title="Preprocessed input file">attachment 17054</a> <a href="attachment.cgi?id=17054&action=edit" title="Preprocessed input file">[details]</a></span>
Preprocessed input file

CFGBuilder::VisitIfStmt in CFG.cpp does not handle a BinaryOperator packaged in
an ExprWithCleanup correctly.  r272296 increases the frequency and cases where
ExprWithCleanups are created.

This causes -Wunreachable-code in Android's ART code
(<a href="https://android.googlesource.com/platform/art/+/c9c055f96005b319d6c582b23432ba3ef0bd7488/runtime/class_table.cc">https://android.googlesource.com/platform/art/+/c9c055f96005b319d6c582b23432ba3ef0bd7488/runtime/class_table.cc</a>).

ToT generates a warning in line 61: (pre-processed source attached.  Invocation
at the bottom)

art/runtime/class_table.cc:61:38: error: code will never be executed
[-Werror,-Wunreachable-code]
    for (const ClassSet& class_set : classes_) {
                                     ^~~~~~~~
1 error generated. 

This is because kIsDebugBuild, checked in line 60, is a constant set to false. 
However, there is another instance of similar dead code in line 173 that
doesn't trigger -Wunreachable-code.  Reverting r272296 does not trigger the
warning either.

CFGBuilder should be taught to step over the ExprWithCleanup when building CFG
for an If statement.

Clang invocation:
clang++ -cc1 -triple x86_64--linux-gnu -emit-llvm-bc -emit-llvm-uselists
-disable-free -main-file-name class_table.cc -mrelocation-model pic -pic-level
2 -mthread-model posix -mllvm -warn-stack-size=2700 -mdisable-fp-elim
-fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu
x86-64 -momit-leaf-frame-pointer -v -dwarf-column-info -debug-info-kind=limited
-dwarf-version=4 -debugger-tuning=gdb -nostdinc++ -O3 -Wno-multichar -W -Wall
-Wno-unused -Winit-self -Wpointer-arith -Werror=int-conversion
-Wno-reserved-id-macro -Wno-format-pedantic -Wno-unused-command-line-argument
-Wno-expansion-to-defined -Wsign-promo -Wno-inconsistent-missing-override
-Wno-null-dereference -Wthread-safety -Wthread-safety-negative
-Wimplicit-fallthrough -Wfloat-equal -Wint-to-void-pointer-cast
-Wused-but-marked-unused -Wdeprecated -Wunreachable-code-break
-Wunreachable-code-return -Wno-constant-conversion -Wno-undefined-var-template
-Wmissing-noreturn -Wall -Werror -Wextra -Wstrict-aliasing -Wunreachable-code
-Wredundant-decls -Wshadow -Wunused -Werror=int-to-pointer-cast
-Werror=pointer-to-int-cast -Werror=address-of-temporary -Werror=return-type
-std=gnu++14 -fdeprecated-macro  -fdebug-prefix-map=/proc/self/cwd=
-ferror-limit 19 -fmessage-length 0 -fvisibility protected -stack-protector 2
-fno-rtti -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics
-vectorize-loops -vectorize-slp -disable-llvm-passes -o class_table.bc -x
c++-cpp-output class_table.ii</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>