[LLVMbugs] [Bug 17676] New: LLVM cannot parse global variables without initializers

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Oct 24 03:37:37 PDT 2013


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: unassignedbugs at nondot.org
          Reporter: anastasia.stulova at arm.com
                CC: llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131024/de805dd6/attachment.html>


More information about the llvm-bugs mailing list