Skip to content

Commit 3e8775d

Browse files
author
Max Schaefer
committed
Automodel: Do not generate features for compiler-generated program elements.
These have dummy locations, which breaks certain invariants that break downstream processing.
1 parent 1b9f59e commit 3e8775d

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

Lines changed: 10 additions & 2 deletions
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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,14 @@ 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+
predicate isFromSource(Element e) {
91+
// not explicitly marked as compiler-generated
92+
not e.isCompilerGenerated() and
93+
// does not have a dummy location
94+
not e.hasLocationInfo(_, 0, 0, 0, 0)
95+
}

0 commit comments

Comments
 (0)