-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC][Clang] Adopt TrailingObjects
convenience API in MacroArgs
#139635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
TrailingObjects
convienence API in MacroArgsTrailingObjects
convenience API in MacroArgs
@llvm/pr-subscribers-clang Author: Rahul Joshi (jurahul) ChangesFull diff: https://github.com/llvm/llvm-project/pull/139635.diff 1 Files Affected:
diff --git a/clang/lib/Lex/MacroArgs.cpp b/clang/lib/Lex/MacroArgs.cpp
index 2f97d9e02bc11..548df16c59f6b 100644
--- a/clang/lib/Lex/MacroArgs.cpp
+++ b/clang/lib/Lex/MacroArgs.cpp
@@ -66,7 +66,7 @@ MacroArgs *MacroArgs::create(const MacroInfo *MI,
"uninitialized array (as opposed to reusing a cached "
"MacroArgs)");
std::copy(UnexpArgTokens.begin(), UnexpArgTokens.end(),
- Result->getTrailingObjects<Token>());
+ Result->getTrailingObjects());
}
return Result;
@@ -119,7 +119,7 @@ const Token *MacroArgs::getUnexpArgument(unsigned Arg) const {
assert(Arg < getNumMacroArguments() && "Invalid arg #");
// The unexpanded argument tokens start immediately after the MacroArgs object
// in memory.
- const Token *Start = getTrailingObjects<Token>();
+ const Token *Start = getTrailingObjects();
const Token *Result = Start;
// Scan to find Arg.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please justify this change, we don't use getTrailingObjects
like this anywhere else and I am not sure I see the point in this change. This should always go in the summary so that a reviewer does not have to guess you intent.
In general we prefer being as explicit as possible since that leads to less ambiguity for future developers working on the code later.
I filled in the description now. I am doing similar changes on LLVM/MLIR side (change has been approved). I added these convenience APIs to TrailingObjects to support the common code patterns of a single trailing type as well as creating an ArrayRef from the trailing objects pointer. |
FYI, LLVM and MLIR change of similar nature: #138554 |
@jurahul Thanks for the pointer in the description. So, in this particular case, we end up invoking the following?
|
Right. With this API , when there is a single trailing type, you can call |
Closed by mistake. |
Note: I tried to do a change similar to LLVM/MLIR where I tried to convert all usage under clang/AST and it became too large, so will split it up into multiple ones. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Thank you, the change makes a lot more sense with the context. |
Adopt convenience API for single trailing type added in #138970.