Problems in __builtin_offsetof locations

The attached C source show two different problems:

$ llvm_new/Debug/bin/clang-cc -W -Wall bug_clang2.c
bug_clang2.c:11:7: error: too many arguments to function call
  fun(333);
  ~~~ ^~~
bug_clang2.c:12:7: error: too many arguments to function call
  fun(__builtin_offsetof(struct s, g));
  ~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bug_clang2.c:13:7: error: too many arguments to function call
  fun(__builtin_offsetof(struct s, f));
  ~~~ ^
3 diagnostics generated.

1) As seen in diagnostic for line 12, the end location of
__builtin_offsetof is not the right paren but the end of location of
subexpression (like in all other prefix unary operators). This is wrong
for __builtin_offsetof.

2) Worse in diagnostic for line 13, the end location of
__builtin_offsetof is invalid (here I don't fully understand how this
happens).

bug_clang2.c (197 Bytes)

Abramo Bagnara wrote:

The attached C source show two different problems:

$ llvm_new/Debug/bin/clang-cc -W -Wall bug_clang2.c
bug_clang2.c:11:7: error: too many arguments to function call
  fun(333);
  ~~~ ^~~
bug_clang2.c:12:7: error: too many arguments to function call
  fun(__builtin_offsetof(struct s, g));
  ~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bug_clang2.c:13:7: error: too many arguments to function call
  fun(__builtin_offsetof(struct s, f));
  ~~~ ^
3 diagnostics generated.

1) As seen in diagnostic for line 12, the end location of
__builtin_offsetof is not the right paren but the end of location of
subexpression (like in all other prefix unary operators). This is wrong
for __builtin_offsetof.
  
Good catch. This seems to be a fault in what Sema gets passed from the parser.

2) Worse in diagnostic for line 13, the end location of
__builtin_offsetof is invalid (here I don't fully understand how this
happens).
  
Also a good catch. This is because we're building an anonymous struct/union member access, which ends up being a different code path.

Please file these as a bug. Patches are welcome, or else I'll look at it closer in the morning and see if it admits a quick fix.

John.

In general, when you come across a bug like this, please file it in the LLVM Bugzilla at

  http://llvm.org/bugs/

  - Doug

Douglas Gregor ha scritto:

The attached C source show two different problems:

$ llvm_new/Debug/bin/clang-cc -W -Wall bug_clang2.c
bug_clang2.c:11:7: error: too many arguments to function call
fun(333);
~~~ ^~~
bug_clang2.c:12:7: error: too many arguments to function call
fun(__builtin_offsetof(struct s, g));
~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bug_clang2.c:13:7: error: too many arguments to function call
fun(__builtin_offsetof(struct s, f));
~~~ ^
3 diagnostics generated.

1) As seen in diagnostic for line 12, the end location of
__builtin_offsetof is not the right paren but the end of location of
subexpression (like in all other prefix unary operators). This is wrong
for __builtin_offsetof.

2) Worse in diagnostic for line 13, the end location of
__builtin_offsetof is invalid (here I don't fully understand how this
happens).

In general, when you come across a bug like this, please file it in the
LLVM Bugzilla at

    http://llvm.org/bugs/

I've already done that. Are you meaning that it was better to *only*
file it in the LLVM Bugzilla?

In general we prefer to send the info about the problem found here to
get some feedback about and then decide whether is better to submit
directly a patch (if we think to be able to do something that meet the
agreement of core developers) or to submit a bug report.

Is it the correct behaviour?

Douglas Gregor ha scritto:

The attached C source show two different problems:

$ llvm_new/Debug/bin/clang-cc -W -Wall bug_clang2.c
bug_clang2.c:11:7: error: too many arguments to function call
fun(333);
~~~ ^~~
bug_clang2.c:12:7: error: too many arguments to function call
fun(__builtin_offsetof(struct s, g));
~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bug_clang2.c:13:7: error: too many arguments to function call
fun(__builtin_offsetof(struct s, f));
~~~ ^
3 diagnostics generated.

1) As seen in diagnostic for line 12, the end location of
__builtin_offsetof is not the right paren but the end of location of
subexpression (like in all other prefix unary operators). This is wrong
for __builtin_offsetof.

2) Worse in diagnostic for line 13, the end location of
__builtin_offsetof is invalid (here I don't fully understand how this
happens).

In general, when you come across a bug like this, please file it in the
LLVM Bugzilla at

   http://llvm.org/bugs/

I've already done that. Are you meaning that it was better to *only*
file it in the LLVM Bugzilla?

Yes, please.

In general we prefer to send the info about the problem found here to
get some feedback about and then decide whether is better to submit
directly a patch (if we think to be able to do something that meet the
agreement of core developers) or to submit a bug report.

Is it the correct behaviour?

For something that is clearly a bug, I think it's best to just file a Bugzilla. If all of the bugs that got filed against Clang went to this mailing list, that traffic could drown out design discussions, questions from Clang users, etc. At some point, we'll probably have a dedicated "bugs" list for Clang where we could discuss specific bugs.

Of course, if the bug needs some discussion, e.g., because you're interested in talking over how the bug could be fixed, then by all means please mail the list.

   - Doug