about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2021-08-05 11:06:32 -0700
committerJosh Stone <jistone@redhat.com>2021-08-05 11:06:32 -0700
commita29239085455964176ab0ad59b097da725813f6f (patch)
tree2108e3c4118e4eccbeeceb57ca9ce303a6e1bc2f /compiler/rustc_codegen_llvm/src
parent41f27d903a2f6e81fbd082235fbdaacc0d356d1e (diff)
downloadrust-a29239085455964176ab0ad59b097da725813f6f.tar.gz
rust-a29239085455964176ab0ad59b097da725813f6f.zip
Only allow LLVM element_type on Array and Vector
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/type_.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/type_.rs b/compiler/rustc_codegen_llvm/src/type_.rs
index 69787df5e07..52ae56b89b3 100644
--- a/compiler/rustc_codegen_llvm/src/type_.rs
+++ b/compiler/rustc_codegen_llvm/src/type_.rs
@@ -203,7 +203,11 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
     }
 
     fn element_type(&self, ty: &'ll Type) -> &'ll Type {
-        unsafe { llvm::LLVMGetElementType(ty) }
+        match self.type_kind(ty) {
+            TypeKind::Array | TypeKind::Vector => unsafe { llvm::LLVMGetElementType(ty) },
+            TypeKind::Pointer => bug!("element_type is not supported for opaque pointers"),
+            other => bug!("element_type called on unsupported type {:?}", other),
+        }
     }
 
     fn vector_length(&self, ty: &'ll Type) -> usize {