This doesn't do anything on its own, but it's the first step towards allowing plugins to define attributes. It does simplify the ParsedAttrInfo generation in ClangAttrEmitter a little though.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Resurrecting this old patch, with the intention of trying to get it committed this time. This is the first of four patches to make it possible for clang plugins to define attributes.
clang/lib/Sema/ParsedAttr.cpp | ||
---|---|---|
144 | I don't think you can do this. The only way to get Info as nullptr is to end up off the end of the array, which is UB. Instead of the map lookup, this should check A.getKind against the range. | |
147 | Currently the behavior of this is to make an invalid attribute kind be UB. Presumably the point here is to make it so that is no longer the case? | |
clang/utils/TableGen/ClangAttrEmitter.cpp | ||
3410 | Why does this take SS AND OS. What is the difference here? Does this actually use OS anymore? | |
3653 | Should the instance be static? Perhaps a static variable in the class itself? | |
3656–3657 | Is there a good reason this doesn't return references? |
clang/lib/Sema/ParsedAttr.cpp | ||
---|---|---|
144 | AttrInfoMap is declared to have size ParsedAttr::UnknownAttribute+1, so when the kind is too large we get an element that wasn't explicitly initialized so will be null. Doing it by kind makes more sense though, so I'll do that. | |
clang/utils/TableGen/ClangAttrEmitter.cpp | ||
3410 | It's because of GenerateCustomAppertainsTo. That generates a function that expects to be at file scope (because emitAttributeMatchRules re-uses the same function), but at the time GenerateAppertainsTo is called SS is in the middle of the ParsedAttrInfo. Previously both the function that GenerateCustomAppertainsTo generates and that this file generates would be at file scope, so both were written to OS. | |
3653 | Making it static makes sense, I'll do that. | |
3656–3657 | You can't have an array of references (C++11 dcl.ref paragraph 5). |
Update based on review comments. Also fix warnings due to missing virtual destructor that I hadn't noticed before.
clang/lib/Sema/ParsedAttr.cpp | ||
---|---|---|
141 | Might as well lower this variable into the function -- no real need for it to have file scope. | |
clang/utils/TableGen/ClangAttrEmitter.cpp | ||
3410 | I think the stream parameter names should be a bit more descriptive here (and perhaps some comments on the function would be a good idea as well). Perhaps FileScopeStream and LexicalScopeStream? |
clang/lib/Sema/ParsedAttr.cpp | ||
---|---|---|
141 | Sure. | |
clang/utils/TableGen/ClangAttrEmitter.cpp | ||
3410 | Actually, looking at this again there's no reason we can't generate the CustomApperatinsTo functions in a loop at the start of EmitClangAttrParsedAttrImpl. That way everything can just go to a single output stream and we don't have this problem. I'll rearrange things to do that instead. |
Move DefaultParsedAttrInfo out of file scope, and move custom appertains-to function generation out of the loop in EmitClangAttrParsedAttrImpl so we only need to use one output stream.
LGTM aside from a minor nit and a question.
clang/lib/Sema/ParsedAttr.cpp | ||
---|---|---|
144 | You can use llvm::array_lengthof() here instead. | |
clang/utils/TableGen/ClangAttrEmitter.cpp | ||
3653 | Would it make sense for this object to be const under the assumption that once we've generated a ParsedAttrInfo object, we don't want to modify its properties? I'm not certain if trying to be const-correct here would be a burden or not, so I don't insist on a change unless it's trivial to support. |
Might as well lower this variable into the function -- no real need for it to have file scope.