Files
swift-mirror/lib/SIL/SILUndef.cpp
Michael Gottesman c9bb5161a1 [ownership] Change SILUndef to return Any ownership for trivial values and owned for non-trivial values.
This is in preparation for verifying that when ownership verification is enabled
that only enums and trivial values can have any ownership. I am doing this in
preparation for eliminating ValueOwnershipKind::Trivial.

rdar://46294760
2018-11-27 17:31:08 -08:00

35 lines
1.1 KiB
C++

//===--- SILUndef.cpp -----------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/SIL/SILUndef.h"
#include "swift/SIL/SILModule.h"
using namespace swift;
static ValueOwnershipKind getOwnershipKindForUndef(SILType type, SILModule &m) {
if (type.isTrivial(m))
return ValueOwnershipKind::Trivial;
return ValueOwnershipKind::Owned;
}
SILUndef::SILUndef(SILType type, SILModule &m)
: ValueBase(ValueKind::SILUndef, type, IsRepresentative::Yes),
ownershipKind(getOwnershipKindForUndef(type, m)) {}
SILUndef *SILUndef::get(SILType ty, SILModule &m) {
// Unique these.
SILUndef *&entry = m.UndefValues[ty];
if (entry == nullptr)
entry = new (m) SILUndef(ty, m);
return entry;
}