Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9d1aeae

Browse files
committedMay 29, 2022
Auto merge of rust-lang#94214 - nikic:rust-opaque-pointers, r=cuviper
Prepare Rust for opaque pointers Fix one codegen bug with opaque pointers, and update our IR tests to accept both typed pointer and opaque pointer IR. This is a bit annoying, but unavoidable if we want decent test coverage on both LLVM 14 and LLVM 15. This prepares Rust for when LLVM will enable opaque pointers by default.
2 parents abc7681 + 1ff051a commit 9d1aeae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+265
-289
lines changed
 

‎compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,20 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
509509
OperandValue::Ref(place.llval, Some(llextra), place.align)
510510
} else if place.layout.is_llvm_immediate() {
511511
let mut const_llval = None;
512+
let llty = place.layout.llvm_type(self);
512513
unsafe {
513514
if let Some(global) = llvm::LLVMIsAGlobalVariable(place.llval) {
514515
if llvm::LLVMIsGlobalConstant(global) == llvm::True {
515-
const_llval = llvm::LLVMGetInitializer(global);
516+
if let Some(init) = llvm::LLVMGetInitializer(global) {
517+
if self.val_ty(init) == llty {
518+
const_llval = Some(init);
519+
}
520+
}
516521
}
517522
}
518523
}
519524
let llval = const_llval.unwrap_or_else(|| {
520-
let load = self.load(place.layout.llvm_type(self), place.llval, place.align);
525+
let load = self.load(llty, place.llval, place.align);
521526
if let abi::Abi::Scalar(scalar) = place.layout.abi {
522527
scalar_load_metadata(self, load, scalar, place.layout, Size::ZERO);
523528
}

‎compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ impl CodegenBackend for LlvmCodegenBackend {
304304
local stack variable in the ABI.)
305305
306306
basic
307-
Generate stack canaries in functions with:
308-
- local variables of `[T; N]` type, where `T` is byte-sized and `N` > 8.
307+
Generate stack canaries in functions with local variables of `[T; N]`
308+
type, where `T` is byte-sized and `N` >= 8.
309309
310310
none
311311
Do not generate stack canaries.

0 commit comments

Comments
 (0)