-
Notifications
You must be signed in to change notification settings - Fork 123
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
Fix the generation of invalid code in some common cases #1088
Conversation
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.
clang-tidy made some suggestions
lib/Differentiator/VisitorBase.cpp
Outdated
CSS.Extend(m_Context, NS, noLoc, noLoc); | ||
} else if (NNS->getKind() == NestedNameSpecifier::TypeSpec) { | ||
const Type* T = NNS->getAsType(); | ||
if (auto* RT = const_cast<RecordType*>(T->getAs<RecordType>())) { |
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.
warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast]
if (auto* RT = const_cast<RecordType*>(T->getAs<RecordType>())) {
^
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1088 +/- ##
==========================================
+ Coverage 94.21% 94.23% +0.01%
==========================================
Files 48 48
Lines 8131 8158 +27
==========================================
+ Hits 7661 7688 +27
Misses 470 470
|
lib/Differentiator/VisitorBase.cpp
Outdated
|
||
std::reverse(NNChain.begin(), NNChain.end()); | ||
|
||
for (auto& n : NNChain) { |
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.
I am wondering if we can't use (or draw inspiration from) https://github.com/llvm-mirror/clang/blob/aa231e4be75ac4759c236b755c57876f76e3cf05/lib/AST/QualTypeNames.cpp#L211
EDIT: That's the right link: https://github.com/llvm/llvm-project/blob/b06954a5d02a41a38b72f7914c791428ccd95318/clang/lib/AST/QualTypeNames.cpp#L214
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.
I saw it but I didn't dive deep into reading it, since I'd thought it's unrelated, cos it's about type names only.
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 routine is practically the same and more complete to what we are trying to do here. It’s not possible to call it though. Maybe we should at least add a fixme and refer to it as a potential place to steal code from. It has a lot of tests and presumably should work more reliably.
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.
alright, a fixme sounds fair. I'll also try to maybe incorporate some more things from it
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.
clang-tidy made some suggestions
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.
clang-tidy made some suggestions
@vgvassilev thanks for the rebase! I'm still working on fixing the last check, seems that it hasn't been affected that much |
@vgvassilev it finally passed all the checks, I'm just going to squash everything now |
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 address the clang-tidy comments?
test/ValidCodeGen/ValidCodeGen.C
Outdated
@@ -0,0 +1,80 @@ | |||
// XFAIL: asserts |
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.
Why do we fail in debug builds here?
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.
I think I just forgot to remove this line. thanks for pointing it out. it should be fine, but let's wait for the checks to pass
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.
oh, seems like it was actually doing something, now I remember. unfortunately, the debug build is very picky. I have a couple of FIXME messages in that place and once they are addressed the XFAIL line can be removed.
the problem is that inside Clang they're using locations to build these nested names, while I'm using other things here, since we don't really have valid locations to provide to those Clang methods (providing valid locations from the original source code doesn't seem to work here). my approach works for nested names with namespace and basic class names, but the debug build runs into some asserts if you try to extend a CXXScopeSpec with a class name this way.
I can remove the XFAIL and update the tests so that they don't contain a class name in the nested name specifier chain and then open another separate issue for this case. does that sound good? or we can just not flag the issue #1050 as solved in this PR and update it to say that it's only partially solved.
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.
Maybe update the tests and remove the xfail flag. Then we can adjust them back when fixing the issue #1050.
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.
@vgvassilev all done. the checks have passed
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.
clang-tidy made some suggestions
@@ -2167,6 +2170,28 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, | |||
utils::BuildMemberExpr(m_Sema, getCurrentScope(), callRes, "adjoint"); | |||
return StmtDiff(resValue, resAdjoint, resAdjoint); | |||
} // Recreate the original call expression. | |||
|
|||
if (const auto* OCE = dyn_cast<CXXOperatorCallExpr>(CE)) { | |||
auto* FD = const_cast<CXXMethodDecl*>( |
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.
warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast]
auto* FD = const_cast<CXXMethodDecl*>(
^
d47e2b7
to
82a6527
Compare
This commit fixes the way Clad generates code. Specifically, it addresses the way operators appear in the generated code in the reverse mode and the way nested name qualifiers are built in both modes. This partially f ixes vgvassilev#1050. Fixes: vgvassilev#1087
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!
This commit fixes the way Clad generates code. Specifically, it addresses the way operators appear in the generated code in the reverse mode and the way nested name qualifiers are built in both modes. This includes a partial fix to #1050.
Fixes: #1087