-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: main
Are you sure you want to change the base?
Conversation
lib/Analysis/OpFoldResultUtils.cpp
Outdated
@@ -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())); |
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.
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
.
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.
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!
Thank you @parsifal-47! I took a brief look and there are a few style changes that are a bit unfamiliar to myself:
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. |
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.
Yes, I agree, unless the style is checked, it won't be followed. Let me set it up. |
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!