Skip to content

Binding non-alias arguments with type parameters fails in llvm #375

Description

@brson

make stage2/std.o CFG_DISABLE_OPTIMIZE=1 results in the following:

Instruction does not dominate all uses!
  %20 = load %tydesc** %19
  store %tydesc* %20, %tydesc** %7
Broken module found, compilation aborted!
Stack dump:
0.      Running pass 'Function Pass Manager' on module 'rust_out'.
1.      Running pass 'Module Verifier' on function '@_rust_thunk1273_deque_create_grow'
Aborted

The following test cases reproduces:

fn grow[T](vec[T] elts) {
  auto copy_op = bind grow[T](elts);
}

fn main() {
}

And fails with the following:

Instruction does not dominate all uses!
  %19 = load %tydesc** %18
  store %tydesc* %19, %tydesc** %6
Broken module found, compilation aborted!
Stack dump:
0.      Running pass 'Function Pass Manager' on module 'rust_out'.
1.      Running pass 'Module Verifier' on function '@_rust_thunk17_grow'
Aborted

The code generated for the thunk in the test case looks like:

define internal fastcc void @_rust_thunk17_grow(i1*, %task*, %10*) {
allocas:
  %3 = alloca [1 x %tydesc*]
  %4 = alloca %tydesc
  %5 = alloca %13*
  br label %copy_args

copy_args:                                        ; preds = %allocas                                                                              
  br label %derived_tydescs

derived_tydescs:                                  ; preds = %copy_args                                                                            
  %6 = getelementptr [1 x %tydesc*]* %3, i32 0, i32 0
  store %tydesc* %19, %tydesc** %6
  %7 = load %tydesc* @_rust_tydesc11_grow
  store %tydesc %7, %tydesc* %4
  %8 = getelementptr %tydesc* %4, i32 0, i32 0
  %9 = getelementptr [1 x %tydesc*]* %3, i32 0, i32 0
  %10 = getelementptr %tydesc* %4, i32 0, i32 0
  store %tydesc** %9, %tydesc*** %10
  %11 = getelementptr %tydesc* %4, i32 0, i32 1
  store i32 ptrtoint (i1** getelementptr (i1** null, i32 1) to i32), i32* %11
  %12 = getelementptr %tydesc* %4, i32 0, i32 2
  store i32 ptrtoint (i1** getelementptr (%15* null, i64 0, i32 1) to i32), i32* %12
  br label %13

; <label>:13                                      ; preds = %derived_tydescs                                                                      
  %14 = bitcast %10* %2 to %20*
  %15 = getelementptr %20* %14, i32 0, i32 1, i32 1
  %16 = getelementptr %22* %15, i32 0, i32 1
  %17 = load %10** %16
  %18 = getelementptr %20* %14, i32 0, i32 1, i32 3, i32 0
  %19 = load %tydesc** %18
  %20 = getelementptr %20* %14, i32 0, i32 1, i32 2, i32 0
  %21 = load %13** %20
  store %13* %21, %13** %5
  %22 = bitcast %13** %5 to i8*
  %23 = getelementptr %tydesc* %4, i32 0, i32 0
  %24 = load %tydesc*** %23
  %25 = getelementptr %tydesc* %4, i32 0, i32 3
  %26 = load void (i1*, %task*, i1*, %tydesc**, i8*)** %25
  call fastcc void %26(i1* null, %task* %1, i1* null, %tydesc** %24, i8* %22)
  %27 = getelementptr %22* %15, i32 0, i32 0
  %28 = bitcast void (i1*, %task*, %10*, %13*)** %27 to void (i1*, %task*, %10*, %tydesc*, %13*)**
  %29 = load void (i1*, %task*, %10*, %tydesc*, %13*)** %28
  call fastcc void %29(i1* %0, %task* %1, %10* %17, %tydesc* %19, %13* %21)
  ret void
}

Note that this only happens when generating unoptimized code - the verifier runs after the optimizer, which seems to hide problems in code generation.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions