https://bugs.llvm.org/show_bug.cgi?id=39043
Bug ID: 39043
Summary: recognize when switch statement is used to implement
goto
Product: new-bugs
Version: 7.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
gcc can correctly optimize this code ( https://godbolt.org/z/1GEhQV ), but
clang cannot: This optimization is important when using goto to build a state
machine, or in the zig and rust languages, which lack goto. In these languages
goto can be implemented with a switch statement, an enum, and continue, but
only correctly if this optimization is done.
#include <stdbool.h>
#include <stdio.h>
enum states {
one,
two,
three,
};
void gotoexample(unsigned char num) {
enum states state = one;
while (true) {
switch (state) {
case one: {
state = two;
break;
} case two: {
state = three;
break;
} case three: {
puts("foo");
return;
}
}
}
}
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs