This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Support free positioning of labels inside compound statements in C
Needs ReviewPublic

Authored by Izaron on Mar 19 2023, 2:07 PM.

Diff Detail

Event Timeline

Izaron created this revision.Mar 19 2023, 2:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 19 2023, 2:07 PM
Izaron requested review of this revision.Mar 19 2023, 2:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 19 2023, 2:07 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

A big TODO: rename ext_c_label_end_of_compound_statement to something like ext_c_label_free_positioning. Since we found out it is more complete than just the end of statements.

clang/lib/Parse/ParseStmt.cpp
695–697
clang/test/OpenMP/threadprivate_messages.cpp
141

TODO: find out if this is okay? (I've got no idea what it does)

clang/test/Parser/c2x-label.c
5–6

TODO: make sure a warning is printed. I couldn't find correct conditions for the warning, I tried and it produced false positive warnings in some other tests =(

P.S. Its C++'s counterpart: https://github.com/llvm/llvm-project/blob/main/clang/test/Parser/cxx2b-label.cpp

aaron.ballman added inline comments.
clang/lib/Parse/ParseStmt.cpp
745

At this point, you know whether you've parsed a declaration statement or not, so you could potentially add the extension diagnostic logic here.

clang/test/OpenMP/threadprivate_messages.cpp
141

CC @mikerice @jyu2 @jdoerfert for opinions on OpenMP impact. There are FIXMEs in the code related to this: https://github.com/llvm/llvm-project/blob/main/clang/lib/Parse/ParseOpenMP.cpp#L2671

clang/test/Parser/c2x-label.c
5–6

Yeah, this would be specific to C because C++ has always allowed a declaration there. I left a comment above with a potential idea.