Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Savotina Valeria, Lab №1, var: 2. #27

Merged
merged 5 commits into from
Mar 21, 2024

Conversation

Savotina
Copy link

The plugin allows all functions that don't have conditions (for example, if, do...while, etc.), add the always_inline attribute.

Comment on lines 14 to 25
if (decl->isFunctionOrFunctionTemplate()) {
if (!decl->hasAttr<clang::AlwaysInlineAttr>()) {
if (auto body = decl->getBody()) {
if (!findСonditionalStatement(body)) {
if (auto loc = decl->getSourceRange(); loc.isValid()) {
decl->addAttr(
clang::AlwaysInlineAttr::Create(*context, loc.getBegin()));
}
}
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In LLVM it is customary to reduce nesting as much as possible:

Suggested change
if (decl->isFunctionOrFunctionTemplate()) {
if (!decl->hasAttr<clang::AlwaysInlineAttr>()) {
if (auto body = decl->getBody()) {
if (!findСonditionalStatement(body)) {
if (auto loc = decl->getSourceRange(); loc.isValid()) {
decl->addAttr(
clang::AlwaysInlineAttr::Create(*context, loc.getBegin()));
}
}
}
}
}
if (!decl->isFunctionOrFunctionTemplate())
return true;
if (decl->hasAttr<clang::AlwaysInlineAttr>())
return true;
if (auto body = decl->getBody()) {
if (findСonditionalStatement(body))
return true;
if (auto loc = decl->getSourceRange(); loc.isValid())
decl->addAttr(
clang::AlwaysInlineAttr::Create(*context, loc.getBegin()));
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-ly4 ok, I see, thanks!

@m-ly4 m-ly4 merged commit be5582a into NN-complr-tech:course-spring-2024 Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants