llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.01k stars 11.95k forks source link

Clang rejects well-formed C11 program using [*] #39434

Open ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f opened 5 years ago

ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f commented 5 years ago
Bugzilla Link 40087
Version trunk
OS All
CC @hfinkel,@zygoloid

Extended Description

Conside the following program (prog.c):

void f(int a[sizeof(int [*])]);

int main() { }

Compile it with the following command line:

clang prog.c -std=c11 -pedantic-errors

It incorrectly gives the following error:

error: star modifier used outside of function prototype

Compiling the program should give no error since it is well-formed according to C11.

ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f commented 5 years ago

I have sent the following question to WG14:

In defect report #​341 the following example was given:

void f(int (*)[sizeof(int (*)[*])]);

In the first response it was stated that there was consensus that this example should be invalid.

The final wording in the resolution seems to imply the opposite: That the example is valid.

Is the example valid or invalid?

I'll get back here when I get a reply.

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 5 years ago

Feel free to ask :)

ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f commented 5 years ago

Will you ask them, or should I do that?

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 5 years ago

Well, #​341 says "There was consensus that the first example should be valid, and the second should be invalid." and there's no indication that that decision was reversed, so I'm still inclined to think that the C wording change fails to reflect the intent. It seems at least worth asking WG14 what they meant.

ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f commented 5 years ago

I tried to report the opposite behaviour in gcc as bug, but was then informed that the final resolusion of defect report 341 do allow such programs.

Defect report:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_341.htm

See discussion in the invalid gcc bug report:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88526

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 5 years ago

I really don't think that's the intended interpretation of the C wording. To the extent that the above fails to violate C11 6.7.6.2/2 and /4, I think that's a bug in the wording.

AaronBallman commented 1 year ago

The question never made it to the WG14 reflectors and the meeting minutes from Spring 2008 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1343.pdf) are effectively useless as to what the committee was thinking when making the decision.

I've asked on the committee reflectors what the intent and history is here.

AaronBallman commented 1 year ago

I asked in reflector message: https://www.open-std.org/jtc1/sc22/wg14/23678 and have not yet heard a response.