[LLVMbugs] [Bug 10613] New: calls to old-style functions possibly wrong

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Aug 8 18:00:08 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10613

           Summary: calls to old-style functions possibly wrong
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ahatanak at gmail.com
                CC: llvmbugs at cs.uiuc.edu


clang seems to treat calls to functions defined in the old-style differently
when optimization level is -O0 and -O3: at level -O3, calls to f1 and f2 in
main look identical while at level -O3, the pointer to f2 is being cast to a
function with ellipsis before it is called. This results in generation of
incorrect code for Mips (and possibly for other targets which have different
calling conventions for functions that have a variable argument list and those
that don't).


// oldstl2.c
// adapted from gcc.c-torture/execute/960513-1.c
#include <stdio.h>
#include <stdlib.h>

void __attribute__((noinline)) f1(double f, int i) {
  printf("%f\n", f + i);
}

void __attribute__((noinline)) f2(f, i)
double f; int i; {
  printf("%f\n", f + i);
}

int main(int argc, char** argv) {
  f1(2.0, 1);
  f2(2.0, 1);

  return 0;
}

$ clang oldstl2.c -o oldstl2.ll -emit-llvm -O3 -S
; ModuleID = 'oldstl2.c'
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"

@.str = private unnamed_addr constant [4 x i8] c"%f\0A\00", align 1

define void @f1(double %f, i32 %i) nounwind uwtable noinline {
entry:
  %conv = sitofp i32 %i to double
  %add = fadd double %conv, %f
  %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x
i8]* @.str, i64 0, i64 0), double %add) nounwind
  ret void
}

declare i32 @printf(i8* nocapture, ...) nounwind

define void @f2(double %f, i32 %i) nounwind uwtable noinline {
entry:
  %conv = sitofp i32 %i to double
  %add = fadd double %conv, %f
  %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x
i8]* @.str, i64 0, i64 0), double %add) nounwind
  ret void
}

define i32 @main(i32 %argc, i8** nocapture %argv) nounwind uwtable {
entry:
  tail call void @f1(double 2.000000e+00, i32 1)
  tail call void @f2(double 2.000000e+00, i32 1) nounwind
  ret i32 0
}


$ clang oldstl2.c -o oldstl2.ll -emit-llvm -O0 -S
// definition of f1 and f2 omitted.
define i32 @main(i32 %argc, i8** %argv) nounwind uwtable {
entry:
  %retval = alloca i32, align 4
  %argc.addr = alloca i32, align 4
  %argv.addr = alloca i8**, align 8
  store i32 0, i32* %retval
  store i32 %argc, i32* %argc.addr, align 4
  store i8** %argv, i8*** %argv.addr, align 8
  call void @f1(double 2.000000e+00, i32 1)
  call void (...)* bitcast (void (double, i32)* @f2 to void (...)*)(double
2.000000e+00, i32 1)
  ret i32 0
}

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list