-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
[Coverage] Let Decision
take account of expansions
#78969
Conversation
I'd be OK going this direction as opposed to #78819, since it doesn't have to scan ahead to add branch regions, but it does add new complexity to the tracking. Can you also post your tests? |
9f97b0b
to
425185c
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.
I have rewritten DecisionRow
and added comments.
Tests are not ready. Please be patient.
: DecisionRegion(&Decision), DecisionStartLoc(Decision.startLoc()), | ||
DecisionEndLoc(Decision.endLoc()) {} | ||
|
||
/// Determine whether `R` is included in `DecisionRegion`. |
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.
Nit:
- Use
\p
or\param
in Doxygen. (http://www.doxygen.jp/commands.html#cmdp) - Backticks unnecessary in Doxygen.
E.g.
\returns true if \p R is included in DecisionRegion
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 haven't written doxygen comments for long time. Please point out any mistakes.
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.
Doxygen comments are not required. I think much new code doesn't use Doxygen...
}); | ||
} | ||
|
||
enum class UpdateResult { |
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 should be documented
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 didn't do since I thought the enums are descriptive.
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.
TODO:
- Revise comments in the latter half
- Construct tests
}); | ||
} | ||
|
||
enum class UpdateResult { |
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 didn't do since I thought the enums are descriptive.
MCDCDecision = &Region; | ||
NumConds = Region.MCDCParams.NumConditions; | ||
// Start recording `Region` as the `Decision` | ||
Decisions.emplace_back(Region); |
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 emplace_back
instead of push_back
?
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 thought it would be made smaller if the constructor has default constructors for SmallVector
.
NumConds = Region.MCDCParams.NumConditions; | ||
// MCDCDecisionRegion should be handled first since it overlaps with | ||
// others inside. | ||
if (MCDCDecisions.registerDecision(Region)) |
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 it reads better if the CounterMappingRegion::MCDCDecisionRegion
guard is moved here. The same applies to MCDCDecisions.processRegion(Region);
I.e. we check different types of Region
here and dispatch actions to MCDCDecisions
.
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 did because of symmetry to processRegion
. I can rework this.
processRegion(const CounterMappingRegion &Region) { | ||
|
||
// Record ExpansionRegion. | ||
if (Region.Kind == CounterMappingRegion::ExpansionRegion) { |
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 it's clearer to move ExpansionRegion
handling to the caller.
This class then doesn't need to check Region.Kind
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 wanted to make MCDCDecisionRecorder
richer, since it simply encapsulated SmallVector<DecisionRecord> Decisions
.
The description is too brief for the involved problem:) Feel free to incorporate my comment #77871 (comment) into the description/commit message. |
Hey everyone. Thanks for this great work! Will you please add this test: #define C c
#define D 1
#define E (C != a) && (C > a)
#define F E
#define G(x) x
void __attribute__((noinline)) func1(void) { return; }
void __attribute__((noinline)) func(int a, int b, int c) {
if (a && D && E || b)
func1();
if (b && D)
func1();
if (a && (b && C) || (D && F))
func1();
if (G(a) && G(b))
func1();
}
int main() {
func(2, 3, 3);
return 0;
} Currently it doesn't seem to work on my side. I'm also glad to investigate that. Revise: I further minimize the problematic |
I think this is correct, but the consumer side complexity makes me wonder whether the additional complexity makes our "boring algorithm" overall worse than GCC https://gcc.gnu.org/pipermail/gcc-patches/2024-January/644269.html (From https://maskray.me/blog/2024-01-28-mc-dc-and-compiler-implementations) Pros:
Cons:
|
@whentojump Could you try #78966, too?
What about "this"? |
From the perspective of embedded, I think it makes more sense to keep the instrumentation light and off-load processing in llvm-cov. Also, I think we can look at better modularization of metadata sections (I.e. keeping them in the executable but out of what is loaded in memory, which is what we do downstream and was discussed at the last Developers' meeting embedded workshop). Even going beyond six conditions isn't that bad, but I don't think 32 conditions (as mentioned in GCC context) is at all typical, especially in embedded context. I know we want this to work outside of embedded as well, but we also have to keep in mind when MC/DC is not only useful but practical to fulfill. Conceivably (just thinking out loud) we may also be able to enable different modes that balance the tradeoffs differently between the different algorithms. |
These two PRs combined worked smoothly for my case. Thanks a lot! |
Decision
take account of expansions
The current implementation (D138849) assumes `Branch`(es) would follow after the corresponding `Decision`. It is not true if `Branch`(es) are forwarded to expanded file ID. As a result, consecutive `Decision`(s) would be confused with insufficient number of `Branch`(es). `Expansion` will point `Branch`(es) in other file IDs if `Expansion` is included in the range of `Decision`. Fixes llvm#77871 --------- Co-authored-by: Alan Phipps <a-phipps@ti.com> (cherry picked from commit d912f1f)
The current implementation (D138849) assumes `Branch`(es) would follow after the corresponding `Decision`. It is not true if `Branch`(es) are forwarded to expanded file ID. As a result, consecutive `Decision`(s) would be confused with insufficient number of `Branch`(es). `Expansion` will point `Branch`(es) in other file IDs if `Expansion` is included in the range of `Decision`. Fixes llvm#77871 --------- Co-authored-by: Alan Phipps <a-phipps@ti.com> (cherry picked from commit d912f1f)
The current implementation (D138849) assumes `Branch`(es) would follow after the corresponding `Decision`. It is not true if `Branch`(es) are forwarded to expanded file ID. As a result, consecutive `Decision`(s) would be confused with insufficient number of `Branch`(es). `Expansion` will point `Branch`(es) in other file IDs if `Expansion` is included in the range of `Decision`. Fixes llvm#77871 --------- Co-authored-by: Alan Phipps <a-phipps@ti.com>
The current implementation (D138849) assumes `Branch`(es) would follow after the corresponding `Decision`. It is not true if `Branch`(es) are forwarded to expanded file ID. As a result, consecutive `Decision`(s) would be confused with insufficient number of `Branch`(es). `Expansion` will point `Branch`(es) in other file IDs if `Expansion` is included in the range of `Decision`. Fixes llvm#77871 --------- Co-authored-by: Alan Phipps <a-phipps@ti.com> (cherry picked from commit d912f1f)
The current implementation (D138849) assumes `Branch`(es) would follow after the corresponding `Decision`. It is not true if `Branch`(es) are forwarded to expanded file ID. As a result, consecutive `Decision`(s) would be confused with insufficient number of `Branch`(es). `Expansion` will point `Branch`(es) in other file IDs if `Expansion` is included in the range of `Decision`. Fixes llvm#77871 --------- Co-authored-by: Alan Phipps <a-phipps@ti.com> (cherry picked from commit d912f1f)
The current implementation (D138849) assumes `Branch`(es) would follow after the corresponding `Decision`. It is not true if `Branch`(es) are forwarded to expanded file ID. As a result, consecutive `Decision`(s) would be confused with insufficient number of `Branch`(es). `Expansion` will point `Branch`(es) in other file IDs if `Expansion` is included in the range of `Decision`. Fixes llvm#77871 --------- Co-authored-by: Alan Phipps <a-phipps@ti.com> (cherry picked from commit d912f1f)
The current implementation (D138849) assumes `Branch`(es) would follow after the corresponding `Decision`. It is not true if `Branch`(es) are forwarded to expanded file ID. As a result, consecutive `Decision`(s) would be confused with insufficient number of `Branch`(es). `Expansion` will point `Branch`(es) in other file IDs if `Expansion` is included in the range of `Decision`. Fixes llvm#77871 --------- Co-authored-by: Alan Phipps <a-phipps@ti.com> (cherry picked from commit d912f1f)
The current implementation (D138849) assumes
Branch
(es) would follow after the correspondingDecision
. It is not true ifBranch
(es) are forwarded to expanded file ID. As a result, consecutiveDecision
(s) would be confused with insufficient number ofBranch
(es).Expansion
will pointBranch
(es) in other file IDs ifExpansion
is included in the range ofDecision
.Fixes #77871