zequanwu added inline comments.

================
Comment at: clang/lib/Sema/AnalysisBasedWarnings.cpp:1518
   UsesMap uses;
+  UsesMap constRefUses;
 
----------------
rnk wrote:
> If possible, it would be nice to avoid having a second map.
I use second map to let the new warning be orthogonal to existing warnings. 
That means when we have both `-Wuninitialized` and 
`-Wno-uninitialized-const-reference`, the old test cases about uninitialized 
variables should all passed. Otherwise, I need to somehow detect the presence 
of `-Wno-uninitialized-const-reference`, which I don't see a way to do that. 
Consider this code if we have only one map:
```
void consume_const_ref(const int &n);
int test_const_ref() {
  int n;
  consume_const_ref(n);
  return n;
}
```
No matter if the flag`-Wno-uninitialized-const-reference` is present or not, we 
still need to add `n` in `consume_const_ref(n);` to `uses` map and then let 
`S.Diag` to decide to diagnose it or not depend on the presence of 
`-Wno-uninitialized-const-reference`. If the flag is given, `S.Diag` will just 
ignore the warning, but uninit var warning will diagnose if `Use.getKind()` 
returns `Always` in 
https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/AnalysisBasedWarnings.cpp#L814
 . That is not desired. Since the original behavior is to ignore the `n` in 
`consume_const_ref(n);` by not adding it to the `uses` map.

If there is a way to detect the presence of 
`-Wno-uninitialized-const-reference` or to know if `Sema::Diag(SourceLocation 
Loc, unsigned DiagID)` actually diagnosed a warning, the use of second map can 
be avoid. 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79895/new/

https://reviews.llvm.org/D79895



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to