[cfe-dev] operator* sema bug

Chris Lattner clattner at apple.com
Sat Dec 15 09:38:13 PST 2007


On Dec 14, 2007, at 11:57 PM, Oliver Hunt wrote:

> So i'm looking at this failure:
> typedef struct { char name[100]; } entry;
> char f1(entry *e) { return *e->name; }
>
>
> The problem appears to be CodeGenFunction::EmitScalarExpr being  
> called on e->name as it believes
> e->name is an array type rather than a scalar, so we assert.
>
> I'm not sure what the appropriate correction should be -- should i fix
> CodeGenFunction::EmitLoadOfLValue
> So that it can handle an array type -- emitting an array type as an  
> lvalue should just be to emit a getElementPtr(array, 0)
>
> Or alternatively have a step during merge to convert *array to  
> array[0]

Hi Oliver,

Sorry for the delay, I've been majorly sick since thursday night.  I  
don't think this is a codegen bug, I think it's a sema bug:

$ clang t3.c -ast-dump
typedef char *__builtin_va_list;
typedef struct <anonymous> entry;

char f1(entry *e)
(CompoundStmt 0x8061e0 <t3.c:2:19, col:38>
   (ReturnStmt 0x8061d0 <col:21, col:32>
     (UnaryOperator 0x8061b0 <col:28, col:32> 'char' prefix '*'
       (MemberExpr 0x806180 <col:29, col:32> 'char [100]' ->name  
0x805f00
         (DeclRefExpr 0x806160 <col:29> 'entry *' ParmVar='e'  
0x806120)))))

Sema is properly inferring that the * has type char, but it isn't  
inserting an implicit cast.  I'd expect to see something like this:

clang t3.c -ast-dump
typedef char *__builtin_va_list;
typedef struct <anonymous> entry;

char f1(entry *e)
(CompoundStmt 0x8061e0 <t3.c:2:19, col:38>
   (ReturnStmt 0x8061d0 <col:21, col:32>
     (UnaryOperator 0x8061b0 <col:28, col:32> 'char' prefix '*'
       (ImplicitCast char*
         (MemberExpr 0x806180 <col:29, col:32> 'char [100]' ->name  
0x805f00
           (DeclRefExpr 0x806160 <col:29> 'entry *' ParmVar='e'  
0x806120))))))

Maybe Steve can take a look if he has a chance,

-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20071215/252b1237/attachment.html>


More information about the cfe-dev mailing list