Visitar URL original
Java: Deprecate `PrimitiveType.getADefaultValue()` by Marcono1234 · Pull Request #6796 · github/codeql · GitHub
The Wayback Machine - https://web.archive.org/web/20211025233224/https://github.com/github/codeql/pull/6796
Skip to content
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

Java: Deprecate PrimitiveType.getADefaultValue() #6796

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

@Marcono1234
Copy link
Contributor

@Marcono1234 Marcono1234 commented Oct 2, 2021

Resolves #6615

See #6615 (comment)

smowton
smowton approved these changes Oct 5, 2021
or
// The default value for primitive types.
init = t.(PrimitiveType).getADefaultValue()
isDefaultValueLiteral(init, t)
Copy link
Contributor

@aschackmull aschackmull Oct 5, 2021

This looks dodgy from a performance point-of-view. Not as much the code change, but rather, this already looked dodgy before the change. So since it probably worked then it's likely that this depends on decent magic, and the changed code will still depend on magic, but since this isn't a certainty, we should verify this before merging (or update the code to not be so full of cartesian products).

Copy link
Contributor

@aschackmull aschackmull Oct 5, 2021

I'm ok with merging if we can verify that the optimiser pushes relevant magic into both predicates to eliminate the CPs.

@@ -27,13 +27,24 @@ predicate flowStep(Expr decl, Expr init) {
decl.(CastExpr).getExpr() = init
}

predicate isDefaultValueLiteral(Literal l, Type t) {
Copy link
Contributor

@smowton smowton Oct 5, 2021

To resolve the cartesian product worry (all reftypes X all nulls), how about just omitting the Type column? This could be just:

Don't flag Expr e if e is (a) null, (b) zero, or (c) of integral type and negative one. Note this actually expands the query slightly to permit Integer i = 0;, but considering we already permit Integer i = -1; then we should probably accept that anyhow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants