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

ret-bang variant trips llvm assert "Invalid constantexpr cast!" #777

Closed
jruderman opened this issue Jul 29, 2011 · 4 comments
Closed

ret-bang variant trips llvm assert "Invalid constantexpr cast!" #777

jruderman opened this issue Jul 29, 2011 · 4 comments

Comments

@jruderman
Copy link
Contributor

fn my_err(s: str) -> ! { log_err s; fail; }
fn main() { my_err("bye") == 3u; }

Assertion failed: (CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"), function getCast, file Constants.cpp, line 1217.

@jruderman
Copy link
Contributor Author

Switch the operands around and we get a different error message:

fn my_err(s: str) -> ! { log_err s; fail; }
fn main() { 3u == my_err("bye"); }

Assertion failed: (getOperand(0)->getType() == getOperand(1)->getType() && "Both operands to ICmp instruction are not of the same type!"), function ICmpInst, file /Users/jruderman/code/llvm/include/llvm/Instructions.h, line 643.

@ghost ghost assigned catamorphism Jul 29, 2011
@jruderman
Copy link
Contributor Author

Here's a version that uses early-ret instead of bang:

fn wsucc(n: int) -> int {
    { ret n + 1 } == 0;
}
fn main() {}

It's interesting that if I replace "==" with "+" I get "error: binary operation + cannot be applied to type _|_". Why is that the case for "+" but not for "=="?

@catamorphism
Copy link
Contributor

"error: binary operation + cannot be applied to type _|_" is a typechecker bug -- values of type _|_ are usable in any context. I'll look into that too.

@catamorphism
Copy link
Contributor

The first two programs enjoyed different results because trans was assuming both sides of the == had the same type, and was choosing what to do based on the RHS type.

If it chooses _|_, then we see the first error message (about the bad cast) because it was falling into cmp glue, since _|_ is not a scalar type.

If it chooses uint, then we see the second error message, because it tries to generate an unsigned int comparison but my_err has the wrong return type.

So far as I can tell, the correct thing to do is to just not generate code for the comparison if one operand is divergently typed. I have a fix which I'm about to check in.

Next I'll look at the early-ret version.

keeperofdakeys pushed a commit to keeperofdakeys/rust that referenced this issue Dec 12, 2017
Add clock_gettime related functions to macOS

Fixes rust-lang/libc#776. The constants were retrieved on macOS 10.12.6. Tried adding `clock_nanosleep` too, but it doesn't seem like macOS' libc includes that yet.
pdietl pushed a commit to pdietl/rust that referenced this issue Apr 23, 2020
…ransition

Update rustc-guide to rustc-dev-guide
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants