Silence static analyzer warnings in LLVMSupport.
authorMichael Ilseman <milseman@apple.com>
Thu, 11 Dec 2014 19:46:38 +0000 (19:46 +0000)
committerMichael Ilseman <milseman@apple.com>
Thu, 11 Dec 2014 19:46:38 +0000 (19:46 +0000)
The static analyzer catches a few potential bugs in LLVMSupport. Add
in asserts to silence the warnings.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224044 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/CommandLine.cpp
lib/Support/ScaledNumber.cpp

index 985c8777701509a26c8ad26f7ef8ff1c230ff4c8..7b06219104e4190a77f7b8e9198c1aee8d38590d 100644 (file)
@@ -323,6 +323,7 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName,
       if (i+1 >= argc)
         return Handler->error("requires a value!");
       // Steal the next argument, like for '-o filename'
+      assert(argv && "null check");
       Value = argv[++i];
     }
     break;
@@ -356,6 +357,7 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName,
   while (NumAdditionalVals > 0) {
     if (i+1 >= argc)
       return Handler->error("not enough values!");
+    assert(argv && "null check");
     Value = argv[++i];
 
     if (CommaSeparateAndAddOccurrence(Handler, i, ArgName, Value, MultiArg))
index fc6d4e7be43a5baaaa3667f7029eec72a3f45b7f..725f4649613df64f46837ef3d5f3a03428060122 100644 (file)
@@ -169,6 +169,8 @@ static std::string toStringAPFloat(uint64_t D, int E, unsigned Precision) {
   int Shift = 63 - (NewE - E);
   assert(Shift <= LeadingZeros);
   assert(Shift == LeadingZeros || NewE == ScaledNumbers::MaxScale);
+  assert((Shift & (1u << std::numeric_limits<int>::digits)) == 0 &&
+         "undefined behavior");
   D <<= Shift;
   E = NewE;