[PATCH] D93222: [RFC][analyzer] Introduce MacroExpansionContext to libAnalysis

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 21 03:26:37 PST 2021


steakhal marked an inline comment as done.
steakhal added inline comments.


================
Comment at: clang/lib/Analysis/MacroExpansionContext.cpp:210
+}
\ No newline at end of file

----------------
martong wrote:
> Missing newline?
I honestly don't know why was that not addressed by clang-format.
Even here, the prebuild bot should have complained about this - if this is an issue.

If you still think I should add that newline, we should also take a look at the `.clang-format`.


================
Comment at: clang/lib/Analysis/MacroExpansionContext.cpp:33
+
+    void MacroExpands(const Token &MacroName, const MacroDefinition &MD,
+                      SourceRange Range, const MacroArgs *Args) override {
----------------
xazax.hun wrote:
> Will we end up recording ranges for intermediate macro expansions? If yes, we might end up recording excessive amount of ranges. Is there any way to only record final expansion ranges in that case?
All top-level macro expansions will insert a new entry to the map. All intermediate macro expansions right after that will have the very same expansion location, so it will just update the 'end' for that expansion chain.
For tracking the final tokens I'm just aggregating them for every //expansion location// in a similar fashion.


================
Comment at: clang/lib/Analysis/MacroExpansionContext.cpp:39
+
+      SourceLocation ExpansionEnd = [Range, &SM = SM, &MacroName] {
+        // If the range is empty, use the length of the macro.
----------------
martong wrote:
> steakhal wrote:
> > xazax.hun wrote:
> > > martong wrote:
> > > > ?
> > > Why do you need the assignment in `&SM = SM`?
> > `SM` is an object member.
> > The lambda should either capture the `this` pointer or a pointer/reference to the referred member (`SM`).
> > I preferred the latter as the lambda doesn't want to access all of the members except this one.
> `[Range, &SM,  &MacroName]` would not work? (why?)
```
MacroExpansionContext.cpp:35:50: error: capture of non-variable 'clang::detail::MacroExpansionRangeRecorder::SM'
MacroExpansionContext.cpp:38:16: error: 'this' was not captured for this lambda function
```


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

https://reviews.llvm.org/D93222



More information about the cfe-commits mailing list