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

            Bug ID: 49599
           Summary: Signed integer overflow causes program to skip the
                    epilogue and fall into another function
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

Comment:

Clang 13 simply does not generate any code for f1 after the undefined behavior
point. So any call onto f1 will eventually ends up fell into f2.

Although the compiler can do anything with an undefined behavior, including
simply crashing, infinite loop, playing some music, or nuke the earth without
violating the C++ specification. I still hope this undefined behavior won't be
that surprising.

This issue is not observed in C frontend, or Clang 12.


Godbolt link for your convenience: https://godbolt.org/z/r3nWrE


Source code:

#include <stdio.h>

void f1(void) {
    for(int i = 0; i >= 0; i++) {
        // Undefined behavior
    }
}

void f2(void) {
    puts("Formatting /dev/sda1...");
    // system("mkfs -t btrfs -f /dev/sda1");
}

// Prevents inlining
void (*volatile p1)(void) = f1;
void (*volatile p2)(void) = f2;

int main(void) {
    puts(__VERSION__);
    p1();
    return 0;
}


Output:

Clang 13.0.0 (https://github.com/llvm/llvm-project.git
fcdf7f6224610a51dc2ff47f2f1e3377329b64a7)
Formatting /dev/sda1...

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to