[PATCH] D17983: Eliminate many benign instances of "potentially uninitialized local variable" warnings

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 9 04:21:47 PST 2016


dsanders added a comment.

Thanks for working on this.


================
Comment at: llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp:2715-2718
@@ -2714,3 +2714,6 @@
 
-  unsigned TrgReg;
+  // TrgReg should never normally be assigned NUM_TARGET_REGS.
+  // If you end up with NUM_TARGET_REGS, you have a bug.
+  // FIXME: is there a better way to ensure TrgReg is assigned something?
+  unsigned TrgReg = Mips::NUM_TARGET_REGS;
   if (TrgOp.isReg())
----------------
I think this should be Mips::NoRegister.

================
Comment at: llvm/lib/Target/Mips/MipsAsmPrinter.cpp:889-938
@@ -888,48 +888,52 @@
   OutStreamer->EmitSymbolAttribute(MSymbol, MCSA_Global);
-  const char *RetType;
+  const char *RetType = "";
   //
   // make the comment field identifying the return and parameter
   // types of the floating point stub
   // # Stub function to call rettype xxxx (params)
   //
   switch (Signature->RetSig) {
   case FRet:
     RetType = "float";
     break;
   case DRet:
     RetType = "double";
     break;
   case CFRet:
     RetType = "complex";
     break;
   case CDRet:
     RetType = "double complex";
     break;
   case NoFPRet:
     RetType = "";
     break;
+  default:
+    llvm_unreachable("Unexpected FPReturnVariant!");
   }
-  const char *Parms;
+  const char *Parms = "";
   switch (Signature->ParamSig) {
   case FSig:
     Parms = "float";
     break;
   case FFSig:
     Parms = "float, float";
     break;
   case FDSig:
     Parms = "float, double";
     break;
   case DSig:
     Parms = "double";
     break;
   case DDSig:
     Parms = "double, double";
     break;
   case DFSig:
     Parms = "double, float";
     break;
   case NoSig:
     Parms = "";
     break;
+  default:
+    llvm_unreachable("Unexpected FPParamVariant!");
   }
----------------
These two are false positives since all the enum values are covered.

The default labels cause warnings when clang is the compiler:
  lib/Target/Mips/MipsAsmPrinter.cpp:911:3: warning: default label in switch which covers all enumeration values [-Wcovered-switch-default]
which will cause -Werror builders to fail.

I'd suggest dropping the default labels to avoid the clang warning, but keeping the initializations to keep your compiler happy.


http://reviews.llvm.org/D17983





More information about the llvm-commits mailing list