[cfe-dev] Broken sizeof(expr) location in SemaExpr.cpp

John McCall rjmccall at apple.com
Sat May 28 13:53:56 PDT 2011


On May 28, 2011, at 7:29 AM, Xi Wang wrote:

> Hi,
> 
> Try `clang -cc1 -ast-dump' on the following case using the trunk
> version, where both sizeof statements should start at column 3.
> 
> void foo(int i)
> {
>  sizeof(i);
>  sizeof(int);
> }
> 
> Clang outputs
> 
>  (UnaryExprOrTypeTraitExpr ... <line:3:9, col:11> 'unsigned long' sizeof
>  ...
>  (UnaryExprOrTypeTraitExpr ... <line:4:3, col:13> 'unsigned long'
> sizeof 'int'))
> 
> Note that when sizeof is applied to an expression, sizeof(i), the
> column number is 9, rather than 3; sizeof(int) is still good.
> 
> I looked through the recent commits.  In rev. 132115, at
> lib/Sema/SemaExpr.cpp:3265, the interface of
> Sena::CreateUnaryExprOrTypeTraitExpr was changed --- it no longer
> takes OpLoc as an argument when sizeof is applied to an expression.
> At line 3290, when creating UnaryExprOrTypeTraitExpr, the code uses
> E->getExprLoc() as the location of sizeof.  This means that in the
> example above, the OpLoc of sizeof(i) was actually that of i.
> 
> I noticed this change because it bit my Clang-based source rewriter.
> Is this intentional or a bug?  Thanks.

This does seem wrong.  Since you've done so much of the
investigation on it, care to write up a patch? :)

John.



More information about the cfe-dev mailing list