Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.
/ jdk22u Public archive

Commit 457526d

Browse files
biboudisVicente Romero
authored and
Vicente Romero
committedFeb 15, 2024
8314275: Incorrect stepping in switch
Backport-of: e3dc6a7a28c4f049eb234c5487fca6c54298aa31
1 parent 2b247d0 commit 457526d

File tree

2 files changed

+84
-0
lines changed
  • src/jdk.compiler/share/classes/com/sun/tools/javac/jvm
  • test/langtools/tools/javac/classfiles/attributes/LineNumberTable

2 files changed

+84
-0
lines changed
 

‎src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java

+5
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,11 @@ private void handleSwitch(JCTree swtch, JCExpression selector, List<JCCase> case
14281428
code.put4(caseidx + 4, offsets[i]);
14291429
}
14301430
}
1431+
1432+
if (swtch instanceof JCSwitchExpression) {
1433+
// Emit line position for the end of a switch expression
1434+
code.statBegin(TreeInfo.endPos(swtch));
1435+
}
14311436
}
14321437
code.endScopes(limit);
14331438
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2024, 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+
/**
24+
* @test
25+
* @bug 8314275
26+
* @summary Tests a line number table attribute for switch expression
27+
* @library /tools/lib /tools/javac/lib ../lib
28+
* @enablePreview
29+
* @modules jdk.compiler/com.sun.tools.javac.api
30+
* jdk.compiler/com.sun.tools.javac.main
31+
* jdk.compiler/com.sun.tools.javac.util
32+
* java.base/jdk.internal.classfile.impl
33+
* @build toolbox.ToolBox InMemoryFileManager TestBase
34+
* @build LineNumberTestBase TestCase
35+
* @run main T8314275
36+
*/
37+
import java.util.List;
38+
public class T8314275 extends LineNumberTestBase {
39+
public static void main(String[] args) throws Exception {
40+
new T8314275().test();
41+
}
42+
43+
public void test() throws Exception {
44+
test(List.of(TEST_CASE));
45+
}
46+
47+
private static final TestCase[] TEST_CASE = new TestCase[] {
48+
new TestCase("""
49+
public class T8314275Expression { // 1
50+
private static double multiply(Integer i) { // 2
51+
double cr = 15; // 3
52+
cr = switch (i) { // 4
53+
case 1 -> cr * 1; // 5
54+
case 2 -> cr * 2; // 6
55+
default -> cr * 4; // 7
56+
}; // 8
57+
return cr; // 9
58+
} //10
59+
} //11
60+
""",
61+
List.of(1, 3, 4, 5, 6, 7, 8, 9),
62+
"T8314275Expression"),
63+
new TestCase("""
64+
public class T8314275Statement { // 1
65+
private static double multiply(Integer i) { // 2
66+
double cr = 15; // 3
67+
switch (i) { // 4
68+
case 1: cr *= 1; break; // 5
69+
case 2: cr *= 2; break; // 6
70+
default: cr *= 4; // 7
71+
}; // 8
72+
return cr; // 9
73+
} //10
74+
} //11
75+
""",
76+
List.of(1, 3, 4, 5, 6, 7, 9),
77+
"T8314275Statement")
78+
};
79+
}

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Feb 15, 2024

@openjdk-notifier[bot]
This repository has been archived.