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 assertion from pointer arithmetic on i686-pc-windows-gnu #66315

Closed
matthewjasper opened this issue Nov 11, 2019 · 2 comments · Fixed by #66318
Closed

LLVM assertion from pointer arithmetic on i686-pc-windows-gnu #66315

matthewjasper opened this issue Nov 11, 2019 · 2 comments · Fixed by #66318
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-windows-gnu Toolchain: GNU, Operating system: Windows O-x86_32 Target: x86 processors, 32 bit (like i686-*)

Comments

@matthewjasper
Copy link
Contributor

The following code, when compiled with opt level of 2 or higher results in an llvm assertion (if they're enabled) on i686-pc-windows-gnu.

#![crate_type="lib"]

pub fn check_overlap(ext: &i32) -> usize {
    let src_usize = &1 as *const _ as usize;
    let dst_usize = ext as *const _ as usize;
    let mut diff = src_usize.wrapping_sub(dst_usize);
    if src_usize > dst_usize {
        diff = diff.wrapping_neg();
    };

    diff
}
llc backtrace when compiling the --emit llvm-ir output
llc: ./src/llvm-project/llvm/include/llvm/CodeGen/MachineOperand.h:527: int64_t llvm::MachineOperand::getImm() const: Assertion `isImm() && "Wrong MachineOperand accessor"' failed.
Stack dump:
0.	Program arguments: ./build/x86_64-unknown-linux-gnu/llvm/bin/llc -O1 /media/matthew/Data1/Matthew/dev/proc-macro2/lib.ll -o - 
1.	Running pass 'Function Pass Manager' on module '/media/matthew/Data1/Matthew/dev/proc-macro2/lib.ll'.
2.	Running pass 'Two-Address instruction pass' on function '@check_overlap'
 #0 0x00007f4aaa65a2de llvm::sys::PrintStackTrace(llvm::raw_ostream&) (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0xa5f2de)
 #1 0x00007f4aaa6580f4 llvm::sys::RunSignalHandlers() (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0xa5d0f4)
 #2 0x00007f4aaa658275 SignalHandler(int) (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0xa5d275)
 #3 0x00007f4aa9845470 (/lib/x86_64-linux-gnu/libc.so.6+0x46470)
 #4 0x00007f4aa98453eb raise /build/glibc-4WA41p/glibc-2.30/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f4aa9824899 abort /build/glibc-4WA41p/glibc-2.30/stdlib/abort.c:81:7
 #6 0x00007f4aa9824769 get_sysdep_segment_value /build/glibc-4WA41p/glibc-2.30/intl/loadmsgcat.c:509:8
 #7 0x00007f4aa9824769 _nl_load_domain /build/glibc-4WA41p/glibc-2.30/intl/loadmsgcat.c:970:34
 #8 0x00007f4aa9836006 (/lib/x86_64-linux-gnu/libc.so.6+0x37006)
 #9 0x00007f4aaccc4c86 llvm::X86InstrInfo::convertToThreeAddress(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::MachineBasicBlock, true, false, void>, false, false>&, llvm::MachineInstr&, llvm::LiveVariables*) const (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0x30c9c86)
#10 0x00007f4aaac50916 (anonymous namespace)::TwoAddressInstructionPass::convertInstTo3Addr(llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&, unsigned int, unsigned int, unsigned int) (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0x1055916)
#11 0x00007f4aaac527e8 (anonymous namespace)::TwoAddressInstructionPass::tryInstructionTransform(llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&, unsigned int, unsigned int, unsigned int, bool) (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0x10577e8)
#12 0x00007f4aaac57155 (anonymous namespace)::TwoAddressInstructionPass::runOnMachineFunction(llvm::MachineFunction&) (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0x105c155)
#13 0x00007f4aaaa04459 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0xe09459)
#14 0x00007f4aaa7a5688 llvm::FPPassManager::runOnFunction(llvm::Function&) (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0xbaa688)
#15 0x00007f4aaa7a57c1 llvm::FPPassManager::runOnModule(llvm::Module&) (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0xbaa7c1)
#16 0x00007f4aaa7a4a19 llvm::legacy::PassManagerImpl::run(llvm::Module&) (./build/x86_64-unknown-linux-gnu/llvm/bin/../lib/libLLVM-9-rust-1.40.0-dev-14a3b1230.so+0xba9a19)
#17 0x00005577274b31ec compileModule(char**, llvm::LLVMContext&) (./build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x1e1ec)
#18 0x00005577274a4dfa main (./build/x86_64-unknown-linux-gnu/llvm/bin/llc+0xfdfa)
#19 0x00007f4aa98261e3 __libc_start_main /build/glibc-4WA41p/glibc-2.30/csu/../csu/libc-start.c:342:3
#20 0x00005577274a4f4e _start (./build/x86_64-unknown-linux-gnu/llvm/bin/llc+0xff4e)
Aborted (core dumped)
@matthewjasper matthewjasper added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-x86 O-windows-gnu Toolchain: GNU, Operating system: Windows labels Nov 11, 2019
@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Nov 11, 2019
@mati865
Copy link
Contributor

mati865 commented Nov 11, 2019

I don't think it's windows-gnu specific: https://bugs.llvm.org/show_bug.cgi?id=43529
I'll try to backport the fix.

@mati865
Copy link
Contributor

mati865 commented Nov 11, 2019

Opened #66318 which waits for bors try (I don't have permission).

@bors bors closed this as completed in 5dda3ee Nov 12, 2019
@Noratrieb Noratrieb added O-x86_32 Target: x86 processors, 32 bit (like i686-*) and removed O-x86-all labels Oct 25, 2023
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. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-windows-gnu Toolchain: GNU, Operating system: Windows O-x86_32 Target: x86 processors, 32 bit (like i686-*)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants