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

            Bug ID: 17676
           Summary: LLVM cannot parse global variables without
                    initializers
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM assembly language parser
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

The llvm IR parser fails to parse a global variable without initializer.

The following line for example:

@x = internal addrspace(2) global i8

would crash with an error message:

error: expected value token
@x = internal addrspace(2) global i8

The LLVM IR spec clearly says initializers are optional: "Global variables may
optionally be initialized" http://llvm.org/docs/LangRef.html#global-variables.

We found these two places where globals are assumed to have an initializer:

lib/Transforms/Scalar/SCCP.cpp
+    if (GV->getType()->getElementType()->isSingleValueType() &&
GV->hasInitializer()) {
-    if (GV->getType()->getElementType()->isSingleValueType()) {

lib/Transforms/IPO/GlobalOpt.cpp
+           if (GV->hasInitializer() && StoredVal == GV->getInitializer()) {
-            if (StoredVal == GV->getInitializer()) {


LLVM r193185

A recent version of clang produces undef initializers:

void f() {static int x;}
@f.x = internal global i32 undef, align 4

Should we make the initializers non optional and use undef? This would make
hasInitializer() always return true and may not be correct.
Should we just fix the parser to accept globals without initializers.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to