This is an archive of the discontinued LLVM Phabricator instance.

Complete the implementation of P2361 Unevaluated string literals
ClosedPublic

Authored by cor3ntin on Jul 25 2023, 6:49 AM.

Details

Summary

The attributes changes were left out of Clang 17.
Attributes that used to take a string literal now accept an unevaluated
string literal instead, which means they reject numeric escape sequences
and strings literal with an encoding prefix - but the later was already
ill-formed in most cases.

We need to know that we are going to parse an unevaluated string literal
before we do - so we can reject numeric escape sequence,
so we derive from Attrs.td which attributes parameters are expected
to be string literals.

Diff Detail

Event Timeline

cor3ntin created this revision.Jul 25 2023, 6:49 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: jdoerfert. · View Herald Transcript
cor3ntin requested review of this revision.Jul 25 2023, 6:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 6:49 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Can you update the patch description with more details about why these changes are being made in this way (to help people doing code archaeology in the future)?

clang/include/clang/Basic/DiagnosticCommonKinds.td
60

This duplicates part of err_attribute_argument_type; probably worth it to update that diagnostic so we get consistent diagnostic wording between attributes expecting string literal arguments.

clang/lib/Parse/ParseDeclCXX.cpp
1029 ↗(On Diff #543955)

Spurious whitespace change is the only change in this file.

clang/lib/Parse/ParseExpr.cpp
3508–3510

Spurious brace changes are the only changes in this file.

clang/test/Parser/cxx-attributes.cpp
44

LOL this is a much better diagnostic than the previous one. :-D

cor3ntin marked 2 inline comments as done.Jul 27 2023, 6:57 AM
cor3ntin added inline comments.
clang/include/clang/Basic/DiagnosticCommonKinds.td
60

I'm not sure there is a good way to do that without changing thousands of tests. I did look into it!

aaron.ballman added inline comments.Jul 27 2023, 7:01 AM
clang/include/clang/Basic/DiagnosticCommonKinds.td
60

If it's a slog, it can be done in a follow-up as an NFC commit.

cor3ntin updated this revision to Diff 544759.Jul 27 2023, 7:07 AM

Update commit message and remove spurious changes

cor3ntin edited the summary of this revision. (Show Details)Jul 27 2023, 7:08 AM
Fznamznon added inline comments.
clang/lib/Parse/ParseDecl.cpp
422
433–434

Should it be

Also, probably else can be removed since there is break above.

cor3ntin updated this revision to Diff 544890.Jul 27 2023, 12:31 PM
cor3ntin edited the summary of this revision. (Show Details)

Fix typo, remove dead code

aaron.ballman accepted this revision.Jul 28 2023, 5:12 AM

LGTM with a minor formatting nit that @Fznamznon had pointed out but was missed.

clang/lib/Parse/ParseDecl.cpp
431–436
This revision is now accepted and ready to land.Jul 28 2023, 5:12 AM
cor3ntin added inline comments.Jul 28 2023, 5:18 AM
clang/lib/Parse/ParseDecl.cpp
431–436

Oups, sorry @Fznamznon, I'll fix that!

barannikov88 added inline comments.Jul 28 2023, 3:56 PM
clang/utils/TableGen/ClangAttrEmitter.cpp
2349

maskTrailingZeros might also be useful

hubert.reinterpretcast added inline comments.
clang/test/Parser/cxx0x-attributes.cpp
450–451

There should be corresponding C tests if, as the release notes text implies, the C behaviour changes (although, again, this direction has not been adopted by the C committee).

cor3ntin updated this revision to Diff 549314.Aug 11 2023, 2:54 AM

Rebase, add C tests

clang/test/Parser/c2x-attributes.c
29

"Typo" fix.

clang/utils/TableGen/ClangAttrEmitter.cpp
2336

Typo fix

2349

@cor3ntin, this comment appears unaddressed.

Additionally, (just for future reference) ++N is suggested for the loop: https://llvm.org/docs/CodingStandards.html#prefer-preincrement.

cor3ntin updated this revision to Diff 549584.Aug 12 2023, 1:28 AM
cor3ntin marked 8 inline comments as done.

Address Hubert's feedback.

clang/lib/Parse/ParseDecl.cpp
431–436

It seems Aaron's request to move the code out of the else was not acted on.

clang/utils/TableGen/ClangAttrEmitter.cpp
2337

Minor nit: Grammar

2345

Do we know that Args.size() is less than 32?

2349–2350
#include <llvm/Support/MathExtras.h>
cor3ntin updated this revision to Diff 549878.Aug 14 2023, 4:40 AM
cor3ntin marked an inline comment as done.

Address Hubert's feedback

cor3ntin added inline comments.Aug 14 2023, 4:42 AM
clang/lib/Parse/ParseDecl.cpp
431–436

Not sure what happened there, I recall doing that. I guess not, thanks!

clang/utils/TableGen/ClangAttrEmitter.cpp
2345

I added an assert

Thanks, @cor3ntin, for addressing my feedback. I am not familiar enough with various aspects of it to approve it, but I see Aaron has already approved it and I think all comments have been addressed.
I also appreciate that the patch helps towards making the internally-used encoding less exposed.