-
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
Initialize adjoints of aggregate types with init lists #1163
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1163 +/- ##
==========================================
+ Coverage 94.55% 94.56% +0.01%
==========================================
Files 51 51
Lines 8919 8947 +28
==========================================
+ Hits 8433 8461 +28
Misses 486 486
|
f29e480
to
8857806
Compare
c429677
to
17786f2
Compare
@@ -4286,6 +4280,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, | |||
if (Expr* customReverseForwFnCall = BuildCallToCustomForwPassFn( | |||
CE->getConstructor(), primalArgs, reverseForwAdjointArgs, | |||
/*baseExpr=*/nullptr)) { | |||
if (RD->isAggregate()) | |||
diag(DiagnosticsEngine::Warning, CE->getBeginLoc(), |
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.
Is here the place where we found the custom forward reverse function and we diagnose we do not need it? If not we should move the check there, and point to the declaration itself with a DiagnosticsEngine::Note
(CE->getDecl()->getBeginLoc()). And of course we should add a test for 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.
I kept the diagnostics in the same place but now the location comes from the declaration. Is it better 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.
We need both a warning on the call site and a note on our he definition. We also need a test.
17786f2
to
c685d4d
Compare
c685d4d
to
95300e1
Compare
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
@@ -418,6 +418,13 @@ namespace clad { | |||
Expr* zero = ConstantFolder::synthesizeLiteral(T, m_Context, /*val=*/0); | |||
return m_Sema.ActOnInitList(noLoc, {zero}, noLoc).get(); | |||
} | |||
if (const auto* RD = T->getAsCXXRecordDecl()) | |||
if (RD->hasDefinition() && !RD->isUnion() && RD->isAggregate()) { | |||
llvm::SmallVector<Expr*, 4> adjParams; |
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: no header providing "llvm::SmallVector" is directly included [misc-include-cleaner]
lib/Differentiator/VisitorBase.cpp:28:
- #include <numeric>
+ #include <llvm/ADT/SmallVector.h>
+ #include <numeric>
if (const auto* RD = T->getAsCXXRecordDecl()) | ||
if (RD->hasDefinition() && !RD->isUnion() && RD->isAggregate()) { | ||
llvm::SmallVector<Expr*, 4> adjParams; | ||
for (const FieldDecl* FD : RD->fields()) |
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: no header providing "clang::FieldDecl" is directly included [misc-include-cleaner]
for (const FieldDecl* FD : RD->fields())
^
clang-tidy review says "All clean, LGTM! 👍" |
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
test/Gradient/UserDefinedTypes.C
Outdated
}}} | ||
|
||
double fn15(double x, double y) { | ||
std::array<double, 2> arr; // expected-warning {{'std::array<double, 2>' is an aggregate type and its constructor does not require a user-defined forward sweep function}} |
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.
This does not need to be a std::array
because we will remove its reverse function. It can be something as simple as an empty class...
d96937c
to
e63086f
Compare
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
@@ -34,7 +34,9 @@ | |||
#include <clang/AST/OperationKinds.h> | |||
#include <clang/Sema/Ownership.h> | |||
|
|||
#include "llvm/ADT/SmallString.h" | |||
#include "llvm/Support/SaveAndRestore.h" |
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: included header SmallString.h is not used directly [misc-include-cleaner]
#include "llvm/Support/SaveAndRestore.h" | |
#include "llvm/Support/SaveAndRestore.h" |
6797990
to
6e4e5a7
Compare
6e4e5a7
to
852b4dc
Compare
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!
With aggregate types, we don't have to rely on the default initialization or custom constructor forward passes to zero-initialize its fields:
This option is incorrect since
_d_x.a
will be initialized to1
:This option could be correct but is just unnecessary:
This PR instead implements a simpler solution: