[LLParser][OpaquePtr] Support forward reference to unnamed function
authorNikita Popov <npopov@redhat.com>
Thu, 10 Feb 2022 11:20:34 +0000 (12:20 +0100)
committerNikita Popov <npopov@redhat.com>
Thu, 10 Feb 2022 11:20:34 +0000 (12:20 +0100)
With opaque pointers, we always create forward references as i8
globals, so it will not be Function here.

llvm/lib/AsmParser/LLParser.cpp
llvm/test/Assembler/opaque-ptr.ll

index 432ec15..4281193 100644 (file)
@@ -5631,7 +5631,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) {
     // types agree.
     auto I = ForwardRefValIDs.find(NumberedVals.size());
     if (I != ForwardRefValIDs.end()) {
-      FwdFn = cast<Function>(I->second.first);
+      FwdFn = I->second.first;
       if (!FwdFn->getType()->isOpaque() && FwdFn->getType() != PFT)
         return error(NameLoc, "type of definition and forward reference of '@" +
                                   Twine(NumberedVals.size()) +
index ad292f8..c4171fa 100644 (file)
@@ -149,3 +149,15 @@ cleanup:
 define void @byval(ptr byval({ i32, i32 }) %0) {
   ret void
 }
+
+; CHECK: define void @call_unnamed_fn() {
+; CHECK:  call void @0()
+define void @call_unnamed_fn() {
+  call void @0()
+  ret void
+}
+
+; CHECK: define void @0() {
+define void @0() {
+  ret void
+}