Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM assembler incorrectly folds comparison #1730

Closed
llvmbot opened this issue Apr 25, 2007 · 4 comments
Closed

LLVM assembler incorrectly folds comparison #1730

llvmbot opened this issue Apr 25, 2007 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla llvm:asmparser miscompilation

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 25, 2007

Bugzilla Link 1358
Resolution FIXED
Resolved on Feb 22, 2010 12:53
Version 1.9
OS Linux
Reporter LLVM Bugzilla Contributor

Extended Description

LLVM is considering that the if is always true.

test:
extern int test_weak () attribute ((weak));

int main(){
int (*t)() = test_weak;
if (t)
return t();
else return 250;
}

llc emits:
.text
.align 16
.globl main
.type main,@function
main:
subl $4, %esp
fnstcw 2(%esp)
movb $2, 3(%esp)
fldcw 2(%esp)
.LBB1_1: #cond_true
call test_weak
addl $4, %esp
ret
.size main, .-main
.weak test_weak

gcc emits:
.file "teste.c"
.text
.p2align 4,,15
.globl main
.type main, @​function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
movl $test_weak, %eax
movl $250, %edx
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $4, %esp
testl %eax, %eax
je .L4
call test_weak
movl %eax, %edx
.L4:
addl $4, %esp
movl %edx, %eax
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.weak test_weak
.ident "GCC: (GNU) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)"
.section .note.GNU-stack,"",@progbits

@llvmbot
Copy link
Collaborator Author

llvmbot commented Apr 25, 2007

assigned to @lattner

@lattner
Copy link
Collaborator

lattner commented Apr 26, 2007

This doesn't happen for me. I get:

$ llvm-gcc t.c -o - -S -O3
...
cmpl $0, L_test_weak$non_lazy_ptr-"L1$pb"(%eax)
je LBB1_2 #UnifiedReturnBlock
LBB1_1: #cond_true

What options are you compiling with?

-Chris

@lattner
Copy link
Collaborator

lattner commented Apr 26, 2007

actually, I'm seeing it now, with llc.

@lattner
Copy link
Collaborator

lattner commented Apr 26, 2007

Fixed, testcase here: test/Assembler/2007-04-25-AssemblerFoldExternWeak.ll

Patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070423/048483.html

-Chris

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
kitano-metro pushed a commit to RIKEN-RCCS/llvm-project that referenced this issue Feb 14, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm:asmparser miscompilation
Projects
None yet
Development

No branches or pull requests

2 participants