[PATCH] D125582: [llvm-ml] Add support for extern proc
Alan Zhao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 13 13:27:47 PDT 2022
ayzhao created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
ayzhao requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
EXTERN PROC isn't really well documented in MSVC, so after poking around
it seems as if it's just a regular extern symbol.
Interestingly enough, under MSVC the following is allowed:
extern foo:proc
mov eax, foo
MSVC will output:
mov eax, 0
while llvm-ml will currently output:
mov eax, dword ptr [foo]
(since foo is an extern)
Arguably, llvm-ml's output makes more sense, even though it's
inconsistent with MSVC ml. However, since moving an extern proc symbol
to a register doesn't really make sense in the first place, we'll treat
it as undefined behavior for now.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125582
Files:
llvm/lib/MC/MCParser/MasmParser.cpp
llvm/test/tools/llvm-ml/extern.asm
llvm/test/tools/llvm-ml/indirect_branch.asm
Index: llvm/test/tools/llvm-ml/indirect_branch.asm
===================================================================
--- llvm/test/tools/llvm-ml/indirect_branch.asm
+++ llvm/test/tools/llvm-ml/indirect_branch.asm
@@ -6,6 +6,8 @@
else
extern fn_ref_extern : dword
endif
+
+extern fn_proc_extern : proc
extern fn_ref_extern_word : word
.data
@@ -248,3 +250,33 @@
; CHECK-32: call word ptr [fn_ref_extern_word]
; CHECK-32-NEXT: jmp word ptr [fn_ref_extern_word]
endif
+
+t23:
+call fn_proc_extern
+jmp fn_proc_extern
+; CHECK-LABEL: t23:
+; CHECK: call fn_proc_extern
+
+t24:
+call [fn_proc_extern]
+jmp [fn_proc_extern]
+; CHECK-LABEL: t24:
+; CHECK: call fn_proc_extern
+
+ifdef rax
+ t25:
+ call qword ptr [fn_ref_extern]
+ jmp qword ptr [fn_ref_extern]
+ ; CHECK-64-LABEL: t25:
+ ; CHECK-64: call qword ptr [rip + fn_ref_extern]
+ ; CHECK-64: jmp qword ptr [rip + fn_ref_extern]
+else
+ t25:
+ call dword ptr [fn_ref_extern]
+ jmp dword ptr [fn_ref_extern]
+ ; CHECK-32-LABEL: t25:
+ ; CHECK-32: call dword ptr [fn_ref_extern]
+ ; CHECK-32: jmp dword ptr [fn_ref_extern]
+endif
+
+end
Index: llvm/test/tools/llvm-ml/extern.asm
===================================================================
--- llvm/test/tools/llvm-ml/extern.asm
+++ llvm/test/tools/llvm-ml/extern.asm
@@ -1,9 +1,10 @@
; RUN: llvm-ml -m32 -filetype=s %s /Fo - | FileCheck %s --check-prefixes=CHECK,CHECK-32
; RUN: llvm-ml -m64 -filetype=s %s /Fo - | FileCheck %s --check-prefixes=CHECK,CHECK-64
-extern foo : dword, bar : word
+extern foo : dword, bar : word, baz : proc
; CHECK: .extern foo
; CHECK: .extern bar
+; CHECK: .extern baz
.code
mov ebx, foo
Index: llvm/lib/MC/MCParser/MasmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/MasmParser.cpp
+++ llvm/lib/MC/MCParser/MasmParser.cpp
@@ -6035,9 +6035,10 @@
if (parseIdentifier(TypeName))
return Error(TypeLoc, "expected type");
AsmTypeInfo Type;
- if (lookUpType(TypeName, Type))
+ if (!lookUpType(TypeName, Type))
+ KnownType[Name.lower()] = Type;
+ else if (!TypeName.equals_insensitive("proc"))
return Error(TypeLoc, "unrecognized type");
- KnownType[Name.lower()] = Type;
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
Sym->setExternal(true);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125582.429342.patch
Type: text/x-patch
Size: 2330 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220513/650fa0ef/attachment.bin>
More information about the llvm-commits
mailing list