Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/CodeGen/PatternInit.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- PatternInit.cpp - Pattern Initialization -------------------------===//
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
#include "PatternInit.h"
10
#include "CodeGenModule.h"
11
#include "llvm/IR/Constant.h"
12
#include "llvm/IR/Type.h"
13
14
llvm::Constant *clang::CodeGen::initializationPatternFor(CodeGenModule &CGM,
15
1.31k
                                                         llvm::Type *Ty) {
16
1.31k
  // The following value is a guaranteed unmappable pointer value and has a
17
1.31k
  // repeated byte-pattern which makes it easier to synthesize. We use it for
18
1.31k
  // pointers as well as integers so that aggregates are likely to be
19
1.31k
  // initialized with this repeated value.
20
1.31k
  // For 32-bit platforms it's a bit trickier because, across systems, only the
21
1.31k
  // zero page can reasonably be expected to be unmapped. We use max 0xFFFFFFFF
22
1.31k
  // assuming that memory access will overlap into zero page.
23
1.31k
  const uint64_t IntValue =
24
1.31k
      CGM.getContext().getTargetInfo().getMaxPointerWidth() < 64
25
1.31k
          ? 
0xFFFFFFFFFFFFFFFFull324
26
1.31k
          : 
0xAAAAAAAAAAAAAAAAull993
;
27
1.31k
  // Floating-point values are initialized as NaNs because they propagate. Using
28
1.31k
  // a repeated byte pattern means that it will be easier to initialize
29
1.31k
  // all-floating-point aggregates and arrays with memset. Further, aggregates
30
1.31k
  // which mix integral and a few floats might also initialize with memset
31
1.31k
  // followed by a handful of stores for the floats. Using fairly unique NaNs
32
1.31k
  // also means they'll be easier to distinguish in a crash.
33
1.31k
  constexpr bool NegativeNaN = true;
34
1.31k
  constexpr uint64_t NaNPayload = 0xFFFFFFFFFFFFFFFFull;
35
1.31k
  if (Ty->isIntOrIntVectorTy()) {
36
686
    unsigned BitWidth = cast<llvm::IntegerType>(
37
686
                            Ty->isVectorTy() ? 
Ty->getVectorElementType()24
:
Ty662
)
38
686
                            ->getBitWidth();
39
686
    if (BitWidth <= 64)
40
674
      return llvm::ConstantInt::get(Ty, IntValue);
41
12
    return llvm::ConstantInt::get(
42
12
        Ty, llvm::APInt::getSplat(BitWidth, llvm::APInt(64, IntValue)));
43
12
  }
44
631
  if (Ty->isPtrOrPtrVectorTy()) {
45
79
    auto *PtrTy = cast<llvm::PointerType>(
46
79
        Ty->isVectorTy() ? 
Ty->getVectorElementType()0
: Ty);
47
79
    unsigned PtrWidth = CGM.getContext().getTargetInfo().getPointerWidth(
48
79
        PtrTy->getAddressSpace());
49
79
    if (PtrWidth > 64)
50
79
      
llvm_unreachable0
("pattern initialization of unsupported pointer width");
51
79
    llvm::Type *IntTy = llvm::IntegerType::get(CGM.getLLVMContext(), PtrWidth);
52
79
    auto *Int = llvm::ConstantInt::get(IntTy, IntValue);
53
79
    return llvm::ConstantExpr::getIntToPtr(Int, PtrTy);
54
552
  }
55
552
  if (Ty->isFPOrFPVectorTy()) {
56
117
    unsigned BitWidth = llvm::APFloat::semanticsSizeInBits(
57
117
        (Ty->isVectorTy() ? 
Ty->getVectorElementType()24
:
Ty93
)
58
117
            ->getFltSemantics());
59
117
    llvm::APInt Payload(64, NaNPayload);
60
117
    if (BitWidth >= 64)
61
60
      Payload = llvm::APInt::getSplat(BitWidth, Payload);
62
117
    return llvm::ConstantFP::getQNaN(Ty, NegativeNaN, &Payload);
63
117
  }
64
435
  if (Ty->isArrayTy()) {
65
174
    // Note: this doesn't touch tail padding (at the end of an object, before
66
174
    // the next array object). It is instead handled by replaceUndef.
67
174
    auto *ArrTy = cast<llvm::ArrayType>(Ty);
68
174
    llvm::SmallVector<llvm::Constant *, 8> Element(
69
174
        ArrTy->getNumElements(),
70
174
        initializationPatternFor(CGM, ArrTy->getElementType()));
71
174
    return llvm::ConstantArray::get(ArrTy, Element);
72
174
  }
73
261
74
261
  // Note: this doesn't touch struct padding. It will initialize as much union
75
261
  // padding as is required for the largest type in the union. Padding is
76
261
  // instead handled by replaceUndef. Stores to structs with volatile members
77
261
  // don't have a volatile qualifier when initialized according to C++. This is
78
261
  // fine because stack-based volatiles don't really have volatile semantics
79
261
  // anyways, and the initialization shouldn't be observable.
80
261
  auto *StructTy = cast<llvm::StructType>(Ty);
81
261
  llvm::SmallVector<llvm::Constant *, 8> Struct(StructTy->getNumElements());
82
776
  for (unsigned El = 0; El != Struct.size(); 
++El515
)
83
515
    Struct[El] = initializationPatternFor(CGM, StructTy->getElementType(El));
84
261
  return llvm::ConstantStruct::get(StructTy, Struct);
85
261
}