[LLVMbugs] [Bug 12162] New: va_start() is mishandled on Windows

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Mar 2 07:03:50 PST 2012


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

             Bug #: 12162
           Summary: va_start() is mishandled on Windows
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: timurrrr at google.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


$ more va_args.c   # Reproducer
#include <stdarg.h>
#include <stdio.h>

void foo(int A, ...) {
  int B;
  va_list L;
  va_start(L, A);
  B = va_arg(L, int);
  printf("foo(%d, %d)\n", A, B);
  va_end(L);
}

int main(void) { foo(1, 2); }

$ cl /nologo va_args.c && va_args.exe  # Expected result
foo(1, 2)

$ clang.exe --version
clang version 3.1 (trunk 150957)
Target: i686-pc-win32
Thread model: posix

$ clang.exe va_args.c && ./a.out  # Actual result
foo(1, 1638208)

$ clang.exe va_args.c -S -emit-llvm

$ more va_args.s
...
define void @foo(i32 %A, ...) nounwind {
  %1 = alloca i32, align 4
  %B = alloca i32, align 4
  %L = alloca i8*, align 4
  store i32 %A, i32* %1, align 4
  %2 = bitcast i32* %1 to i8*
  %3 = getelementptr inbounds i8* %2, i32 4    # %3 = &A + 1
  store i8* %3, i8** %L, align 4               # L = &A + 1
  %4 = load i8** %L, align 4
  %5 = getelementptr inbounds i8* %4, i32 4    # %5 = (&A + 1) + 1
  store i8* %5, i8** %L, align 4               # L = &A + 2
  %6 = getelementptr inbounds i8* %5, i32 -4   # load ((&A + 2) - 1) == (&A +
1) ?
  %7 = bitcast i8* %6 to i32*
  %8 = load i32* %7, align 4
  store i32 %8, i32* %B, align 4
  %9 = load i32* %1, align 4
  %10 = load i32* %B, align 4
  %11 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([13 x i8]*
@.str, i32 0, i32 0), i32 %9, i32 %10)
  store i8* null, i8** %L, align 4
  ret void
}
...

-- 
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