Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/BadLongOverflowSpecializationTest.java @ 18221:2c68474cc893
Truffle: add a test to track an ImplicitCast bug
author | Benoit Daloze <benoit.daloze@jku.at> |
---|---|
date | Fri, 31 Oct 2014 10:44:05 +0100 |
parents | |
children | eecda5abf627 |
comparison
equal
deleted
inserted
replaced
18220:890d284b2771 | 18221:2c68474cc893 |
---|---|
1 /* | |
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.dsl.test; | |
24 | |
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; | |
26 import static org.junit.Assert.*; | |
27 | |
28 import java.math.*; | |
29 | |
30 import org.junit.*; | |
31 | |
32 import com.oracle.truffle.api.*; | |
33 import com.oracle.truffle.api.dsl.*; | |
34 import com.oracle.truffle.api.dsl.test.BadLongOverflowSpecializationTestFactory.AddNodeFactory; | |
35 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; | |
36 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; | |
37 | |
38 public class BadLongOverflowSpecializationTest { | |
39 | |
40 @NodeChildren({@NodeChild("left"), @NodeChild("right")}) | |
41 abstract static class BinaryNode extends ValueNode { | |
42 } | |
43 | |
44 abstract static class AddNode extends BinaryNode { | |
45 @Specialization(rewriteOn = ArithmeticException.class) | |
46 int add(int left, int right) { | |
47 return ExactMath.addExact(left, right); | |
48 } | |
49 | |
50 @Specialization | |
51 long addIntWithOverflow(int left, int right) { | |
52 return (long) left + (long) right; | |
53 } | |
54 | |
55 @Specialization(rewriteOn = ArithmeticException.class) | |
56 Object add(long left, long right) { | |
57 return ExactMath.addExact(left, right); | |
58 } | |
59 | |
60 @Specialization | |
61 BigInteger addSlow(long left, long right) { | |
62 return BigInteger.valueOf(left).add(BigInteger.valueOf(right)); | |
63 } | |
64 } | |
65 | |
66 @Test | |
67 @Ignore | |
68 public void testAdd() { | |
69 TestRootNode<AddNode> node = createRoot(AddNodeFactory.getInstance()); | |
70 | |
71 long index = -1; | |
72 int baseStep = 0; | |
73 Object r1 = executeWith(node, index, baseStep); | |
74 assertEquals(-1L, r1); | |
75 | |
76 long err = 5000; | |
77 long errStep = 2000; | |
78 Object r2 = executeWith(node, err, errStep); | |
79 | |
80 assertEquals(Long.class, r2.getClass()); | |
81 assertEquals(7000L, r2); | |
82 } | |
83 } |