Skip to content

Commit 8a00fa7

Browse files
committed
Assert struct constant values matches struct member count
1 parent 4c3ed2b commit 8a00fa7

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Sources/LLVM/StructType.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ public struct StructType: IRType {
5757
/// Creates a constant value of this structure type initialized with the given
5858
/// list of values.
5959
///
60+
/// - precondition: values.count == aggregate.elementCount
6061
/// - parameter values: A list of values of members of this structure.
6162
///
6263
/// - returns: A value representing a constant value of this structure type.
6364
public func constant(values: [IRValue]) -> Constant<Struct> {
65+
assert(numericCast(values.count) == LLVMCountStructElementTypes(llvm), "The number of values must match the number of elements in the aggregate")
6466
var vals = values.map { $0.asLLVM() as Optional }
6567
return vals.withUnsafeMutableBufferPointer { buf in
6668
return Constant(llvm: LLVMConstNamedStruct(asLLVM(),

0 commit comments

Comments
 (0)