New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 19405 - Invalid optimization with -fPIC
Summary: Invalid optimization with -fPIC
Status: NEW
Alias: None
Product: libraries
Classification: Unclassified
Component: Interprocedural Optimizations (show other bugs)
Version: 3.3
Hardware: PC Linux
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-11 15:38 PDT by Jan Hubicka
Modified: 2014-09-17 03:27 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Hubicka 2014-04-11 15:38:24 PDT
#include "stdio.h"
int
b(void)
{
  return 1;
}

int a(int (*b)(void))
{
  return b();
}

m()
{
  int i;
  for (i=0; i<1000000;i++)
   i+=a(b);
  printf ("%i\n",i);
  c();
}

With -O2 -fPIC is compiled as (on Linux):
m:                                      # @m
        .cfi_startproc
# BB#0:
        pushq   %rax
.Ltmp3:
        .cfi_def_cfa_offset 16
        leaq    .L.str(%rip), %rdi
        movl    $1000000, %esi          # imm = 0xF4240
        xorb    %al, %al
        callq   printf@PLT
        xorb    %al, %al
        popq    %rdx
        jmp     c@PLT                   # TAILCALL
.Ltmp4:

This is not valid, since ELF interpositionallows you to replace a by different function returning different value.