LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 22060 - MC generated wrong code for label arithmetic
Summary: MC generated wrong code for label arithmetic
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: MC (show other bugs)
Version: trunk
Hardware: PC Windows NT
: P release blocker
Assignee: David Majnemer
URL:
Keywords:
Depends on:
Blocks: 22374
  Show dependency tree
 
Reported: 2014-12-30 02:27 PST by hume
Modified: 2015-02-09 00:31 PST (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments
the sample (932 bytes, text/plain)
2014-12-30 02:27 PST, hume
Details

Note You need to log in before you can comment on or make changes to this bug.
Description hume 2014-12-30 02:27:39 PST
Created attachment 13606 [details]
the sample

see aa.s in attachment, then

llvm-mc -arch=x86 -triple=pc-windows-msvc -filetype=obj aa.s -o aa.obj

we disassemble the aa.obj and can found following 

	calll	L18$pb
L18$pb:
	popl	%eax
	leal	"?WndProc@@YGJPAUHWND__@@IIJ@Z"-L18$pb(%eax), %eax
	movl	24(%ebp), %ecx
	movl	20(%ebp), %edx
	movl	16(%ebp), %esi
	movl	12(%ebp), %edi
	movl	8(%ebp), %ebx
	movl	%eax, 76(%esp)          # 4-byte Spill
  retl

	.def	 "?WndProc@@YGJPAUHWND__@@IIJ@Z";
	.scl	2;
	.type	32;
	.endef
	.globl	"?WndProc@@YGJPAUHWND__@@IIJ@Z"
"?WndProc@@YGJPAUHWND__@@IIJ@Z":        # @"\01?WndProc@@YGJPAUHWND__@@IIJ@Z"
# BB#0:
	pushl	%ebp
	movl	%esp, %ebp
  retl

is assembled to 

.text:00000000                 public ?SetUpWindow@@YAPAUHWND__@@PBD0HHPAUHINSTANCE__@@@Z
.text:00000000 ?SetUpWindow@@YAPAUHWND__@@PBD0HHPAUHINSTANCE__@@@Z proc near
.text:00000000
.text:00000000 arg_0           = dword ptr  8
.text:00000000 arg_4           = dword ptr  0Ch
.text:00000000 arg_8           = dword ptr  10h
.text:00000000 arg_C           = dword ptr  14h
.text:00000000 arg_10          = dword ptr  18h
.text:00000000
.text:00000000                 push    ebp
.text:00000001                 mov     ebp, esp
.text:00000003
.text:00000003 loc_3:
.text:00000003                 push    ebx
.text:00000004                 push    edi
.text:00000005                 push    esi
.text:00000006                 and     esp, 0FFFFFFF8h
.text:00000009                 sub     esp, 80h
.text:0000000F                 call    $+5
.text:00000014                 pop     eax
.text:00000015
.text:00000015 loc_15:
.text:00000015                 lea     eax, [eax+3]
.text:0000001B                 mov     ecx, [ebp+arg_10]
.text:0000001E                 mov     edx, [ebp+arg_C]
.text:00000021                 mov     esi, [ebp+arg_8]
.text:00000024                 mov     edi, [ebp+arg_4]
.text:00000027                 mov     ebx, [ebp+arg_0]
.text:0000002A                 mov     [esp+4Ch], eax
.text:0000002E                 retn
.text:0000002E ?SetUpWindow@@YAPAUHWND__@@PBD0HHPAUHINSTANCE__@@@Z endp ; sp-analysis failed


.text:00000015                 lea     eax, [eax+3] 

obviuosly it is not the right code for:

leal	"?WndProc@@YGJPAUHWND__@@IIJ@Z"-L18$pb(%eax), %eax
Comment 1 Hans Wennborg 2015-02-06 15:35:24 PST
Confirmed that this is a regression from 3.5 to 3.6 (and trunk).

objdump diff from 3.5 to 3.6:

@@ -14,7 +14,7 @@
    9:	81 ec 80 00 00 00    	sub    $0x80,%esp
    f:	e8 00 00 00 00       	call   14 <?SetUpWindow@@YAPAUHWND__@@PBD0HHPAUHINSTANCE__@@@Z+0x14>
   14:	58                   	pop    %eax
-  15:	8d 80 1b 00 00 00    	lea    0x1b(%eax),%eax
+  15:	8d 80 03 00 00 00    	lea    0x3(%eax),%eax
   1b:	8b 4d 18             	mov    0x18(%ebp),%ecx
   1e:	8b 55 14             	mov    0x14(%ebp),%edx
   21:	8b 75 10             	mov    0x10(%ebp),%esi

That certainly looks like a real problem.
Comment 2 Hans Wennborg 2015-02-06 16:18:46 PST
Bisection points to r221678.

David, can you take a look?
Comment 3 David Majnemer 2015-02-06 19:22:30 PST
Hi,

Can I please get some IR? I'm a little confused as to how we could generate this assembly.
Comment 4 David Majnemer 2015-02-09 00:31:56 PST
Fixed in r228565.