[llvm] 8a1b5f2 - [llvm-ml] Add support for extern proc
Alan Zhao via llvm-commits
llvm-commits at lists.llvm.org
Fri May 13 14:21:05 PDT 2022
Author: Alan Zhao
Date: 2022-05-13T17:20:55-04:00
New Revision: 8a1b5f26808429a157835a8011e6b58fe3361e0f
URL: https://github.com/llvm/llvm-project/commit/8a1b5f26808429a157835a8011e6b58fe3361e0f
DIFF: https://github.com/llvm/llvm-project/commit/8a1b5f26808429a157835a8011e6b58fe3361e0f.diff
LOG: [llvm-ml] Add support for extern proc
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.
Reviewed By: epastor
Differential Revision: https://reviews.llvm.org/D125582
Added:
Modified:
llvm/lib/MC/MCParser/MasmParser.cpp
llvm/test/tools/llvm-ml/extern.asm
llvm/test/tools/llvm-ml/indirect_branch.asm
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp
index da84a91eddd97..0ba1076f20cf1 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -6034,10 +6034,12 @@ bool MasmParser::parseDirectiveExtern() {
SMLoc TypeLoc = getTok().getLoc();
if (parseIdentifier(TypeName))
return Error(TypeLoc, "expected type");
- AsmTypeInfo Type;
- if (lookUpType(TypeName, Type))
- return Error(TypeLoc, "unrecognized type");
- KnownType[Name.lower()] = Type;
+ if (!TypeName.equals_insensitive("proc")) {
+ AsmTypeInfo Type;
+ if (lookUpType(TypeName, Type))
+ return Error(TypeLoc, "unrecognized type");
+ KnownType[Name.lower()] = Type;
+ }
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
Sym->setExternal(true);
diff --git a/llvm/test/tools/llvm-ml/extern.asm b/llvm/test/tools/llvm-ml/extern.asm
index 87cfba48e9488..cec75ad2662ee 100644
--- a/llvm/test/tools/llvm-ml/extern.asm
+++ b/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
diff --git a/llvm/test/tools/llvm-ml/indirect_branch.asm b/llvm/test/tools/llvm-ml/indirect_branch.asm
index 391153b73e993..12c847c47df0e 100644
--- a/llvm/test/tools/llvm-ml/indirect_branch.asm
+++ b/llvm/test/tools/llvm-ml/indirect_branch.asm
@@ -6,6 +6,8 @@ ifdef rax
else
extern fn_ref_extern : dword
endif
+
+extern fn_proc_extern : proc
extern fn_ref_extern_word : word
.data
@@ -248,3 +250,31 @@ else
; 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
+
+t25:
+; CHECK-LABEL: t25:
+ifdef rax
+ call qword ptr [fn_ref_extern]
+ jmp qword ptr [fn_ref_extern]
+ ; CHECK-64: call qword ptr [rip + fn_ref_extern]
+ ; CHECK-64: jmp qword ptr [rip + fn_ref_extern]
+else
+ call dword ptr [fn_ref_extern]
+ jmp dword ptr [fn_ref_extern]
+ ; CHECK-32: call dword ptr [fn_ref_extern]
+ ; CHECK-32: jmp dword ptr [fn_ref_extern]
+endif
+
+end
More information about the llvm-commits
mailing list