Skip to content

Commit f263f0d

Browse files
committed
[GR-45047] Handle 0 values in tck division verifier
PullRequest: graalpython/2751
2 parents 0164b80 + 99f97ec commit f263f0d

File tree

11 files changed

+78
-14
lines changed

11 files changed

+78
-14
lines changed

graalpython/com.oracle.graal.python.pegparser.generator/pegjava/java_generator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2021, 2022, Oracle and/or its affiliates.
1+
# Copyright (c) 2021, 2023, Oracle and/or its affiliates.
22
# Copyright (C) 1996-2021 Python Software Foundation
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -374,7 +374,7 @@ def __str__(self) -> str:
374374
}
375375

376376
LICENSE = '''/*
377-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
377+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
378378
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
379379
*
380380
* The Universal Permissive License (UPL), Version 1.0
@@ -904,6 +904,7 @@ def generate(self, filename: str) -> None:
904904
self.print(IMPORTS)
905905
className = os.path.splitext(os.path.basename(self.file.name))[0]
906906
self.print('@SuppressWarnings({"all", "cast"})')
907+
self.print('@SuppressFBWarnings')
907908
self.print("public final class %s extends AbstractParser {" % className)
908909
# Java needs a few fields declarations. Also, we're now in a class
909910
self.level += 1

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/Parser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -54,6 +54,7 @@
5454
import java.util.List;
5555

5656
@SuppressWarnings({"all", "cast"})
57+
@SuppressFBWarnings
5758
public final class Parser extends AbstractParser {
5859

5960
private static final Object[][][] reservedKeywords = new Object[][][]{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.pegparser;
42+
43+
import java.lang.annotation.Retention;
44+
import java.lang.annotation.RetentionPolicy;
45+
46+
@Retention(RetentionPolicy.CLASS)
47+
public @interface SuppressFBWarnings {
48+
/**
49+
* The set of FindBugs
50+
* <a href="http://findbugs.sourceforge.net/bugDescriptions.html">warnings</a> that are to be
51+
* suppressed in annotated element. The value can be a bug category, kind or pattern.
52+
*/
53+
java.lang.String[] value() default {};
54+
}

graalpython/com.oracle.graal.python.tck/src/com/oracle/graal/python/tck/PythonProvider.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public Collection<? extends Snippet> createValueConstructors(Context context) {
172172
"bool:True", BOOL, "True",
173173
"bool:False", BOOL, "False",
174174
"int", INT, "1",
175+
// "int:0", INT, "0", // disabled due to GR-45046
175176
"float", FLOAT, "1.1",
176177
"complex", COMPLEX, "1.0j",
177178
"str", STR, "class pstr(str):\n pass\npstr('hello world')",
@@ -522,8 +523,12 @@ public void accept(SnippetRun snippetRun) throws PolyglotException {
522523
Value par0 = parameters.get(0);
523524
Value par1 = parameters.get(1);
524525

525-
// If anumber/Boolean should be divided, ignore if divisor is Boolean false
526-
if (!par0.isNumber() && !par0.isBoolean() || !par1.isBoolean() || par1.asBoolean()) {
526+
// If a number should be divided by 0 or false, expect an exception
527+
if ((par0.isNumber() || par0.isBoolean()) && (par1.isBoolean() && par1.asBoolean() == false || par1.isNumber() && par1.fitsInInt() && par1.asInt() == 0)) {
528+
if (snippetRun.getException() == null || !snippetRun.getException().getMessage().contains("division by zero")) {
529+
throw new AssertionError("Division by 0 should have raised");
530+
}
531+
} else {
527532
ResultVerifier.getDefaultResultVerifier().accept(snippetRun);
528533
}
529534
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static RootCallTarget getOrCreateCallTarget(PExternalFunctionWrapper sig, Python
447447
return null;
448448
}
449449
nodeKlass = MethKeywordsRoot.class;
450-
rootNodeFunction = doArgAndResultConversion ? l -> new MethKeywordsRoot(l, name, isStatic, sig) : l -> new MethKeywordsRoot(l, name, isStatic);
450+
rootNodeFunction = l -> new MethKeywordsRoot(l, name, isStatic, sig);
451451
break;
452452
case VARARGS:
453453
nodeKlass = MethVarargsRoot.class;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
import com.oracle.graal.python.builtins.objects.PNone;
160160
import com.oracle.graal.python.compiler.OpCodes.CollectionBits;
161161
import com.oracle.graal.python.lib.PyObjectRichCompareBool;
162+
import com.oracle.graal.python.util.SuppressFBWarnings;
162163
import com.oracle.graal.python.pegparser.AbstractParser;
163164
import com.oracle.graal.python.pegparser.ErrorCallback;
164165
import com.oracle.graal.python.pegparser.ErrorCallback.ErrorType;
@@ -3679,6 +3680,7 @@ private BlockInfo.Loop unwindBlockStack(UnwindType type) {
36793680
}
36803681

36813682
@Override
3683+
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH") // info is not null guaranteed by parser
36823684
public Void visit(StmtTy.Break node) {
36833685
setLocation(node);
36843686
setLocation(node);
@@ -3691,6 +3693,7 @@ public Void visit(StmtTy.Break node) {
36913693
}
36923694

36933695
@Override
3696+
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH") // info is not null guaranteed by parser
36943697
public Void visit(StmtTy.Continue node) {
36953698
setLocation(node);
36963699
BlockInfo.Loop info = unwindBlockStack(UnwindType.CONTINUE);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MatchClassNode.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,4 @@ private static boolean contains(VirtualFrame frame, Object[] seen, Object name,
186186
public static MatchClassNode create() {
187187
return MatchClassNodeGen.create();
188188
}
189-
190-
public static MatchClassNode getUncached() {
191-
return MatchClassNodeGen.getUncached();
192-
}
193189
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/AsyncHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.oracle.graal.python.runtime.exception.PException;
7070
import com.oracle.graal.python.util.PythonUtils;
7171
import com.oracle.graal.python.util.Supplier;
72+
import com.oracle.graal.python.util.SuppressFBWarnings;
7273
import com.oracle.truffle.api.CompilerAsserts;
7374
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7475
import com.oracle.truffle.api.RootCallTarget;
@@ -312,6 +313,7 @@ public boolean isInternal() {
312313
* regular intervals to run on a separate thread, or if it will be polled. The caller needs to
313314
* ensure that the AsyncAction passed into this method does not block in the latter case.
314315
*/
316+
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH") // context.get() is never null here
315317
void registerAction(Supplier<AsyncAction> actionSupplier) {
316318
CompilerAsserts.neverPartOfCompilation();
317319
if (ImageInfo.inImageBuildtimeCode() || context.get().getOption(PythonOptions.NoAsyncActions)) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/SuppressFBWarnings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -50,5 +50,5 @@
5050
* <a href="http://findbugs.sourceforge.net/bugDescriptions.html">warnings</a> that are to be
5151
* suppressed in annotated element. The value can be a bug category, kind or pattern.
5252
*/
53-
java.lang.String[] value();
53+
java.lang.String[] value() default {};
5454
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/WeakIdentityHashMap.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -373,6 +373,7 @@ private static int indexFor(int h, int length) {
373373
/**
374374
* Expunges stale entries from the table.
375375
*/
376+
@SuppressFBWarnings(value = "SA_FIELD_SELF_ASSIGNMENT")
376377
private void expungeStaleEntries() {
377378
for (Object x; (x = queue.poll()) != null; ) {
378379
synchronized (queue) {
@@ -838,6 +839,7 @@ private abstract class HashIterator<T> implements Iterator<T> {
838839
index = isEmpty() ? 0 : table.length;
839840
}
840841

842+
@SuppressFBWarnings(value = "SA_FIELD_SELF_ASSIGNMENT")
841843
public boolean hasNext() {
842844
Entry<K,V>[] t = table;
843845

0 commit comments

Comments
 (0)