[clang] [Attributes] Support Attributes being declared as only supporting late parsing when passing an experimental feature flag (PR #88596)

Yeoul Na via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 15 15:35:38 PDT 2024


================
@@ -592,6 +592,16 @@ class AttrSubjectMatcherAggregateRule<AttrSubject subject> {
 
 def SubjectMatcherForNamed : AttrSubjectMatcherAggregateRule<Named>;
 
+// Late Attribute parsing mode enum
+class LateAttrParseKind <int val> {
+  int Kind = val;
+}
+def LateAttrParseNever : LateAttrParseKind<0>; // Never late parsed
+def LateAttrParseAlways: LateAttrParseKind<1>; // Always late parsed
+// Late parsed if `-fexperimental-late-parse-attributes` is on and parsed
+// normally if off.
+def LateAttrParseExperimentalOnly : LateAttrParseKind<2>;
----------------
rapidsna wrote:

I'd propose slightly different semantics for `LateAttrParseAlways` and `LateAttrParseExperimentalOnly`, and renaming accordingly. 

Before this patch, if an attribute was marked `LateParsed=1`, it meant late parsing is enabled for C++ and at the declaration attributes position. However, the same attribute was not late parsed when it is compiled for C.

Therefore, having `LateParsed=1` mean "always late parsed" would be misleading. Instead, it should be something like `LateAttrParseStandard` to indicate the attribute will be late parsed in a conventional way, for C++ on the declaration attribute positions.

Then, `LateParsed=2` should capture the experimental (extended) semantics to enable late parsing for C on both the decl and type attribute positions (in the future), which would be controlled by `-fexperimental-late-parse-attributes`. When the flag is disabled, it should fall back to the same behavior as `LateParsed=1`. For `counted_by` which is a C only attribute, it means no late parsing would enabled because it will be compiled only for C.

Consider `guarded_by`, which is marked `LateParsed=1` and is also available for C++. Let's say we adopt `LateAttrParseExperimental` for `guarded_by`.  With the flag, the code below will compile for C (though that is a lie because a naked field reference doesn't work for C atm https://github.com/llvm/llvm-project/issues/20777, but that's a separate issue and let's assume we've somehow resolved that issue).

```
struct guarded_int {
  int value __attribute__((guarded_by(m));
  struct mutex m;
};
```

Without the flag, it won't be late parsed for C, but it should continue to be late parsed for C++ on the decl attribute positions like before.

https://github.com/llvm/llvm-project/pull/88596


More information about the cfe-commits mailing list