Skip to content
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

Clang tidy integration #172

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

parsifal-47
Copy link
Contributor

I know, it may look invasive, but do not hesitate to ask for changes, I tried to exclude some policies that are often violated in the code like braces-around-statements or the ones that are producing false alarms.

Test plugin does not fix errors, it only checks for compliance.

Let me know what you think and feel free to ask questions!

@@ -91,7 +85,7 @@ OpFoldResult addOFRs(const OpFoldResult lhs, const OpFoldResult rhs,
b.create<arith::ConstantOp>(loc, b.getIndexAttr(lhsIntAttr.value()));
lhsValue = lhsOp.getResult();
} else {
assert(isa<IndexType>(lhsValue.getType()));
assert(lhsValue && isa<IndexType>(lhsValue.getType()));

Choose a reason for hiding this comment

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

What was the reason that this one had to change? It seems like we expect lhsValue to be non-null in the else case (same with rhsValue). I think a better change here would be to not initialize lhsValue at the declaration and instead initialize it in each branch. Like the following:

Value lhsValue;
if (...) {
  ...
  lhsValue = lhsOp.getResult();
} else {
  lhsValue = cast<Value>(lhs);
  assert(...);
}

Make sure to use cast and not dyn_cast. Do the same with rhsValue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for this change is, Null pointer deference is Undefined behavior. The code you suggesting will behave the same, cast will crash if lhs cannot be casted to Value. But I agree it is better, updated, thank you!

@nhat-nguyen
Copy link
Collaborator

Thank you @parsifal-47! I took a brief look and there are a few style changes that are a bit unfamiliar to myself:

  • unused arguments don't have names but instead use /* name */
  • auto * for pointers

I don't know how common these patterns are, but I think we should probably keep these intact. @red1bluelost Any thoughts?

Another unrelated question: we use clang-format with the llvm style internally but not clang-tidy. What is the main difference between clang-tidy and clang-format? Is it common to use both?

Also I think it would be good to have a github action that automatically checks for style violations.

@parsifal-47
Copy link
Contributor Author

Another unrelated question: we use clang-format with the llvm style internally but not clang-tidy. What is the main difference between clang-tidy and clang-format? Is it common to use both?

clang-format has no static analysis. It doesn't use clang parser, it uses its own lightweight parser which is optimized for formatting, it results in different reading of the code and some engineers do not like it. I was using it multiple projects and can set it up here.

Also I think it would be good to have a github action that automatically checks for style violations.

Yes, I agree, unless the style is checked, it won't be followed. Let me set it up.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants