Skip to content

llvm lint: "Undefined behavior: Call argument type mismatches callee parameter type" with mixing debug and release #48310

Closed
@matthiaskrgr

Description

@matthiaskrgr
Member

This was reduced from https://github.com/ogham/rust-ansi-term (lib crate) @ 090e0a383d73a43e2f80a7b466e8feeee97c4c76

add this to cargo.toml

[profile.release]
debug=true
opt-level=3

and this as your lib.rs:

use std::fmt;

pub struct Infix(bool, bool);

impl fmt::Display for Infix {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let f: &mut fmt::Write = f;
        write!(f, "")
    }
}

build with

$ RUSTFLAGS="-C passes=lint"  cargo build --release 
   Compiling ansi_term v0.10.2 (file:///tmp/rust-ansi-term)
Undefined behavior: Call argument type mismatches callee parameter type
  %6 = call zeroext i1 bitcast (i1 (%"core::fmt::Formatter"*, %"core::fmt::Arguments"*)* @"_ZN71_$LT$core..fmt..Formatter$LT$$u27$a$GT$$u20$as$u20$core..fmt..Write$GT$9write_fmt17hf4780c35b427924cE" to i1 ({}*, %"core::fmt::Arguments"*)*)({}* nonnull %4, %"core::fmt::Arguments"* noalias nocapture dereferenceable(48) %3), !dbg !119
    Finished release [optimized + debuginfo] target(s) in 0.20 secs

EDIT: meta:

rustc 1.25.0-nightly (58a8e0c27 2018-02-16)
binary: rustc
commit-hash: 58a8e0c27152e9306f8e0cd4fa3a162f5ae8e8c4
commit-date: 2018-02-16
host: x86_64-unknown-linux-gnu
release: 1.25.0-nightly
LLVM version: 6.0

// cc #7463

Activity

added
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
on Feb 19, 2018
matthiaskrgr

matthiaskrgr commented on Apr 27, 2019

@matthiaskrgr
MemberAuthor

Another example from rusts own codebase

trait Foo {
    extern fn borrow(&self);
    extern fn take(self: Box<Self>);
}

struct Bar;
impl Foo for Bar {
    extern fn borrow(&self) {}
    extern fn take(self: Box<Self>) {}
}

fn main() {
    let foo: Box<dyn Foo> = Box::new(Bar);
    foo.borrow();
    foo.take()
}

src/test/run-pass/issues/issue-51907.rs ( when compiled with rustc -C passes=lint -C opt-level=3)

Undefined behavior: Call argument type mismatches callee parameter type
  invoke void bitcast (void (%Bar*)* @"_ZN53_$LT$issue_51907..Bar$u20$as$u20$issue_51907..Foo$GT$6borrow17h4e556b6e6bab9df2E" to void ({}*)*)({}* align 1 %7)
          to label %9 unwind label %19
jonas-schievink

jonas-schievink commented on Apr 27, 2019

@jonas-schievink
Contributor

Nominating to figure out how bad this is. Might be related to #55976.

hanna-kruppe

hanna-kruppe commented on Apr 27, 2019

@hanna-kruppe
Contributor

I believe LLVM's linting is in the wrong here. The purported type mismatch is that the caller passes {}* as first argument but the callee was declared with parameter type %Bar*. But the pointee type doesn't matter [1], all pointers are passed the same, so this call is perfectly ABI-compatible.

[1] slight caveat -- currently it still matters for sret "arguments", because those are not simply passing a pointer but modifying the stack layout based on the size of the pointed-to type, but I don't see that happening here.

pnkfelix

pnkfelix commented on May 2, 2019

@pnkfelix
Member

triage: P-high for two tasks: 1. resolve whether this is indeed an LLVM bug, and if so, 2. filing a bug against LLVM.

removing nomination since I don't think there's much to discuss beyond 1. what's already in @rkruppe's comment and 2. assigning the issue (like any other P-high T-compiler issue) to someone on the compiler team to address.

pnkfelix

pnkfelix commented on Jun 24, 2019

@pnkfelix
Member

This seems like it was resolved between rustc 1.28.0 (9634041 2018-07-30) and rustc 1.29.0 (aa3ca19 2018-09-11)

matthiaskrgr

matthiaskrgr commented on Jun 24, 2019

@matthiaskrgr
MemberAuthor

I can still reproduce with rustc 1.37.0-nightly (929b48ec9 2019-06-21)

pnkfelix

pnkfelix commented on Jun 24, 2019

@pnkfelix
Member

More specifically, it was resolved between rustc 1.29.0-nightly (e5f6498 2018-07-10) and rustc 1.29.0-nightly (64f7de9 2018-07-12)

pnkfelix

pnkfelix commented on Jun 24, 2019

@pnkfelix
Member

@matthiaskrgr hmm, interesting. Are you reproducing via the reduced version from this comment above (which is what I am doing)? Or some other reproduction?

7 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pnkfelix@matthiaskrgr@bstrie@TimNN@jonas-schievink

        Issue actions

          llvm lint: "Undefined behavior: Call argument type mismatches callee parameter type" with mixing debug and release · Issue #48310 · rust-lang/rust