<html>
    <head>
      <base href="https://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 --- - Inconsistency in dereferencing of void pointers"
   href="https://llvm.org/bugs/show_bug.cgi?id=25867">25867</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Inconsistency in dereferencing of void pointers
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>barannikov88@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider the following example:

void f()
{
    void *p1;
    volatile void *p2;

    *p1;
    *p2;

    p1[0];
    p2[0];
}

All of operations on p1 and p2 are dereferencing operations ((C99 6.5.2.1p2 The
definition of the subscript operator [] is that E1[E2] is identical to
(*((E1)+(E2))).), but they are treated differently when generating llvm IR:

//  %p1 = alloca i8*, align 4
//  %p2 = alloca i8*, align 4

    *p1;
//  %0 = load i8*, i8** %p1, align 4

    *p2;
//  %1 = load i8*, i8** %p2, align 4

    p1[0];
//  %2 = load i8*, i8** %p1, align 4
//  %arrayidx = getelementptr inbounds i8, i8* %2, i32 0
//  %3 = load i8, i8* %arrayidx

    p2[0];
//  %4 = load i8*, i8** %p2, align 4
//  %arrayidx1 = getelementptr inbounds i8, i8* %4, i32 0

//  ret void

Operation p1[0] does load, others do not.


Also, '*p2' and 'p2[0]' are lvalues, while '*p1' and 'p1[0]' are not:
    |-UnaryOperator 0xf688c88 <line:6:5, col:6> 'void' prefix '*'
    | `-ImplicitCastExpr 0xf688c78 <col:6> 'void *' <LValueToRValue>
    |   `-DeclRefExpr 0xf688c60 <col:6> 'void *' lvalue Var 0xf688ba0 'p1'
'void *'
    |-UnaryOperator 0xf688cc8 <line:9:5, col:6> 'volatile void' lvalue prefix
'*'
    | `-ImplicitCastExpr 0xf688cb8 <col:6> 'volatile void *' <LValueToRValue>
    |   `-DeclRefExpr 0xf688c9c <col:6> 'volatile void *' lvalue Var 0xf688c18
'p2' 'volatile void *'
    |-ArraySubscriptExpr 0xf688d20 <line:12:5, col:9> 'void'
    | |-ImplicitCastExpr 0xf688d10 <col:5> 'void *' <LValueToRValue>
    | | `-DeclRefExpr 0xf688cdc <col:5> 'void *' lvalue Var 0xf688ba0 'p1'
'void *'
    | `-IntegerLiteral 0xf688cf8 <col:8> 'int' 0
    `-ArraySubscriptExpr 0xf688d78 <line:17:5, col:9> 'volatile void' lvalue
      |-ImplicitCastExpr 0xf688d68 <col:5> 'volatile void *' <LValueToRValue>
      | `-DeclRefExpr 0xf688d34 <col:5> 'volatile void *' lvalue Var 0xf688c18
'p2' 'volatile void *'
      `-IntegerLiteral 0xf688d50 <col:8> 'int' 0</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>