Fix #23224 - ImportC: parse C23 [[...]] attribute-specifier-sequences#23242
Fix #23224 - ImportC: parse C23 [[...]] attribute-specifier-sequences#23242PetarKirov wants to merge 1 commit into
Conversation
|
Thanks for your pull request, @PetarKirov! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
dkorpel
left a comment
There was a problem hiding this comment.
Before we start merging all this AI generated code in dmd, I'd like the whole C23 operation to be justified and approved. #23223 (comment)
|
I can open PRs for some of the other small C23 features, but I also prefer waiting for approval, before wasting effort.
Although I didn't have opportunity to contribute to D (lack of time) in recent years, I still deeply care about its success. This includes both the maintenance and the reputation (e.g. who would want to use a project merging unreviewed vibe-slop). I've spent a lot of care on extracting the relevant parts of the C23 spec, iterating on the tests (that's how I found the bug fixed by the first commit) and reviewing the changes to cparse.d and expressionsem.d. It certainly wasn't just a one shot "implement this feature, make no mistakes!" 😄 |
dkorpel
left a comment
There was a problem hiding this comment.
Code looks good logically, but in an overly verbose AI style. Like, do we really need 62 mentions of C23 6.7.13?
Please fix the duplicate deprecation message issue in a separate PR.
736b04f to
5594a12
Compare
|
It might even be relevant to reconsider the approach taken to implement this too. This is currently doing quite a lot of heavy lifting in the parser just to support What about dealing with the contents of |
|
@ibuclaw Initially, my goal was to map:
Additionally, So for this reason, I found it natural (easier and more efficient) to do this in the parser. That said, I agree that its wasteful to throw this information after having spent the effort of parsing it. So inserting a CAttributeDeclaration node for at least the unknown attributes (still not convinced about the ones we do know about) seem like a good idea. I'll think about it more. |
|
dependant PR merged, needs rebase. |
…ences
ImportC now understands the C23 attribute syntax (C23 6.7.13) wherever a
GNU __attribute__ is accepted: on declarations, pointers, struct/union/enum
tags, struct members, enumerators, function parameters, and statements.
[[deprecated]]/[[deprecated("msg")]] (6.7.13.5) maps to D's deprecated, and
[[deprecated]] on an enumerator deprecates the D enum member. [[noreturn]]/
[[_Noreturn]] (6.7.13.7) sets the function's noreturn flag (a backend codegen
hint, not D's noreturn type). The remaining standard attributes
([[nodiscard]], [[maybe_unused]], [[fallthrough]], [[unsequenced]],
[[reproducible]]), vendor-prefixed (gnu::, clang::) and unknown attributes
are accepted and ignored. A standard attribute spelled attr and __attr__
are treated identically (6.7.13.1).
5594a12 to
3b07cc6
Compare
|
@thewilsonator rebased |
|
For the attributes that do have a direct mapping to D, it all gets set in the Scope during semantic time. See AttribDeclaration createNewScope. May need expanding to include C attributes not considered an attribute by D (nothrow? Haven't checked whether this is mapped in cparser) |
Part of #23223. Adds C23
[[...]]attribute-specifier-sequence support to ImportC, ontop of a small standalone fix for a pre-existing deprecation-diagnostic bug that the
feature depends on.
N3220 (C23's final spec working draft) can be found here: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf
Commits
Fix #23241— duplicate deprecation message for enum member accessed by nameA deprecated enum member accessed by its unqualified name (an anonymous enum member,
one brought into scope via
with, or — with this PR — an ImportC enumerator) reportedthe deprecation twice: once during name resolution and again in
getVarExp(), whichperforms the deprecated/disabled checks itself. The enum member is now checked once.
Fix #23224— ImportC: parse C23[[...]]attribute-specifier-sequencesImportC now understands the C23 attribute syntax (C23 §6.7.13) wherever a GNU
__attribute__is accepted: on declarations, pointers, struct/union/enum tags, structmembers, enumerators, function parameters, and statements. It mirrors the existing
GNU-attribute parser and funnels into the same
Specifiermachinery (no new AST nodes).[[deprecated]]/[[deprecated("msg")]](§6.7.13.5) and[[noreturn]]/[[_Noreturn]](§6.7.13.7) map to their D equivalents;[[deprecated]]on anenumerator deprecates the D enum member.
[[nodiscard]],[[maybe_unused]],[[fallthrough]],[[unsequenced]],[[reproducible]], vendor-prefixed (gnu::,clang::) and unknown attributes areaccepted and ignored.
__attr__spelling is treated identically toattr(§6.7.13.1).[[noreturn]]maps to the existingFuncDeclaration.noreturnflag (a backendSFLexitcodegen hint), consistent with how
_Noreturn/__attribute__((noreturn))alreadybehave (#12966) — not the D
noreturntype, since C'snoreturnis advisory and mayapply to non-
void/ value-returning functions.Tests
compilable/c23attributes.c— every attribute in every accepted position.compilable/testc23attributes.d— imports the above and uses__traits(isDeprecated)to verify the D-observable effects (functions and enum members).
fail_compilation/c23attributes_deprecated.c—[[deprecated]]fires under-de.compilable/deprecated_enum_member.d— the Duplicate deprecation message when a deprecated enum member is accessed by name #23241 regression (single diagnostic).The full ImportC test suite and all deprecation-output tests pass locally.