ahatanak wrote:

Sorry for reporting this over a year after this PR was merged, but we recently 
found a regression it introduced in `-Wunreachable-code`.

The warning fires when there's code following calls to functions annotated with 
`analyzer_noreturn`. The warning is a false positive, as those functions, 
unlike functions annotated with `noreturn`, do return, so code after the calls 
isn't dead code.

For example:

```
extern void Assert(const char *) __attribute__((analyzer_noreturn));
void f(int x) {
  if (x) return;
  Assert("bad");
  use(3); // warning: code will never be executed
}

The change is correct for almost every other analysis and warning. For example, 
it fixes false positives in `-Wreturn-type` and `-Wimplicit-fallthrough`.

Gábor and I discussed two ways to fix it:

1. Have `-Wunreachable-code` consume a different CFG that does not respect the 
attribute. This may cost compile time, since the CFG could be built more than 
once per function.

2. Instead of omitting the edges, add a special "analyzer noreturn" edge or 
marker that each analysis can choose to consume or ignore. This is the 
preferred option.

Does that direction sound right?

https://github.com/llvm/llvm-project/pull/150952
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to