Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if statements not cleanly short-circuiting on Apple Silicon with optimizations #60695

Closed
mckib2 opened this issue Feb 12, 2023 · 2 comments
Closed
Labels
invalid Resolved as invalid, i.e. not a bug llvm:optimizations

Comments

@mckib2
Copy link

mckib2 commented Feb 12, 2023

Overflows are reported for -O2 and -O3 due to evaluation of unsafe calculations in if-statements that should have been guarded by a previous condition short-circuiting. We only observe this on certain versions of MacOS, e.g., Monterrey 12.6.

Reproducer:

// main.cpp
#include <iostream>
#include <limits>
#include <cfenv>

int main(int argc, char** argv) {
    if (argc != 2) {
        return 1;
    }
    const double x = std::atof(argv[1]);
    double f1 = std::numeric_limits<double>::max();
    double res;
    if((x < 1) && (std::numeric_limits<double>::max() * x < f1)) {
        std::cout << "if branch\n";
    } else {
        std::cout << "else branch\n";
    }

    if(std::fetestexcept(FE_OVERFLOW)) {
        std::cout << "overflow reported\n";
    } else {
        std::cout << "overflow not reported\n";
    }

    return 0;
}

// output:
//     else branch
//     overflow reported

Build:

clang++ -g -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk -O2 -std=gnu++14 main.cpp

Run:

./a.out 42.0

Version information:

% clang++ --version
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
@fhahn
Copy link
Contributor

fhahn commented Feb 13, 2023

I am unable to reproduce this with upstream clang. To report issue's with Apple Clang, please use https://feedbackassistant.apple.com/.

I am going to close this issue for now. If this reproduces with upstream Clang, please share updated instructions and I'll re-open the issue.

@fhahn fhahn closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2023
@EugeneZelenko EugeneZelenko added the invalid Resolved as invalid, i.e. not a bug label Feb 13, 2023
@mckib2
Copy link
Author

mckib2 commented Feb 15, 2023

I wouldn't have expected to see it with upstream -- this has been notoriously hard for us to get reproducible environments ourselves. I will try submitting to apple, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Resolved as invalid, i.e. not a bug llvm:optimizations
Projects
None yet
Development

No branches or pull requests

3 participants