[prev in list] [next in list] [prev in thread] [next in thread] 

List:       llvm-bugs
Subject:    [LLVMbugs] [Bug 6168] New: clang emits missing fields as undef
From:       bugzilla-daemon () cs ! uiuc ! edu
Date:       2010-01-29 1:02:35
Message-ID: bug-6168-206 () http ! llvm ! org/bugs/
[Download RAW message or body]

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

           Summary: clang emits missing fields as undef instead of 0
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs@nondot.org
        ReportedBy: jyasskin@google.com
                CC: llvmbugs@cs.uiuc.edu


C99 6.7.8 p21 says, "If there are fewer initializers in a brace-enclosed list
than there are elements or members of an aggregate, ... the remainder of the
aggregate shall be initialized implicitly the same as objects that have static
storage duration."  p10 says static objects are initialized to null or zero.

Clang, instead, initializes the remainder of the aggregate to "undef". In many
cases, this will produce the right result because lots of optimizers treat
undef as 0, but that's certainly not guaranteed.

For example:

$ cat test.c
struct ManyFields {
  int a;
  int b;
  int c;
  char d;
  int e;
  int f;
};

extern struct ManyFields FewInits;
struct ManyFields FewInits = {1, 2};

$ clang -std=c99 -femit-all-decls -emit-llvm -S test.c -o -
; ModuleID = 'test.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"

%0 = type { i32, i32, [16 x i8] }

@FewInits = global %0 { i32 1, i32 2, [16 x i8] undef }, align 4 ; <%0*>
[#uses=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.
_______________________________________________
LLVMbugs mailing list
LLVMbugs@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic