Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/APSInt.cpp
Line
Count
Source
1
//===-- llvm/ADT/APSInt.cpp - Arbitrary Precision Signed Int ---*- C++ -*--===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements the APSInt class, which is a simple class that
10
// represents an arbitrary sized integer that knows its signedness.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "llvm/ADT/APSInt.h"
15
#include "llvm/ADT/FoldingSet.h"
16
#include "llvm/ADT/StringRef.h"
17
18
using namespace llvm;
19
20
4.27M
APSInt::APSInt(StringRef Str) {
21
4.27M
  assert(!Str.empty() && "Invalid string length");
22
4.27M
23
4.27M
  // (Over-)estimate the required number of bits.
24
4.27M
  unsigned NumBits = ((Str.size() * 64) / 19) + 2;
25
4.27M
  APInt Tmp(NumBits, Str, /*radix=*/10);
26
4.27M
  if (Str[0] == '-') {
27
92.7k
    unsigned MinBits = Tmp.getMinSignedBits();
28
92.7k
    if (MinBits > 0 && MinBits < NumBits)
29
92.7k
      Tmp = Tmp.trunc(MinBits);
30
92.7k
    *this = APSInt(Tmp, /*isUnsigned=*/false);
31
92.7k
    return;
32
92.7k
  }
33
4.18M
  unsigned ActiveBits = Tmp.getActiveBits();
34
4.18M
  if (ActiveBits > 0 && 
ActiveBits < NumBits3.75M
)
35
3.75M
    Tmp = Tmp.trunc(ActiveBits);
36
4.18M
  *this = APSInt(Tmp, /*isUnsigned=*/true);
37
4.18M
}
38
39
6.04M
void APSInt::Profile(FoldingSetNodeID& ID) const {
40
6.04M
  ID.AddInteger((unsigned) (IsUnsigned ? 
14.27M
:
01.76M
));
41
6.04M
  APInt::Profile(ID);
42
6.04M
}