[clang] Reapply "[Analyzer][CFG] Correctly handle rebuilt default arg and default init expression" (PR #127338)
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 20 11:39:34 PST 2025
nico wrote:
Thanks for the warning! It's a cool feature, but the diagnostic is IMHO not super great at the moment.
I'm doing the cleanup for the warning in Chromium at the moment, and here's an example that's now analyzed (from <https://source.chromium.org/chromium/chromium/src/+/main:net/dns/httpssvc_metrics.cc;l=25?q=httpssvc_metrics>):
```
enum HttpssvcDnsRcode TranslateDnsRcodeForHttpssvcExperiment(uint8_t rcode) {
switch (rcode) {
case dns_protocol::kRcodeNOERROR:
return HttpssvcDnsRcode::kNoError;
case dns_protocol::kRcodeFORMERR:
return HttpssvcDnsRcode::kFormErr;
case dns_protocol::kRcodeSERVFAIL:
return HttpssvcDnsRcode::kServFail;
case dns_protocol::kRcodeNXDOMAIN:
return HttpssvcDnsRcode::kNxDomain;
case dns_protocol::kRcodeNOTIMP:
return HttpssvcDnsRcode::kNotImp;
case dns_protocol::kRcodeREFUSED:
return HttpssvcDnsRcode::kRefused;
default:
return HttpssvcDnsRcode::kUnrecognizedRcode;
}
NOTREACHED();
}
```
Here's the diagnostic:
```
[4890/84790] CXX obj/net/dns/dns/httpssvc_metrics.o
In file included from ../../net/dns/httpssvc_metrics.cc:5:
In file included from ../../net/dns/httpssvc_metrics.h:13:
In file included from ../../base/containers/flat_set.h:12:
In file included from ../../base/containers/flat_tree.h:19:
../../base/check.h:200:11: warning: code will never be executed [-Wunreachable-code]
200 | base::Location::CurrentWithoutFunctionName());
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
```
It points to somewhere in the implementation of `NOTREACHED()`. It does not mention where the invocation of that macro that causes the diagnostic is. (At least it prints the right cc file, but not where in that file I'm supposed to look.)
https://github.com/llvm/llvm-project/pull/127338
More information about the cfe-commits
mailing list