[cfe-dev] False positive for -Wunreachable-code
Tom Care
tcare at apple.com
Tue Aug 3 10:30:55 PDT 2010
-Wunreachable-code works by looking for CFG blocks without predecessors. If we compare the two attached CFGs, we can see that when the destructor is present there is an extra 'unreachable' block that starts with the throw statement. I'm guessing this has to do with the implementation of C++ destructors and exceptions (implicit destructor call?), but I'm not an expert in this area. I'll let someone with more C++ CFG knowledge confirm.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CFG-with-destructor.dot
Type: application/msword
Size: 645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100803/c8e7adbd/attachment.dot>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CFG-without-destructor.dot
Type: application/msword
Size: 542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100803/c8e7adbd/attachment-0001.dot>
-------------- next part --------------
On Aug 3, 2010, at 8:22 AM, Abramo Bagnara wrote:
>
> The following typescript shows that clang incorrectly seems to mark as
> unreachable a throw of a temporary.
>
> Please note that if I remove the destructor of struct s, no warning is
> generated.
>
> $ cat w.cc
> struct s {
> explicit s() { }
> ~s() { }
> };
>
> int f_bad(int x) {
> if (x)
> throw s();
> return 0;
> }
>
> int f_good(int x) {
> if (x) {
> s e;
> throw e;
> }
> return 0;
> }
> $ llvm/Debug+Asserts/bin/clang++ -Wunreachable-code -c w.cc
> w.cc:8:5: warning: will never be executed [-Wunreachable-code]
> throw s();
> ^~~~~~~~~
> 1 warning generated.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list