<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 --- - section attribute extension causes miscompile"
   href="http://llvm.org/bugs/show_bug.cgi?id=17246">17246</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>section attribute extension causes miscompile
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>All
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>david.majnemer@gmail.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>const int i2 __attribute__((section("INITDATA"))) = 30;
int i1 __attribute__((section("INITDATA"))) = 0;

clang using C language semantics will IR-gen:
@i2 = constant i32 30, section "INITDATA", align 4
@i1 = global i32 0, section "INITDATA", align 4

LLVM CodeGen gives us:
        .type   i2,@object              # @i2
        .section        INITDATA,"a",@progbits
        .globl  i2
        .align  4
i2:
        .long   30                      # 0x1e
        .size   i2, 4

        .type   i1,@object              # @i1
        .globl  i1
        .align  4
i1:
        .long   0                       # 0x0
        .size   i1, 4

notice the flags in the section directive, we only state that it is allocatable
but do not mention that it is writable.

Where do we fix this? Is this valid IR? The IR verifier has no issue with it.

note that flipping the order of i1 and i2 yields "aw" for the section
directive's flags, making everything A-OK.

Additionally:
1. icc gets it wrong in the exact same way
2. gcc fails at understanding this semantically but it's assembler catches it
in the end.

My opinion:
We shouldn't tie down our IR to whatever whacky thing happens in GCC.  Instead,
we should widen the flags of the section as much as possible to capture
everything specified with the attribute.  Then it will Just Work (TM) without
having to teach clang when it's ok for two global variables to be in the same
section.</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>