mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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
35 lines
1.1 KiB
C++
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;
|
|
}
|