[PATCH] D59628: Add support for __attribute__((objc_class_stub))

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 1 11:55:02 PDT 2019


rjmccall added inline comments.


================
Comment at: lib/Sema/SemaDeclObjC.cpp:4131-4133
+      if (!getLangOpts().ObjCRuntime.allowsClassStubs()) {
+        Diag(IntfDecl->getLocation(), diag::err_class_stub_not_supported);
+      }
----------------
aaron.ballman wrote:
> This should be done in Attr.td. You'll need to add a new LangOpt subclass (around line 298 or so are examples), and then add it to the `LangOpts` array when defining the attribute. Then you can remove this code as well as the new diagnostic.
I don't think there's a way to run arbitrary code in a `LangOpt` right now, but it should be relatively straightforward to generalize `ClangAttrEmitter` to handle this.  Just add an optional `Code` property to `LangOpt` that's expressed in terms of an assumed variable `LangOpts`, so that `Attr.td` could have a line like:

```
  def ObjCClassStubsAllowed : LangOpt<"ObjCClassStubsAllowed", "LangOpts.ObjCRuntime.allowsClassStubs()">;
```

`ClangAttrEmitter` would take that expression, parenthesize it, and use it where it currently expands to `"LangOpts." + Name`.  It should be possible to remove the `Negated` field in favor of this.

I guess that's probably worth doing vs. just having some hard-coded logic.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59628/new/

https://reviews.llvm.org/D59628





More information about the cfe-commits mailing list