Save a few spurious clang warnings in the generated code

65 views
Skip to first unread message

Antony Lee

unread,
Feb 8, 2016, 3:56:14 AM2/8/16
to cython...@googlegroups.com
Compiling the following code

#cython: boundscheck=False
def main(double[:, ::1] x):
    return x[0]

with clang generates a bunch of warnings.  A few of them can be trivially avoided by marking a branch as knowingly dead:

testmod.c:1356:15: warning: code will never be executed [-Wunreachable-code]
    if (0 && (__pyx_tmp_idx < 0 || __pyx_tmp_idx >= __pyx_tmp_shape)) {
              ^~~~~~~~~~~~~
testmod.c:1356:9: note: silence by adding parentheses to mark code as explicitly dead
    if (0 && (__pyx_tmp_idx < 0 || __pyx_tmp_idx >= __pyx_tmp_shape)) {
        ^
        /* DISABLES CODE */ ( )

(i.e., write "if ((0) && ...)" instead of "if (0 &&)")

This heuristic was introduced in clang at this commit: http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20140324/102207.html

Antony
Reply all
Reply to author
Forward
0 new messages