[LLVMdev] Uninitialized variable - question

Jakub Staszak kubastaszak at gmail.com
Sat Nov 24 02:08:09 PST 2012


I was wondering about the case below. I tried to find any information in C standard, but I found nothing.
In this case, variable "i" is uninitialized, but it is the _same_ value passed as an argument, so only of "a" or "b" should be printed.

What I found is that with -O2:
LLVM (trunk) prints both "a" and "b"
GCC (4.2) prints both "a" and "b"
GCC (trunk) prints "b" only.

As I said, I don't know what standard says here.

#include <stdio.h>

void f(int i) __attribute__((noinline));
void g(int i) __attribute__((noinline));

void f(int i) {
  if (i) printf("a\n");

void g(int i) {
  if (!i) printf("b\n");

int main() {
  int i;

- Kuba

More information about the llvm-dev mailing list