[LLVMdev] Uninitialized variable - question

Patrik Hägglund H patrik.h.hagglund at ericsson.com
Sat Nov 24 03:57:01 PST 2012


I think that the relevant part in C11 is section 6.2.6.1, which tells you that accessing a trap representation, _other than using a char type_, is undefined. Objects of automatic storage, which don't have an initializer are of indeterminate value, which either is an unspecified value or a trap representation.

> What I found is that with -O2:
> LLVM (trunk) prints both "a" and "b"

 I can't reproduce this with r168538. I only get "a".

Regards,
Patrik Hägglund

-----Original Message-----
From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Jakub Staszak
Sent: den 24 november 2012 11:08
To: llvmdev at cs.uiuc.edu
Subject: [LLVMdev] Uninitialized variable - question

Hello,

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;
  f(i);
  g(i);
}


- Kuba





_______________________________________________
LLVM Developers mailing list
LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list