llvm-project/clang/test/Sema/warn-unreachable-ms.c
Nico Weber 699670e764 Implement CFG construction for __try / __except / __leave.
This makes -Wunreachable-code work for programs containing SEH (except for
__finally, which is still missing for now).

__try is modeled like try (but simpler since it can only have a single __except
or __finally), __except is fairly similar to catch (but simpler, since it can't
contain declarations). __leave is implemented similarly to break / continue.

Use the existing addTryDispatchBlock infrastructure (which
FindUnreachableCode() in ReachableCode.cpp uses via cfg->try_blocks_begin()) to
mark things in the __except blocks as reachable.

Re-use TryTerminatedBlock. This means we add EH edges from calls to the __try
block, but not from all other statements. While this is incomplete, it matches
LLVM's SEH codegen support. Also, in practice, BuildOpts.AddEHEdges is always
false in practice from what I can tell, so we never even insert the call EH
edges either.

https://reviews.llvm.org/D36914

llvm-svn: 311561
2017-08-23 15:33:16 +00:00

56 lines
919 B
C

// RUN: %clang_cc1 %s -triple=i686-pc-win32 -fsyntax-only -verify -fms-extensions -Wunreachable-code
void f();
void g1() {
__try {
f();
__leave;
f(); // expected-warning{{will never be executed}}
} __except(1) {
f();
}
// Completely empty.
__try {
} __except(1) {
}
__try {
f();
return;
} __except(1) { // Filter expression should not be marked as unreachable.
// Empty __except body.
}
}
void g2() {
__try {
// Nested __try.
__try {
f();
__leave;
f(); // expected-warning{{will never be executed}}
} __except(2) {
}
f();
__leave;
f(); // expected-warning{{will never be executed}}
} __except(1) {
f();
}
}
void g3() {
__try {
__try {
f();
} __except (1) {
__leave; // should exit outer try
}
__leave;
f(); // expected-warning{{never be executed}}
} __except (1) {
}
}