<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - LLVM cannot parse global variables without initializers"
   href="http://llvm.org/bugs/show_bug.cgi?id=17676">17676</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM cannot parse global variables without initializers
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM assembly language parser
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>anastasia.stulova@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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" <a href="http://llvm.org/docs/LangRef.html#global-variables">http://llvm.org/docs/LangRef.html#global-variables</a>.

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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>