<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clang -emit-llvm produces illegal output (not accepted by opt)"
   href="https://bugs.llvm.org/show_bug.cgi?id=35609">35609</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang -emit-llvm produces illegal output (not accepted by opt)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>post+llvm@ralfj.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>## Steps to reproduce:

Compile the following program with `clang -emit-llvm`:

```
void test(void (*f)()) {
}
```

Try to run the resulting IR through `opt`.

## Expected behavior:

`opt` should accept the IR generated by clang.

## Actual behavior:

`opt` rejects the IR as being invalid:
```
opt-6.0: cpp-6.ll:6:25: error: expected type
define void @test(void (*)())(void ()*) #0 !dbg !7 {
                        ^
```

For reference, the IR is
```
; ModuleID =
'/tmp/compiler-explorer-compiler1171110-53-upsl4.lwnj7/example.cpp'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: noinline nounwind optnone uwtable
define void @test(void (*)())(void ()*) #0 !dbg !7 {
  %2 = alloca void ()*, align 8
  store void ()* %0, void ()** %2, align 8
  call void @llvm.dbg.declare(metadata void ()** %2, metadata !13, metadata
!DIExpression()), !dbg !14
  ret void, !dbg !15
}

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1

attributes #0 = { noinline nounwind optnone uwtable
"correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false"
"less-precise-fpmad"="false" "no-frame-pointer-elim"="true"
"no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false"
"no-jump-tables"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
"stack-protector-buffer-size"="8" "target-cpu"="x86-64"
"target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #1 = { nounwind readnone speculatable }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer:
"clang version 6.0.0 (trunk 320285)", isOptimized: false, runtimeVersion: 0,
emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename:
"/tmp/compiler-explorer-compiler1171110-53-upsl4.lwnj7/example.cpp", directory:
"/compiler-explorer")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"clang version 6.0.0 (trunk 320285)"}
!7 = distinct !DISubprogram(name: "test", linkageName: "test(void (*)())",
scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true,
scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables:
!2)
!8 = !DISubroutineType(types: !9)
!9 = !{null, !10}
!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
!11 = !DISubroutineType(types: !12)
!12 = !{null}
!13 = !DILocalVariable(name: "f", arg: 1, scope: !7, file: !1, line: 1, type:
!10)
!14 = !DILocation(line: 1, column: 18, scope: !7)
!15 = !DILocation(line: 2, column: 1, scope: !7)
```</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>