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

LLVM assert with boolean negation in unreachable code #7344

Closed
bytwise opened this issue Jun 24, 2013 · 1 comment
Closed

LLVM assert with boolean negation in unreachable code #7344

bytwise opened this issue Jun 24, 2013 · 1 comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@bytwise
Copy link
Contributor

bytwise commented Jun 24, 2013

In the latest master the following code

fn foo() -> bool { false }
fn main() {
    return;
    !foo();
}

produces

rustc: /build/rust-git/src/rust/src/llvm/include/llvm/Support/Casting.h:231: typename llvm::enable_if<llvm::is_same<Y, typename llvm::simplify_type<From>::SimpleType>, typename llvm::cast_retty<X, Y*>::ret_type>::type llvm::cast(Y*) [with X = llvm::SequentialType; Y = llvm::Type; typename llvm::enable_if<llvm::is_same<Y, typename llvm::simplify_type<From>::SimpleType>, typename llvm::cast_retty<X, Y*>::ret_type>::type = llvm::SequentialType*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

The failure still happens if you replace foo() by any expression which returns bool. But as soon as you remove the ! it compiles just fine.

@huonw
Copy link
Member

huonw commented Jul 16, 2013

Possibly the same issue (at least, it gives the same assertion):

fn main() {
    let x = "foo";
    return;
    if x == "foo" {}
}

It doesn't happen if x is a primitive type like int or float.

This appears to be a crash in the depths of trans_to_datum... I'm having a look at it now, but I probably won't make much progress. Backtrace for the code in the issue:

#0  0x00007ffff37b11e5 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff37b4398 in __GI_abort () at abort.c:90
#2  0x00007ffff37aa272 in __assert_fail_base (fmt=0x7ffff38e7900 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x7ffff4ee2d40 "isa<X>(Val) && \"cast<Ty>() argument of incompatible type!\"", file=file@entry=0x7ffff4ee2ce0 "/home/huon/rust/src/llvm/include/llvm/Support/Casting.h", line=line@entry=231, function=function@entry=0x7ffff54839a0 <_ZZN4llvm4castINS_14SequentialTypeENS_4TypeEEENS_9enable_ifINS_7is_sameIT0_NS_13simplify_typeIS5_E10SimpleTypeEEENS_10cast_rettyIT_PS5_E8ret_typeEE4typeESC_E19__PRETTY_FUNCTION__> "typename llvm::enable_if<llvm::is_same<Y, typename llvm::simplify_type<From>::SimpleType>, typename llvm::cast_retty<X, Y*>::ret_type>::type llvm::cast(Y*) [with X = llvm::SequentialType; Y = llvm::Ty"...) at assert.c:92
#3  0x00007ffff37aa322 in __GI___assert_fail (assertion=0x7ffff4ee2d40 "isa<X>(Val) && \"cast<Ty>() argument of incompatible type!\"", file=0x7ffff4ee2ce0 "/home/huon/rust/src/llvm/include/llvm/Support/Casting.h", line=231, function=0x7ffff54839a0 <_ZZN4llvm4castINS_14SequentialTypeENS_4TypeEEENS_9enable_ifINS_7is_sameIT0_NS_13simplify_typeIS5_E10SimpleTypeEEENS_10cast_rettyIT_PS5_E8ret_typeEE4typeESC_E19__PRETTY_FUNCTION__> "typename llvm::enable_if<llvm::is_same<Y, typename llvm::simplify_type<From>::SimpleType>, typename llvm::cast_retty<X, Y*>::ret_type>::type llvm::cast(Y*) [with X = llvm::SequentialType; Y = llvm::Ty"...) at assert.c:101
#4  0x00007ffff4daee84 in LLVMGetElementType () from /usr/local/bin/../lib/librustllvm.so
#5  0x00007ffff61046f5 in middle::trans::build::LoadRangeAssert::_55594db7263cd047::_0$x2e8$x2dpre () from /usr/local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#6  0x00007ffff6104516 in middle::trans::datum::__extensions__::meth_26894::to_value_llval::_7eff40c77bdb254::_0$x2e8$x2dpre () from /usr/local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#7  0x00007ffff61043ad in middle::trans::datum::__extensions__::meth_26891::to_value_datum::_7fae9ce1f4e115c3::_0$x2e8$x2dpre () from /usr/local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#8  0x00007ffff6105199 in middle::trans::datum::__extensions__::meth_26908::to_appropriate_datum::_7fae9ce1f4e115c3::_0$x2e8$x2dpre () from /usr/local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#9  0x00007ffff613c4c7 in middle::trans::expr::trans_to_datum_unadjusted::_4ecb3fec4142e0c1::_0$x2e8$x2dpre () from /usr/local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#10 0x00007ffff60dae2f in middle::trans::expr::trans_to_datum::_4ecb3fec4142e0c1::_0$x2e8$x2dpre () from /usr/local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#11 0x00007ffff614bd7b in middle::trans::expr::trans_unary_datum::_3071da634f922af2::_0$x2e8$x2dpre () from /usr/local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so
#12 0x00007ffff6143b0b in middle::trans::expr::trans_rvalue_datum_unadjusted::_4ecb3fec4142e0c1::_0$x2e8$x2dpre () from /usr/local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.8-pre.so

@huonw huonw closed this as completed in e252277 Jul 16, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 21, 2022
Ensure new_ret_no_self is not fired if impl Trait<Self> is returned.

Fix rust-lang#7344: ensure new_ret_no_self is not fired if `impl Trait<Self>` is returned.

changelog: [`new_ret_no_self`]: No longer lints when `impl Trait<Self>` is returned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

2 participants