[llvm-bugs] [Bug 46561] New: Clang produces wrong code with -O1 (Combine redundant instructions on function)

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 2 12:17:14 PDT 2020


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

            Bug ID: 46561
           Summary: Clang produces wrong code with -O1 (Combine redundant
                    instructions on function)
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: Vsevolod.Livinskij at frtk.ru
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

opt-bisect limit points to Combine redundant instructions on function

>$ clang++ -w -O1 driver.cpp func.cpp && ./a.out 
42
>$ clang++ -w -O0 driver.cpp func.cpp && ./a.out 
0

Reproducer:
Func.cpp 
extern const bool tf_4_var_4;
extern const int tf_4_var_72;
extern unsigned long long int tf_4_var_124;
extern bool tf_4_array_3;
extern const bool tf_4_ptr_1;

void tf_4_foo() {
    if (~(tf_4_var_72 ? tf_4_ptr_1 * tf_4_array_3 ^ ~tf_4_var_4 : 0))
        tf_4_var_124 = 0;
}

Driver.cpp 
#include <stdio.h>
#include "init.h"

const bool tf_4_var_4 = true;
const int tf_4_var_72 = 2085646722;
unsigned long long int tf_4_var_124 = 42;
bool tf_4_array_3 = false;
const bool tf_4_ptr_1 = true;

extern void tf_4_foo();

int main() {
    tf_4_foo();
    printf("%llu\n", tf_4_var_124);
    return 0;
}

Init.h 
extern const bool tf_4_var_4;
extern const int tf_4_var_72;
extern unsigned long long int tf_4_var_124;
extern bool tf_4_array_3;
extern const bool tf_4_ptr_1;

Clang version:
clang version 11.0.0 (https://github.com/llvm/llvm-project.git
565e37c7702d181804c12d36b6010c513c9b3417)

-- 
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/20200702/88740ee5/attachment.html>


More information about the llvm-bugs mailing list