Skip to content

Fix clktreedelay crash#9839

Open
openroad-ci wants to merge 6 commits intoThe-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:fix_clktreedelay_crash
Open

Fix clktreedelay crash#9839
openroad-ci wants to merge 6 commits intoThe-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:fix_clktreedelay_crash

Conversation

@openroad-ci
Copy link
Collaborator

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
@gemini-code-assist
Copy link
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

Copy link
Contributor

@github-actions github-actions bot left a 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

insDelay = (rise + fall) / 2.0;
insDelay = (rise != 0 && fall != 0)
? (rise + fall) / 2.0
: (rise != 0 ? rise : fall);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                                 : (rise != 0 ? rise : fall);
                                    ^
Additional context

src/cts/src/LatencyBalancer.cpp:201: parent conditional operator here

                  insDelay = (rise != 0 && fall != 0)
                             ^

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a simple ternary operator and no need for another variable to store intermediate results

if (rise != 0 || fall != 0) {
insDelay = (rise + fall) / 2.0;
insDelay = (rise != 0 && fall != 0) ? (rise + fall) / 2.0
: (rise != 0 ? rise : fall);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                                                    : (rise != 0 ? rise : fall);
                                                       ^
Additional context

src/cts/src/LatencyBalancer.cpp:345: parent conditional operator here

                insDelay = (rise != 0 && fall != 0) ? (rise + fall) / 2.0
                           ^

double delayPerSec = (rise + fall) / 2.0;
double delayPerSec = (rise != 0 && fall != 0)
? (rise + fall) / 2.0
: (rise != 0 ? rise : fall);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                                 : (rise != 0 ? rise : fall);
                                    ^
Additional context

src/cts/src/TritonCTS.cpp:2205: parent conditional operator here

        double delayPerSec = (rise != 0 && fall != 0)
                             ^

ins_delay = (rise + fall) / 2.0;
}
(rise != 0 && fall != 0) ? (rise + fall) / 2.0
: (rise != 0 ? rise : fall);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                                   : (rise != 0 ? rise : fall);
                                      ^
Additional context

src/gui/src/clockWidget.cpp:1340: parent conditional operator here

          (rise != 0 && fall != 0) ? (rise + fall) / 2.0
          ^

ins_delay = (rise + fall) / 2.0;
}
(rise != 0 && fall != 0) ? (rise + fall) / 2.0
: (rise != 0 ? rise : fall);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: expression result unused [clang-diagnostic-unused-value]

                                   : (rise != 0 ? rise : fall);
                                                         ^

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
@dsengupta0628
Copy link
Contributor

/gemini review

Copy link
Contributor

@github-actions github-actions bot left a 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

ins_delay = (rise + fall) / 2.0;
}
ins_delay = (rise != 0 && fall != 0) ? (rise + fall) / 2.0
: (rise != 0 ? rise : fall);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                                               : (rise != 0 ? rise : fall);
                                                  ^
Additional context

src/gui/src/clockWidget.cpp:1340: parent conditional operator here

          ins_delay = (rise != 0 && fall != 0) ? (rise + fall) / 2.0
                      ^

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request consistently updates the calculation of insertion delays across multiple files. The change introduces a ternary operator to handle cases where either rise or fall delay might be zero, ensuring that if only one is non-zero, that value is used directly instead of averaging with zero. If both are non-zero, they are averaged. This makes the delay calculation more robust and explicit, preventing potential misinterpretations of delay values when one component is absent. The change also improves code conciseness in clockWidget.cpp by removing a redundant if condition.

Comment on lines +202 to +204
insDelay = (rise != 0 && fall != 0)
? (rise + fall) / 2.0
: (rise != 0 ? rise : fall);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The updated logic for insDelay correctly handles scenarios where either rise or fall might be zero. This prevents averaging with a zero value when only one valid delay is present, making the calculation more robust and accurate.

Comment on lines +346 to +347
insDelay = (rise != 0 && fall != 0) ? (rise + fall) / 2.0
: (rise != 0 ? rise : fall);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This change improves the robustness of the insDelay calculation by explicitly handling cases where rise or fall might be zero. If only one is non-zero, that value is used directly, which is a more accurate representation than averaging with zero.

Comment on lines +2206 to +2208
double delayPerSec = (rise != 0 && fall != 0)
? (rise + fall) / 2.0
: (rise != 0 ? rise : fall);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The modification to delayPerSec calculation ensures that if only one of rise or fall is non-zero, that specific value is used. This is a good improvement for correctness and clarity, as it avoids diluting a valid delay with a zero value.

Comment on lines +1341 to +1342
ins_delay = (rise != 0 && fall != 0) ? (rise + fall) / 2.0
: (rise != 0 ? rise : fall);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This change streamlines the ins_delay calculation by directly using the ternary operator, removing the redundant if condition. The logic remains correct, as ins_delay will be 0.0 if both rise and fall are zero, and will use the single non-zero value if only one is present, or their average if both are non-zero. This improves code conciseness and readability.

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
Copy link
Contributor

@github-actions github-actions bot left a 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

insDelay
= (rise != 0 && fall != 0)
? (rise + fall) / 2.0
: (rise != 0
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                            : (rise != 0
                               ^
Additional context

src/cts/src/LatencyBalancer.cpp:202: parent conditional operator here

                      = (rise != 0 && fall != 0)
                        ^

insDelay
= (rise != 0 && fall != 0)
? (rise + fall) / 2.0
: (rise != 0
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                          : (rise != 0
                             ^
Additional context

src/cts/src/LatencyBalancer.cpp:349: parent conditional operator here

                    = (rise != 0 && fall != 0)
                      ^

double delayPerSec
= (rise != 0 && fall != 0)
? (rise + fall) / 2.0
: (rise != 0
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                  : (rise != 0
                     ^
Additional context

src/cts/src/TritonCTS.cpp:2206: parent conditional operator here

            = (rise != 0 && fall != 0)
              ^

ins_delay
= (rise != 0 && fall != 0)
? (rise + fall) / 2.0
: (rise != 0
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                    : (rise != 0
                       ^
Additional context

src/gui/src/clockWidget.cpp:1341: parent conditional operator here

              = (rise != 0 && fall != 0)
                ^

@dsengupta0628
Copy link
Contributor

@maliberty
Copy link
Member

Fix rather than NOLINT as it isn't terribly readable.

Signed-off-by: dsengupta0628 <dsengupta@precisioninno.com>
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Member

@maliberty maliberty left a comment

Choose a reason for hiding this comment

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

code looks fine

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