[clang] 7096e04 - [Sema] Use isAlwaysUninit for -Wuninitialized-const-reference after D79895

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 2 11:25:24 PDT 2020


Author: Fangrui Song
Date: 2020-06-02T11:25:04-07:00
New Revision: 7096e04a6831d4668c39b388ccd166f84de69191

URL: https://github.com/llvm/llvm-project/commit/7096e04a6831d4668c39b388ccd166f84de69191
DIFF: https://github.com/llvm/llvm-project/commit/7096e04a6831d4668c39b388ccd166f84de69191.diff

LOG: [Sema] Use isAlwaysUninit for -Wuninitialized-const-reference after D79895

Added: 
    

Modified: 
    clang/lib/Analysis/UninitializedValues.cpp
    clang/test/SemaCXX/warn-uninitialized-const-reference.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/UninitializedValues.cpp b/clang/lib/Analysis/UninitializedValues.cpp
index facda6ee616e..3d44d1c070fe 100644
--- a/clang/lib/Analysis/UninitializedValues.cpp
+++ b/clang/lib/Analysis/UninitializedValues.cpp
@@ -673,7 +673,7 @@ void TransferFunctions::reportUse(const Expr *ex, const VarDecl *vd) {
 
 void TransferFunctions::reportConstRefUse(const Expr *ex, const VarDecl *vd) {
   Value v = vals[vd];
-  if (isUninitialized(v))
+  if (isAlwaysUninit(v))
     handler.handleConstRefUseOfUninitVariable(vd, getUninitUse(ex, vd, v));
 }
 

diff  --git a/clang/test/SemaCXX/warn-uninitialized-const-reference.cpp b/clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
index de0c124e1a09..292793ba483a 100644
--- a/clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
+++ b/clang/test/SemaCXX/warn-uninitialized-const-reference.cpp
@@ -14,7 +14,7 @@ int const_ref_use(const int &i);
 A const_use_A(const A a);
 int const_use(const int i);
 
-void f() {
+void f(int a) {
   int i;
   const_ref_use(i);             // expected-warning {{variable 'i' is uninitialized when passed as a const reference argument here}}
   int j = j + const_ref_use(j); // expected-warning {{variable 'j' is uninitialized when used within its own initialization}} expected-warning {{variable 'j' is uninitialized when passed as a const reference argument here}}
@@ -28,4 +28,9 @@ void f() {
 
   A a5;
   const_ref_use_A(a5);
+
+  int m;
+  if (a < 42)
+    m = 1;
+  const_ref_use(m);
 }


        


More information about the cfe-commits mailing list