Skip to content

Commit ac8e92e

Browse files
authored
Merge pull request #15264 from github/max-schaefer/automodel-exclude-generated-calls
Automodel: Do not generate features for compiler-generated program elements.
2 parents 77b0c7f + 9b7cfd8 commit ac8e92e

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

+10-2
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,31 @@ newtype JavaRelatedLocationType =
2626

2727
newtype TApplicationModeEndpoint =
2828
TExplicitArgument(Call call, DataFlow::Node arg) {
29+
AutomodelJavaUtil::isFromSource(call) and
2930
exists(Argument argExpr |
3031
arg.asExpr() = argExpr and call = argExpr.getCall() and not argExpr.isVararg()
3132
)
3233
} or
3334
TInstanceArgument(Call call, DataFlow::Node arg) {
34-
arg = DataFlow::getInstanceArgument(call) and not call instanceof ConstructorCall
35+
AutomodelJavaUtil::isFromSource(call) and
36+
arg = DataFlow::getInstanceArgument(call) and
37+
not call instanceof ConstructorCall
3538
} or
3639
TImplicitVarargsArray(Call call, DataFlow::Node arg, int idx) {
40+
AutomodelJavaUtil::isFromSource(call) and
3741
exists(Argument argExpr |
3842
arg.asExpr() = argExpr and
3943
call.getArgument(idx) = argExpr and
4044
argExpr.isVararg() and
4145
not exists(int i | i < idx and call.getArgument(i).(Argument).isVararg())
4246
)
4347
} or
44-
TMethodReturnValue(Call call) { not call instanceof ConstructorCall } or
48+
TMethodReturnValue(Call call) {
49+
AutomodelJavaUtil::isFromSource(call) and
50+
not call instanceof ConstructorCall
51+
} or
4552
TOverriddenParameter(Parameter p, Method overriddenMethod) {
53+
AutomodelJavaUtil::isFromSource(p) and
4654
not p.getCallable().callsConstructor(_) and
4755
p.getCallable().(Method).overrides(overriddenMethod)
4856
}

java/ql/automodel/src/AutomodelFrameworkModeCharacteristics.qll

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,33 @@ newtype JavaRelatedLocationType =
2525

2626
newtype TFrameworkModeEndpoint =
2727
TExplicitParameter(Parameter p) {
28+
AutomodelJavaUtil::isFromSource(p) and
2829
not p.getType() instanceof PrimitiveType and
2930
not p.getType() instanceof BoxedType and
3031
not p.getType() instanceof NumberType
3132
} or
32-
TQualifier(Callable c) { not c instanceof Constructor } or
33+
TQualifier(Callable c) { AutomodelJavaUtil::isFromSource(c) and not c instanceof Constructor } or
3334
TReturnValue(Callable c) {
35+
AutomodelJavaUtil::isFromSource(c) and
3436
c instanceof Constructor
3537
or
38+
AutomodelJavaUtil::isFromSource(c) and
3639
c instanceof Method and
3740
(
3841
not c.getReturnType() instanceof VoidType and
3942
not c.getReturnType() instanceof PrimitiveType
4043
)
4144
} or
4245
TOverridableParameter(Method m, Parameter p) {
46+
AutomodelJavaUtil::isFromSource(p) and
4347
p.getCallable() = m and
4448
m instanceof ModelExclusions::ModelApi and
4549
not m.getDeclaringType().isFinal() and
4650
not m.isFinal() and
4751
not m.isStatic()
4852
} or
4953
TOverridableQualifier(Method m) {
54+
AutomodelJavaUtil::isFromSource(m) and
5055
m instanceof ModelExclusions::ModelApi and
5156
not m.getDeclaringType().isFinal() and
5257
not m.isFinal() and

java/ql/automodel/src/AutomodelJavaUtil.qll

+18
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,21 @@ predicate includeAutomodelCandidate(string package, string type, string name, st
8282
not automodelCandidateFilter(_, _, _, _) or
8383
automodelCandidateFilter(package, type, name, signature)
8484
}
85+
86+
/**
87+
* Holds if the given program element corresponds to a piece of source code,
88+
* that is, it is not compiler-generated.
89+
*
90+
* Note: This is a stricter check than `Element::fromSource`, which simply
91+
* checks whether the element is in a source file as opposed to a JAR file.
92+
* There can be compiler-generated elements in source files (especially for
93+
* Kotlin), which we also want to exclude.
94+
*/
95+
predicate isFromSource(Element e) {
96+
// from a source file (not a JAR)
97+
e.fromSource() and
98+
// not explicitly marked as compiler-generated
99+
not e.isCompilerGenerated() and
100+
// does not have a dummy location
101+
not e.hasLocationInfo(_, 0, 0, 0, 0)
102+
}

0 commit comments

Comments
 (0)