https://llvm.org/bugs/show_bug.cgi?id=25867
Bug ID: 25867 Summary: Inconsistency in dereferencing of void pointers Product: clang Version: 3.7 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P Component: Frontend Assignee: unassignedclangb...@nondot.org Reporter: baranniko...@gmail.com CC: llvm-bugs@lists.llvm.org Classification: Unclassified 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 -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs